Search in sources :

Example 6 with TokenResponse

use of org.corfudb.protocols.wireprotocol.TokenResponse in project CorfuDB by CorfuDB.

the class ChainReplicationViewTest method ensureAllUnitsContainData.

@Test
@SuppressWarnings("unchecked")
public void ensureAllUnitsContainData() throws Exception {
    addServer(SERVERS.PORT_0);
    addServer(SERVERS.PORT_1);
    addServer(SERVERS.PORT_2);
    bootstrapAllServers(new TestLayoutBuilder().addLayoutServer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_0).buildSegment().setReplicationMode(Layout.ReplicationMode.CHAIN_REPLICATION).buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_1).addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build());
    //configure the layout accordingly
    CorfuRuntime r = getRuntime().connect();
    UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
    byte[] testPayload = "hello world".getBytes();
    r.getAddressSpaceView().write(new TokenResponse(0, 0, 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.
    assertThat(getLogUnit(SERVERS.PORT_0)).matchesDataAtAddress(0, testPayload);
    assertThat(getLogUnit(SERVERS.PORT_1)).matchesDataAtAddress(0, testPayload);
    assertThat(getLogUnit(SERVERS.PORT_2)).matchesDataAtAddress(0, testPayload);
}
Also used : TestLayoutBuilder(org.corfudb.infrastructure.TestLayoutBuilder) TokenResponse(org.corfudb.protocols.wireprotocol.TokenResponse) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) UUID(java.util.UUID) Test(org.junit.Test)

Example 7 with TokenResponse

use of org.corfudb.protocols.wireprotocol.TokenResponse in project CorfuDB by CorfuDB.

the class ChainReplicationViewTest method canReadWriteToMultiple.

@Test
@SuppressWarnings("unchecked")
public void canReadWriteToMultiple() throws Exception {
    addServer(SERVERS.PORT_0);
    addServer(SERVERS.PORT_1);
    addServer(SERVERS.PORT_2);
    bootstrapAllServers(new TestLayoutBuilder().addLayoutServer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_0).buildSegment().setReplicationMode(Layout.ReplicationMode.CHAIN_REPLICATION).buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_1).addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build());
    //configure the layout accordingly
    CorfuRuntime r = getRuntime().connect();
    UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
    byte[] testPayload = "hello world".getBytes();
    r.getAddressSpaceView().write(new TokenResponse(0, runtime.getLayoutView().getLayout().getEpoch(), 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)).isTrue();
}
Also used : TestLayoutBuilder(org.corfudb.infrastructure.TestLayoutBuilder) TokenResponse(org.corfudb.protocols.wireprotocol.TokenResponse) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) UUID(java.util.UUID) Test(org.junit.Test)

Example 8 with TokenResponse

use of org.corfudb.protocols.wireprotocol.TokenResponse 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 9 with TokenResponse

use of org.corfudb.protocols.wireprotocol.TokenResponse in project CorfuDB by CorfuDB.

the class CheckpointWriter method startGlobalSnapshotTxn.

public static long startGlobalSnapshotTxn(CorfuRuntime rt) {
    TokenResponse tokenResponse = rt.getSequencerView().nextToken(Collections.EMPTY_SET, 0);
    long globalTail = tokenResponse.getToken().getTokenValue();
    rt.getObjectsView().TXBuild().setType(TransactionType.SNAPSHOT).setSnapshot(globalTail).begin();
    AbstractTransactionalContext context = TransactionalContext.getCurrentContext();
    return context.getSnapshotTimestamp();
}
Also used : TokenResponse(org.corfudb.protocols.wireprotocol.TokenResponse) AbstractTransactionalContext(org.corfudb.runtime.object.transactions.AbstractTransactionalContext)

Example 10 with TokenResponse

use of org.corfudb.protocols.wireprotocol.TokenResponse in project CorfuDB by CorfuDB.

the class QuorumReplicationProtocolAdditionalTests method canReadWrite.

@Test
@SuppressWarnings("unchecked")
public void canReadWrite() throws Exception {
    CorfuRuntime r = getDefaultRuntime();
    UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
    byte[] testPayload = "hello world".getBytes();
    r.getAddressSpaceView().write(new TokenResponse(0, r.getLayoutView().getLayout().getEpoch(), Collections.singletonMap(streamA, Address.NO_BACKPOINTER)), testPayload);
    ILogData x = r.getAddressSpaceView().read(0);
    assertNotNull(x.getRank());
    assertThat(r.getAddressSpaceView().read(0L).getPayload(r)).isEqualTo("hello world".getBytes());
    assertThat(r.getAddressSpaceView().read(0L).containsStream(streamA)).isTrue();
    assertThat((IMetadata.DataRank) r.getAddressSpaceView().read(0L).getMetadataMap().get(IMetadata.LogUnitMetadataType.RANK)).isNotNull();
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) 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

TokenResponse (org.corfudb.protocols.wireprotocol.TokenResponse)13 Test (org.junit.Test)10 CorfuRuntime (org.corfudb.runtime.CorfuRuntime)9 UUID (java.util.UUID)8 AbstractViewTest (org.corfudb.runtime.view.AbstractViewTest)5 TestLayoutBuilder (org.corfudb.infrastructure.TestLayoutBuilder)2 IStreamView (org.corfudb.runtime.view.stream.IStreamView)2 LogUnitServer (org.corfudb.infrastructure.LogUnitServer)1 CheckpointEntry (org.corfudb.protocols.logprotocol.CheckpointEntry)1 MultiSMREntry (org.corfudb.protocols.logprotocol.MultiSMREntry)1 SMREntry (org.corfudb.protocols.logprotocol.SMREntry)1 ILogData (org.corfudb.protocols.wireprotocol.ILogData)1 AbstractTransactionalContext (org.corfudb.runtime.object.transactions.AbstractTransactionalContext)1 BackpointerStreamView (org.corfudb.runtime.view.stream.BackpointerStreamView)1