Search in sources :

Example 41 with LogData

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

the class StreamLogWithRankedAddressSpaceTest method testHigherRankAgainstProposal.

@Test
public void testHigherRankAgainstProposal() {
    StreamLogFiles log = new StreamLogFiles(getContext(), false);
    long address = 0;
    writeToLog(log, address, DataType.RANK_ONLY, "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 42 with LogData

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

the class AbstractReplicationProtocolTest method overwriteThrowsException.

/** Check to make sure that overwriting a previously
     * written entry results in an OverwriteException.
     */
@Test
@SuppressWarnings("unchecked")
public void overwriteThrowsException() throws Exception {
    setupNodes();
    //begin tests
    final CorfuRuntime r = getDefaultRuntime();
    final IReplicationProtocol rp = getProtocol();
    final Layout layout = r.getLayoutView().getLayout();
    LogData d1 = getLogData(0, "1".getBytes());
    LogData d2 = getLogData(0, "2".getBytes());
    rp.write(layout, d1);
    assertThatThrownBy(() -> rp.write(layout, d2)).isInstanceOf(OverwriteException.class);
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) Layout(org.corfudb.runtime.view.Layout) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test) AbstractViewTest(org.corfudb.runtime.view.AbstractViewTest)

Example 43 with LogData

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

the class AbstractReplicationProtocolTest method getLogData.

LogData getLogData(long globalAddress, byte[] payload) {
    ByteBuf b = Unpooled.buffer();
    Serializers.CORFU.serialize(payload, b);
    LogData d = new LogData(DataType.DATA, b);
    d.setGlobalAddress(globalAddress);
    return d;
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) ByteBuf(io.netty.buffer.ByteBuf)

Example 44 with LogData

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

the class ChainReplicationProtocolTest method failedWriteIsPropagated.

/** Check to see that a writer correctly
     * completes a failed write from another client.
     */
@Test
public void failedWriteIsPropagated() throws Exception {
    setupNodes();
    //begin tests
    final CorfuRuntime r = getDefaultRuntime();
    final IReplicationProtocol rp = getProtocol();
    final Layout layout = r.getLayoutView().getLayout();
    LogData failedWrite = getLogData(0, "failed".getBytes());
    LogData incompleteWrite = getLogData(0, "incomplete".getBytes());
    // Write the incomplete write to the head of the chain
    r.getRouter(SERVERS.ENDPOINT_0).getClient(LogUnitClient.class).write(incompleteWrite);
    // Attempt to write using the replication protocol.
    // Should result in an overwrite exception
    assertThatThrownBy(() -> rp.write(layout, failedWrite)).isInstanceOf(OverwriteException.class);
    // At this point, a direct read of the tail should
    // reflect the -other- clients value
    ILogData readResult = r.getRouter(SERVERS.ENDPOINT_0).getClient(LogUnitClient.class).read(0).get().getReadSet().get(0L);
    assertThat(readResult.getPayload(r)).isEqualTo("incomplete".getBytes());
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) LogUnitClient(org.corfudb.runtime.clients.LogUnitClient) Layout(org.corfudb.runtime.view.Layout) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test)

Example 45 with LogData

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

the class LogUnitClientTest method valueCanBeAdopted.

@Test
public void valueCanBeAdopted() throws ExecutionException, InterruptedException {
    byte[] testString = "hello world".getBytes();
    client.write(0, Collections.<UUID>emptySet(), new IMetadata.DataRank(1), testString, Collections.emptyMap()).get();
    LogData r = client.read(0).get().getReadSet().get(0L);
    assertThat(r.getType()).isEqualTo(DataType.DATA);
    assertThat(r.getPayload(new CorfuRuntime())).isEqualTo(testString);
    try {
        ILogData data = createEmptyData(0, DataType.RANK_ONLY, new IMetadata.DataRank(2)).getSerialized();
        client.write(data).get();
        fail();
    } catch (Exception e) {
        // expected
        assertEquals(ValueAdoptedException.class, e.getCause().getClass());
        ValueAdoptedException ex = (ValueAdoptedException) e.getCause();
        ReadResponse read = ex.getReadResponse();
        LogData log = read.getReadSet().get(0l);
        assertThat(log.getType()).isEqualTo(DataType.DATA);
        assertThat(log.getPayload(new CorfuRuntime())).isEqualTo(testString);
        ;
    }
    r = client.read(0).get().getReadSet().get(0L);
    assertThat(r.getType()).isEqualTo(DataType.DATA);
    assertThat(r.getPayload(new CorfuRuntime())).isEqualTo(testString);
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) ReadResponse(org.corfudb.protocols.wireprotocol.ReadResponse) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) UUID(java.util.UUID) DataCorruptionException(org.corfudb.runtime.exceptions.DataCorruptionException) OverwriteException(org.corfudb.runtime.exceptions.OverwriteException) TrimmedException(org.corfudb.runtime.exceptions.TrimmedException) DataOutrankedException(org.corfudb.runtime.exceptions.DataOutrankedException) ValueAdoptedException(org.corfudb.runtime.exceptions.ValueAdoptedException) ExecutionException(java.util.concurrent.ExecutionException) ValueAdoptedException(org.corfudb.runtime.exceptions.ValueAdoptedException) Test(org.junit.Test)

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