<commit_before>package org.mitallast.queue.queue.service.translog;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mitallast.queue.common.UUIDs;
import org.mitallast.queue.queue.QueueMessage;
import org.mitallast.queue.queue.service.BaseQueueMessageTest;

import java.io.File;
import java.io.IOException;

public class FileQueueMessageAppendTransactionLogTest extends BaseQueueMessageTest {

    private File metaFile;
    private File dataFile;
    private FileQueueMessageAppendTransactionLog transactionLog;

    @Override
    @Before
    public void setUp() throws Exception {
        super.setUp();
        metaFile = folder.newFile();
        dataFile = folder.newFile();
        transactionLog = new FileQueueMessageAppendTransactionLog(metaFile, dataFile);
        transactionLog.initializeNew();
    }

    @Override
    @After
    public void tearDown() throws Exception {
        super.tearDown();
        transactionLog.close();
    }

    @Test
    public void testPutAndRead() throws IOException {
        QueueMessage newMessage = createMessageWithUuid();
        int pos = transactionLog.putMessage(newMessage);
        assert pos == 0;
        QueueMessage savedMessage = transactionLog.readMessage(newMessage.getUuid());
        assert newMessage.equals(savedMessage) : newMessage + " != " + savedMessage;
    }

    @Test
    public void testPutDeleteAndRead() throws IOException {
        QueueMessage newMessage = createMessageWithUuid();
        transactionLog.putMessage(newMessage);
        transactionLog.markMessageDeleted(newMessage.getUuid());
        QueueMessage savedMessage = transactionLog.readMessage(newMessage.getUuid());
        assert savedMessage == null;
    }

    @Test
    public void testInitializeExists() throws IOException {
        QueueMessage newMessage = createMessageWithUuid();
        transactionLog.putMessage(newMessage);

        try (FileQueueMessageAppendTransactionLog transactionLogExists =
                     new FileQueueMessageAppendTransactionLog(metaFile, dataFile)) {
            transactionLogExists.initializeExists();
            QueueMessage existsMessage = transactionLogExists.readMessage(newMessage.getUuid());
            assert existsMessage != null;
            assert newMessage.equals(existsMessage);
        }
    }

    @Test
    public void testMeta() throws IOException {
        FileQueueMessageAppendTransactionLog.QueueMessageMeta messageMeta =
                new FileQueueMessageAppendTransactionLog.QueueMessageMeta(UUIDs.generateRandom(), 13, 2314, 2341324, 0);
        transactionLog.writeMeta(messageMeta, 0l);
        FileQueueMessageAppendTransactionLog.QueueMessageMeta messageMetaActual = transactionLog.readMeta(0l);
        assert messageMeta.equals(messageMetaActual);
    }
}<commit_msg>add asset message<commit_after>package org.mitallast.queue.queue.service.translog;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mitallast.queue.common.UUIDs;
import org.mitallast.queue.queue.QueueMessage;
import org.mitallast.queue.queue.service.BaseQueueMessageTest;

import java.io.File;
import java.io.IOException;

public class FileQueueMessageAppendTransactionLogTest extends BaseQueueMessageTest {

    private File metaFile;
    private File dataFile;
    private FileQueueMessageAppendTransactionLog transactionLog;

    @Override
    @Before
    public void setUp() throws Exception {
        super.setUp();
        metaFile = folder.newFile();
        dataFile = folder.newFile();
        transactionLog = new FileQueueMessageAppendTransactionLog(metaFile, dataFile);
        transactionLog.initializeNew();
    }

    @Override
    @After
    public void tearDown() throws Exception {
        super.tearDown();
        transactionLog.close();
    }

    @Test
    public void testPutAndRead() throws IOException {
        QueueMessage newMessage = createMessageWithUuid();
        int pos = transactionLog.putMessage(newMessage);
        assert pos == 0;
        QueueMessage savedMessage = transactionLog.readMessage(newMessage.getUuid());
        assert newMessage.equals(savedMessage) : newMessage + " != " + savedMessage;
    }

    @Test
    public void testPutDeleteAndRead() throws IOException {
        QueueMessage newMessage = createMessageWithUuid();
        transactionLog.putMessage(newMessage);
        transactionLog.markMessageDeleted(newMessage.getUuid());
        QueueMessage savedMessage = transactionLog.readMessage(newMessage.getUuid());
        assert savedMessage == null;
    }

    @Test
    public void testInitializeExists() throws IOException {
        QueueMessage newMessage = createMessageWithUuid();
        transactionLog.putMessage(newMessage);

        try (FileQueueMessageAppendTransactionLog transactionLogExists =
                     new FileQueueMessageAppendTransactionLog(metaFile, dataFile)) {
            transactionLogExists.initializeExists();
            QueueMessage existsMessage = transactionLogExists.readMessage(newMessage.getUuid());
            assert existsMessage != null;
            assert newMessage.equals(existsMessage);
        }
    }

    @Test
    public void testMeta() throws IOException {
        FileQueueMessageAppendTransactionLog.QueueMessageMeta messageMeta =
                new FileQueueMessageAppendTransactionLog.QueueMessageMeta(UUIDs.generateRandom(), 13, 2314, 2341324, 0);
        transactionLog.writeMeta(messageMeta, 0l);
        FileQueueMessageAppendTransactionLog.QueueMessageMeta messageMetaActual = transactionLog.readMeta(0l);
        assert messageMeta.equals(messageMetaActual) : "\n" + messageMeta + " != \n" + messageMetaActual;
    }
}
{'fraction_non_alphanumeric': 0.08201892744479496, 'fraction_numerical': 0.005958640028040659, 'mean_word_length': 3.5257731958762886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3442315', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1418, 'n_words': 292}