/** * Restarts the internal testing server. It is required to call {@link #stop()} before calling * {@link #restart()}. */ public void restart() throws Exception { mTestingZooKeeperServer.restart(); } }
/** * The ZooKeeper connection string aka `zookeeper.connect` in `hostnameOrIp:port` format. * Example: `127.0.0.1:2181`. * * <p>You can use this to e.g. tell Kafka brokers how to connect to this instance. */ String connectString() { return server.getConnectString(); }
void stop() throws IOException { log.debug("Shutting down embedded ZooKeeper server at {} ...", server.getConnectString()); server.close(); log.debug("Shutdown of embedded ZooKeeper server at {} completed", server.getConnectString()); }
private void setupServerAndCurator() throws Exception { server = new TestingServer(); timing = new Timing(); curator = CuratorFrameworkFactory .builder() .connectString(server.getConnectString()) .sessionTimeoutMs(timing.session()) .connectionTimeoutMs(timing.connection()) .retryPolicy(new RetryOneTime(1)) .compressionProvider(new PotentiallyGzippedCompressionProvider(true)) .build(); }
@BeforeClass public static void setup() throws Exception { zkServer = new TestingServer(true); }
protected void tearDownServerAndCurator() { try { curator.close(); server.close(); } catch (IOException ex) { throw new RuntimeException(ex); } }
@AfterClass public static void teardown() throws Exception { if (zkServer != null) { zkServer.stop(); zkServer = null; } }
/** * @param port port to use * @param tempDirectory directory to use */ public RestartableTestingServer(int port, File tempDirectory) throws Exception { super(new InstanceSpec(tempDirectory, port, -1, -1, true, -1), true); mTestingZooKeeperServer = Whitebox.getInternalState(this, "testingZooKeeperServer"); }
void tearDown() throws Exception { cf.close(); testingCluster.stop(); }
/** {@inheritDoc} */ @Override public void close() throws IOException { stop(); if (state.compareAndSet(State.STOPPED, State.CLOSED)) { InstanceSpec spec = getInstanceSpec(); if (spec.deleteDataDirectoryOnClose()) DirectoryUtils.deleteRecursively(spec.getDataDirectory()); } }
public void run() { try { QuorumPeerConfig config = configBuilder.buildConfig(thisInstanceIndex); main.runFromConfig(config); } catch (Exception e) { logger.error(String.format("From testing server (random state: %s) for instance: %s", String.valueOf(configBuilder.isFromRandom()), getInstanceSpec()), e); } } }).start();
/** * @param configBuilder Config builder. * @param thisInstanceIndex This instance index. */ public TestingZooKeeperServer(QuorumConfigBuilder configBuilder, int thisInstanceIndex) { this.configBuilder = configBuilder; this.thisInstanceIndex = thisInstanceIndex; main = (configBuilder.size() > 1) ? new FixedTestingQuorumPeerMain() : new TestingZooKeeperMain(); }
/** * */ public InstanceSpec getInstanceSpec() { return configBuilder.getInstanceSpec(thisInstanceIndex); }
/** * */ public Collection<InstanceSpec> getInstanceSpecs() { return configBuilder.getInstanceSpecs(); }
/** */ private void clearTmpDir() throws Exception { deleteRecursively(tmpDir); }
/** {@inheritDoc} */ public QuorumPeer getQuorumPeer() { return main.getQuorumPeer(); }
/** * */ public void stop() throws IOException { if (state.compareAndSet(State.STARTED, State.STOPPED)) main.close(); }
protected void setupServerAndCurator() throws Exception { server = new TestingServer(); timing = new Timing(); curator = CuratorFrameworkFactory .builder() .connectString(server.getConnectString()) .sessionTimeoutMs(timing.session()) .connectionTimeoutMs(timing.connection()) .retryPolicy(new RetryOneTime(1)) .compressionProvider(new PotentiallyGzippedCompressionProvider(true)) .build(); }
@AfterClass public static void tearDown() throws Exception { if (zkServer != null) { zkServer.close(); zkServer = null; } }