@Test public void voidLockFailsWhenServerDown() throws Exception { ZookeeperLockRegistry registry = new ZookeeperLockRegistry(this.client); Lock lock1 = registry.obtain("foo"); lock1.lock(); testingServer.stop(); Lock lock2 = registry.obtain("bar"); assertFalse("Should not have been able to lock with zookeeper server stopped!", lock2.tryLock(1, TimeUnit.SECONDS)); testingServer.restart(); assertTrue("Should have been able to lock with zookeeper server restarted!", lock2.tryLock(10, TimeUnit.SECONDS)); assertTrue("Should have still held lock1", lock1.tryLock(1, TimeUnit.SECONDS)); Lock lock3 = registry.obtain("foobar"); assertTrue("Should have been able to a obtain new lock!", lock3.tryLock(1, TimeUnit.SECONDS)); lock1.unlock(); lock1.unlock(); lock2.unlock(); lock3.unlock(); registry.destroy(); }
/** * Restarts the internal Test zookeeper server instance. */ public void restart() { // If we have no instance yet if (zkServer == null) { // Call start instead and return. start(); return; } // Otherwise call restart. try { zkServer.restart(); } catch (final Exception exception) { throw new RuntimeException(exception.getMessage(), exception); } }
public void restartServer() throws IOException { try { testingServer.restart(); } catch (Exception e) { Throwables.propagateIfPossible(e, IOException.class); throw Throwables.propagate(e); } }
/** * Starts the internal Test zookeeper server instance. */ public void start() { try { if (zkServer == null) { // Define configuration final InstanceSpec zkInstanceSpec = new InstanceSpec( Utils.createTempDirectory(), -1, -1, -1, false, -1, -1, 1000 ); // Create instance logger.info("Starting Zookeeper test server"); zkServer = new TestingServer(zkInstanceSpec, true); } else { // Instance already exists, so 'start' by calling restart on instance. logger.info("Restarting Zookeeper test server"); zkServer.restart(); } } catch (final Exception exception) { throw new RuntimeException(exception.getMessage(), exception); } }
assertTrue(isLeader(monitor)); LOGGER.debug("testSingleServerZkRestart(): restarting Zk server"); zkServer.restart(); assertTrue(isLeader(monitor)); LOGGER.info("testSingleServerZkRestart({}, leaderCount = {}", i, monitor.getLeaderCount());