Search in sources :

Example 11 with CorfuRuntime

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

the class SequencerViewTest method canAcquireFirstToken.

@Test
public void canAcquireFirstToken() {
    CorfuRuntime r = getDefaultRuntime();
    assertThat(r.getSequencerView().nextToken(Collections.emptySet(), 1).getToken()).isEqualTo(new Token(0L, 0L));
}
Also used : CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Token(org.corfudb.protocols.wireprotocol.Token) Test(org.junit.Test)

Example 12 with CorfuRuntime

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

the class SequencerViewTest method tokensAreIncrementing.

@Test
public void tokensAreIncrementing() {
    CorfuRuntime r = getDefaultRuntime();
    assertThat(r.getSequencerView().nextToken(Collections.emptySet(), 1).getToken()).isEqualTo(new Token(0L, 0L));
    assertThat(r.getSequencerView().nextToken(Collections.emptySet(), 1).getToken()).isEqualTo(new Token(1L, 0L));
}
Also used : CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Token(org.corfudb.protocols.wireprotocol.Token) Test(org.junit.Test)

Example 13 with CorfuRuntime

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

the class SequencerViewTest method checkTokenWorks.

@Test
public void checkTokenWorks() {
    CorfuRuntime r = getDefaultRuntime();
    assertThat(r.getSequencerView().nextToken(Collections.emptySet(), 1).getToken()).isEqualTo(new Token(0L, 0L));
    assertThat(r.getSequencerView().nextToken(Collections.emptySet(), 0).getToken()).isEqualTo(new Token(0L, 0L));
}
Also used : CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Token(org.corfudb.protocols.wireprotocol.Token) Test(org.junit.Test)

Example 14 with CorfuRuntime

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

the class ManagementServer method failureDetectorTask.

/**
     * This contains the complete failure detection and handling mechanism.
     * <p>
     * It first checks whether the current node is bootstrapped.
     * If not, it continues checking in intervals of 1 second.
     * If yes, it sets up the corfuRuntime and continues execution
     * of the policy.
     * <p>
     * It executes the policy which detects and reports failures.
     * Once detected, it triggers the trigger handler which takes care of
     * dispatching the appropriate handler.
     * <p>
     * Currently executing the periodicPollPolicy.
     * It executes the the polling at an interval of every 1 second.
     * After every poll it checks for any failures detected.
     */
private void failureDetectorTask() {
    CorfuRuntime corfuRuntime = getCorfuRuntime();
    corfuRuntime.invalidateLayout();
    // Fetch the latest layout view through the runtime.
    safeUpdateLayout(corfuRuntime.getLayoutView().getLayout());
    // Execute the failure detection policy once.
    failureDetectorPolicy.executePolicy(latestLayout, corfuRuntime);
    // Get the server status from the policy and check for failures.
    PollReport pollReport = failureDetectorPolicy.getServerStatus();
    // Analyze the poll report and trigger failure handler if needed.
    analyzePollReportAndTriggerHandler(pollReport);
}
Also used : CorfuRuntime(org.corfudb.runtime.CorfuRuntime)

Example 15 with CorfuRuntime

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

the class StreamIT method simpleStreamTest.

//    @Test
public void simpleStreamTest() throws Exception {
    Process corfuServerProcess = new CorfuServerRunner().setHost(corfuSingleNodeHost).setPort(corfuSingleNodePort).runServer();
    CorfuRuntime rt = createDefaultRuntime();
    rt.setCacheDisabled(true);
    Random rand = new Random();
    UUID streamId = CorfuRuntime.getStreamID(Integer.toString(rand.nextInt()));
    IStreamView s1 = rt.getStreamsView().get(streamId);
    // Verify that the stream is empty
    assertThat(s1.hasNext()).isFalse();
    // Generate and append random data
    int entrySize = Integer.valueOf(PROPERTIES.getProperty("largeEntrySize"));
    final int numEntries = 100;
    byte[][] data = new byte[numEntries][entrySize];
    for (int x = 0; x < numEntries; x++) {
        rand.nextBytes(data[x]);
        s1.append(data[x]);
    }
    // Read back the data and verify it is correct
    for (int x = 0; x < numEntries; x++) {
        ILogData entry = s1.nextUpTo(x);
        byte[] tmp = (byte[]) entry.getPayload(rt);
        assertThat(tmp).isEqualTo(data[x]);
    }
    assertThat(shutdownCorfuServer(corfuServerProcess)).isTrue();
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) Random(java.util.Random) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) UUID(java.util.UUID) IStreamView(org.corfudb.runtime.view.stream.IStreamView)

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