コード例 #1
0
  @Test
  public void testDuplicateUnregister() throws Exception {
    _registry.register(FOO);

    _registry.unregister(FOO);
    _registry.unregister(FOO);
  }
コード例 #2
0
  @Test
  public void testServiceNodeIsDeletedWhenRegistryIsClosed() throws Exception {
    ZooKeeperPersistentEphemeralNode node = mock(ZooKeeperPersistentEphemeralNode.class);
    when(_nodeFactory.create(anyString(), any(byte[].class))).thenReturn(node);

    _registry.register(FOO);

    _registry.close();

    verify(node).close(anyLong(), any(TimeUnit.class));
  }
コード例 #3
0
  @Test
  public void testDuplicateRegister() throws Exception {
    ZooKeeperPersistentEphemeralNode firstNode = mock(ZooKeeperPersistentEphemeralNode.class);
    ZooKeeperPersistentEphemeralNode secondNode = mock(ZooKeeperPersistentEphemeralNode.class);
    when(_nodeFactory.create(anyString(), any(byte[].class))).thenReturn(firstNode, secondNode);

    _registry.register(FOO);
    _registry.register(FOO);

    verify(_nodeFactory, times(2)).create(eq(FOO_PATH), Matchers.<byte[]>any());
    verify(firstNode).close(anyLong(), any(TimeUnit.class));
  }
コード例 #4
0
  @Test
  public void testRegister() throws Exception {
    ZooKeeperPersistentEphemeralNode node = mock(ZooKeeperPersistentEphemeralNode.class);
    when(_nodeFactory.create(anyString(), any(byte[].class))).thenReturn(node);

    _registry.register(FOO);

    ArgumentCaptor<byte[]> dataCaptor = ArgumentCaptor.forClass(byte[].class);

    verify(_nodeFactory).create(eq(FOO_PATH), dataCaptor.capture());
    assertEquals(FOO, ServiceEndPointJsonCodec.fromJson(new String(dataCaptor.getValue())));
    verify(node, never()).close(anyLong(), any(TimeUnit.class));
  }
コード例 #5
0
 @Test(expected = IllegalStateException.class)
 public void testLargePayloadSize() {
   int padding = ServiceEndPointJsonCodec.toJson(FOO).getBytes(Charsets.UTF_8).length;
   String payload = Strings.repeat("x", MAX_DATA_SIZE - padding);
   _registry.register(newEndPoint(FOO.getServiceName(), FOO.getId(), payload), false);
 }
コード例 #6
0
 @Test(expected = IllegalStateException.class)
 public void testUnregisterAfterClose() throws Exception {
   _registry.close();
   _registry.unregister(FOO);
 }
コード例 #7
0
 @Test(expected = NullPointerException.class)
 public void testUnregisterNullService() throws Exception {
   _registry.unregister(null);
 }
コード例 #8
0
 @After
 public void teardown() throws Exception {
   _registry.close();
 }
コード例 #9
0
  @Test
  public void testUnregisterWithoutFirstRegistering() throws Exception {
    _registry.unregister(FOO);

    verify(_nodeFactory, never()).create(eq(FOO_PATH), Matchers.<byte[]>any());
  }
コード例 #10
0
 @Test
 public void testEmptyPayload() {
   _registry.register(newEndPoint(FOO.getServiceName(), FOO.getId(), ""), false);
 }
コード例 #11
0
 @Test
 public void testMediumPayloadSize() {
   int padding = ServiceEndPointJsonCodec.toJson(FOO).getBytes(Charsets.UTF_8).length;
   String payload = Strings.repeat("x", MAX_DATA_SIZE - padding - 1);
   _registry.register(newEndPoint(FOO.getServiceName(), FOO.getId(), payload), false);
 }