TestingServer zkTestServer; @Before public void startZookeeper() throws Exception { zkTestServer = new TestingServer(2181); cli = CuratorFrameworkFactory.newClient(zkTestServer.getConnectString(), new RetryOneTime(2000)); } @After public void stopZookeeper() throws IOException { cli.close(); zkTestServer.stop(); }
public static CuratorFramework createZkClient(TestingServer testingZKServer, Closer closer) throws InterruptedException { CuratorFramework curatorFramework = closer.register(CuratorFrameworkFactory.newClient(testingZKServer.getConnectString(), new RetryOneTime(2000))); curatorFramework.start(); if (! curatorFramework.blockUntilConnected(60, TimeUnit.SECONDS)) { throw new RuntimeException("Time out waiting to connect to ZK!"); } return curatorFramework; } }
@Test public void testGetZookeeperBasedJobLock() throws Exception { Closer closer = Closer.create(); try { TestingServer testingServer = closer.register(new TestingServer(-1)); Properties properties = new Properties(); properties.setProperty(ConfigurationKeys.JOB_NAME_KEY, "JobLockFactoryTest-" + System.currentTimeMillis()); properties.setProperty(ConfigurationKeys.JOB_LOCK_TYPE, ZookeeperBasedJobLock.class.getName()); properties.setProperty(ZookeeperBasedJobLock.CONNECTION_STRING, testingServer.getConnectString()); properties.setProperty(ZookeeperBasedJobLock.MAX_RETRY_COUNT, "1"); properties.setProperty(ZookeeperBasedJobLock.LOCKS_ACQUIRE_TIMEOUT_MILLISECONDS, "1000"); properties.setProperty(ZookeeperBasedJobLock.RETRY_BACKOFF_SECONDS, "1"); properties.setProperty(ZookeeperBasedJobLock.SESSION_TIMEOUT_SECONDS, "180"); properties.setProperty(ZookeeperBasedJobLock.CONNECTION_TIMEOUT_SECONDS, "30"); JobLock jobLock = closer.register(LegacyJobLockFactoryManager.getJobLock(properties, new JobLockEventListener())); MatcherAssert.assertThat(jobLock, Matchers.instanceOf(ZookeeperBasedJobLock.class)); } finally { closer.close(); } } }
protected static CuratorFramework createNewClient() throws InterruptedException { CuratorFramework client = CuratorFrameworkFactory.newClient(testingServer.getConnectString(), new BoundedExponentialBackoffRetry(100, 1000, 3)); client.start(); return client; }
@Test(timeout = 60_000L) public void testSessionKilled() throws Exception curator.start(); curator.blockUntilConnected(); Announcer announcer = new Announcer(curator, exec); KillSession.kill(curator.getZookeeperClient().getZooKeeper(), server.getConnectString());
public static void main(String[] args) throws Exception { TestingServer server = new TestingServer(); CuratorFramework client = null; try { client = createSimple(server.getConnectString()); client.start(); client.create().creatingParentsIfNeeded().forPath(PATH, "test".getBytes()); CloseableUtils.closeQuietly(client); client = createWithOptions(server.getConnectString(), new ExponentialBackoffRetry(1000, 3), 1000, 1000); client.start(); System.out.println(new String(client.getData().forPath(PATH))); } catch (Exception ex) { ex.printStackTrace(); } finally { CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(server); } }
@Before public void setup() { conf = new HiveConf(); lockObjData = new HiveLockObjectData("1", "10", "SHARED", "show tables", conf); hiveLock = new HiveLockObject(TABLE, lockObjData); zLock = new ZooKeeperHiveLock(TABLE_LOCK_PATH, hiveLock, HiveLockMode.SHARED); while (server == null) { try { server = new TestingServer(); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder(); client = builder.connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1)).build(); client.start(); } catch (Exception e) { System.err.println("Getting bind exception - retrying to allocate server"); server = null; } } }
public SubPubTest() throws Exception { this.testingServer = new TestingServer(); client = AsyncCuratorFramework.wrap(CuratorFrameworkFactory.newClient(testingServer.getConnectString(), new RetryOneTime(1))); executorService = Executors.newSingleThreadScheduledExecutor(); }
LOG.info("Testing ZK Server listening on: " + testingZKServer.getConnectString()); CuratorFrameworkFactory.newClient(testingZKServer.getConnectString(), new RetryOneTime(2000))); this.curatorFramework.start(); ConfigValueFactory.fromAnyRef(testingZKServer.getConnectString())) .resolve();
@Before public void setup() throws Exception { testZkServer = new TestingServer(true); zookeeperUrl = testZkServer.getConnectString(); RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); client = CuratorFrameworkFactory.newClient(zookeeperUrl, retryPolicy); client.start(); discoverer = new ServiceDiscoverer(client, "/maas/discover"); discoverer.start(); }
@Test public void test() throws Exception { try(Closer closer = Closer.create()) { Map<String, String> configMap = Maps.newHashMap(); TestingServer zkTestingServer = closer.register(new TestingServer(-1)); configMap.put(ThrottlingGuiceServletConfig.ZK_STRING_KEY, zkTestingServer.getConnectString()); configMap.put(ThrottlingGuiceServletConfig.HA_CLUSTER_NAME, TestFailover.class.getSimpleName() + "_cluster"); Config config = ConfigFactory.parseMap(configMap); ThrottlingGuiceServletConfig server2001 = createServerAtPort(config, 2001); PermitAllocation allocation = sendRequestToServer(server2001, 10); Assert.assertTrue(allocation.getPermits() >= 1); ThrottlingGuiceServletConfig server2002 = createServerAtPort(config, 2002); allocation = sendRequestToServer(server2001, 10); Assert.assertTrue(allocation.getPermits() >= 1); try { sendRequestToServer(server2002, 10); Assert.fail(); } catch (RestLiServiceException exc) { Assert.assertTrue(exc.hasErrorDetails()); Assert.assertTrue(exc.getErrorDetails().containsKey(LimiterServerResource.LOCATION_301)); Assert.assertEquals(new URI(exc.getErrorDetails().get(LimiterServerResource.LOCATION_301).toString()).getPort(), 2001); } server2001.close(); allocation = sendRequestToServer(server2002, 10); Assert.assertTrue(allocation.getPermits() >= 1); } }
@Before public void setup() throws Exception { testZkServer = new TestingServer(true); zookeeperUrl = testZkServer.getConnectString(); client = ConfigurationsUtils.getClient(zookeeperUrl); client.start(); File sensorDir = new File(new File(TestConstants.SAMPLE_CONFIG_PATH), ENRICHMENT.getDirectory()); sensors.addAll(Collections2.transform( Arrays.asList(sensorDir.list()) , s -> Iterables.getFirst(Splitter.on('.').split(s), "null"))); tmpDir = TestUtils.createTempDir(this.getClass().getName()); configDir = TestUtils.createDir(tmpDir, "config"); parsersDir = TestUtils.createDir(configDir, "parsers"); enrichmentsDir = TestUtils.createDir(configDir, "enrichments"); indexingDir = TestUtils.createDir(configDir, "indexing"); pushAllConfigs(); }
public static void main(String[] args) throws Exception { TestingServer server = new TestingServer(); CuratorFramework client = null; try { client = createSimple(server.getConnectString()); client.start(); ZKPaths.mkdirs(client.getZookeeperClient().getZooKeeper(),"/a"); ZKPaths.mkdirs(client.getZookeeperClient().getZooKeeper(),"/another/path"); ZKPaths.mkdirs(client.getZookeeperClient().getZooKeeper(),"/yet/another/path"); transaction(client); } catch (Exception ex) { ex.printStackTrace(); } finally { CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(server); } }
public static CuratorFramework createClient(final TestingServer server) { return CuratorFrameworkFactory.newClient( server.getConnectString(), new RetryOneTime(1)); }
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(); }
void start() { try { server = new TestingServer(curatorPort, true); this.curator = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1000)); this.curator.start(); this.curator.blockUntilConnected(10, TimeUnit.SECONDS); initializer.accept(this); } catch (Exception ex) { throw new IllegalStateException("Failed to start Zookeeper", ex); } }
MockDGAModel.start(8282); testZkServer = new TestingServer(true); zookeeperUrl = testZkServer.getConnectString(); RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); client = CuratorFrameworkFactory.newClient(zookeeperUrl, retryPolicy); client.start(); context = new Context.Builder() .with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> client)
@Test public void testPersistWatermarkStateToZk() throws IOException { CheckpointableWatermark watermark = new DefaultCheckpointableWatermark("source", new LongWatermark(startTime)); TaskState taskState = new TaskState(); taskState.setJobId(TEST_JOB_ID); taskState.setProp(ConfigurationKeys.JOB_NAME_KEY, "JobName-" + startTime); // watermark storage configuration taskState.setProp(StateStoreBasedWatermarkStorage.WATERMARK_STORAGE_TYPE_KEY, "zk"); taskState.setProp(StateStoreBasedWatermarkStorage.WATERMARK_STORAGE_CONFIG_PREFIX + ZkStateStoreConfigurationKeys.STATE_STORE_ZK_CONNECT_STRING_KEY, testingServer.getConnectString()); StateStoreBasedWatermarkStorage watermarkStorage = new StateStoreBasedWatermarkStorage(taskState); watermarkStorage.commitWatermarks(ImmutableList.of(watermark)); Map<String, CheckpointableWatermark> watermarkMap = watermarkStorage.getCommittedWatermarks(DefaultCheckpointableWatermark.class, ImmutableList.of("source")); Assert.assertEquals(watermarkMap.size(), 1); Assert.assertEquals(((LongWatermark) watermarkMap.get("source").getWatermark()).getValue(), startTime); }
@Before public void setup() throws Exception { testZkServer = new TestingServer(true); zookeeperUrl = testZkServer.getConnectString(); client = ConfigurationsUtils.getClient(zookeeperUrl); client.start(); expectedGlobalConfig = ConfigurationsUtils.readGlobalConfigFromFile(TestConstants.SAMPLE_CONFIG_PATH); expectedSensorParserConfigMap = ConfigurationsUtils.readSensorParserConfigsFromFile(TestConstants.PARSER_CONFIGS_PATH); expectedSensorEnrichmentConfigMap = ConfigurationsUtils.readSensorEnrichmentConfigsFromFile(TestConstants.ENRICHMENTS_CONFIGS_PATH); }
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(); }