Search in sources :

Example 31 with LogData

use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.

the class StreamLogFilesTest method testOverwriteException.

@Test
public void testOverwriteException() {
    StreamLog log = new StreamLogFiles(getContext(), false);
    ByteBuf b = Unpooled.buffer();
    byte[] streamEntry = "Payload".getBytes();
    Serializers.CORFU.serialize(streamEntry, b);
    long address0 = 0;
    log.append(address0, new LogData(DataType.DATA, b));
    assertThatThrownBy(() -> log.append(address0, new LogData(DataType.DATA, b))).isInstanceOf(OverwriteException.class);
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test) AbstractCorfuTest(org.corfudb.AbstractCorfuTest)

Example 32 with LogData

use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.

the class StreamLogFilesTest method testReadingUnknownAddress.

@Test
public void testReadingUnknownAddress() {
    StreamLog log = new StreamLogFiles(getContext(), false);
    ByteBuf b = Unpooled.buffer();
    byte[] streamEntry = "Payload".getBytes();
    Serializers.CORFU.serialize(streamEntry, b);
    long address0 = 0;
    long address1 = 1;
    long address2 = 2;
    log.append(address0, new LogData(DataType.DATA, b));
    log.append(address2, new LogData(DataType.DATA, b));
    assertThat(log.read(address1)).isNull();
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test) AbstractCorfuTest(org.corfudb.AbstractCorfuTest)

Example 33 with LogData

use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.

the class StreamLogFilesTest method writeToLog.

private void writeToLog(StreamLog log, long address) {
    ByteBuf b = Unpooled.buffer();
    byte[] streamEntry = "Payload".getBytes();
    Serializers.CORFU.serialize(streamEntry, b);
    log.append(address, new LogData(DataType.DATA, b));
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) ByteBuf(io.netty.buffer.ByteBuf)

Example 34 with LogData

use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.

the class StreamLogFilesTest method multiThreadedReadWrite.

@Test
public void multiThreadedReadWrite() throws Exception {
    String logDir = getDirPath();
    StreamLog log = new StreamLogFiles(getContext(), false);
    ByteBuf b = Unpooled.buffer();
    byte[] streamEntry = "Payload".getBytes();
    Serializers.CORFU.serialize(streamEntry, b);
    final int num_threads = PARAMETERS.CONCURRENCY_SOME;
    final int num_entries = PARAMETERS.NUM_ITERATIONS_LOW;
    scheduleConcurrently(num_threads, threadNumber -> {
        int base = threadNumber * num_entries;
        for (int i = base; i < base + num_entries; i++) {
            long address = (long) i;
            log.append(address, new LogData(DataType.DATA, b));
        }
    });
    executeScheduled(num_threads, PARAMETERS.TIMEOUT_LONG);
    // verify that addresses 0 to 2000 have been used up
    for (int x = 0; x < num_entries * num_threads; x++) {
        long address = (long) x;
        LogData data = log.read(address);
        byte[] bytes = (byte[]) data.getPayload(null);
        assertThat(bytes).isEqualTo(streamEntry);
    }
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test) AbstractCorfuTest(org.corfudb.AbstractCorfuTest)

Example 35 with LogData

use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.

the class StreamLogFilesTest method testSync.

@Test
@SuppressWarnings("checkstyle:magicnumber")
public void testSync() throws Exception {
    StreamLogFiles log = new StreamLogFiles(getContext(), false);
    ByteBuf b = Unpooled.buffer();
    byte[] streamEntry = "Payload".getBytes();
    Serializers.CORFU.serialize(streamEntry, b);
    long seg1 = StreamLogFiles.RECORDS_PER_LOG_FILE * 0 + 1;
    long seg2 = StreamLogFiles.RECORDS_PER_LOG_FILE * 1 + 1;
    long seg3 = StreamLogFiles.RECORDS_PER_LOG_FILE * 2 + 1;
    log.append(seg1, new LogData(DataType.DATA, b));
    log.append(seg2, new LogData(DataType.DATA, b));
    log.append(seg3, new LogData(DataType.DATA, b));
    assertThat(log.getChannelsToSync().size()).isEqualTo(3);
    log.sync(true);
    assertThat(log.getChannelsToSync().size()).isEqualTo(0);
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test) AbstractCorfuTest(org.corfudb.AbstractCorfuTest)

Aggregations

LogData (org.corfudb.protocols.wireprotocol.LogData)45 Test (org.junit.Test)32 ILogData (org.corfudb.protocols.wireprotocol.ILogData)21 AbstractCorfuTest (org.corfudb.AbstractCorfuTest)18 ByteBuf (io.netty.buffer.ByteBuf)15 CorfuRuntime (org.corfudb.runtime.CorfuRuntime)9 UUID (java.util.UUID)8 DataOutrankedException (org.corfudb.runtime.exceptions.DataOutrankedException)8 ExecutionException (java.util.concurrent.ExecutionException)5 ReadResponse (org.corfudb.protocols.wireprotocol.ReadResponse)5 IMetadata (org.corfudb.protocols.wireprotocol.IMetadata)4 ValueAdoptedException (org.corfudb.runtime.exceptions.ValueAdoptedException)4 Layout (org.corfudb.runtime.view.Layout)4 LogUnitServer (org.corfudb.infrastructure.LogUnitServer)3 AbstractViewTest (org.corfudb.runtime.view.AbstractViewTest)3 File (java.io.File)2 LogUnitClient (org.corfudb.runtime.clients.LogUnitClient)2 OverwriteException (org.corfudb.runtime.exceptions.OverwriteException)2 QuorumUnreachableException (org.corfudb.runtime.exceptions.QuorumUnreachableException)2 QuorumFuturesFactory (org.corfudb.runtime.view.QuorumFuturesFactory)2