예제 #1
0
 /**
  * Initialize the Test Called before every test case method. Stubs out some test channels, add to
  * the Server Node and initializes the Hive
  */
 @Before
 public void initialize() {
   channel1 = new Channel("1");
   channel2 = new Channel("2");
   channel3 = new Channel("3");
   serverNodes = new ServerNodes();
   try {
     serverNodes.add(channel1);
     serverNodes.add(channel2);
     serverNodes.add(channel3);
     hive = new Hive(serverNodes);
     channel1.getBuffer().clear();
     channel2.getBuffer().clear();
     channel3.getBuffer().clear();
   } catch (IOException e) {
     fail();
   }
 }
예제 #2
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);
  }