use of org.corfudb.protocols.wireprotocol.TokenResponse in project CorfuDB by CorfuDB.
the class QuorumReplicationProtocolAdditionalTests method canReadWriteToMultiple.
@Test
@SuppressWarnings("unchecked")
public void canReadWriteToMultiple() throws Exception {
//configure the layout accordingly
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);
assertThat(r.getAddressSpaceView().read(0L).getPayload(getRuntime())).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();
}
use of org.corfudb.protocols.wireprotocol.TokenResponse in project CorfuDB by CorfuDB.
the class QuorumReplicationProtocolAdditionalTests method canReadWriteConcurrent.
@Test
@SuppressWarnings("unchecked")
public void canReadWriteConcurrent() 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, r.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);
assertNotNull(r.getAddressSpaceView().read(0L).getRank());
assertThat((IMetadata.DataRank) r.getAddressSpaceView().read(0L).getMetadataMap().get(IMetadata.LogUnitMetadataType.RANK)).isNotNull();
}
use of org.corfudb.protocols.wireprotocol.TokenResponse in project CorfuDB by CorfuDB.
the class StreamViewTest method streamWithHoleFill.
@Test
@SuppressWarnings("unchecked")
public void streamWithHoleFill() throws Exception {
UUID streamA = CorfuRuntime.getStreamID("stream A");
byte[] testPayload = "hello world".getBytes();
byte[] testPayload2 = "hello world2".getBytes();
IStreamView sv = r.getStreamsView().get(streamA);
sv.append(testPayload);
//generate a stream hole
TokenResponse tr = r.getSequencerView().nextToken(Collections.singleton(streamA), 1);
// read from an address that hasn't been written to
// causing a hole fill
r.getAddressSpaceView().read(tr.getToken().getTokenValue());
tr = r.getSequencerView().nextToken(Collections.singleton(streamA), 1);
// read from an address that hasn't been written to
// causing a hole fill
r.getAddressSpaceView().read(tr.getToken().getTokenValue());
sv.append(testPayload2);
//make sure we can still read the stream.
assertThat(sv.next().getPayload(getRuntime())).isEqualTo(testPayload);
assertThat(sv.next().getPayload(getRuntime())).isEqualTo(testPayload2);
}
use of org.corfudb.protocols.wireprotocol.TokenResponse in project CorfuDB by CorfuDB.
the class QuorumReplicationProtocolAdditionalTests method checkReadOnEmptyPosition.
@Test
@SuppressWarnings("unchecked")
public void checkReadOnEmptyPosition() throws Exception {
//configure the layout accordingly
CorfuRuntime r = getDefaultRuntime();
LogUnitServer u0 = getLogUnit(SERVERS.PORT_0);
UUID streamA = CorfuRuntime.getStreamID("stream A");
byte[] testPayload = "hello world".getBytes();
//generate a stream hole
TokenResponse tr = r.getSequencerView().nextToken(Collections.singleton(streamA), 1);
IStreamView sv = r.getStreamsView().get(streamA);
sv.append(testPayload);
tr = r.getSequencerView().nextToken(Collections.singleton(streamA), 1);
//make sure we can still read the stream.
assertThat(sv.next().getPayload(getRuntime())).isEqualTo(testPayload);
int address = 0;
assertThat(r.getAddressSpaceView().read(address++).getType()).isEqualTo(DataType.HOLE);
assertThat(r.getAddressSpaceView().read(address++).getType()).isEqualTo(DataType.DATA);
assertThat(r.getAddressSpaceView().read(address++).getType()).isEqualTo(DataType.HOLE);
// TODO(mwei) - fix me
// assertThat(r.getAddressSpaceView().read(address++).getType()).isEqualTo(DataType.EMPTY);
}
use of org.corfudb.protocols.wireprotocol.TokenResponse in project CorfuDB by CorfuDB.
the class CheckpointSmokeTest method writeCheckpointRecords.
private void writeCheckpointRecords(UUID streamId, String checkpointAuthor, UUID checkpointId, Object[] objects, Runnable l1, Runnable l2, boolean write1, boolean write2, boolean write3) throws Exception {
BackpointerStreamView sv = new BackpointerStreamView(r, streamId);
Map<CheckpointEntry.CheckpointDictKey, String> mdKV = new HashMap<>();
mdKV.put(CheckpointEntry.CheckpointDictKey.START_TIME, "The perfect time");
// Write cp #1 of 3
if (write1) {
TokenResponse tokResp1 = r.getSequencerView().nextToken(Collections.singleton(streamId), 0);
long addr1 = tokResp1.getToken().getTokenValue();
mdKV.put(CheckpointEntry.CheckpointDictKey.START_LOG_ADDRESS, Long.toString(addr1 + 1));
CheckpointEntry cp1 = new CheckpointEntry(CheckpointEntry.CheckpointEntryType.START, checkpointAuthor, checkpointId, mdKV, null);
sv.append(cp1, null, null);
}
// Interleaving opportunity #1
l1.run();
// Write cp #2 of 3
if (write2) {
MultiSMREntry smrEntries = new MultiSMREntry();
if (objects != null) {
for (int i = 0; i < objects.length; i++) {
smrEntries.addTo(new SMREntry("put", (Object[]) objects[i], Serializers.JSON));
}
}
CheckpointEntry cp2 = new CheckpointEntry(CheckpointEntry.CheckpointEntryType.CONTINUATION, checkpointAuthor, checkpointId, mdKV, smrEntries);
sv.append(cp2, null, null);
}
// Interleaving opportunity #2
l2.run();
// Write cp #3 of 3
if (write3) {
CheckpointEntry cp3 = new CheckpointEntry(CheckpointEntry.CheckpointEntryType.END, checkpointAuthor, checkpointId, mdKV, null);
sv.append(cp3, null, null);
}
}
Aggregations