Search in sources :

Example 61 with CorfuRuntime

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

the class FailureHandlerDispatcherTest method updateLayoutOnFailure.

/**
     * triggers the handler with failure and checks for update in layout.
     */
@Test
public void updateLayoutOnFailure() {
    addServer(SERVERS.PORT_0);
    addServer(SERVERS.PORT_1);
    addServer(SERVERS.PORT_2);
    Layout originalLayout = new TestLayoutBuilder().setEpoch(1L).addLayoutServer(SERVERS.PORT_0).addLayoutServer(SERVERS.PORT_1).addLayoutServer(SERVERS.PORT_2).addSequencer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_1).addSequencer(SERVERS.PORT_2).buildSegment().buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_1).addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build();
    bootstrapAllServers(originalLayout);
    CorfuRuntime corfuRuntime = new CorfuRuntime();
    corfuRuntime.addLayoutServer(getEndpoint(SERVERS.PORT_0));
    corfuRuntime.addLayoutServer(getEndpoint(SERVERS.PORT_1));
    corfuRuntime.addLayoutServer(getEndpoint(SERVERS.PORT_2));
    corfuRuntime.connect();
    Set<String> failedServers = new HashSet<>();
    failedServers.add(getEndpoint(SERVERS.PORT_2));
    FailureHandlerDispatcher failureHandlerDispatcher = new FailureHandlerDispatcher();
    IFailureHandlerPolicy failureHandlerPolicy = new PurgeFailurePolicy();
    failureHandlerDispatcher.dispatchHandler(failureHandlerPolicy, originalLayout, corfuRuntime, failedServers);
    Layout expectedLayout = new TestLayoutBuilder().setEpoch(2L).addLayoutServer(SERVERS.PORT_0).addLayoutServer(SERVERS.PORT_1).addSequencer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_1).buildSegment().buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_1).addToSegment().addToLayout().build();
    assertThat(getLayoutServer(SERVERS.PORT_0).getCurrentLayout()).isEqualTo(getLayoutServer(SERVERS.PORT_1).getCurrentLayout()).isEqualTo(expectedLayout);
}
Also used : Layout(org.corfudb.runtime.view.Layout) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractViewTest(org.corfudb.runtime.view.AbstractViewTest)

Example 62 with CorfuRuntime

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

the class CheckpointTest method emptyCkpointTest.

@Test
public void emptyCkpointTest() throws Exception {
    final String streamNameA = "mystreamA";
    final String streamNameB = "mystreamB";
    final String author = "periodicCkpoint";
    myRuntime = getDefaultRuntime().connect();
    Map<String, Long> m2A = instantiateMap(streamNameA);
    Map<String, Long> m2B = instantiateMap(streamNameB);
    scheduleConcurrently(1, ignored_task_num -> {
        CorfuRuntime currentRuntime = getMyRuntime();
        for (int i = 0; i < PARAMETERS.NUM_ITERATIONS_VERY_LOW; i++) {
            MultiCheckpointWriter mcw1 = new MultiCheckpointWriter();
            mcw1.addMap((SMRMap) m2A);
            mcw1.addMap((SMRMap) m2B);
            long firstGlobalAddress1 = mcw1.appendCheckpoints(currentRuntime, author);
        }
    });
    scheduleConcurrently(PARAMETERS.NUM_ITERATIONS_LOW, ignored_task_num -> {
        setRuntime();
        Map<String, Long> localm2A = instantiateMap(streamNameA);
        Map<String, Long> localm2B = instantiateMap(streamNameB);
        for (int i = 0; i < PARAMETERS.NUM_ITERATIONS_MODERATE; i++) {
            assertThat(localm2A.get(String.valueOf(i))).isNull();
            assertThat(localm2B.get(String.valueOf(i))).isNull();
        }
    });
    executeScheduled(PARAMETERS.CONCURRENCY_SOME, PARAMETERS.TIMEOUT_LONG);
    // System.out.println("done executeScheduled");
    setRuntime();
    Map<String, Long> localm2A = instantiateMap(streamNameA);
    Map<String, Long> localm2B = instantiateMap(streamNameB);
    for (int i = 0; i < PARAMETERS.NUM_ITERATIONS_MODERATE; i++) {
        assertThat(localm2A.get(String.valueOf(i))).isNull();
        assertThat(localm2B.get(String.valueOf(i))).isNull();
    }
}
Also used : MultiCheckpointWriter(org.corfudb.runtime.MultiCheckpointWriter) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) AbstractObjectTest(org.corfudb.runtime.object.AbstractObjectTest) Test(org.junit.Test)

Example 63 with CorfuRuntime

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

the class CheckpointTest method periodicCkpointTestNoUpdates.

