Search in sources :

Example 36 with LogData

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

the class StreamLogWithRankedAddressSpaceTest method testProposalWithLowerRankAgainstData.

@Test
public void testProposalWithLowerRankAgainstData() {
    StreamLogFiles log = new StreamLogFiles(getContext(), false);
    long address = 0;
    writeToLog(log, address, DataType.DATA, "v-1", 2);
    LogData value1 = log.read(address);
    assertTrue(new String(value1.getData()).contains("v-1"));
    try {
        writeToLog(log, address, DataType.RANK_ONLY, "v-2", 1);
        fail();
    } catch (DataOutrankedException e) {
    // expected
    }
    LogData value2 = log.read(address);
    assertTrue(new String(value2.getData()).contains("v-1"));
    log.close();
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) DataOutrankedException(org.corfudb.runtime.exceptions.DataOutrankedException) Test(org.junit.Test) AbstractCorfuTest(org.corfudb.AbstractCorfuTest)

Example 37 with LogData

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

the class StreamLogWithRankedAddressSpaceTest method testLowerRank.

@Test
public void testLowerRank() {
    StreamLogFiles log = new StreamLogFiles(getContext(), false);
    long address = 0;
    writeToLog(log, address, DataType.DATA, "v-1", 2);
    LogData value1 = log.read(address);
    assertTrue(new String(value1.getData()).contains("v-1"));
    try {
        writeToLog(log, address, DataType.DATA, "v-2", 1);
        fail();
    } catch (DataOutrankedException e) {
    // expected
    }
    LogData value2 = log.read(address);
    assertTrue(new String(value2.getData()).contains("v-1"));
    log.close();
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) DataOutrankedException(org.corfudb.runtime.exceptions.DataOutrankedException) Test(org.junit.Test) AbstractCorfuTest(org.corfudb.AbstractCorfuTest)

Example 38 with LogData

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

the class StreamLogWithRankedAddressSpaceTest method writeToLog.

private void writeToLog(StreamLog log, long address, DataType dataType, String payload, IMetadata.DataRank rank) {
    ByteBuf b = Unpooled.buffer();
    byte[] streamEntry = payload.getBytes();
    Serializers.CORFU.serialize(streamEntry, b);
    LogData data = new LogData(dataType, b);
    data.setRank(rank);
    log.append(address, data);
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) ByteBuf(io.netty.buffer.ByteBuf)

Example 39 with LogData

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

the class StreamLogWithRankedAddressSpaceTest method testHigherRank.

@Test
public void testHigherRank() {
    StreamLogFiles log = new StreamLogFiles(getContext(), false);
    long address = 0;
    writeToLog(log, address, DataType.DATA, "v-1", 1);
    LogData value1 = log.read(address);
    assertTrue(new String(value1.getData()).contains("v-1"));
    writeToLog(log, address, DataType.DATA, "v-2", 2);
    LogData value2 = log.read(address);
    assertTrue(new String(value2.getData()).contains("v-2"));
    log.close();
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) Test(org.junit.Test) AbstractCorfuTest(org.corfudb.AbstractCorfuTest)

Example 40 with LogData

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

the class StreamLogWithRankedAddressSpaceTest method testProposalWithHigherRankAgainstData.

@Test
public void testProposalWithHigherRankAgainstData() {
    StreamLogFiles log = new StreamLogFiles(getContext(), false);
    long address = 0;
    writeToLog(log, address, DataType.DATA, "v-1", 1);
    LogData value1 = log.read(address);
    assertTrue(new String(value1.getData()).contains("v-1"));
    try {
        writeToLog(log, address, DataType.RANK_ONLY, "v-2", 2);
        fail();
    } catch (ValueAdoptedException e) {
        LogData logData = e.getReadResponse().getReadSet().get(0l);
        assertTrue(new String(logData.getData()).contains("v-1"));
    }
    LogData value2 = log.read(address);
    assertTrue(new String(value2.getData()).contains("v-1"));
    log.close();
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) ValueAdoptedException(org.corfudb.runtime.exceptions.ValueAdoptedException) 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