Search in sources :

Example 1 with InstanceSpec

use of org.apache.curator.test.InstanceSpec in project helios by spotify.

the class ZooKeeperTestingClusterManager method createPeers.

private List<InstanceSpec> createPeers(final int numPeers) {
    final ImmutableList.Builder<InstanceSpec> peers = ImmutableList.builder();
    for (int i = 0; i < numPeers; i++) {
        final int port = temporaryPorts.localPort("zk-client" + i);
        final int electionPort = temporaryPorts.localPort("zk-elect" + i);
        final int quorumPort = temporaryPorts.localPort("zk-quorum" + i);
        final Path peerDir = peerDir(i);
        try {
            Files.createDirectory(peerDir);
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
        final InstanceSpec spec = new InstanceSpec(peerDir.toFile(), port, electionPort, quorumPort, true, i);
        peers.add(spec);
    }
    return peers.build();
}
Also used : Path(java.nio.file.Path) InstanceSpec(org.apache.curator.test.InstanceSpec) ImmutableList(com.google.common.collect.ImmutableList) IOException(java.io.IOException)

Example 2 with InstanceSpec

use of org.apache.curator.test.InstanceSpec in project ignite by apache.

the class ZookeeperIpFinderTest method testFourNodesKillRestartZookeeper.

/**
     * @throws Exception If failed.
     */
public void testFourNodesKillRestartZookeeper() throws Exception {
    allowDuplicateRegistrations = false;
    // start 4 nodes
    System.setProperty(TcpDiscoveryZookeeperIpFinder.PROP_ZK_CONNECTION_STRING, zkCluster.getConnectString());
    startGrids(4);
    // wait until all grids are started
    waitForRemoteNodes(grid(0), 3);
    // each node will only register itself
    assertEquals(4, zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size());
    // remember ZK server configuration and stop the cluster
    Collection<InstanceSpec> instances = zkCluster.getInstances();
    zkCluster.stop();
    Thread.sleep(1000);
    // start the cluster with the previous configuration
    zkCluster = new TestingCluster(instances);
    zkCluster.start();
    // block the client until connected
    zkCurator.blockUntilConnected();
    // check that the nodes have registered again
    assertEquals(4, zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size());
    // stop all grids
    stopAllGrids();
    assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            try {
                return 0 == zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size();
            } catch (Exception e) {
                U.error(log, "Failed to wait for zk condition", e);
                return false;
            }
        }
    }, 20000));
}
Also used : InstanceSpec(org.apache.curator.test.InstanceSpec) TestingCluster(org.apache.curator.test.TestingCluster) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate)

Example 3 with InstanceSpec

use of org.apache.curator.test.InstanceSpec in project hadoop by apache.

the class TestLeaderElectorService method testZKClusterDown.

// 1. rm1 active
// 2. restart zk cluster
// 3. rm1 will first relinquish leadership and re-acquire leadership
@Test
public void testZKClusterDown() throws Exception {
    rm1 = startRM("rm1", HAServiceState.ACTIVE);
    // stop zk cluster
    zkCluster.stop();
    waitFor(rm1, HAServiceState.STANDBY);
    Collection<InstanceSpec> instanceSpecs = zkCluster.getInstances();
    zkCluster = new TestingCluster(instanceSpecs);
    zkCluster.start();
    // rm becomes active again
    waitFor(rm1, HAServiceState.ACTIVE);
}
Also used : InstanceSpec(org.apache.curator.test.InstanceSpec) TestingCluster(org.apache.curator.test.TestingCluster) Test(org.junit.Test)

Example 4 with InstanceSpec

use of org.apache.curator.test.InstanceSpec in project hadoop by apache.

the class TestLeaderElectorService method testKillZKInstance.

// 1. rm1 active
// 2. rm2 standby
// 3. kill the current connected zk instance
// 4. either rm1 or rm2 will become active.
@Test
public void testKillZKInstance() throws Exception {
    rm1 = startRM("rm1", HAServiceState.ACTIVE);
    rm2 = startRM("rm2", HAServiceState.STANDBY);
    CuratorBasedElectorService service = (CuratorBasedElectorService) rm1.getRMContext().getLeaderElectorService();
    ZooKeeper zkClient = service.getCuratorClient().getZookeeperClient().getZooKeeper();
    InstanceSpec connectionInstance = zkCluster.findConnectionInstance(zkClient);
    zkCluster.killServer(connectionInstance);
    // wait for rm1 or rm2 to be active by randomness
    GenericTestUtils.waitFor(new Supplier<Boolean>() {

        @Override
        public Boolean get() {
            try {
                HAServiceState rm1State = rm1.getAdminService().getServiceStatus().getState();
                HAServiceState rm2State = rm2.getAdminService().getServiceStatus().getState();
                return (rm1State.equals(HAServiceState.ACTIVE) && rm2State.equals(HAServiceState.STANDBY)) || (rm1State.equals(HAServiceState.STANDBY) && rm2State.equals(HAServiceState.ACTIVE));
            } catch (IOException e) {
            }
            return false;
        }
    }, 2000, 15000);
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) InstanceSpec(org.apache.curator.test.InstanceSpec) HAServiceState(org.apache.hadoop.ha.HAServiceProtocol.HAServiceState) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 5 with InstanceSpec

use of org.apache.curator.test.InstanceSpec in project zipkin by openzipkin.

the class SampleRateUpdateGuardTest method shouldStillBeOneLeaderAfterZKFailure.

@Test
public void shouldStillBeOneLeaderAfterZKFailure() throws Exception {
    SampleRateUpdateGuard guard1 = guard(new ZooKeeperCollectorSampler.Builder());
    SampleRateUpdateGuard guard2 = guard(new ZooKeeperCollectorSampler.Builder());
    waitForALeader(guard1, guard2);
    SampleRateUpdateGuard leader = guard1.latch.hasLeadership() ? guard1 : guard2;
    InstanceSpec instance = zookeeper.cluster.findConnectionInstance(leader.client.getZookeeperClient().getZooKeeper());
    zookeeper.cluster.killServer(instance);
    waitForALeader(guard1, guard2);
    assertThat(guard1.latch.hasLeadership() ^ guard2.latch.hasLeadership()).withFailMessage("After a ZK node failure, one guard, but not both, should be the leader").isTrue();
}
Also used : InstanceSpec(org.apache.curator.test.InstanceSpec) Test(org.junit.Test)

Aggregations

InstanceSpec (org.apache.curator.test.InstanceSpec)5 Test (org.junit.Test)3 IOException (java.io.IOException)2 TestingCluster (org.apache.curator.test.TestingCluster)2 ImmutableList (com.google.common.collect.ImmutableList)1 Path (java.nio.file.Path)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 HAServiceState (org.apache.hadoop.ha.HAServiceProtocol.HAServiceState)1 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1