Search in sources :

Example 51 with CorfuRuntime

use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.

the class SequencerViewTest method checkBackPointersWork.

@Test
public void checkBackPointersWork() {
    CorfuRuntime r = getDefaultRuntime();
    UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
    UUID streamB = UUID.nameUUIDFromBytes("stream B".getBytes());
    assertThat(r.getSequencerView().nextToken(Collections.singleton(streamA), 1).getBackpointerMap()).containsEntry(streamA, Address.NON_EXIST);
    assertThat(r.getSequencerView().nextToken(Collections.singleton(streamA), 0).getBackpointerMap()).isEmpty();
    assertThat(r.getSequencerView().nextToken(Collections.singleton(streamB), 1).getBackpointerMap()).containsEntry(streamB, Address.NON_EXIST);
    assertThat(r.getSequencerView().nextToken(Collections.singleton(streamB), 0).getBackpointerMap()).isEmpty();
    assertThat(r.getSequencerView().nextToken(Collections.singleton(streamA), 1).getBackpointerMap()).containsEntry(streamA, 0L);
    assertThat(r.getSequencerView().nextToken(Collections.singleton(streamB), 1).getBackpointerMap()).containsEntry(streamB, 1L);
}
Also used : CorfuRuntime(org.corfudb.runtime.CorfuRuntime) UUID(java.util.UUID) Test(org.junit.Test)

Example 52 with CorfuRuntime

use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.

the class SequencerViewTest method checkStreamTokensWork.

@Test
public void checkStreamTokensWork() {
    CorfuRuntime r = getDefaultRuntime();
    UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
    UUID streamB = UUID.nameUUIDFromBytes("stream B".getBytes());
    assertThat(r.getSequencerView().nextToken(Collections.singleton(streamA), 1).getToken()).isEqualTo(new Token(0L, 0L));
    assertThat(r.getSequencerView().nextToken(Collections.singleton(streamA), 0).getToken()).isEqualTo(new Token(0L, 0L));
    assertThat(r.getSequencerView().nextToken(Collections.singleton(streamB), 1).getToken()).isEqualTo(new Token(1L, 0L));
    assertThat(r.getSequencerView().nextToken(Collections.singleton(streamB), 0).getToken()).isEqualTo(new Token(1L, 0L));
    assertThat(r.getSequencerView().nextToken(Collections.singleton(streamA), 0).getToken()).isEqualTo(new Token(0L, 0L));
}
Also used : CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Token(org.corfudb.protocols.wireprotocol.Token) UUID(java.util.UUID) Test(org.junit.Test)

Example 53 with CorfuRuntime

use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.

the class StreamViewTest method canReadWriteFromCachedStream.

@Test
@SuppressWarnings("unchecked")
public void canReadWriteFromCachedStream() throws Exception {
    CorfuRuntime r = getDefaultRuntime().connect().setCacheDisabled(false);
    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 : CorfuRuntime(org.corfudb.runtime.CorfuRuntime) UUID(java.util.UUID) IStreamView(org.corfudb.runtime.view.stream.IStreamView) Test(org.junit.Test)

Example 54 with CorfuRuntime

use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.

the class LayoutViewTest method canSetLayout.

@Test
public void canSetLayout() throws Exception {
    CorfuRuntime r = getDefaultRuntime().connect();
    Layout l = new TestLayoutBuilder().setEpoch(1).addLayoutServer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_0).buildSegment().buildStripe().addLogUnit(SERVERS.PORT_0).addToSegment().addToLayout().build();
    l.setRuntime(r);
    l.moveServersToEpoch();
    r.getLayoutView().updateLayout(l, 1L);
    r.invalidateLayout();
    assertThat(r.getLayoutView().getLayout().epoch).isEqualTo(1L);
}
Also used : TestLayoutBuilder(org.corfudb.infrastructure.TestLayoutBuilder) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test)

Example 55 with CorfuRuntime

use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.

the class ObjectsViewTest method cannotCopyNonCorfuObject.

@Test
@SuppressWarnings("unchecked")
public void cannotCopyNonCorfuObject() throws Exception {
    //begin tests
    CorfuRuntime r = getDefaultRuntime();
    assertThatThrownBy(() -> {
        r.getObjectsView().copy(new HashMap<String, String>(), CorfuRuntime.getStreamID("test"));
    }).isInstanceOf(RuntimeException.class);
}
Also used : HashMap(java.util.HashMap) 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