use of org.corfudb.runtime.view.stream.IStreamView in project CorfuDB by CorfuDB.
the class StreamViewTest method canReadWriteFromStreamWithoutBackpointers.
@Test
@SuppressWarnings("unchecked")
public void canReadWriteFromStreamWithoutBackpointers() throws Exception {
r.setBackpointersDisabled(true);
UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
byte[] testPayload = "hello world".getBytes();
IStreamView sv = r.getStreamsView().get(streamA);
scheduleConcurrently(PARAMETERS.NUM_ITERATIONS_LOW, i -> sv.append(testPayload));
executeScheduled(PARAMETERS.CONCURRENCY_SOME, PARAMETERS.TIMEOUT_NORMAL);
scheduleConcurrently(PARAMETERS.NUM_ITERATIONS_LOW, i -> assertThat(sv.next().getPayload(getRuntime())).isEqualTo("hello world".getBytes()));
executeScheduled(PARAMETERS.CONCURRENCY_SOME, PARAMETERS.TIMEOUT_NORMAL);
assertThat(sv.next()).isEqualTo(null);
}
use of org.corfudb.runtime.view.stream.IStreamView in project CorfuDB by CorfuDB.
the class StreamViewTest method streamWillHoleFill.
@Test
@SuppressWarnings("unchecked")
public void streamWillHoleFill() throws Exception {
//begin tests
UUID streamA = CorfuRuntime.getStreamID("stream A");
byte[] testPayload = "hello world".getBytes();
// Generate a hole.
r.getSequencerView().nextToken(Collections.singleton(streamA), 1);
// 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 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();
}
use of org.corfudb.runtime.view.stream.IStreamView in project CorfuDB by CorfuDB.
the class LayoutViewTest method reconfigurationDuringDataOperations.
/**
* Fail a server and reconfigure
* while data operations are going on.
* Details:
* Start with a configuration of 3 servers SERVERS.PORT_0, SERVERS.PORT_1, SERVERS.PORT_2.
* Perform data operations. Fail SERVERS.PORT_1 and reconfigure to have only SERVERS.PORT_0 and SERVERS.PORT_2.
* Perform data operations while the reconfiguration is going on. The operations should
* be stuck till the new configuration is chosen and then complete after that.
* FIXME: We cannot failover the server with the primary sequencer yet.
*
* @throws Exception
*/
@Test
public void reconfigurationDuringDataOperations() throws Exception {
addServer(SERVERS.PORT_0);
addServer(SERVERS.PORT_1);
addServer(SERVERS.PORT_2);
Layout l = new TestLayoutBuilder().setEpoch(1L).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_1).addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build();
bootstrapAllServers(l);
CorfuRuntime corfuRuntime = getRuntime(l).connect();
// Thread to reconfigure the layout
CountDownLatch startReconfigurationLatch = new CountDownLatch(1);
CountDownLatch layoutReconfiguredLatch = new CountDownLatch(1);
Thread t = new Thread(() -> {
try {
startReconfigurationLatch.await();
corfuRuntime.invalidateLayout();
// Fail the network link between the client and test server
addServerRule(SERVERS.PORT_1, new TestRule().always().drop());
// New layout removes the failed server SERVERS.PORT_0
Layout newLayout = new TestLayoutBuilder().setEpoch(l.getEpoch() + 1).addLayoutServer(SERVERS.PORT_0).addLayoutServer(SERVERS.PORT_2).addSequencer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_2).buildSegment().buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build();
newLayout.setRuntime(corfuRuntime);
//TODO need to figure out if we can move to
//update layout
newLayout.moveServersToEpoch();
corfuRuntime.getLayoutView().updateLayout(newLayout, newLayout.getEpoch());
corfuRuntime.invalidateLayout();
log.debug("layout updated new layout {}", corfuRuntime.getLayoutView().getLayout());
layoutReconfiguredLatch.countDown();
} catch (Exception e) {
e.printStackTrace();
}
});
t.start();
// verify writes and reads happen before and after the reconfiguration
IStreamView sv = corfuRuntime.getStreamsView().get(CorfuRuntime.getStreamID("streamA"));
// This append will happen before the reconfiguration while the read for this append
// will happen after reconfiguration
writeAndReadStream(corfuRuntime, sv, startReconfigurationLatch, layoutReconfiguredLatch);
// Write and read after reconfiguration.
writeAndReadStream(corfuRuntime, sv, startReconfigurationLatch, layoutReconfiguredLatch);
t.join();
}
use of org.corfudb.runtime.view.stream.IStreamView in project CorfuDB by CorfuDB.
the class ObjectsViewTest method unrelatedStreamDoesNotConflict.
@Test
@SuppressWarnings("unchecked")
public void unrelatedStreamDoesNotConflict() throws Exception {
//begin tests
CorfuRuntime r = getDefaultRuntime();
Map<String, String> smrMap = r.getObjectsView().build().setStreamName("map a").setTypeToken(new TypeToken<SMRMap<String, String>>() {
}).open();
IStreamView streamB = r.getStreamsView().get(CorfuRuntime.getStreamID("b"));
smrMap.put("a", "b");
streamB.append(new SMREntry("hi", new Object[] { "hello" }, Serializers.PRIMITIVE));
//this TX should not conflict
assertThat(smrMap).doesNotContainKey("b");
r.getObjectsView().TXBegin();
String b = smrMap.get("a");
smrMap.put("b", b);
r.getObjectsView().TXEnd();
assertThat(smrMap).containsEntry("b", "b");
}
Aggregations