Search in sources :

Example 16 with CorfuRuntime

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

the class CheckpointTest method periodicCkpointTest.

@Test
public void periodicCkpointTest() 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 -> {
        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)) == null || localm2A.get(String.valueOf(i)) == (long) i).isTrue();
            assertThat(localm2B.get(String.valueOf(i)) == null || localm2B.get(String.valueOf(i)) == (long) 0).isTrue();
        }
    });
    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 17 with CorfuRuntime

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

the class LayoutViewTest method canTolerateLayoutServerFailure.

@Test
public void canTolerateLayoutServerFailure() throws Exception {
    addServer(SERVERS.PORT_0);
    addServer(SERVERS.PORT_1);
    bootstrapAllServers(new TestLayoutBuilder().setEpoch(1L).addLayoutServer(SERVERS.PORT_0).addLayoutServer(SERVERS.PORT_1).addSequencer(SERVERS.PORT_0).buildSegment().buildStripe().addLogUnit(SERVERS.PORT_0).addToSegment().addToLayout().build());
    CorfuRuntime r = getRuntime().connect();
    // Fail the network link between the client and test server
    addServerRule(SERVERS.PORT_1, new TestRule().always().drop());
    r.invalidateLayout();
    r.getStreamsView().get(CorfuRuntime.getStreamID("hi")).hasNext();
}
Also used : TestRule(org.corfudb.runtime.clients.TestRule) TestLayoutBuilder(org.corfudb.infrastructure.TestLayoutBuilder) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test)

Example 18 with CorfuRuntime

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

the class LayoutViewTest method reconfigurationDuringDataOperations.

/**
     * Fail a server and reconfigure
     * while data operations are going on.
     * Details:
     * Start with a configuration of 3 servers SERVERS.PORT_0, SERVERS.PORT_1, SERVERS.PORT_2.
     * Perform data operations. Fail SERVERS.PORT_1 and reconfigure to have only SERVERS.PORT_0 and SERVERS.PORT_2.
     * Perform data operations while the reconfiguration is going on. The operations should
     * be stuck till the new configuration is chosen and then complete after that.
     * FIXME: We cannot failover the server with the primary sequencer yet.
     *
     * @throws Exception
     */
@Test
public void reconfigurationDuringDataOperations() throws Exception {
    addServer(SERVERS.PORT_0);
    addServer(SERVERS.PORT_1);
    addServer(SERVERS.PORT_2);
    Layout l = 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(l);
    CorfuRuntime corfuRuntime = getRuntime(l).connect();
    // Thread to reconfigure the layout
    CountDownLatch startReconfigurationLatch = new CountDownLatch(1);
    CountDownLatch layoutReconfiguredLatch = new CountDownLatch(1);
    Thread t = new Thread(() -> {
        try {
            startReconfigurationLatch.await();
            corfuRuntime.invalidateLayout();
            // Fail the network link between the client and test server
            addServerRule(SERVERS.PORT_1, new TestRule().always().drop());
            // New layout removes the failed server SERVERS.PORT_0
            Layout newLayout = new TestLayoutBuilder().setEpoch(l.getEpoch() + 1).addLayoutServer(SERVERS.PORT_0).addLayoutServer(SERVERS.PORT_2).addSequencer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_2).buildSegment().buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build();
            newLayout.setRuntime(corfuRuntime);
            //TODO need to figure out if we can move to
            //update layout
            newLayout.moveServersToEpoch();
            corfuRuntime.getLayoutView().updateLayout(newLayout, newLayout.getEpoch());
            corfuRuntime.invalidateLayout();
            log.debug("layout updated new layout {}", corfuRuntime.getLayoutView().getLayout());
            layoutReconfiguredLatch.countDown();
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
    t.start();
    // verify writes and reads happen before and after the reconfiguration
    IStreamView sv = corfuRuntime.getStreamsView().get(CorfuRuntime.getStreamID("streamA"));
    // This append will happen before the reconfiguration while the read for this append
    // will happen after reconfiguration
    writeAndReadStream(corfuRuntime, sv, startReconfigurationLatch, layoutReconfiguredLatch);
    // Write and read after reconfiguration.
    writeAndReadStream(corfuRuntime, sv, startReconfigurationLatch, layoutReconfiguredLatch);
    t.join();
}
Also used : TestRule(org.corfudb.runtime.clients.TestRule) TestLayoutBuilder(org.corfudb.infrastructure.TestLayoutBuilder) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) CountDownLatch(java.util.concurrent.CountDownLatch) IStreamView(org.corfudb.runtime.view.stream.IStreamView) Test(org.junit.Test)

Example 19 with CorfuRuntime

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

the class LayoutViewTest method canGetLayout.

//@Test
public void canGetLayout() {
    CorfuRuntime r = getDefaultRuntime().connect();
    Layout l = r.getLayoutView().getCurrentLayout();
    assertThat(l.asJSONString()).isNotNull();
}
Also used : CorfuRuntime(org.corfudb.runtime.CorfuRuntime)

Example 20 with CorfuRuntime

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

the class ManagementViewTest method setAggressiveTimeouts.

/**
     * Sets aggressive timeouts for all the router endpoints on all the runtimes.
     * <p>
     * @param layout        Layout to get all server endpoints.
     * @param corfuRuntimes All runtimes whose routers' timeouts are to be set.
     */
public void setAggressiveTimeouts(Layout layout, CorfuRuntime... corfuRuntimes) {
    layout.getAllServers().forEach(routerEndpoint -> {
        for (CorfuRuntime runtime : corfuRuntimes) {
            runtime.getRouter(routerEndpoint).setTimeoutConnect(PARAMETERS.TIMEOUT_VERY_SHORT.toMillis());
            runtime.getRouter(routerEndpoint).setTimeoutResponse(PARAMETERS.TIMEOUT_VERY_SHORT.toMillis());
            runtime.getRouter(routerEndpoint).setTimeoutRetry(PARAMETERS.TIMEOUT_VERY_SHORT.toMillis());
        }
    });
}
Also used : CorfuRuntime(org.corfudb.runtime.CorfuRuntime)

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