Search in sources :

Example 21 with LogData

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

the class LogUnitClientTest method backpointersCanBeWrittenAndRead.

@Test
public void backpointersCanBeWrittenAndRead() throws Exception {
    final long ADDRESS_0 = 1337L;
    final long ADDRESS_1 = 1338L;
    byte[] testString = "hello world".getBytes();
    client.write(0, Collections.<UUID>emptySet(), null, testString, ImmutableMap.<UUID, Long>builder().put(CorfuRuntime.getStreamID("hello"), ADDRESS_0).put(CorfuRuntime.getStreamID("hello2"), ADDRESS_1).build()).get();
    LogData r = client.read(0).get().getReadSet().get(0L);
    assertThat(r.getBackpointerMap()).containsEntry(CorfuRuntime.getStreamID("hello"), ADDRESS_0);
    assertThat(r.getBackpointerMap()).containsEntry(CorfuRuntime.getStreamID("hello2"), ADDRESS_1);
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) UUID(java.util.UUID) Test(org.junit.Test)

Example 22 with LogData

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

the class LogUnitClientTest method holeFillCannotBeOverwritten.

@Test
public void holeFillCannotBeOverwritten() throws Exception {
    byte[] testString = "hello world".getBytes();
    client.fillHole(0).get();
    LogData r = client.read(0).get().getReadSet().get(0L);
    assertThat(r.getType()).isEqualTo(DataType.HOLE);
    assertThatThrownBy(() -> client.write(0, Collections.<UUID>emptySet(), null, testString, Collections.emptyMap()).get()).isInstanceOf(ExecutionException.class).hasCauseInstanceOf(OverwriteException.class);
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 23 with LogData

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

the class LogUnitClientTest method canReadWrite.

@Test
public void canReadWrite() throws Exception {
    byte[] testString = "hello world".getBytes();
    client.write(0, Collections.<UUID>emptySet(), null, 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);
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) UUID(java.util.UUID) Test(org.junit.Test)

Example 24 with LogData

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

the class LogUnitClientTest method cannotOutrank.

@Test
public void cannotOutrank() throws ExecutionException, InterruptedException {
    byte[] testString = "hello world".getBytes();
    client.write(0, Collections.<UUID>emptySet(), new IMetadata.DataRank(2), 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);
    byte[] testString2 = "hello world 2".getBytes();
    try {
        client.write(0, Collections.<UUID>emptySet(), new IMetadata.DataRank(1), testString2, Collections.emptyMap()).get();
        fail();
    } catch (ExecutionException e) {
        // expected
        assertEquals(DataOutrankedException.class, e.getCause().getClass());
    }
    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) LogData(org.corfudb.protocols.wireprotocol.LogData) DataOutrankedException(org.corfudb.runtime.exceptions.DataOutrankedException) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 25 with LogData

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

the class LogUnitClientTest method holeFillCannotOverwrite.

@Test
public void holeFillCannotOverwrite() throws Exception {
    byte[] testString = "hello world".getBytes();
    client.write(0, Collections.<UUID>emptySet(), null, testString, Collections.emptyMap()).get();
    LogData r = client.read(0).get().getReadSet().get(0L);
    assertThat(r.getType()).isEqualTo(DataType.DATA);
    assertThatThrownBy(() -> client.fillHole(0).get()).isInstanceOf(ExecutionException.class).hasCauseInstanceOf(OverwriteException.class);
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) 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