Search in sources :

Example 1 with IStreamView

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

Example 2 with IStreamView

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

Example 3 with IStreamView

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

Example 4 with IStreamView

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);
}
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 5 with IStreamView

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

Aggregations

IStreamView (org.corfudb.runtime.view.stream.IStreamView)19 Test (org.junit.Test)18 CorfuRuntime (org.corfudb.runtime.CorfuRuntime)11 UUID (java.util.UUID)10 MultiObjectSMREntry (org.corfudb.protocols.logprotocol.MultiObjectSMREntry)3 MultiSMREntry (org.corfudb.protocols.logprotocol.MultiSMREntry)3 SMREntry (org.corfudb.protocols.logprotocol.SMREntry)3 ILogData (org.corfudb.protocols.wireprotocol.ILogData)3 TypeToken (com.google.common.reflect.TypeToken)2 TestLayoutBuilder (org.corfudb.infrastructure.TestLayoutBuilder)2 TokenResponse (org.corfudb.protocols.wireprotocol.TokenResponse)2 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Semaphore (java.util.concurrent.Semaphore)1 LogUnitServer (org.corfudb.infrastructure.LogUnitServer)1 TestRule (org.corfudb.runtime.clients.TestRule)1 SMRMap (org.corfudb.runtime.collections.SMRMap)1 AbstractViewTest (org.corfudb.runtime.view.AbstractViewTest)1