Search in sources :

Example 1 with QuorumUtil

use of org.apache.zookeeper.test.QuorumUtil in project zookeeper by apache.

the class ReconfigFailureCasesTest method testReconfigVersionConditionFails.

/*
     * Tests that a conditional reconfig fails if the specified version doesn't correspond
     * to the version of the current config.
     */
@Test
public void testReconfigVersionConditionFails() throws Exception {
    // create 3 servers
    qu = new QuorumUtil(1);
    qu.disableJMXTest = true;
    qu.startAll();
    ZooKeeper[] zkArr = ReconfigTest.createHandles(qu);
    ZooKeeperAdmin[] zkAdminArr = ReconfigTest.createAdminHandles(qu);
    List<String> leavingServers = new ArrayList<String>();
    leavingServers.add("3");
    try {
        zkAdminArr[1].reconfigure(null, leavingServers, null, 8, null);
        Assert.fail("Reconfig should have failed since the current config version is not 8");
    } catch (KeeperException.BadVersionException e) {
    // We expect this to happen.
    } catch (Exception e) {
        Assert.fail("Should have been BadVersionException!");
    }
    ReconfigTest.closeAllHandles(zkArr, zkAdminArr);
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ArrayList(java.util.ArrayList) QuorumUtil(org.apache.zookeeper.test.QuorumUtil) ZooKeeperAdmin(org.apache.zookeeper.admin.ZooKeeperAdmin) KeeperException(org.apache.zookeeper.KeeperException) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.Test) ReconfigTest(org.apache.zookeeper.test.ReconfigTest)

Example 2 with QuorumUtil

use of org.apache.zookeeper.test.QuorumUtil in project zookeeper by apache.

the class ReconfigFailureCasesTest method testIncrementalReconfigInvokedOnHiearchicalQS.

/*
     * Tests that an incremental reconfig fails if the current config is hiearchical.
     */
@Test
public void testIncrementalReconfigInvokedOnHiearchicalQS() throws Exception {
    // create 5 servers
    qu = new QuorumUtil(2);
    qu.disableJMXTest = true;
    qu.startAll();
    ZooKeeper[] zkArr = ReconfigTest.createHandles(qu);
    ZooKeeperAdmin[] zkAdminArr = ReconfigTest.createAdminHandles(qu);
    ArrayList<String> members = new ArrayList<String>();
    members.add("group.1=3:4:5");
    members.add("group.2=1:2");
    members.add("weight.1=0");
    members.add("weight.2=0");
    members.add("weight.3=1");
    members.add("weight.4=1");
    members.add("weight.5=1");
    for (int i = 1; i <= 5; i++) {
        members.add("server." + i + "=127.0.0.1:" + qu.getPeer(i).peer.getQuorumAddress().getPort() + ":" + qu.getPeer(i).peer.getElectionAddress().getPort() + ";" + "127.0.0.1:" + qu.getPeer(i).peer.getClientPort());
    }
    // Change the quorum system from majority to hierarchical.
    ReconfigTest.reconfig(zkAdminArr[1], null, null, members, -1);
    ReconfigTest.testNormalOperation(zkArr[1], zkArr[2]);
    // Attempt an incremental reconfig.
    List<String> leavingServers = new ArrayList<String>();
    leavingServers.add("3");
    try {
        zkAdminArr[1].reconfigure(null, leavingServers, null, -1, null);
        Assert.fail("Reconfig should have failed since the current config isn't Majority QS");
    } catch (KeeperException.BadArgumentsException e) {
    // We expect this to happen.
    } catch (Exception e) {
        Assert.fail("Should have been BadArgumentsException!");
    }
    ReconfigTest.closeAllHandles(zkArr, zkAdminArr);
}
Also used : ArrayList(java.util.ArrayList) ZooKeeperAdmin(org.apache.zookeeper.admin.ZooKeeperAdmin) KeeperException(org.apache.zookeeper.KeeperException) ZooKeeper(org.apache.zookeeper.ZooKeeper) QuorumUtil(org.apache.zookeeper.test.QuorumUtil) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.Test) ReconfigTest(org.apache.zookeeper.test.ReconfigTest)

Example 3 with QuorumUtil

use of org.apache.zookeeper.test.QuorumUtil in project zookeeper by apache.

the class ReconfigFailureCasesTest method testTooFewRemainingPariticipants.

/*
     * Test that a reconfiguration fails if the proposed change would leave the
     * cluster with less than 2 participants (StandaloneEnabled = true).
     * StandaloneDisabledTest.java (startSingleServerTest) checks that if
     * StandaloneEnabled = false its legal to remove all but one remaining
     * server.
     */
