ZooKeeperServiceRegistry implements ServiceRegistry { @Override public void unregister(ServiceEndPoint endPoint) { checkState(!_closed); checkNotNull(endPoint); String path = makeEndPointPath(endPoint); PersistentEphemeralNode node = _nodes.remove(path); if (node != null) { closeNode(node); String serviceName = endPoint.getServiceName(); _numRegisteredEndpoints.getUnchecked(serviceName).dec(); } } ZooKeeperServiceRegistry(CuratorFramework curator, MetricRegistry metrics); @VisibleForTesting  ZooKeeperServiceRegistry(NodeFactory nodeFactory, MetricRegistry metrics); @Override void register(ServiceEndPoint endPoint); @Override void unregister(ServiceEndPoint endPoint); @Override synchronized void close(); static String makeServicePath(String serviceName);  }
@Test(expected = NullPointerException.class) public void testUnregisterNullService() throws Exception { _registry.unregister(null); }
@Test public void testUnregister() throws Exception { PersistentEphemeralNode node = mock(PersistentEphemeralNode.class); when(_nodeFactory.create(anyString(), any(byte[].class))).thenReturn(node); _registry.register(FOO); _registry.unregister(FOO); verify(node).close(anyLong(), any(TimeUnit.class)); }
@Test public void testUnregisterWithoutFirstRegistering() throws Exception { _registry.unregister(FOO); verify(_nodeFactory, never()).create(eq(FOO_PATH), any(byte[].class)); }