Search in sources :

Example 1 with TokenResponse

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

the class QuorumReplicationProtocolAdditionalTests method canReadWriteToMultiple.

@Test
@SuppressWarnings("unchecked")
public void canReadWriteToMultiple() 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, r.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();
    assertThat((IMetadata.DataRank) r.getAddressSpaceView().read(0L).getMetadataMap().get(IMetadata.LogUnitMetadataType.RANK)).isNotNull();
}
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)

Example 2 with TokenResponse

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

the class QuorumReplicationProtocolAdditionalTests method canReadWriteConcurrent.

@Test
@SuppressWarnings("unchecked")
public void canReadWriteConcurrent() 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, r.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);
    assertNotNull(r.getAddressSpaceView().read(0L).getRank());
    assertThat((IMetadata.DataRank) r.getAddressSpaceView().read(0L).getMetadataMap().get(IMetadata.LogUnitMetadataType.RANK)).isNotNull();
}
Also used : TokenResponse(org.corfudb.protocols.wireprotocol.TokenResponse) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test) AbstractViewTest(org.corfudb.runtime.view.AbstractViewTest)

Example 3 with TokenResponse

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

the class StreamViewTest method streamWithHoleFill.

@Test
@SuppressWarnings("unchecked")
public void streamWithHoleFill() throws Exception {
    UUID streamA = CorfuRuntime.getStreamID("stream A");
    byte[] testPayload = "hello world".getBytes();
    byte[] testPayload2 = "hello world2".getBytes();
    IStreamView sv = r.getStreamsView().get(streamA);
    sv.append(testPayload);
    //generate a stream hole
    TokenResponse tr = r.getSequencerView().nextToken(Collections.singleton(streamA), 1);
    // read from an address that hasn't been written to
    // causing a hole fill
    r.getAddressSpaceView().read(tr.getToken().getTokenValue());
    tr = r.getSequencerView().nextToken(Collections.singleton(streamA), 1);
    // read from an address that hasn't been written to
    // causing a hole fill
    r.getAddressSpaceView().read(tr.getToken().getTokenValue());
    sv.append(testPayload2);
    //make sure we can still read the stream.
    assertThat(sv.next().getPayload(getRuntime())).isEqualTo(testPayload);
    assertThat(sv.next().getPayload(getRuntime())).isEqualTo(testPayload2);
}
Also used : TokenResponse(org.corfudb.protocols.wireprotocol.TokenResponse) UUID(java.util.UUID) IStreamView(org.corfudb.runtime.view.stream.IStreamView) Test(org.junit.Test)

Example 4 with TokenResponse

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

the class QuorumReplicationProtocolAdditionalTests method checkReadOnEmptyPosition.

@Test
@SuppressWarnings("unchecked")
public void checkReadOnEmptyPosition() throws Exception {
    //configure the layout accordingly
    CorfuRuntime r = getDefaultRuntime();
    LogUnitServer u0 = getLogUnit(SERVERS.PORT_0);
    UUID streamA = CorfuRuntime.getStreamID("stream A");
    byte[] testPayload = "hello world".getBytes();
    //generate a stream hole
    TokenResponse tr = r.getSequencerView().nextToken(Collections.singleton(streamA), 1);
    IStreamView sv = r.getStreamsView().get(streamA);
    sv.append(testPayload);
    tr = r.getSequencerView().nextToken(Collections.singleton(streamA), 1);
    //make sure we can still read the stream.
    assertThat(sv.next().getPayload(getRuntime())).isEqualTo(testPayload);
    int address = 0;
    assertThat(r.getAddressSpaceView().read(address++).getType()).isEqualTo(DataType.HOLE);
    assertThat(r.getAddressSpaceView().read(address++).getType()).isEqualTo(DataType.DATA);
    assertThat(r.getAddressSpaceView().read(address++).getType()).isEqualTo(DataType.HOLE);
//      TODO(mwei) - fix me
//      assertThat(r.getAddressSpaceView().read(address++).getType()).isEqualTo(DataType.EMPTY);
}
Also used : TokenResponse(org.corfudb.protocols.wireprotocol.TokenResponse) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) LogUnitServer(org.corfudb.infrastructure.LogUnitServer) UUID(java.util.UUID) IStreamView(org.corfudb.runtime.view.stream.IStreamView) Test(org.junit.Test) AbstractViewTest(org.corfudb.runtime.view.AbstractViewTest)

Example 5 with TokenResponse

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

the class CheckpointSmokeTest method writeCheckpointRecords.

private void writeCheckpointRecords(UUID streamId, String checkpointAuthor, UUID checkpointId, Object[] objects, Runnable l1, Runnable l2, boolean write1, boolean write2, boolean write3) throws Exception {
    BackpointerStreamView sv = new BackpointerStreamView(r, streamId);
    Map<CheckpointEntry.CheckpointDictKey, String> mdKV = new HashMap<>();
    mdKV.put(CheckpointEntry.CheckpointDictKey.START_TIME, "The perfect time");
    // Write cp #1 of 3
    if (write1) {
        TokenResponse tokResp1 = r.getSequencerView().nextToken(Collections.singleton(streamId), 0);
        long addr1 = tokResp1.getToken().getTokenValue();
        mdKV.put(CheckpointEntry.CheckpointDictKey.START_LOG_ADDRESS, Long.toString(addr1 + 1));
        CheckpointEntry cp1 = new CheckpointEntry(CheckpointEntry.CheckpointEntryType.START, checkpointAuthor, checkpointId, mdKV, null);
        sv.append(cp1, null, null);
    }
    // Interleaving opportunity #1
    l1.run();
    // Write cp #2 of 3
    if (write2) {
        MultiSMREntry smrEntries = new MultiSMREntry();
        if (objects != null) {
            for (int i = 0; i < objects.length; i++) {
                smrEntries.addTo(new SMREntry("put", (Object[]) objects[i], Serializers.JSON));
            }
        }
        CheckpointEntry cp2 = new CheckpointEntry(CheckpointEntry.CheckpointEntryType.CONTINUATION, checkpointAuthor, checkpointId, mdKV, smrEntries);
        sv.append(cp2, null, null);
    }
    // Interleaving opportunity #2
    l2.run();
    // Write cp #3 of 3
    if (write3) {
        CheckpointEntry cp3 = new CheckpointEntry(CheckpointEntry.CheckpointEntryType.END, checkpointAuthor, checkpointId, mdKV, null);
        sv.append(cp3, null, null);
    }
}
Also used : CheckpointEntry(org.corfudb.protocols.logprotocol.CheckpointEntry) TokenResponse(org.corfudb.protocols.wireprotocol.TokenResponse) MultiSMREntry(org.corfudb.protocols.logprotocol.MultiSMREntry) SMREntry(org.corfudb.protocols.logprotocol.SMREntry) BackpointerStreamView(org.corfudb.runtime.view.stream.BackpointerStreamView) MultiSMREntry(org.corfudb.protocols.logprotocol.MultiSMREntry)

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