Search in sources :

Example 36 with CorfuRuntime

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

the class SealIT method RuntimeWithWrongEpochGetUpdated.

@Test
public void RuntimeWithWrongEpochGetUpdated() throws Exception {
    Process corfuProcess = new CorfuServerRunner().setHost(corfuSingleNodeHost).setPort(corfuSingleNodePort).runServer();
    CorfuRuntime cr1 = createDefaultRuntime();
    CorfuRuntime cr2 = createDefaultRuntime();
    Long beforeAddress = cr2.getSequencerView().nextToken(new HashSet<>(), 1).getToken().getTokenValue();
    /* We will trigger a Paxos round, this is what will happen:
         *   1. Set our layout (same than before) with a new Epoch
         *   2. Seal the server(s)
         *   3. Propose the new layout by driving paxos.
         */
    Layout currentLayout = cr1.getLayoutView().getCurrentLayout();
    /* 1 */
    currentLayout.setEpoch(currentLayout.getEpoch() + 1);
    /* 2 */
    currentLayout.moveServersToEpoch();
    /* 3 */
    cr1.getLayoutView().updateLayout(currentLayout, 0);
    /* Now cr2 is still stuck in the previous epoch. The next time it will ask for a token,
         * emit a read or a write (msgs type that validate the epoch on the server side) it should
         * receive a WrongEpochException. This exception is taken care of by the AbstractView class in
         * the layoutHelper function.
         *
         * Upon receiving a wrong epoch, the new epoch will be set internally, and it will invalidate
         * the layout.
         *
         * These steps get cr2 in the new epoch.
         */
    Long afterAddress = cr2.getSequencerView().nextToken(new HashSet<>(), 1).getToken().getTokenValue();
    assertThat(cr2.getLayoutView().getCurrentLayout().getEpoch()).isEqualTo(cr1.getLayoutView().getCurrentLayout().getEpoch());
    assertThat(afterAddress).isEqualTo(beforeAddress + 1);
    assertThat(shutdownCorfuServer(corfuProcess)).isTrue();
}
Also used : Layout(org.corfudb.runtime.view.Layout) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test)

Example 37 with CorfuRuntime

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

the class LogUnitClientTest method canReadWrite.

@Test
public void canReadWrite() throws Exception {
    byte[] testString = "hello world".getBytes();
    client.write(0, Collections.<UUID>emptySet(), null, testString, Collections.emptyMap()).get();
    LogData r = client.read(0).get().getReadSet().get(0L);
    assertThat(r.getType()).isEqualTo(DataType.DATA);
    assertThat(r.getPayload(new CorfuRuntime())).isEqualTo(testString);
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) UUID(java.util.UUID) Test(org.junit.Test)

Example 38 with CorfuRuntime

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

the class LogUnitClientTest method cannotOutrank.

@Test
public void cannotOutrank() throws ExecutionException, InterruptedException {
    byte[] testString = "hello world".getBytes();
    client.write(0, Collections.<UUID>emptySet(), new IMetadata.DataRank(2), testString, Collections.emptyMap()).get();
    LogData r = client.read(0).get().getReadSet().get(0L);
    assertThat(r.getType()).isEqualTo(DataType.DATA);
    assertThat(r.getPayload(new CorfuRuntime())).isEqualTo(testString);
    byte[] testString2 = "hello world 2".getBytes();
    try {
        client.write(0, Collections.<UUID>emptySet(), new IMetadata.DataRank(1), testString2, Collections.emptyMap()).get();
        fail();
    } catch (ExecutionException e) {
        // expected
        assertEquals(DataOutrankedException.class, e.getCause().getClass());
    }
    r = client.read(0).get().getReadSet().get(0L);
    assertThat(r.getType()).isEqualTo(DataType.DATA);
    assertThat(r.getPayload(new CorfuRuntime())).isEqualTo(testString);
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) DataOutrankedException(org.corfudb.runtime.exceptions.DataOutrankedException) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 39 with CorfuRuntime

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

the class LogUnitClientTest method canReadWriteRanked.

@Test
public void canReadWriteRanked() throws Exception {
    byte[] testString = "hello world".getBytes();
    client.write(0, Collections.<UUID>emptySet(), new IMetadata.DataRank(1), testString, Collections.emptyMap()).get();
    LogData r = client.read(0).get().getReadSet().get(0L);
    assertThat(r.getType()).isEqualTo(DataType.DATA);
    assertThat(r.getPayload(new CorfuRuntime())).isEqualTo(testString);
    byte[] testString2 = "hello world 2".getBytes();
    client.write(0, Collections.<UUID>emptySet(), new IMetadata.DataRank(2), testString2, Collections.emptyMap()).get();
    r = client.read(0).get().getReadSet().get(0L);
    assertThat(r.getType()).isEqualTo(DataType.DATA);
    assertThat(r.getPayload(new CorfuRuntime())).isEqualTo(testString2);
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) UUID(java.util.UUID) Test(org.junit.Test)

Example 40 with CorfuRuntime

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

the class CorfuSMRObjectProxyTest method canUseCustomSerializer.

/** Disabled pending resolution of issue #285
    @Test
    public void deadLockTest() throws Exception {
        CorfuRuntime runtime = getDefaultRuntime().connect();
        Map<String, Integer> map =
                runtime.getObjectsView()
                        .build()
                        .setStreamName("M")
                        .setType(SMRMap.class)
                        .open();

        for(int x = 0; x < PARAMETERS.NUM_ITERATIONS_LOW; x++) {
            // thread 1: update "a" and "b" atomically
            Thread t1 = new Thread(() -> {
                runtime.getObjectsView().TXBegin();
                map.put("a", 1);
                map.put("b", 1);
                runtime.getObjectsView().TXEnd();
            }
            );
            t1.start();

            // thread 2: read "a", then "b"
            Thread t2 = new Thread(() -> {
                map.get("a");
                map.get("b");
            });
            t2.start();

            t1.join(PARAMETERS.TIMEOUT_NORMAL.toMillis());
            t2.join(PARAMETERS.TIMEOUT_NORMAL.toMillis());

            assertThat(t1.isAlive()).isFalse();
            assertThat(t2.isAlive()).isFalse();
        }
    }

    @Test
    @SuppressWarnings("unchecked")
    public void canUsePrimitiveSerializer()
            throws Exception {
        //begin tests
        CorfuRuntime r = getDefaultRuntime().connect();
        TestClassWithPrimitives test = r.getObjectsView().build()
                .setType(TestClassWithPrimitives.class)
                .setStreamName("test")
                .setSerializer(Serializers.PRIMITIVE)
                .open();

        test.setPrimitive("hello world".getBytes());
        assertThat(test.getPrimitive())
                .isEqualTo("hello world".getBytes());
    }
     **/
@Test
@SuppressWarnings("unchecked")
public void canUseCustomSerializer() throws Exception {
    //Register a custom serializer and use it with an SMR object
    ISerializer customSerializer = new CustomSerializer((byte) (Serializers.SYSTEM_SERIALIZERS_COUNT + 1));
    Serializers.registerSerializer(customSerializer);
    CorfuRuntime r = getDefaultRuntime();
    Map<String, String> test = r.getObjectsView().build().setType(SMRMap.class).setStreamName("test").setSerializer(customSerializer).open();
    test.put("a", "b");
    test.get("a");
    assertThat(test.get("a")).isEqualTo("b");
}
Also used : SMRMap(org.corfudb.runtime.collections.SMRMap) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) CustomSerializer(org.corfudb.CustomSerializer) ISerializer(org.corfudb.util.serializer.ISerializer) 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