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);
}
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);
}
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");
}
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);
}
Aggregations