예제 #1
0
 // Add Multiple Channels to a Quorum
 @Test
 public void testAddN() throws IOException {
   quorum1 = new Quorum("q1test", hive, channel1);
   quorum1.addChannel(channel2);
   assertTrue(quorum1.getList().getNodesMap().containsValue(channel2));
   quorum1.addChannel(channel3);
   assertTrue(quorum1.getList().getNodesMap().containsValue(channel3));
 }
예제 #2
0
 // Verify that Duplicate Channel result in a failure
 @Test(expected = IOException.class)
 public void testDuplicateChannelFailure() throws IOException {
   quorum1 = new Quorum("q1test", hive, channel1);
   quorum1.addChannel(channel2);
   assertTrue(quorum1.getList().getNodesMap().containsValue(channel2));
   quorum1.addChannel(channel2);
   fail();
 }
예제 #3
0
 // Verify that the Quorum Creation behave appropriately
 @Test
 public void testQuorumCreation() throws IOException {
   quorum1 = new Quorum("q1test", hive, channel1);
   assertEquals(quorum1.Id, "q1test");
   assertTrue(quorum1.getList().getNodesMap().containsValue(channel1));
   assertTrue(hive.contains("q1test"));
   assertTrue(quorum1.isAlive());
 }
예제 #4
0
 // Fail adding a channel to Non-Existent Room
 @Test(expected = IOException.class)
 public void testSendMessageToNonExistentRoom() throws IOException {
   quorum1 = new Quorum("q1test", hive, channel1);
   quorum1.removeChannel(channel1);
   Utility.pause(500);
   quorum1.addChannel(channel2);
   fail();
 }
예제 #5
0
 // Verify that Duplicate Quourms added to the Hive Fails
 @Test
 public void testDuplicateQuorumFailure() {
   try {
     quorum1 = new Quorum("q1test", hive, channel1);
     quorumOne = new Quorum("q1test", hive, channel1);
     fail();
   } catch (IOException e) {
   }
   assertTrue(quorum1.getList().getNodesMap().containsValue(channel1));
   assertTrue(hive.contains("q1test"));
   assertTrue(hive.getQuorumsMap().containsValue(quorum1));
   assertFalse(hive.getQuorumsMap().containsValue(quorumOne));
   assertTrue(quorum1.isAlive());
 }
예제 #6
0
  // Send message to the entire room
  @Test
  public void testSendMessageToQuorum() throws IOException {
    quorum1 = new Quorum("q1test", hive, channel1);
    quorum1.addChannel(channel2);
    assertTrue(quorum1.getList().getNodesMap().containsValue(channel2));
    quorum1.addChannel(channel3);
    assertTrue(quorum1.getList().getNodesMap().containsValue(channel3));

    channel1.getBuffer().clear();
    channel2.getBuffer().clear();
    channel3.getBuffer().clear();

    quorum1.updateBuffer("test-test-test");
    Utility.pause(500);

    String s1 = channel1.getBuffer().poll();
    assertEquals(s1, "Message (q1test): test-test-test");
    assertEquals(channel1.getBuffer().poll(), null);
    assertEquals(channel2.getBuffer().poll(), "Message (q1test): test-test-test");
    assertEquals(channel2.getBuffer().poll(), null);
    assertEquals(channel3.getBuffer().poll(), "Message (q1test): test-test-test");
    assertEquals(channel3.getBuffer().poll(), null);
  }
예제 #7
0
  // Remove all channels from Quorum and verify that the Quorum is removed
  @Test
  public void testRemoveAllChannels() throws IOException {
    quorum1 = new Quorum("q1test", hive, channel1);
    quorum1.addChannel(channel2);
    assertTrue(quorum1.getList().getNodesMap().containsValue(channel2));
    quorum1.addChannel(channel3);
    assertTrue(quorum1.getList().getNodesMap().containsValue(channel3));

    quorum1.removeChannel(channel1);
    quorum1.removeChannel(channel2);
    quorum1.removeChannel(channel3);
    Utility.pause(500);

    assertFalse(quorum1.getList().getNodesMap().containsValue(channel2));
    assertFalse(quorum1.getList().getNodesMap().containsValue(channel1));
    assertFalse(quorum1.getList().getNodesMap().containsValue(channel3));

    assertFalse(hive.contains("q1test"));
    assertFalse(hive.getQuorumsMap().containsValue(quorum1));
    assertFalse(quorum1.isAlive());
  }