@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)); }
@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); }
@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); }