use of org.corfudb.infrastructure.TestServerRouter in project CorfuDB by CorfuDB.
the class AbstractClientTest method resetTest.
@Before
public void resetTest() {
serverRouter = new TestServerRouter();
router = new TestClientRouter(serverRouter);
getServersForTest().stream().forEach(serverRouter::addServer);
getClientsForTest().stream().forEach(router::addClient);
}
use of org.corfudb.infrastructure.TestServerRouter in project CorfuDB by CorfuDB.
the class ManagementViewTest method removeSingleNodeFailure.
/**
* 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 removing the failed node.
*
* @throws Exception
*/
@Test
public void removeSingleNodeFailure() throws Exception {
// Creating server contexts with PurgeFailurePolicies.
ServerContext sc0 = new ServerContextBuilder().setSingle(false).setServerRouter(new TestServerRouter(SERVERS.PORT_0)).setPort(SERVERS.PORT_0).build();
ServerContext sc1 = new ServerContextBuilder().setSingle(false).setServerRouter(new TestServerRouter(SERVERS.PORT_1)).setPort(SERVERS.PORT_1).build();
ServerContext sc2 = new ServerContextBuilder().setSingle(false).setServerRouter(new TestServerRouter(SERVERS.PORT_2)).setPort(SERVERS.PORT_2).build();
sc0.setFailureHandlerPolicy(new PurgeFailurePolicy());
sc1.setFailureHandlerPolicy(new PurgeFailurePolicy());
sc2.setFailureHandlerPolicy(new PurgeFailurePolicy());
addServer(SERVERS.PORT_0, sc0);
addServer(SERVERS.PORT_1, sc1);
addServer(SERVERS.PORT_2, sc2);
Layout l = new TestLayoutBuilder().setEpoch(1L).addLayoutServer(SERVERS.PORT_0).addLayoutServer(SERVERS.PORT_1).addLayoutServer(SERVERS.PORT_2).addSequencer(SERVERS.PORT_0).buildSegment().buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build();
bootstrapAllServers(l);
CorfuRuntime corfuRuntime = new CorfuRuntime();
l.getLayoutServers().forEach(corfuRuntime::addLayoutServer);
corfuRuntime.connect();
// Initiating all failure handlers.
for (String server : l.getAllServers()) {
corfuRuntime.getRouter(server).getClient(ManagementClient.class).initiateFailureHandler().get();
}
// Setting aggressive timeouts
setAggressiveTimeouts(l, corfuRuntime, getManagementServer(SERVERS.PORT_0).getCorfuRuntime(), getManagementServer(SERVERS.PORT_1).getCorfuRuntime(), getManagementServer(SERVERS.PORT_2).getCorfuRuntime());
// Adding a rule on SERVERS.PORT_1 to drop all packets
addServerRule(SERVERS.PORT_1, new TestRule().always().drop());
getManagementServer(SERVERS.PORT_1).shutdown();
for (int i = 0; i < PARAMETERS.NUM_ITERATIONS_LOW; i++) {
corfuRuntime.invalidateLayout();
if (corfuRuntime.getLayoutView().getLayout().getEpoch() == 2L) {
break;
}
Thread.sleep(PARAMETERS.TIMEOUT_VERY_SHORT.toMillis());
}
Layout l2 = corfuRuntime.getLayoutView().getLayout();
assertThat(l2.getEpoch()).isEqualTo(2L);
assertThat(l2.getLayoutServers().size()).isEqualTo(2);
assertThat(l2.getLayoutServers().contains(SERVERS.ENDPOINT_1)).isFalse();
}
use of org.corfudb.infrastructure.TestServerRouter in project CorfuDB by CorfuDB.
the class TestClientRouterTest method onlyDropEpochChangeMessages.
@Test
public void onlyDropEpochChangeMessages() {
TestServerRouter tsr = new TestServerRouter();
BaseServer bs = new BaseServer();
tsr.addServer(bs);
TestClientRouter tcr = new TestClientRouter(tsr);
BaseClient bc = new BaseClient();
tcr.addClient(bc);
tcr.rules.add(new TestRule().matches(x -> x.getMsgType().equals(CorfuMsgType.SET_EPOCH)).drop());
assertThat(bc.pingSync()).isTrue();
final long NEW_EPOCH = 9L;
assertThatThrownBy(() -> bc.setRemoteEpoch(NEW_EPOCH).get()).hasCauseInstanceOf(TimeoutException.class);
}
use of org.corfudb.infrastructure.TestServerRouter in project CorfuDB by CorfuDB.
the class TestClientRouterTest method testRuleDropsMessages.
@Test
public void testRuleDropsMessages() {
TestServerRouter tsr = new TestServerRouter();
BaseServer bs = new BaseServer();
tsr.addServer(bs);
TestClientRouter tcr = new TestClientRouter(tsr);
BaseClient bc = new BaseClient();
tcr.addClient(bc);
assertThat(bc.pingSync()).isTrue();
tcr.rules.add(new TestRule().always().drop());
assertThat(bc.pingSync()).isFalse();
}
use of org.corfudb.infrastructure.TestServerRouter in project CorfuDB by CorfuDB.
the class QuorumReplicationProtocolAdditionalTests method sendMessage.
public void sendMessage(LogUnitServer s, CorfuMsg message) {
TestServerRouter router = new TestServerRouter();
router.addServer(s);
message.setClientID(testClientId);
message.setRequestID(requestCounter.getAndIncrement());
router.sendServerMessage(message);
}
Aggregations