Search in sources :

Example 41 with CorfuRuntime

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

Example 42 with CorfuRuntime

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

Example 43 with CorfuRuntime

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

Example 44 with CorfuRuntime

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

Example 45 with CorfuRuntime

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);
}
Also used : 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)

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