Search in sources :

Example 16 with IStreamView

use of org.corfudb.runtime.view.stream.IStreamView in project CorfuDB by CorfuDB.

the class StreamViewTest method canReadWriteFromCachedStream.

@Test
@SuppressWarnings("unchecked")
public void canReadWriteFromCachedStream() throws Exception {
    CorfuRuntime r = getDefaultRuntime().connect().setCacheDisabled(false);
    UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
    byte[] testPayload = "hello world".getBytes();
    IStreamView sv = r.getStreamsView().get(streamA);
    sv.append(testPayload);
    assertThat(sv.next().getPayload(getRuntime())).isEqualTo("hello world".getBytes());
    assertThat(sv.next()).isEqualTo(null);
}
Also used : CorfuRuntime(org.corfudb.runtime.CorfuRuntime) UUID(java.util.UUID) IStreamView(org.corfudb.runtime.view.stream.IStreamView) Test(org.junit.Test)

Example 17 with IStreamView

use of org.corfudb.runtime.view.stream.IStreamView in project CorfuDB by CorfuDB.

the class StreamViewTest method streamCanSurviveOverwriteException.

@Test
@SuppressWarnings("unchecked")
public void streamCanSurviveOverwriteException() throws Exception {
    UUID streamA = CorfuRuntime.getStreamID("stream A");
    byte[] testPayload = "hello world".getBytes();
    // read from an address that hasn't been written to
    // causing a hole fill
    r.getAddressSpaceView().read(0L);
    // Write to the stream, and read back. The hole should be filled.
    IStreamView sv = r.getStreamsView().get(streamA);
    sv.append(testPayload);
    assertThat(sv.next().getPayload(getRuntime())).isEqualTo("hello world".getBytes());
    assertThat(sv.next()).isEqualTo(null);
}
Also used : UUID(java.util.UUID) IStreamView(org.corfudb.runtime.view.stream.IStreamView) Test(org.junit.Test)

Example 18 with IStreamView

use of org.corfudb.runtime.view.stream.IStreamView in project CorfuDB by CorfuDB.

the class WriteAfterWriteTransactionContextTest method concurrentModificationsCauseAbort.

@Test
public void concurrentModificationsCauseAbort() {
    getRuntime().setTransactionLogging(true);
    getMap();
    t(1, () -> write("k", "v1"));
    t(1, this::WWTXBegin);
    t(2, this::WWTXBegin);
    t(1, () -> get("k"));
    t(2, () -> get("k"));
    t(1, () -> write("k", "v2"));
    t(2, () -> write("k", "v3"));
    t(1, this::TXEnd);
    t(2, this::TXEnd).assertThrows().isInstanceOf(TransactionAbortedException.class);
    assertThat(getMap()).containsEntry("k", "v2").doesNotContainEntry("k", "v3");
    IStreamView txStream = getRuntime().getStreamsView().get(ObjectsView.TRANSACTION_STREAM_ID);
    List<ILogData> txns = txStream.remainingUpTo(Long.MAX_VALUE);
    assertThat(txns).hasSize(1);
    assertThat(txns.get(0).getLogEntry(getRuntime()).getType()).isEqualTo(LogEntry.LogEntryType.MULTIOBJSMR);
    MultiObjectSMREntry tx1 = (MultiObjectSMREntry) txns.get(0).getLogEntry(getRuntime());
    assertThat(tx1.getEntryMap().size()).isEqualTo(1);
    MultiSMREntry entryMap = tx1.getEntryMap().entrySet().iterator().next().getValue();
    assertThat(entryMap).isNotNull();
    assertThat(entryMap.getUpdates().size()).isEqualTo(1);
    SMREntry smrEntry = entryMap.getUpdates().get(0);
    Object[] args = smrEntry.getSMRArguments();
    assertThat(smrEntry.getSMRMethod()).isEqualTo("put");
    assertThat((String) args[0]).isEqualTo("k");
    assertThat((String) args[1]).isEqualTo("v2");
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) MultiSMREntry(org.corfudb.protocols.logprotocol.MultiSMREntry) SMREntry(org.corfudb.protocols.logprotocol.SMREntry) MultiObjectSMREntry(org.corfudb.protocols.logprotocol.MultiObjectSMREntry) MultiObjectSMREntry(org.corfudb.protocols.logprotocol.MultiObjectSMREntry) IStreamView(org.corfudb.runtime.view.stream.IStreamView) MultiSMREntry(org.corfudb.protocols.logprotocol.MultiSMREntry) Test(org.junit.Test)

