use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class StreamViewTest method canSeekOnStream.
@Test
public void canSeekOnStream() 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());
// Try reading two entries
assertThat(sv.next().getPayload(r)).isEqualTo("a".getBytes());
assertThat(sv.next().getPayload(r)).isEqualTo("b".getBytes());
// Seeking to the beginning
sv.seek(0);
assertThat(sv.next().getPayload(r)).isEqualTo("a".getBytes());
// Seeking to the end
sv.seek(2);
assertThat(sv.next().getPayload(r)).isEqualTo("c".getBytes());
// Seeking to the middle
sv.seek(1);
assertThat(sv.next().getPayload(r)).isEqualTo("b".getBytes());
}
use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class StreamViewTest method canFindInStream.
@Test
public void canFindInStream() throws Exception {
CorfuRuntime r = getDefaultRuntime().connect();
IStreamView svA = r.getStreamsView().get(CorfuRuntime.getStreamID("stream A"));
IStreamView svB = r.getStreamsView().get(CorfuRuntime.getStreamID("stream B"));
// Append some entries
final long A_GLOBAL = 0;
svA.append("a".getBytes());
final long B_GLOBAL = 1;
svB.append("b".getBytes());
final long C_GLOBAL = 2;
svA.append("c".getBytes());
final long D_GLOBAL = 3;
svB.append("d".getBytes());
final long E_GLOBAL = 4;
svA.append("e".getBytes());
// See if we can find entries:
// Should find entry "c"
assertThat(svA.find(B_GLOBAL, IStreamView.SearchDirection.FORWARD)).isEqualTo(C_GLOBAL);
// Should find entry "a"
assertThat(svA.find(B_GLOBAL, IStreamView.SearchDirection.REVERSE)).isEqualTo(A_GLOBAL);
// Should find entry "e"
assertThat(svA.find(E_GLOBAL, IStreamView.SearchDirection.FORWARD_INCLUSIVE)).isEqualTo(E_GLOBAL);
// Should find entry "c"
assertThat(svA.find(C_GLOBAL, IStreamView.SearchDirection.REVERSE_INCLUSIVE)).isEqualTo(C_GLOBAL);
// From existing to existing:
// Should find entry "b"
assertThat(svB.find(D_GLOBAL, IStreamView.SearchDirection.REVERSE)).isEqualTo(B_GLOBAL);
// Should find entry "d"
assertThat(svB.find(B_GLOBAL, IStreamView.SearchDirection.FORWARD)).isEqualTo(D_GLOBAL);
// Bounds:
assertThat(svB.find(D_GLOBAL, IStreamView.SearchDirection.FORWARD)).isEqualTo(Address.NOT_FOUND);
}
use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class StreamsViewTest method canCopyStream.
@Test
@SuppressWarnings("unchecked")
public void canCopyStream() throws Exception {
//begin tests
CorfuRuntime r = getDefaultRuntime().connect();
UUID streamA = CorfuRuntime.getStreamID("stream A");
UUID streamACopy = CorfuRuntime.getStreamID("stream A copy");
byte[] testPayload = "hello world".getBytes();
byte[] testPayloadCopy = "hello world copy".getBytes();
IStreamView sv = r.getStreamsView().get(streamA);
sv.append(testPayload);
assertThat(sv.next().getPayload(getRuntime())).isEqualTo(testPayload);
assertThat(sv.next()).isEqualTo(null);
SequencerView sequencerView = r.getSequencerView();
IStreamView svCopy = r.getStreamsView().copy(streamA, streamACopy, sequencerView.nextToken(Collections.singleton(sv.getID()), 0).getToken().getTokenValue());
assertThat(svCopy.next().getPayload(getRuntime())).isEqualTo(testPayload);
assertThat(svCopy.next()).isEqualTo(null);
svCopy.append(testPayloadCopy);
assertThat(svCopy.next().getPayload(getRuntime())).isEqualTo(testPayloadCopy);
assertThat(svCopy.next()).isEqualTo(null);
assertThat(sv.next()).isEqualTo(null);
}
use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class AbstractReplicationProtocolTest method readOnlyCommitted.
/** Check to make sure reads never return empty in
* the case of an unwritten address.
*/
@Test
@SuppressWarnings("unchecked")
public void readOnlyCommitted() throws Exception {
setupNodes();
//begin tests
final CorfuRuntime r = getDefaultRuntime();
final IReplicationProtocol rp = getProtocol();
final Layout layout = r.getLayoutView().getLayout();
ILogData read = rp.read(layout, 0);
assertThat(read.getType()).isNotEqualTo(DataType.EMPTY);
read = rp.read(layout, 1);
assertThat(read.getType()).isNotEqualTo(DataType.EMPTY);
}
use of org.corfudb.runtime.CorfuRuntime 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);
}
Aggregations