use of org.corfudb.protocols.wireprotocol.TokenResponse in project CorfuDB by CorfuDB.
the class ChainReplicationViewTest method ensureAllUnitsContainData.
@Test
@SuppressWarnings("unchecked")
public void ensureAllUnitsContainData() throws Exception {
addServer(SERVERS.PORT_0);
addServer(SERVERS.PORT_1);
addServer(SERVERS.PORT_2);
bootstrapAllServers(new TestLayoutBuilder().addLayoutServer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_0).buildSegment().setReplicationMode(Layout.ReplicationMode.CHAIN_REPLICATION).buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_1).addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build());
//configure the layout accordingly
CorfuRuntime r = getRuntime().connect();
UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
byte[] testPayload = "hello world".getBytes();
r.getAddressSpaceView().write(new TokenResponse(0, 0, Collections.singletonMap(streamA, Address.NO_BACKPOINTER)), testPayload);
assertThat(r.getAddressSpaceView().read(0L).getPayload(getRuntime())).isEqualTo("hello world".getBytes());
assertThat(r.getAddressSpaceView().read(0L).containsStream(streamA));
// Ensure that the data was written to each logunit.
assertThat(getLogUnit(SERVERS.PORT_0)).matchesDataAtAddress(0, testPayload);
assertThat(getLogUnit(SERVERS.PORT_1)).matchesDataAtAddress(0, testPayload);
assertThat(getLogUnit(SERVERS.PORT_2)).matchesDataAtAddress(0, testPayload);
}
use of org.corfudb.protocols.wireprotocol.TokenResponse in project CorfuDB by CorfuDB.
the class ChainReplicationViewTest method canReadWriteToMultiple.
@Test
@SuppressWarnings("unchecked")
public void canReadWriteToMultiple() throws Exception {
addServer(SERVERS.PORT_0);
addServer(SERVERS.PORT_1);
addServer(SERVERS.PORT_2);
bootstrapAllServers(new TestLayoutBuilder().addLayoutServer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_0).buildSegment().setReplicationMode(Layout.ReplicationMode.CHAIN_REPLICATION).buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_1).addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build());
//configure the layout accordingly
CorfuRuntime r = getRuntime().connect();
UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
byte[] testPayload = "hello world".getBytes();
r.getAddressSpaceView().write(new TokenResponse(0, runtime.getLayoutView().getLayout().getEpoch(), Collections.singletonMap(streamA, Address.NO_BACKPOINTER)), testPayload);
assertThat(r.getAddressSpaceView().read(0L).getPayload(getRuntime())).isEqualTo("hello world".getBytes());
assertThat(r.getAddressSpaceView().read(0L).containsStream(streamA)).isTrue();
}
use of org.corfudb.protocols.wireprotocol.TokenResponse in project CorfuDB by CorfuDB.
the class ChainReplicationViewTest method canReadWriteToSingleConcurrent.
@Test
@SuppressWarnings("unchecked")
public void canReadWriteToSingleConcurrent() throws Exception {
CorfuRuntime r = getDefaultRuntime();
final int numberThreads = 5;
final int numberRecords = 1_000;
scheduleConcurrently(numberThreads, threadNumber -> {
int base = threadNumber * numberRecords;
for (int i = base; i < base + numberRecords; i++) {
r.getAddressSpaceView().write(new TokenResponse((long) i, runtime.getLayoutView().getLayout().getEpoch(), Collections.singletonMap(CorfuRuntime.getStreamID("a"), Address.NO_BACKPOINTER)), Integer.toString(i).getBytes());
}
});
executeScheduled(numberThreads, PARAMETERS.TIMEOUT_LONG);
scheduleConcurrently(numberThreads, threadNumber -> {
int base = threadNumber * numberRecords;
for (int i = base; i < base + numberRecords; i++) {
assertThat(r.getAddressSpaceView().read(i).getPayload(getRuntime())).isEqualTo(Integer.toString(i).getBytes());
}
});
executeScheduled(numberThreads, PARAMETERS.TIMEOUT_LONG);
}
use of org.corfudb.protocols.wireprotocol.TokenResponse in project CorfuDB by CorfuDB.
the class CheckpointWriter method startGlobalSnapshotTxn.
public static long startGlobalSnapshotTxn(CorfuRuntime rt) {
TokenResponse tokenResponse = rt.getSequencerView().nextToken(Collections.EMPTY_SET, 0);
long globalTail = tokenResponse.getToken().getTokenValue();
rt.getObjectsView().TXBuild().setType(TransactionType.SNAPSHOT).setSnapshot(globalTail).begin();
AbstractTransactionalContext context = TransactionalContext.getCurrentContext();
return context.getSnapshotTimestamp();
}
use of org.corfudb.protocols.wireprotocol.TokenResponse in project CorfuDB by CorfuDB.
the class QuorumReplicationProtocolAdditionalTests method canReadWrite.
@Test
@SuppressWarnings("unchecked")
public void canReadWrite() throws Exception {
CorfuRuntime r = getDefaultRuntime();
UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
byte[] testPayload = "hello world".getBytes();
r.getAddressSpaceView().write(new TokenResponse(0, r.getLayoutView().getLayout().getEpoch(), Collections.singletonMap(streamA, Address.NO_BACKPOINTER)), testPayload);
ILogData x = r.getAddressSpaceView().read(0);
assertNotNull(x.getRank());
assertThat(r.getAddressSpaceView().read(0L).getPayload(r)).isEqualTo("hello world".getBytes());
assertThat(r.getAddressSpaceView().read(0L).containsStream(streamA)).isTrue();
assertThat((IMetadata.DataRank) r.getAddressSpaceView().read(0L).getMetadataMap().get(IMetadata.LogUnitMetadataType.RANK)).isNotNull();
}
Aggregations