Search in sources :

Example 31 with CorfuRuntime

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

the class ChainReplicationViewTest method canReadWriteToSingleConcurrent.

@Test
@SuppressWarnings("unchecked")
public void canReadWriteToSingleConcurrent() throws Exception {
    CorfuRuntime r = getDefaultRuntime();
    final int numberThreads = 5;
    final int numberRecords = 1_000;
    scheduleConcurrently(numberThreads, threadNumber -> {
        int base = threadNumber * numberRecords;
        for (int i = base; i < base + numberRecords; i++) {
            r.getAddressSpaceView().write(new TokenResponse((long) i, runtime.getLayoutView().getLayout().getEpoch(), Collections.singletonMap(CorfuRuntime.getStreamID("a"), Address.NO_BACKPOINTER)), Integer.toString(i).getBytes());
        }
    });
    executeScheduled(numberThreads, PARAMETERS.TIMEOUT_LONG);
    scheduleConcurrently(numberThreads, threadNumber -> {
        int base = threadNumber * numberRecords;
        for (int i = base; i < base + numberRecords; i++) {
            assertThat(r.getAddressSpaceView().read(i).getPayload(getRuntime())).isEqualTo(Integer.toString(i).getBytes());
        }
    });
    executeScheduled(numberThreads, PARAMETERS.TIMEOUT_LONG);
}
Also used : TokenResponse(org.corfudb.protocols.wireprotocol.TokenResponse) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test)

Example 32 with CorfuRuntime

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

the class LayoutSealTest method getLayout.

/**
     * Gets a layout with 5 Servers:
     * PORT_0, PORT_1, PORT_2, PORT_3, PORT_4
     * Sets the replication view as specified.
     *
     * @param replicationMode Replication view to set all segments in the layout with.
     * @return  Built layout with a connected runtime.
     */
public Layout getLayout(Layout.ReplicationMode replicationMode) {
    addServer(SERVERS.PORT_0);
    addServer(SERVERS.PORT_1);
    addServer(SERVERS.PORT_2);
    addServer(SERVERS.PORT_3);
    addServer(SERVERS.PORT_4);
    Layout l = new TestLayoutBuilder().setEpoch(1).addLayoutServer(SERVERS.PORT_0).addLayoutServer(SERVERS.PORT_1).addLayoutServer(SERVERS.PORT_2).addSequencer(SERVERS.PORT_0).buildSegment().setReplicationMode(replicationMode).buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_1).addLogUnit(SERVERS.PORT_2).addToSegment().buildStripe().addLogUnit(SERVERS.PORT_3).addLogUnit(SERVERS.PORT_4).addToSegment().addToLayout().build();
    bootstrapAllServers(l);
    CorfuRuntime corfuRuntime = getRuntime(l).connect();
    l.setRuntime(corfuRuntime);
    setAggressiveTimeouts(l);
    return l;
}
Also used : TestLayoutBuilder(org.corfudb.infrastructure.TestLayoutBuilder) CorfuRuntime(org.corfudb.runtime.CorfuRuntime)

Example 33 with CorfuRuntime

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

the class CorfuSMRObjectProxyTest method canOpenObjectWithTwoRuntimes.

@Test
public void canOpenObjectWithTwoRuntimes() throws Exception {
    getDefaultRuntime();
    final int TEST_VALUE = 42;
    TestClass testClass = (TestClass) instantiateCorfuObject(new TypeToken<TestClass>() {
    }, "test");
    testClass.set(TEST_VALUE);
    assertThat(testClass.get()).isEqualTo(TEST_VALUE);
    CorfuRuntime runtime2 = new CorfuRuntime(getDefaultEndpoint());
    runtime2.connect();
    TestClass testClass2 = (TestClass) instantiateCorfuObject(runtime2, new TypeToken<TestClass>() {
    }, "test");
    assertThat(testClass2.get()).isEqualTo(TEST_VALUE);
}
Also used : TypeToken(com.google.common.reflect.TypeToken) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test)

Example 34 with CorfuRuntime

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

the class CmdletIT method testCorfuSequencerCmdlet.

/**
     * Testing corfu_sequencer next-token and latest
     *
     * @throws Exception
     */
@Test
public void testCorfuSequencerCmdlet() throws Exception {
    corfuServerProcess = new CorfuServerRunner().setPort(PORT).runServer();
    final String streamA = "streamA";
    CorfuRuntime runtime = createRuntime(ENDPOINT);
    String commandNextToken = CORFU_PROJECT_DIR + "bin/corfu_sequencer -i " + streamA + " -c " + ENDPOINT + " next-token 3";
    runCmdletGetOutput(commandNextToken);
    Token token = runtime.getSequencerView().nextToken(Collections.singleton(CorfuRuntime.getStreamID(streamA)), 0).getToken();
    String commandLatest = CORFU_PROJECT_DIR + "bin/corfu_sequencer -i " + streamA + " -c " + ENDPOINT + " latest";
    String output = runCmdletGetOutput(commandLatest);
    assertThat(output.contains(token.toString())).isTrue();
    shutdownCorfuServer(corfuServerProcess);
}
Also used : CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Token(org.corfudb.protocols.wireprotocol.Token) Test(org.junit.Test)

Example 35 with CorfuRuntime

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

the class CmdletIT method testCorfuStreamCmdlet.

/**
     * Testing corfu_stream append and read.
     *
     * @throws Exception
     */
@Test
public void testCorfuStreamCmdlet() throws Exception {
    corfuServerProcess = new CorfuServerRunner().setPort(PORT).runServer();
    final String streamA = "streamA";
    CorfuRuntime runtime = createRuntime(ENDPOINT);
    IStreamView streamViewA = runtime.getStreamsView().get(CorfuRuntime.getStreamID(streamA));
    String payload1 = "Hello";
    streamViewA.append(payload1.getBytes());
    String commandRead = CORFU_PROJECT_DIR + "bin/corfu_stream -i " + streamA + " -c " + ENDPOINT + " read";
    String output = runCmdletGetOutput(commandRead);
    assertThat(output.contains(payload1)).isTrue();
    String payload2 = "World";
    String commandAppend = "echo '" + payload2 + "' | " + CORFU_PROJECT_DIR + "bin/corfu_stream -i " + streamA + " -c " + ENDPOINT + " append";
    runCmdletGetOutput(commandAppend);
    assertThat(streamViewA.next().getPayload(runtime)).isEqualTo(payload1.getBytes());
    assertThat(streamViewA.next().getPayload(runtime)).isEqualTo((payload2 + "\n").getBytes());
    assertThat(streamViewA.next()).isNull();
    shutdownCorfuServer(corfuServerProcess);
}
Also used : CorfuRuntime(org.corfudb.runtime.CorfuRuntime) IStreamView(org.corfudb.runtime.view.stream.IStreamView) 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