예제 #1
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();
 }
예제 #2
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());
  }
예제 #3
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);
  }