@Test
public void periodicCkpointTestNoUpdates() throws Exception {
    final String streamNameA = "mystreamA";
    final String streamNameB = "mystreamB";
    final String author = "periodicCkpoint";
    myRuntime = getDefaultRuntime().connect();
    Map<String, Long> m2A = instantiateMap(streamNameA);
    Map<String, Long> m2B = instantiateMap(streamNameB);
    // pre-populate map
    for (int i = 0; i < PARAMETERS.NUM_ITERATIONS_MODERATE; i++) {
        m2A.put(String.valueOf(i), (long) i);
        m2B.put(String.valueOf(i), (long) 0);
    }
    scheduleConcurrently(1, ignored_task_num -> {
        CorfuRuntime currentRuntime = getMyRuntime();
        for (int i = 0; i < PARAMETERS.NUM_ITERATIONS_VERY_LOW; i++) {
            MultiCheckpointWriter mcw1 = new MultiCheckpointWriter();
            mcw1.addMap((SMRMap) m2A);
            mcw1.addMap((SMRMap) m2B);
            long firstGlobalAddress1 = mcw1.appendCheckpoints(currentRuntime, author);
        }
    });
    scheduleConcurrently(PARAMETERS.NUM_ITERATIONS_LOW, ignored_task_num -> {
        setRuntime();
        Map<String, Long> localm2A = instantiateMap(streamNameA);
        Map<String, Long> localm2B = instantiateMap(streamNameB);
        for (int i = 0; i < PARAMETERS.NUM_ITERATIONS_MODERATE; i++) {
            assertThat(localm2A.get(String.valueOf(i))).isEqualTo((long) i);
            assertThat(localm2B.get(String.valueOf(i))).isEqualTo((long) 0);
        }
    });
    executeScheduled(PARAMETERS.CONCURRENCY_SOME, PARAMETERS.TIMEOUT_LONG);
    // System.out.println("done executeScheduled");
    setRuntime();
    Map<String, Long> localm2A = instantiateMap(streamNameA);
    Map<String, Long> localm2B = instantiateMap(streamNameB);
    for (int i = 0; i < PARAMETERS.NUM_ITERATIONS_MODERATE; i++) {
        assertThat(localm2A.get(String.valueOf(i))).isEqualTo((long) i);
        assertThat(localm2B.get(String.valueOf(i))).isEqualTo(0L);
    }
}
Also used : MultiCheckpointWriter(org.corfudb.runtime.MultiCheckpointWriter) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) AbstractObjectTest(org.corfudb.runtime.object.AbstractObjectTest) Test(org.junit.Test)

Example 64 with CorfuRuntime

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

the class ManagementServer method getCorfuRuntime.

/**
     * Returns a connected instance of the CorfuRuntime.
     *
     * @return A connected instance of runtime.
     */
public synchronized CorfuRuntime getCorfuRuntime() {
    if (corfuRuntime == null) {
        corfuRuntime = new CorfuRuntime();
        if ((Boolean) opts.get("--enable-tls")) {
            corfuRuntime.enableTls((String) opts.get("--keystore"), (String) opts.get("--keystore-password-file"), (String) opts.get("--truststore"), (String) opts.get("--truststore-password-file"));
            if ((Boolean) opts.get("--enable-sasl-plain-text-auth")) {
                corfuRuntime.enableSaslPlainText((String) opts.get("--sasl-plain-text-username-file"), (String) opts.get("--sasl-plain-text-password-file"));
            }
        }
        // Runtime can be set up either using the layout or the bootstrapEndpoint address.
        if (latestLayout != null)
            latestLayout.getLayoutServers().forEach(ls -> corfuRuntime.addLayoutServer(ls));
        else
            corfuRuntime.addLayoutServer(bootstrapEndpoint);
        corfuRuntime.connect();
        log.info("Corfu Runtime connected successfully");
    }
    return corfuRuntime;
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) CorfuPayloadMsg(org.corfudb.protocols.wireprotocol.CorfuPayloadMsg) Getter(lombok.Getter) FailureDetectorMsg(org.corfudb.protocols.wireprotocol.FailureDetectorMsg) MethodHandles(java.lang.invoke.MethodHandles) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CorfuMsgType(org.corfudb.protocols.wireprotocol.CorfuMsgType) Executors(java.util.concurrent.Executors) Layout(org.corfudb.runtime.view.Layout) TimeUnit(java.util.concurrent.TimeUnit) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Slf4j(lombok.extern.slf4j.Slf4j) NodeMetrics(org.corfudb.format.Types.NodeMetrics) Future(java.util.concurrent.Future) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CorfuMsg(org.corfudb.protocols.wireprotocol.CorfuMsg) ManagementClient(org.corfudb.runtime.clients.ManagementClient) Map(java.util.Map) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Collections(java.util.Collections) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 65 with CorfuRuntime

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

the class QuorumReplicationProtocolAdditionalTests method ensureAllUnitsContainData.

@Test
@SuppressWarnings("unchecked")
public void ensureAllUnitsContainData() throws Exception {
    //configure the layout accordingly
    CorfuRuntime r = getDefaultRuntime();
    UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
    byte[] testPayload = "hello world".getBytes();
    r.getAddressSpaceView().write(new TokenResponse(0, 1, Collections.singletonMap(streamA, Address.NO_BACKPOINTER)), testPayload);
    assertThat(r.getAddressSpaceView().read(0L).getPayload(getRuntime())).isEqualTo("hello world".getBytes());
    assertThat(r.getAddressSpaceView().read(0L).containsStream(streamA));
    // Ensure that the data was written to each logunit.
    LogUnitServerAssertions.assertThat(getLogUnit(SERVERS.PORT_0)).matchesDataAtAddress(0, testPayload);
    LogUnitServerAssertions.assertThat(getLogUnit(SERVERS.PORT_1)).matchesDataAtAddress(0, testPayload);
    LogUnitServerAssertions.assertThat(getLogUnit(SERVERS.PORT_2)).matchesDataAtAddress(0, testPayload);
}
Also used : TokenResponse(org.corfudb.protocols.wireprotocol.TokenResponse) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) UUID(java.util.UUID) 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