Java Code Examples for org.apache.curator.test.KillSession#kill()
The following examples show how to use
org.apache.curator.test.KillSession#kill() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestTreeCache.java From xian with Apache License 2.0 | 6 votes |
@Test public void testKilledSession() throws Exception { client.create().forPath("/test"); cache = newTreeCacheWithListeners(client, "/test"); cache.start(); assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test"); assertEvent(TreeCacheEvent.Type.INITIALIZED); client.create().forPath("/test/foo", "foo".getBytes()); assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/foo"); client.create().withMode(CreateMode.EPHEMERAL).forPath("/test/me", "data".getBytes()); assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/me"); KillSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString()); assertEvent(TreeCacheEvent.Type.CONNECTION_SUSPENDED); assertEvent(TreeCacheEvent.Type.CONNECTION_LOST); assertEvent(TreeCacheEvent.Type.CONNECTION_RECONNECTED); assertEvent(TreeCacheEvent.Type.NODE_REMOVED, "/test/me", "data".getBytes()); assertEvent(TreeCacheEvent.Type.INITIALIZED); assertNoMoreEvents(); }
Example 2
Source File: ZookeeperElectionServiceTest.java From shardingsphere-elasticjob-cloud with Apache License 2.0 | 6 votes |
@Test @Ignore public void assertContend() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000)); client.start(); client.blockUntilConnected(); ZookeeperElectionService service = new ZookeeperElectionService(HOST_AND_PORT, client, ELECTION_PATH, electionCandidate); service.start(); ElectionCandidate anotherElectionCandidate = mock(ElectionCandidate.class); CuratorFramework anotherClient = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000)); ZookeeperElectionService anotherService = new ZookeeperElectionService("ANOTHER_CLIENT:8899", anotherClient, ELECTION_PATH, anotherElectionCandidate); anotherClient.start(); anotherClient.blockUntilConnected(); anotherService.start(); KillSession.kill(client.getZookeeperClient().getZooKeeper(), EmbedTestingServer.getConnectionString()); service.stop(); verify(anotherElectionCandidate).startLeadership(); }
Example 3
Source File: ZookeeperElectionServiceTest.java From shardingsphere-elasticjob-lite with Apache License 2.0 | 6 votes |
@Test @Ignore public void assertContend() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000)); client.start(); client.blockUntilConnected(); ZookeeperElectionService service = new ZookeeperElectionService(HOST_AND_PORT, client, ELECTION_PATH, electionCandidate); service.start(); ElectionCandidate anotherElectionCandidate = mock(ElectionCandidate.class); CuratorFramework anotherClient = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000)); ZookeeperElectionService anotherService = new ZookeeperElectionService("ANOTHER_CLIENT:8899", anotherClient, ELECTION_PATH, anotherElectionCandidate); anotherClient.start(); anotherClient.blockUntilConnected(); anotherService.start(); KillSession.kill(client.getZookeeperClient().getZooKeeper(), EmbedTestingServer.getConnectionString()); service.stop(); verify(anotherElectionCandidate).startLeadership(); }
Example 4
Source File: TestFrameworkEdges.java From xian with Apache License 2.0 | 5 votes |
@Test public void testSessionKilled() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); client.start(); try { client.create().forPath("/sessionTest"); final AtomicBoolean sessionDied = new AtomicBoolean(false); Watcher watcher = new Watcher() { @Override public void process(WatchedEvent event) { if ( event.getState() == Event.KeeperState.Expired ) { sessionDied.set(true); } } }; client.checkExists().usingWatcher(watcher).forPath("/sessionTest"); KillSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString()); Assert.assertNotNull(client.checkExists().forPath("/sessionTest")); Assert.assertTrue(sessionDied.get()); } finally { CloseableUtils.closeQuietly(client); } }
Example 5
Source File: TestServiceDiscovery.java From xian with Apache License 2.0 | 5 votes |
@Test public void testCrashedInstance() throws Exception { List<Closeable> closeables = Lists.newArrayList(); try { Timing timing = new Timing(); CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); closeables.add(client); client.start(); ServiceInstance<String> instance = ServiceInstance.<String>builder().payload("thing").name("test").port(10064).build(); ServiceDiscovery<String> discovery = new ServiceDiscoveryImpl<String>(client, "/test", new JsonInstanceSerializer<String>(String.class), new FastjsonServiceDefinitionSerializer<>(String.class), instance, false); closeables.add(discovery); discovery.start(); Assert.assertEquals(discovery.queryForInstances("test").size(), 1); KillSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString()); Thread.sleep(timing.multiple(1.5).session()); Assert.assertEquals(discovery.queryForInstances("test").size(), 1); } finally { Collections.reverse(closeables); for ( Closeable c : closeables ) { CloseableUtils.closeQuietly(c); } } }
Example 6
Source File: ZkStatusServiceTest.java From vespa with Apache License 2.0 | 5 votes |
private static void killSession(CuratorFramework curatorFramework, TestingServer testingServer) { try { KillSession.kill(curatorFramework.getZookeeperClient().getZooKeeper(), testingServer.getConnectString()); } catch (Exception e) { throw new RuntimeException("Failed killing session. ", e); } }
Example 7
Source File: TestPersistentEphemeralNode.java From xian with Apache License 2.0 | 4 votes |
public void killSession(CuratorFramework curator) throws Exception { KillSession.kill(curator.getZookeeperClient().getZooKeeper(), curator.getZookeeperClient().getCurrentConnectionString()); }
Example 8
Source File: TestNodeCache.java From xian with Apache License 2.0 | 4 votes |
@Test public void testKilledSession() throws Exception { NodeCache cache = null; Timing timing = new Timing(); CuratorFramework client = null; try { client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); client.start(); client.create().creatingParentsIfNeeded().forPath("/test/node", "start".getBytes()); cache = new NodeCache(client, "/test/node"); cache.start(true); final CountDownLatch latch = new CountDownLatch(1); cache.getListenable().addListener ( new NodeCacheListener() { @Override public void nodeChanged() throws Exception { latch.countDown(); } } ); KillSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString()); Thread.sleep(timing.multiple(1.5).session()); Assert.assertEquals(cache.getCurrentData().getData(), "start".getBytes()); client.setData().forPath("/test/node", "new data".getBytes()); Assert.assertTrue(timing.awaitLatch(latch)); } finally { CloseableUtils.closeQuietly(cache); CloseableUtils.closeQuietly(client); } }
Example 9
Source File: TestInterProcessMutexBase.java From xian with Apache License 2.0 | 4 votes |
@Test public void testKilledSession() throws Exception { final Timing timing = new Timing(); CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new ExponentialBackoffRetry(100, 3)); client.start(); try { final InterProcessLock mutex1 = makeLock(client); final InterProcessLock mutex2 = makeLock(client); final Semaphore semaphore = new Semaphore(0); ExecutorCompletionService<Object> service = new ExecutorCompletionService<Object>(Executors.newFixedThreadPool(2)); service.submit ( new Callable<Object>() { @Override public Object call() throws Exception { mutex1.acquire(); semaphore.release(); Thread.sleep(1000000); return null; } } ); service.submit ( new Callable<Object>() { @Override public Object call() throws Exception { mutex2.acquire(); semaphore.release(); Thread.sleep(1000000); return null; } } ); Assert.assertTrue(timing.acquireSemaphore(semaphore, 1)); KillSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString()); Assert.assertTrue(timing.acquireSemaphore(semaphore, 1)); } finally { client.close(); } }
Example 10
Source File: TestServiceDiscovery.java From xian with Apache License 2.0 | 4 votes |
@Test public void testCrashedServerMultiInstances() throws Exception { List<Closeable> closeables = Lists.newArrayList(); try { Timing timing = new Timing(); CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); closeables.add(client); client.start(); final Semaphore semaphore = new Semaphore(0); ServiceInstance<String> instance1 = ServiceInstance.<String>builder().payload("thing").name("test").port(10064).build(); ServiceInstance<String> instance2 = ServiceInstance.<String>builder().payload("thing").name("test").port(10065).build(); ServiceDiscovery<String> discovery = new ServiceDiscoveryImpl<String>(client, "/test", new JsonInstanceSerializer<String>(String.class),new FastjsonServiceDefinitionSerializer<>(String.class), instance1, false) { @Override protected void internalRegisterService(ServiceInstance<String> service) throws Exception { super.internalRegisterService(service); semaphore.release(); } }; closeables.add(discovery); discovery.start(); discovery.registerService(instance2); timing.acquireSemaphore(semaphore, 2); Assert.assertEquals(discovery.queryForInstances("test").size(), 2); KillSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString()); server.stop(); server.restart(); closeables.add(server); timing.acquireSemaphore(semaphore, 2); Assert.assertEquals(discovery.queryForInstances("test").size(), 2); } finally { for ( Closeable c : closeables ) { CloseableUtils.closeQuietly(c); } } }
Example 11
Source File: TestServiceDiscovery.java From xian with Apache License 2.0 | 4 votes |
@Test public void testCrashedServer() throws Exception { List<Closeable> closeables = Lists.newArrayList(); try { Timing timing = new Timing(); CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); closeables.add(client); client.start(); final Semaphore semaphore = new Semaphore(0); ServiceInstance<String> instance = ServiceInstance.<String>builder().payload("thing").name("test").port(10064).build(); ServiceDiscovery<String> discovery = new ServiceDiscoveryImpl<String>(client, "/test", new JsonInstanceSerializer<String>(String.class), new FastjsonServiceDefinitionSerializer<>(String.class),instance, false) { @Override protected void internalRegisterService(ServiceInstance<String> service) throws Exception { super.internalRegisterService(service); semaphore.release(); } }; closeables.add(discovery); discovery.start(); timing.acquireSemaphore(semaphore); Assert.assertEquals(discovery.queryForInstances("test").size(), 1); KillSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString()); server.stop(); server.restart(); closeables.add(server); timing.acquireSemaphore(semaphore); Assert.assertEquals(discovery.queryForInstances("test").size(), 1); } finally { for ( Closeable c : closeables ) { CloseableUtils.closeQuietly(c); } } }
Example 12
Source File: ZooKeeperTest.java From curator-extensions with Apache License 2.0 | 4 votes |
@SuppressWarnings("UnusedDeclaration") public void killSession(CuratorFramework curator) throws Exception { CuratorZookeeperClient client = curator.getZookeeperClient(); KillSession.kill(client.getZooKeeper(), client.getCurrentConnectionString()); }
Example 13
Source File: KillZkSession.java From dremio-oss with Apache License 2.0 | 2 votes |
/** * Kill the given ZK session * * @param clusterCoordinator the cluster coordinator owning the session */ public static void kill(ZKClusterCoordinator clusterCoordinator) throws Exception { KillSession.kill(clusterCoordinator.getZkClient().getZooKeeperClient(), clusterCoordinator.getZkClient().getConnectionString()); }