Search in sources :

Example 26 with ILogData

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

the class WriteAfterWriteTransactionContextTest method concurrentModificationsCauseAbort.

@Test
public void concurrentModificationsCauseAbort() {
    getRuntime().setTransactionLogging(true);
    getMap();
    t(1, () -> write("k", "v1"));
    t(1, this::WWTXBegin);
    t(2, this::WWTXBegin);
    t(1, () -> get("k"));
    t(2, () -> get("k"));
    t(1, () -> write("k", "v2"));
    t(2, () -> write("k", "v3"));
    t(1, this::TXEnd);
    t(2, this::TXEnd).assertThrows().isInstanceOf(TransactionAbortedException.class);
    assertThat(getMap()).containsEntry("k", "v2").doesNotContainEntry("k", "v3");
    IStreamView txStream = getRuntime().getStreamsView().get(ObjectsView.TRANSACTION_STREAM_ID);
    List<ILogData> txns = txStream.remainingUpTo(Long.MAX_VALUE);
    assertThat(txns).hasSize(1);
    assertThat(txns.get(0).getLogEntry(getRuntime()).getType()).isEqualTo(LogEntry.LogEntryType.MULTIOBJSMR);
    MultiObjectSMREntry tx1 = (MultiObjectSMREntry) txns.get(0).getLogEntry(getRuntime());
    assertThat(tx1.getEntryMap().size()).isEqualTo(1);
    MultiSMREntry entryMap = tx1.getEntryMap().entrySet().iterator().next().getValue();
    assertThat(entryMap).isNotNull();
    assertThat(entryMap.getUpdates().size()).isEqualTo(1);
    SMREntry smrEntry = entryMap.getUpdates().get(0);
    Object[] args = smrEntry.getSMRArguments();
    assertThat(smrEntry.getSMRMethod()).isEqualTo("put");
    assertThat((String) args[0]).isEqualTo("k");
    assertThat((String) args[1]).isEqualTo("v2");
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) MultiSMREntry(org.corfudb.protocols.logprotocol.MultiSMREntry) SMREntry(org.corfudb.protocols.logprotocol.SMREntry) MultiObjectSMREntry(org.corfudb.protocols.logprotocol.MultiObjectSMREntry) MultiObjectSMREntry(org.corfudb.protocols.logprotocol.MultiObjectSMREntry) IStreamView(org.corfudb.runtime.view.stream.IStreamView) MultiSMREntry(org.corfudb.protocols.logprotocol.MultiSMREntry) Test(org.junit.Test)

Example 27 with ILogData

use of org.corfudb.protocols.wireprotocol.ILogData 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

ILogData (org.corfudb.protocols.wireprotocol.ILogData)27 LogData (org.corfudb.protocols.wireprotocol.LogData)9 Test (org.junit.Test)9 CorfuRuntime (org.corfudb.runtime.CorfuRuntime)8 Layout (org.corfudb.runtime.view.Layout)4 UUID (java.util.UUID)3 Nonnull (javax.annotation.Nonnull)3 SMREntry (org.corfudb.protocols.logprotocol.SMREntry)3 ReadResponse (org.corfudb.protocols.wireprotocol.ReadResponse)3 OverwriteException (org.corfudb.runtime.exceptions.OverwriteException)3 QuorumUnreachableException (org.corfudb.runtime.exceptions.QuorumUnreachableException)3 AbstractViewTest (org.corfudb.runtime.view.AbstractViewTest)3 QuorumFuturesFactory (org.corfudb.runtime.view.QuorumFuturesFactory)3 IStreamView (org.corfudb.runtime.view.stream.IStreamView)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 MultiObjectSMREntry (org.corfudb.protocols.logprotocol.MultiObjectSMREntry)2 MultiSMREntry (org.corfudb.protocols.logprotocol.MultiSMREntry)2 IMetadata (org.corfudb.protocols.wireprotocol.IMetadata)2 LogUnitClient (org.corfudb.runtime.clients.LogUnitClient)2 DataOutrankedException (org.corfudb.runtime.exceptions.DataOutrankedException)2