Search in sources :

Example 6 with CorfuRuntime

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());
}
Also used : CorfuRuntime(org.corfudb.runtime.CorfuRuntime) IStreamView(org.corfudb.runtime.view.stream.IStreamView) Test(org.junit.Test)

Example 7 with CorfuRuntime

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());
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) Layout(org.corfudb.runtime.view.Layout) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test) AbstractViewTest(org.corfudb.runtime.view.AbstractViewTest)

Example 8 with CorfuRuntime

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());
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) LogUnitClient(org.corfudb.runtime.clients.LogUnitClient) Layout(org.corfudb.runtime.view.Layout) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test)

Example 9 with CorfuRuntime

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);
}
Also used : TokenResponse(org.corfudb.protocols.wireprotocol.TokenResponse) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) LogUnitServer(org.corfudb.infrastructure.LogUnitServer) UUID(java.util.UUID) IStreamView(org.corfudb.runtime.view.stream.IStreamView) Test(org.junit.Test) AbstractViewTest(org.corfudb.runtime.view.AbstractViewTest)

Example 10 with CorfuRuntime

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();
}
Also used : CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test)

Aggregations

CorfuRuntime (org.corfudb.runtime.CorfuRuntime)68 Test (org.junit.Test)56 UUID (java.util.UUID)18 ILogData (org.corfudb.protocols.wireprotocol.ILogData)13 IStreamView (org.corfudb.runtime.view.stream.IStreamView)13 TestLayoutBuilder (org.corfudb.infrastructure.TestLayoutBuilder)12 TokenResponse (org.corfudb.protocols.wireprotocol.TokenResponse)11 AbstractViewTest (org.corfudb.runtime.view.AbstractViewTest)11 Layout (org.corfudb.runtime.view.Layout)10 TypeToken (com.google.common.reflect.TypeToken)9 LogData (org.corfudb.protocols.wireprotocol.LogData)9 TransactionAbortedException (org.corfudb.runtime.exceptions.TransactionAbortedException)6 Semaphore (java.util.concurrent.Semaphore)5 TestRule (org.corfudb.runtime.clients.TestRule)5 SMRMap (org.corfudb.runtime.collections.SMRMap)5 Map (java.util.Map)4 Token (org.corfudb.protocols.wireprotocol.Token)4 Collections (java.util.Collections)3 ExecutionException (java.util.concurrent.ExecutionException)3 TimeUnit (java.util.concurrent.TimeUnit)3