Example #1
0
  @Test
  public void testDeleteChildWithCallback() throws Exception {
    ZooKeeper zk = getClient(0);
    configure("/cache02", zk);

    TestCallback cb = new TestCallback();
    LeaderCache dut = new LeaderCache(zk, "/cache02", cb);
    dut.start(true);
    Map<Integer, Long> cache = cb.m_cache;
    assertEquals("3 items cached.", 3, cache.size());

    zk.delete("/cache02/1", -1);
    while (true) {
      cache = cb.m_cache;
      if (cache.size() == 3) {
        Thread.sleep(1);
      } else {
        break;
      }
    }
    assertEquals("Item removed", 2, cache.size());
    assertEquals(null, cache.get(1));
    assertEquals(12345678, cache.get(0).longValue());
    assertEquals(11223344, cache.get(2).longValue());

    dut.shutdown();
    zk.close();
  }
Example #2
0
  @Test
  public void testUpdate() throws Exception {
    ZooKeeper zk = getClient(0);
    ZooKeeper zk2 = getClient(0);
    MailboxTracker tracker = new MailboxTracker(zk, handler);
    MailboxPublisher publisher = new MailboxPublisher(VoltZK.mailboxes + "/1");

    VoltZK.createPersistentZKNodes(zk);

    publisher.registerMailbox(MailboxType.ExecutionSite, new MailboxNodeContent(1L, 0));
    publisher.publish(zk2);

    publisher = new MailboxPublisher(VoltZK.mailboxes + "/2");
    publisher.registerMailbox(MailboxType.ExecutionSite, new MailboxNodeContent(2L, 1));
    publisher.publish(zk);

    tracker.start();

    // The ephemaral node just created will disappear and we should get an update
    zk2.close();
    while (handler.m_handleCount.get() < 2) {
      Thread.sleep(1);
    }

    Map<MailboxType, List<MailboxNodeContent>> value = handler.m_mailboxes;
    assertTrue(value.containsKey(MailboxType.ExecutionSite));
    List<MailboxNodeContent> list = value.get(MailboxType.ExecutionSite);
    assertEquals(1, list.size());
    assertEquals(2, list.get(0).HSId.longValue());
    assertEquals(1, list.get(0).partitionId.intValue());
    tracker.shutdown();
  }
Example #3
0
  @Test
  public void testModifyChildWithCallback() throws Exception {
    ZooKeeper zk = getClient(0);
    configure("/cache03", zk);

    TestCallback cb = new TestCallback();
    LeaderCache dut = new LeaderCache(zk, "/cache03", cb);
    dut.start(true);
    Map<Integer, Long> cache = cb.m_cache;

    assertEquals("3 items cached.", 3, cache.size());
    assertEquals(12345678, cache.get(0).longValue());

    dut.put(0, 23456789);
    while (true) {
      cache = cb.m_cache;
      if (cache.get(0) == 23456789) {
        break;
      }
    }
    cache = cb.m_cache;
    assertEquals("3 items cached.", 3, cache.size());
    assertEquals(23456789, cache.get(0).longValue());
    assertEquals(87654321, cache.get(1).longValue());
    assertEquals(11223344, cache.get(2).longValue());

    dut.shutdown();
    zk.close();
  }
Example #4
0
  @Test
  public void testModifyChild() throws Exception {
    ZooKeeper zk = getClient(0);
    configure("/cache03", zk);

    LeaderCache dut = new LeaderCache(zk, "/cache03");
    dut.start(true);
    Map<Integer, Long> cache = dut.pointInTimeCache();

    assertEquals("3 items cached.", 3, cache.size());
    assertEquals(12345678, dut.get(0).longValue());

    zk.setData("/cache03/0", Long.toString(23456789).getBytes(), -1);
    while (true) {
      if (dut.get(0) == 23456789) {
        break;
      }
    }
    assertEquals("3 items cached.", 3, cache.size());
    assertEquals(23456789L, dut.get(0).longValue());
    assertEquals(87654321L, dut.get(1).longValue());
    assertEquals(11223344L, dut.get(2).longValue());

    dut.shutdown();
    zk.close();
  }
Example #5
0
  @Test
  public void testInitialCacheWithCallback() throws Exception {
    ZooKeeper zk = getClient(0);
    configure("/cache01", zk);

    TestCallback cb = new TestCallback();
    LeaderCache dut = new LeaderCache(zk, "/cache01", cb);
    dut.start(true);

    assertEquals("3 items cached.", 3, cb.m_cache.size());
    assertEquals(12345678, cb.m_cache.get(0).longValue());
    assertEquals(87654321, cb.m_cache.get(1).longValue());
    assertEquals(11223344, cb.m_cache.get(2).longValue());

    dut.shutdown();
    zk.close();
  }
Example #6
0
  @Test
  public void testInitialCache() throws Exception {
    ZooKeeper zk = getClient(0);
    configure("/cache01", zk);

    LeaderCache dut = new LeaderCache(zk, "/cache01");
    dut.start(true);
    Map<Integer, Long> cache = dut.pointInTimeCache();

    assertEquals("3 items cached.", 3, cache.size());
    assertEquals(12345678L, dut.get(0).longValue());
    assertEquals(87654321L, dut.get(1).longValue());
    assertEquals(11223344L, dut.get(2).longValue());

    dut.shutdown();
    zk.close();
  }
Example #7
0
  @Test
  public void testAddChildWithPutWithCallback() throws Exception {
    ZooKeeper zk = getClient(0);
    configure("/cache04", zk);

    TestCallback cb = new TestCallback();
    LeaderCache dut = new LeaderCache(zk, "/cache04", cb);
    dut.start(true);
    Map<Integer, Long> cache = cb.m_cache;

    dut.put(3, 88776655);

    while (true) {
      cache = cb.m_cache;
      if (cache.size() == 3) {
        Thread.sleep(1);
      } else {
        break;
      }
    }
    assertEquals("Item added", 4, cache.size());
    assertEquals(12345678, cache.get(0).longValue());
    assertEquals(87654321, cache.get(1).longValue());
    assertEquals(11223344, cache.get(2).longValue());
    assertEquals(88776655, cache.get(3).longValue());

    // modify the new child and make sure it has a watch set.
    dut.put(3, 99887766);
    while (true) {
      cache = cb.m_cache;
      if (cache.get(3) == 99887766) {
        break;
      }
    }
    assertEquals("Items accounted for.", 4, cache.size());
    assertEquals(99887766, cache.get(3).longValue());

    dut.shutdown();
    zk.close();
  }