Search in sources :

Example 1 with ServerContext

use of org.corfudb.infrastructure.ServerContext 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();
}
Also used : TestServerRouter(org.corfudb.infrastructure.TestServerRouter) TestRule(org.corfudb.runtime.clients.TestRule) ServerContext(org.corfudb.infrastructure.ServerContext) TestLayoutBuilder(org.corfudb.infrastructure.TestLayoutBuilder) ServerContextBuilder(org.corfudb.infrastructure.ServerContextBuilder) PurgeFailurePolicy(org.corfudb.infrastructure.PurgeFailurePolicy) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test)

Aggregations

PurgeFailurePolicy (org.corfudb.infrastructure.PurgeFailurePolicy)1 ServerContext (org.corfudb.infrastructure.ServerContext)1 ServerContextBuilder (org.corfudb.infrastructure.ServerContextBuilder)1 TestLayoutBuilder (org.corfudb.infrastructure.TestLayoutBuilder)1 TestServerRouter (org.corfudb.infrastructure.TestServerRouter)1 CorfuRuntime (org.corfudb.runtime.CorfuRuntime)1 TestRule (org.corfudb.runtime.clients.TestRule)1 Test (org.junit.Test)1