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");
}
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);
}
Aggregations