use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class FailureHandlerDispatcherTest method updateLayoutOnFailure.
/**
* triggers the handler with failure and checks for update in layout.
*/
@Test
public void updateLayoutOnFailure() {
addServer(SERVERS.PORT_0);
addServer(SERVERS.PORT_1);
addServer(SERVERS.PORT_2);
Layout originalLayout = 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(originalLayout);
CorfuRuntime corfuRuntime = new CorfuRuntime();
corfuRuntime.addLayoutServer(getEndpoint(SERVERS.PORT_0));
corfuRuntime.addLayoutServer(getEndpoint(SERVERS.PORT_1));
corfuRuntime.addLayoutServer(getEndpoint(SERVERS.PORT_2));
corfuRuntime.connect();
Set<String> failedServers = new HashSet<>();
failedServers.add(getEndpoint(SERVERS.PORT_2));
FailureHandlerDispatcher failureHandlerDispatcher = new FailureHandlerDispatcher();
IFailureHandlerPolicy failureHandlerPolicy = new PurgeFailurePolicy();
failureHandlerDispatcher.dispatchHandler(failureHandlerPolicy, originalLayout, corfuRuntime, failedServers);
Layout expectedLayout = new TestLayoutBuilder().setEpoch(2L).addLayoutServer(SERVERS.PORT_0).addLayoutServer(SERVERS.PORT_1).addSequencer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_1).buildSegment().buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_1).addToSegment().addToLayout().build();
assertThat(getLayoutServer(SERVERS.PORT_0).getCurrentLayout()).isEqualTo(getLayoutServer(SERVERS.PORT_1).getCurrentLayout()).isEqualTo(expectedLayout);
}
use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class CheckpointTest method emptyCkpointTest.
@Test
public void emptyCkpointTest() throws Exception {
final String streamNameA = "mystreamA";
final String streamNameB = "mystreamB";
final String author = "periodicCkpoint";
myRuntime = getDefaultRuntime().connect();
Map<String, Long> m2A = instantiateMap(streamNameA);
Map<String, Long> m2B = instantiateMap(streamNameB);
scheduleConcurrently(1, ignored_task_num -> {
CorfuRuntime currentRuntime = getMyRuntime();
for (int i = 0; i < PARAMETERS.NUM_ITERATIONS_VERY_LOW; i++) {
MultiCheckpointWriter mcw1 = new MultiCheckpointWriter();
mcw1.addMap((SMRMap) m2A);
mcw1.addMap((SMRMap) m2B);
long firstGlobalAddress1 = mcw1.appendCheckpoints(currentRuntime, author);
}
});
scheduleConcurrently(PARAMETERS.NUM_ITERATIONS_LOW, ignored_task_num -> {
setRuntime();
Map<String, Long> localm2A = instantiateMap(streamNameA);
Map<String, Long> localm2B = instantiateMap(streamNameB);
for (int i = 0; i < PARAMETERS.NUM_ITERATIONS_MODERATE; i++) {
assertThat(localm2A.get(String.valueOf(i))).isNull();
assertThat(localm2B.get(String.valueOf(i))).isNull();
}
});
executeScheduled(PARAMETERS.CONCURRENCY_SOME, PARAMETERS.TIMEOUT_LONG);
// System.out.println("done executeScheduled");
setRuntime();
Map<String, Long> localm2A = instantiateMap(streamNameA);
Map<String, Long> localm2B = instantiateMap(streamNameB);
for (int i = 0; i < PARAMETERS.NUM_ITERATIONS_MODERATE; i++) {
assertThat(localm2A.get(String.valueOf(i))).isNull();
assertThat(localm2B.get(String.valueOf(i))).isNull();
}
}
use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class CheckpointTest method periodicCkpointTestNoUpdates.
@Test
public void periodicCkpointTestNoUpdates() throws Exception {
final String streamNameA = "mystreamA";
final String streamNameB = "mystreamB";
final String author = "periodicCkpoint";
myRuntime = getDefaultRuntime().connect();
Map<String, Long> m2A = instantiateMap(streamNameA);
Map<String, Long> m2B = instantiateMap(streamNameB);
// pre-populate map
for (int i = 0; i < PARAMETERS.NUM_ITERATIONS_MODERATE; i++) {
m2A.put(String.valueOf(i), (long) i);
m2B.put(String.valueOf(i), (long) 0);
}
scheduleConcurrently(1, ignored_task_num -> {
CorfuRuntime currentRuntime = getMyRuntime();
for (int i = 0; i < PARAMETERS.NUM_ITERATIONS_VERY_LOW; i++) {
MultiCheckpointWriter mcw1 = new MultiCheckpointWriter();
mcw1.addMap((SMRMap) m2A);
mcw1.addMap((SMRMap) m2B);
long firstGlobalAddress1 = mcw1.appendCheckpoints(currentRuntime, author);
}
});
scheduleConcurrently(PARAMETERS.NUM_ITERATIONS_LOW, ignored_task_num -> {
setRuntime();
Map<String, Long> localm2A = instantiateMap(streamNameA);
Map<String, Long> localm2B = instantiateMap(streamNameB);
for (int i = 0; i < PARAMETERS.NUM_ITERATIONS_MODERATE; i++) {
assertThat(localm2A.get(String.valueOf(i))).isEqualTo((long) i);
assertThat(localm2B.get(String.valueOf(i))).isEqualTo((long) 0);
}
});
executeScheduled(PARAMETERS.CONCURRENCY_SOME, PARAMETERS.TIMEOUT_LONG);
// System.out.println("done executeScheduled");
setRuntime();
Map<String, Long> localm2A = instantiateMap(streamNameA);
Map<String, Long> localm2B = instantiateMap(streamNameB);
for (int i = 0; i < PARAMETERS.NUM_ITERATIONS_MODERATE; i++) {
assertThat(localm2A.get(String.valueOf(i))).isEqualTo((long) i);
assertThat(localm2B.get(String.valueOf(i))).isEqualTo(0L);
}
}
use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class ManagementServer method getCorfuRuntime.
/**
* Returns a connected instance of the CorfuRuntime.
*
* @return A connected instance of runtime.
*/
public synchronized CorfuRuntime getCorfuRuntime() {
if (corfuRuntime == null) {
corfuRuntime = new CorfuRuntime();
if ((Boolean) opts.get("--enable-tls")) {
corfuRuntime.enableTls((String) opts.get("--keystore"), (String) opts.get("--keystore-password-file"), (String) opts.get("--truststore"), (String) opts.get("--truststore-password-file"));
if ((Boolean) opts.get("--enable-sasl-plain-text-auth")) {
corfuRuntime.enableSaslPlainText((String) opts.get("--sasl-plain-text-username-file"), (String) opts.get("--sasl-plain-text-password-file"));
}
}
// Runtime can be set up either using the layout or the bootstrapEndpoint address.
if (latestLayout != null)
latestLayout.getLayoutServers().forEach(ls -> corfuRuntime.addLayoutServer(ls));
else
corfuRuntime.addLayoutServer(bootstrapEndpoint);
corfuRuntime.connect();
log.info("Corfu Runtime connected successfully");
}
return corfuRuntime;
}
use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class QuorumReplicationProtocolAdditionalTests method ensureAllUnitsContainData.
@Test
@SuppressWarnings("unchecked")
public void ensureAllUnitsContainData() 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, 1, 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));
// Ensure that the data was written to each logunit.
LogUnitServerAssertions.assertThat(getLogUnit(SERVERS.PORT_0)).matchesDataAtAddress(0, testPayload);
LogUnitServerAssertions.assertThat(getLogUnit(SERVERS.PORT_1)).matchesDataAtAddress(0, testPayload);
LogUnitServerAssertions.assertThat(getLogUnit(SERVERS.PORT_2)).matchesDataAtAddress(0, testPayload);
}
Aggregations