use of org.corfudb.runtime.view.stream.IStreamView in project CorfuDB by CorfuDB.
the class StreamViewTest method canReadWriteFromStreamConcurrent.
@Test
@SuppressWarnings("unchecked")
public void canReadWriteFromStreamConcurrent() throws Exception {
UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
byte[] testPayload = "hello world".getBytes();
IStreamView sv = r.getStreamsView().get(streamA);
scheduleConcurrently(PARAMETERS.NUM_ITERATIONS_LOW, i -> sv.append(testPayload));
executeScheduled(PARAMETERS.CONCURRENCY_SOME, PARAMETERS.TIMEOUT_NORMAL);
scheduleConcurrently(PARAMETERS.NUM_ITERATIONS_LOW, i -> assertThat(sv.next().getPayload(getRuntime())).isEqualTo("hello world".getBytes()));
executeScheduled(PARAMETERS.CONCURRENCY_SOME, PARAMETERS.TIMEOUT_NORMAL);
assertThat(sv.next()).isEqualTo(null);
}
use of org.corfudb.runtime.view.stream.IStreamView in project CorfuDB by CorfuDB.
the class StreamViewTest method canDoPreviousOnStream.
@Test
public void canDoPreviousOnStream() throws Exception {
CorfuRuntime r = getDefaultRuntime().connect();
IStreamView sv = r.getStreamsView().get(CorfuRuntime.getStreamID("stream A"));
// Append some entries
sv.append("a".getBytes());
sv.append("b".getBytes());
sv.append("c".getBytes());
// Move backward should return null
assertThat(sv.previous()).isNull();
// Move forward
// "a"
sv.next();
// "b"
sv.next();
// Should be now "a"
assertThat(sv.previous().getPayload(r)).isEqualTo("a".getBytes());
// Move forward, should be now "b"
assertThat(sv.next().getPayload(r)).isEqualTo("b".getBytes());
// "c"
sv.next();
// null
sv.next();
// Should be now "b"
assertThat(sv.previous().getPayload(r)).isEqualTo("b".getBytes());
}
use of org.corfudb.runtime.view.stream.IStreamView 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.runtime.view.stream.IStreamView 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.runtime.view.stream.IStreamView in project CorfuDB by CorfuDB.
the class StreamViewTest method canReadWriteFromStream.
@Test
@SuppressWarnings("unchecked")
public void canReadWriteFromStream() throws Exception {
UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
byte[] testPayload = "hello world".getBytes();
IStreamView sv = r.getStreamsView().get(streamA);
sv.append(testPayload);
assertThat(sv.next().getPayload(getRuntime())).isEqualTo("hello world".getBytes());
assertThat(sv.next()).isEqualTo(null);
}
Aggregations