Example 19 with IStreamView

use of org.corfudb.runtime.view.stream.IStreamView in project CorfuDB by CorfuDB.

the class ManagementViewTest method testSequencerFailover.

/**
     * Scenario with 3 nodes: SERVERS.PORT_0, SERVERS.PORT_1 and SERVERS.PORT_2.
     * We fail SERVERS.PORT_1 and then wait for one of the other two servers to
     * handle this failure, propose a new layout and we assert on the epoch change.
     * The failure is handled by ConserveFailureHandlerPolicy.
     * No nodes are removed from the layout, but are marked unresponsive.
     * A sequencer failover takes place where the next working sequencer is reset
     * and made the primary.
     *
     * @throws Exception
     */
@Test
public void testSequencerFailover() throws Exception {
    getManagementTestLayout();
    final long beforeFailure = 5L;
    final long afterFailure = 10L;
    IStreamView sv = getCorfuRuntime().getStreamsView().get(CorfuRuntime.getStreamID("streamA"));
    byte[] testPayload = "hello world".getBytes();
    sv.append(testPayload);
    sv.append(testPayload);
    sv.append(testPayload);
    sv.append(testPayload);
    sv.append(testPayload);
    assertThat(getSequencer(SERVERS.PORT_1).getGlobalLogTail().get()).isEqualTo(beforeFailure);
    assertThat(getSequencer(SERVERS.PORT_0).getGlobalLogTail().get()).isEqualTo(0L);
    induceSequencerFailureAndWait();
    // verify that a failover sequencer was started with the correct starting-tail
    //
    assertThat(getSequencer(SERVERS.PORT_0).getGlobalLogTail().get()).isEqualTo(beforeFailure);
    sv.append(testPayload);
    sv.append(testPayload);
    sv.append(testPayload);
    sv.append(testPayload);
    sv.append(testPayload);
    // verify the failover layout
    //
    Layout expectedLayout = new TestLayoutBuilder().setEpoch(2L).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_2).addToSegment().addToLayout().addUnresponsiveServer(SERVERS.PORT_1).build();
    assertThat(getCorfuRuntime().getLayoutView().getLayout()).isEqualTo(expectedLayout);
    // verify that the new sequencer is advancing the tail properly
    assertThat(getSequencer(SERVERS.PORT_0).getGlobalLogTail().get()).isEqualTo(afterFailure);
    // sanity check that no other sequencer is active
    assertThat(getSequencer(SERVERS.PORT_2).getGlobalLogTail().get()).isEqualTo(0L);
}
Also used : TestLayoutBuilder(org.corfudb.infrastructure.TestLayoutBuilder) IStreamView(org.corfudb.runtime.view.stream.IStreamView) Test(org.junit.Test)

Aggregations

IStreamView (org.corfudb.runtime.view.stream.IStreamView)19 Test (org.junit.Test)18 CorfuRuntime (org.corfudb.runtime.CorfuRuntime)11 UUID (java.util.UUID)10 MultiObjectSMREntry (org.corfudb.protocols.logprotocol.MultiObjectSMREntry)3 MultiSMREntry (org.corfudb.protocols.logprotocol.MultiSMREntry)3 SMREntry (org.corfudb.protocols.logprotocol.SMREntry)3 ILogData (org.corfudb.protocols.wireprotocol.ILogData)3 TypeToken (com.google.common.reflect.TypeToken)2 TestLayoutBuilder (org.corfudb.infrastructure.TestLayoutBuilder)2 TokenResponse (org.corfudb.protocols.wireprotocol.TokenResponse)2 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Semaphore (java.util.concurrent.Semaphore)1 LogUnitServer (org.corfudb.infrastructure.LogUnitServer)1 TestRule (org.corfudb.runtime.clients.TestRule)1 SMRMap (org.corfudb.runtime.collections.SMRMap)1 AbstractViewTest (org.corfudb.runtime.view.AbstractViewTest)1