예제 #1
0
 /**
  * Simple testing of adding and removing peers, basically shows that all interactions with ZK work
  *
  * @throws Exception
  */
 @Test
 public void testAddRemovePeer() throws Exception {
   // Add a valid peer
   admin.addPeer(ID_ONE, KEY_ONE);
   // try adding the same (fails)
   try {
     admin.addPeer(ID_ONE, KEY_ONE);
   } catch (IllegalArgumentException iae) {
     // OK!
   }
   assertEquals(1, admin.getPeersCount());
   // Try to remove an inexisting peer
   try {
     admin.removePeer(ID_SECOND);
     fail();
   } catch (IllegalArgumentException iae) {
     // OK!
   }
   assertEquals(1, admin.getPeersCount());
   // Add a second since multi-slave is supported
   try {
     admin.addPeer(ID_SECOND, KEY_SECOND);
   } catch (IllegalStateException iae) {
     fail();
   }
   assertEquals(2, admin.getPeersCount());
   // Remove the first peer we added
   admin.removePeer(ID_ONE);
   assertEquals(1, admin.getPeersCount());
   admin.removePeer(ID_SECOND);
   assertEquals(0, admin.getPeersCount());
 }
예제 #2
0
  /**
   * basic checks that when we add a peer that it is enabled, and that we can disable
   *
   * @throws Exception
   */
  @Test
  public void testEnableDisable() throws Exception {
    admin.addPeer(ID_ONE, KEY_ONE);
    assertEquals(1, admin.getPeersCount());
    assertTrue(admin.getPeerState(ID_ONE));
    admin.disablePeer(ID_ONE);

    assertFalse(admin.getPeerState(ID_ONE));
    try {
      admin.getPeerState(ID_SECOND);
    } catch (IllegalArgumentException iae) {
      // OK!
    }
    admin.removePeer(ID_ONE);
  }