use of org.corfudb.protocols.wireprotocol.ILogData in project CorfuDB by CorfuDB.
the class ChainReplicationProtocolTest method failedWriteCanBeRead.
/** Check to see that a read correctly
* completes a failed write from another client.
*/
@Test
public void failedWriteCanBeRead() throws Exception {
setupNodes();
//begin tests
final CorfuRuntime r = getDefaultRuntime();
final IReplicationProtocol rp = getProtocol();
final Layout layout = r.getLayoutView().getLayout();
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);
// At this point, a read
// reflect the -other- clients value
ILogData readResult = rp.read(layout, 0);
assertThat(readResult.getPayload(r)).isEqualTo("incomplete".getBytes());
}
use of org.corfudb.protocols.wireprotocol.ILogData in project CorfuDB by CorfuDB.
the class AddressSpaceView method write.
/** Write the given log data using a token, returning
* either when the write has been completed successfully,
* or throwing an OverwriteException if another value
* has been adopted, or a WrongEpochException if the
* token epoch is invalid.
*
* @param token The token to use for the write.
* @param data The data to write.
* @throws OverwriteException If the globalAddress given
* by the token has adopted
* another value.
* @throws WrongEpochException If the token epoch is invalid.
*/
public void write(IToken token, Object data) throws OverwriteException {
final ILogData ld = new LogData(DataType.DATA, data);
layoutHelper(l -> {
if (token.getEpoch() != l.getEpoch()) {
throw new WrongEpochException(l.getEpoch());
}
ld.useToken(token);
l.getReplicationMode(token.getTokenValue()).getReplicationProtocol(runtime).write(l, ld);
return null;
});
// Cache the successful write
if (!runtime.isCacheDisabled()) {
readCache.put(token.getTokenValue(), ld);
}
}
use of org.corfudb.protocols.wireprotocol.ILogData in project CorfuDB by CorfuDB.
the class StreamIT method simpleStreamTest.
// @Test
public void simpleStreamTest() throws Exception {
Process corfuServerProcess = new CorfuServerRunner().setHost(corfuSingleNodeHost).setPort(corfuSingleNodePort).runServer();
CorfuRuntime rt = createDefaultRuntime();
rt.setCacheDisabled(true);
Random rand = new Random();
UUID streamId = CorfuRuntime.getStreamID(Integer.toString(rand.nextInt()));
IStreamView s1 = rt.getStreamsView().get(streamId);
// Verify that the stream is empty
assertThat(s1.hasNext()).isFalse();
// Generate and append random data
int entrySize = Integer.valueOf(PROPERTIES.getProperty("largeEntrySize"));
final int numEntries = 100;
byte[][] data = new byte[numEntries][entrySize];
for (int x = 0; x < numEntries; x++) {
rand.nextBytes(data[x]);
s1.append(data[x]);
}
// Read back the data and verify it is correct
for (int x = 0; x < numEntries; x++) {
ILogData entry = s1.nextUpTo(x);
byte[] tmp = (byte[]) entry.getPayload(rt);
assertThat(tmp).isEqualTo(data[x]);
}
assertThat(shutdownCorfuServer(corfuServerProcess)).isTrue();
}
use of org.corfudb.protocols.wireprotocol.ILogData in project CorfuDB by CorfuDB.
the class LogUnitClientTest method createEmptyData.
private ILogData.SerializationHandle createEmptyData(long position, DataType type, IMetadata.DataRank rank) {
ILogData data = new LogData(type);
data.setRank(rank);
data.setGlobalAddress(position);
return data.getSerializedForm();
}
use of org.corfudb.protocols.wireprotocol.ILogData in project CorfuDB by CorfuDB.
the class AbstractTransactionContextTest method ensureEmptyWriteSetIsNotWritten.
/** Ensure that empty write sets are not written to the log.
* This test applies to all contexts which is why it is in
* the abstract test.
*/
@Test
public void ensureEmptyWriteSetIsNotWritten() {
TXBegin();
long result = getRuntime().getObjectsView().TXEnd();
ILogData ld = getRuntime().getAddressSpaceView().peek(0);
assertThat(ld).isNull();
assertThat(result).isEqualTo(AbstractTransactionalContext.NOWRITE_ADDRESS);
}
Aggregations