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