@Test
public void testTooFewRemainingPariticipants() throws Exception {
    // create 3 servers
    qu = new QuorumUtil(1);
    qu.disableJMXTest = true;
    qu.startAll();
    ZooKeeper[] zkArr = ReconfigTest.createHandles(qu);
    ZooKeeperAdmin[] zkAdminArr = ReconfigTest.createAdminHandles(qu);
    List<String> leavingServers = new ArrayList<String>();
    leavingServers.add("2");
    leavingServers.add("3");
    try {
        zkAdminArr[1].reconfigure(null, leavingServers, null, -1, null);
        Assert.fail("Reconfig should have failed since the current config version is not 8");
    } catch (KeeperException.BadArgumentsException e) {
    // We expect this to happen.
    } catch (Exception e) {
        Assert.fail("Should have been BadArgumentsException!");
    }
    ReconfigTest.closeAllHandles(zkArr, zkAdminArr);
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ArrayList(java.util.ArrayList) QuorumUtil(org.apache.zookeeper.test.QuorumUtil) ZooKeeperAdmin(org.apache.zookeeper.admin.ZooKeeperAdmin) KeeperException(org.apache.zookeeper.KeeperException) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.Test) ReconfigTest(org.apache.zookeeper.test.ReconfigTest)

Example 4 with QuorumUtil

use of org.apache.zookeeper.test.QuorumUtil in project zookeeper by apache.

the class ReconfigFailureCasesTest method testLeaderTimesoutOnNewQuorum.

/*
     * Tests that if a quorum of a new config is synced with the leader and a reconfig
     * is allowed to start but then the new quorum is lost, the leader will time out and
     * we go to leader election.
     */
@Test
public void testLeaderTimesoutOnNewQuorum() throws Exception {
    // create 3 servers
    qu = new QuorumUtil(1);
    qu.disableJMXTest = true;
    qu.startAll();
    ZooKeeper[] zkArr = ReconfigTest.createHandles(qu);
    ZooKeeperAdmin[] zkAdminArr = ReconfigTest.createAdminHandles(qu);
    List<String> leavingServers = new ArrayList<String>();
    leavingServers.add("3");
    qu.shutdown(2);
    try {
        // Since we just shut down server 2, its still considered "synced"
        // by the leader, which allows us to start the reconfig
        // (PrepRequestProcessor checks that a quorum of the new
        // config is synced before starting a reconfig).
        // We try to remove server 3, which requires a quorum of {1,2,3}
        // (we have that) and of {1,2}, but 2 is down so we won't get a
        // quorum of new config ACKs.
        zkAdminArr[1].reconfigure(null, leavingServers, null, -1, null);
        Assert.fail("Reconfig should have failed since we don't have quorum of new config");
    } catch (KeeperException.ConnectionLossException e) {
    // We expect leader to lose quorum of proposed config and time out
    } catch (Exception e) {
        Assert.fail("Should have been ConnectionLossException!");
    }
    // The leader should time out and remaining servers should go into
    // LOOKING state. A new leader won't be established since that
    // would require completing the reconfig, which is not possible while
    // 2 is down.
    Assert.assertEquals(QuorumStats.Provider.LOOKING_STATE, qu.getPeer(1).peer.getServerState());
    Assert.assertEquals(QuorumStats.Provider.LOOKING_STATE, qu.getPeer(3).peer.getServerState());
    ReconfigTest.closeAllHandles(zkArr, zkAdminArr);
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ArrayList(java.util.ArrayList) QuorumUtil(org.apache.zookeeper.test.QuorumUtil) ZooKeeperAdmin(org.apache.zookeeper.admin.ZooKeeperAdmin) KeeperException(org.apache.zookeeper.KeeperException) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.Test) ReconfigTest(org.apache.zookeeper.test.ReconfigTest)

Example 5 with QuorumUtil

use of org.apache.zookeeper.test.QuorumUtil in project zookeeper by apache.

the class ZxidRolloverTest method setUp.

@Before
public void setUp() throws Exception {
    System.setProperty("zookeeper.admin.enableServer", "false");
    // set the snap count to something low so that we force log rollover
    // and verify that is working as part of the epoch rollover.
    SyncRequestProcessor.setSnapCount(7);
    qu = new QuorumUtil(1);
    startAll();
    for (int i = 0; i < zkClients.length; i++) {
        zkClientWatchers[i] = new CountdownWatcher();
        PeerStruct peer = qu.getPeer(i + 1);
        zkClients[i] = new ZooKeeper("127.0.0.1:" + peer.clientPort, ClientTest.CONNECTION_TIMEOUT, zkClientWatchers[i]);
    }
    waitForClientsConnected();
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) CountdownWatcher(org.apache.zookeeper.test.ClientBase.CountdownWatcher) QuorumUtil(org.apache.zookeeper.test.QuorumUtil) PeerStruct(org.apache.zookeeper.test.QuorumUtil.PeerStruct) Before(org.junit.Before)

Aggregations

ZooKeeper (org.apache.zookeeper.ZooKeeper)5 QuorumUtil (org.apache.zookeeper.test.QuorumUtil)5 ArrayList (java.util.ArrayList)4 KeeperException (org.apache.zookeeper.KeeperException)4 ZooKeeperAdmin (org.apache.zookeeper.admin.ZooKeeperAdmin)4 ReconfigTest (org.apache.zookeeper.test.ReconfigTest)4 Test (org.junit.Test)4 CountdownWatcher (org.apache.zookeeper.test.ClientBase.CountdownWatcher)1 PeerStruct (org.apache.zookeeper.test.QuorumUtil.PeerStruct)1 Before (org.junit.Before)1