Ejemplo n.º 1
0
  @Test
  public void testUpdateMembershipData() throws Exception {
    Supplier<byte[]> dataSupplier = new EasyMockTest.Clazz<Supplier<byte[]>>() {}.createMock();

    byte[] initial = "start".getBytes();
    expect(dataSupplier.get()).andReturn(initial);

    byte[] second = "update".getBytes();
    expect(dataSupplier.get()).andReturn(second);

    replay(dataSupplier);

    Membership membership = joinGroup.join(dataSupplier, onLoseMembership);
    assertArrayEquals(
        "Initial setting is incorrect.",
        initial,
        zkClient.get().getData(membership.getMemberPath(), false, null));

    assertArrayEquals(
        "Updating supplier should not change membership data",
        initial,
        zkClient.get().getData(membership.getMemberPath(), false, null));

    membership.updateMemberData();
    assertArrayEquals(
        "Updating membership should change data",
        second,
        zkClient.get().getData(membership.getMemberPath(), false, null));

    verify(dataSupplier);
  }
  @Test
  public void testStormZkRoot() {
    String stormRoot = "/storm-zk-root";

    List<String> children = null;

    try {
      children = zkClient.get().getChildren(stormRoot, null);
    } catch (KeeperException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (TimeoutException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    for (String string : children) {
      System.out.println(string);
    }
  }