use of org.corfudb.runtime.CorfuRuntime 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);
}
use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class LayoutSealTest method getLayout.
/**
* Gets a layout with 5 Servers:
* PORT_0, PORT_1, PORT_2, PORT_3, PORT_4
* Sets the replication view as specified.
*
* @param replicationMode Replication view to set all segments in the layout with.
* @return Built layout with a connected runtime.
*/
public Layout getLayout(Layout.ReplicationMode replicationMode) {
addServer(SERVERS.PORT_0);
addServer(SERVERS.PORT_1);
addServer(SERVERS.PORT_2);
addServer(SERVERS.PORT_3);
addServer(SERVERS.PORT_4);
Layout l = new TestLayoutBuilder().setEpoch(1).addLayoutServer(SERVERS.PORT_0).addLayoutServer(SERVERS.PORT_1).addLayoutServer(SERVERS.PORT_2).addSequencer(SERVERS.PORT_0).buildSegment().setReplicationMode(replicationMode).buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_1).addLogUnit(SERVERS.PORT_2).addToSegment().buildStripe().addLogUnit(SERVERS.PORT_3).addLogUnit(SERVERS.PORT_4).addToSegment().addToLayout().build();
bootstrapAllServers(l);
CorfuRuntime corfuRuntime = getRuntime(l).connect();
l.setRuntime(corfuRuntime);
setAggressiveTimeouts(l);
return l;
}
use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class CorfuSMRObjectProxyTest method canOpenObjectWithTwoRuntimes.
@Test
public void canOpenObjectWithTwoRuntimes() throws Exception {
getDefaultRuntime();
final int TEST_VALUE = 42;
TestClass testClass = (TestClass) instantiateCorfuObject(new TypeToken<TestClass>() {
}, "test");
testClass.set(TEST_VALUE);
assertThat(testClass.get()).isEqualTo(TEST_VALUE);
CorfuRuntime runtime2 = new CorfuRuntime(getDefaultEndpoint());
runtime2.connect();
TestClass testClass2 = (TestClass) instantiateCorfuObject(runtime2, new TypeToken<TestClass>() {
}, "test");
assertThat(testClass2.get()).isEqualTo(TEST_VALUE);
}
use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class CmdletIT method testCorfuSequencerCmdlet.
/**
* Testing corfu_sequencer next-token and latest
*
* @throws Exception
*/
@Test
public void testCorfuSequencerCmdlet() throws Exception {
corfuServerProcess = new CorfuServerRunner().setPort(PORT).runServer();
final String streamA = "streamA";
CorfuRuntime runtime = createRuntime(ENDPOINT);
String commandNextToken = CORFU_PROJECT_DIR + "bin/corfu_sequencer -i " + streamA + " -c " + ENDPOINT + " next-token 3";
runCmdletGetOutput(commandNextToken);
Token token = runtime.getSequencerView().nextToken(Collections.singleton(CorfuRuntime.getStreamID(streamA)), 0).getToken();
String commandLatest = CORFU_PROJECT_DIR + "bin/corfu_sequencer -i " + streamA + " -c " + ENDPOINT + " latest";
String output = runCmdletGetOutput(commandLatest);
assertThat(output.contains(token.toString())).isTrue();
shutdownCorfuServer(corfuServerProcess);
}
use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class CmdletIT method testCorfuStreamCmdlet.
/**
* Testing corfu_stream append and read.
*
* @throws Exception
*/
@Test
public void testCorfuStreamCmdlet() throws Exception {
corfuServerProcess = new CorfuServerRunner().setPort(PORT).runServer();
final String streamA = "streamA";
CorfuRuntime runtime = createRuntime(ENDPOINT);
IStreamView streamViewA = runtime.getStreamsView().get(CorfuRuntime.getStreamID(streamA));
String payload1 = "Hello";
streamViewA.append(payload1.getBytes());
String commandRead = CORFU_PROJECT_DIR + "bin/corfu_stream -i " + streamA + " -c " + ENDPOINT + " read";
String output = runCmdletGetOutput(commandRead);
assertThat(output.contains(payload1)).isTrue();
String payload2 = "World";
String commandAppend = "echo '" + payload2 + "' | " + CORFU_PROJECT_DIR + "bin/corfu_stream -i " + streamA + " -c " + ENDPOINT + " append";
runCmdletGetOutput(commandAppend);
assertThat(streamViewA.next().getPayload(runtime)).isEqualTo(payload1.getBytes());
assertThat(streamViewA.next().getPayload(runtime)).isEqualTo((payload2 + "\n").getBytes());
assertThat(streamViewA.next()).isNull();
shutdownCorfuServer(corfuServerProcess);
}
Aggregations