use of org.corfudb.runtime.CorfuRuntime 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.CorfuRuntime in project CorfuDB by CorfuDB.
the class AbstractReplicationProtocolTest method canWriteRead.
/** Check if we can write and then read the value
* that was written.
*/
@Test
@SuppressWarnings("unchecked")
public void canWriteRead() throws Exception {
setupNodes();
//begin tests
final CorfuRuntime r = getDefaultRuntime();
final IReplicationProtocol rp = getProtocol();
final Layout layout = r.getLayoutView().getLayout();
LogData data = getLogData(0, "hello world".getBytes());
rp.write(layout, data);
ILogData read = rp.read(layout, 0);
assertThat(read.getType()).isEqualTo(DataType.DATA);
assertThat(read.getGlobalAddress()).isEqualTo(0);
assertThat(read.getPayload(r)).isEqualTo("hello world".getBytes());
}
use of org.corfudb.runtime.CorfuRuntime 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.runtime.CorfuRuntime 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.CorfuRuntime in project CorfuDB by CorfuDB.
the class ObjectsViewTest method canAbortNoTransaction.
@Test
@SuppressWarnings("unchecked")
public void canAbortNoTransaction() throws Exception {
//begin tests
CorfuRuntime r = getDefaultRuntime();
r.getObjectsView().TXAbort();
}
Aggregations