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(); }
@Test public void testExternalizedFSCheckpointsWithLocalRecoveryZookeeper() throws Exception { TestingServer zkServer = new TestingServer(); zkServer.start(); try { final File checkpointDir = temporaryFolder.newFolder(); testExternalizedCheckpoints( checkpointDir, zkServer.getConnectString(), createFsStateBackend(checkpointDir), true); } finally { zkServer.stop(); } }
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(); }
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()); }
/** * Creates and starts a ZooKeeper instance. */ ZooKeeperEmbedded() throws Exception { log.debug("Starting embedded ZooKeeper server..."); this.server = createTestingServer(); log.debug("Embedded ZooKeeper server at {} uses the temp directory at {}", server.getConnectString(), server.getTempDirectory()); }
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 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); } }
@Test public void testServerFailover() throws Exception { try (Closer closer = Closer.create()) { TestingServer zkTestingServer = closer.register(new TestingServer(-1)); configMap.put(ThrottlingGuiceServletConfig.ZK_STRING_KEY, zkTestingServer.getConnectString()); configMap.put(ThrottlingGuiceServletConfig.HA_CLUSTER_NAME, RestliServiceBasedLimiterTest.class.getSimpleName() + "_cluster"); .build(); Assert.assertNotNull(limiter.acquirePermits(20)); limiter.clearAllStoredPermits(); Assert.assertNotNull(limiter.acquirePermits(20)); Assert.assertEquals(parsePortOfCurrentServerPrefix(requestSender), 2501); limiter.clearAllStoredPermits();
@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); }
public static void clear(TestingServer testingServer) throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient( testingServer.getConnectString(), new RetryOneTime(RETRY_DELAY_MS)); client.start(); for (String rootNode : client.getChildren().forPath("/")) { if (!rootNode.equals(ZOOKEEPER_ROOT_NODE_NAME)) { client.delete().deletingChildrenIfNeeded().forPath("/" + rootNode); } } client.close(); } }
@Test(timeout = 60_000L) public void testSessionKilled() throws Exception curator.start(); curator.blockUntilConnected(); Announcer announcer = new Announcer(curator, exec); try { curator.inTransaction().create().forPath("/somewhere").and().commit(); announcer.start(); KillSession.kill(curator.getZookeeperClient().getZooKeeper(), server.getConnectString());
@Test public void testDeployment() throws Exception { awsDeployment.start(); RetryPolicy retryPolicy = new RetryOneTime(1); try (CuratorFramework client = CuratorFrameworkFactory.newClient(zookeeper.getConnectString(), retryPolicy)) { client.start(); client.blockUntilConnected(); String path = "/test-path/i-1234567890abcdef0"; Thread.sleep(2000); assertNotNull(client.checkExists().forPath(path)); String data = new String(client.getData().forPath(path)); ObjectMapper objectMapper = new ObjectMapper(); DeploymentPayload payload = objectMapper.readValue(data, new TypeReference<DeploymentPayload>() {}); assertEquals("10.158.112.84", payload.getHost()); assertEquals(443, payload.getPort()); assertEquals("us-west-2b", payload.getAvailabilityZone()); } } }
protected static CuratorFramework createNewClient() throws InterruptedException { CuratorFramework client = CuratorFrameworkFactory.newClient(testingServer.getConnectString(), new BoundedExponentialBackoffRetry(100, 1000, 3)); client.start(); return client; }
@Test public void testWriteHostnameDeterministicRuleEngineConfig() throws Exception { try (TestingServer server = new TestingServer()) { server.start(); HostnameDeterministicRuleEngineConfig config = new HostnameDeterministicRuleEngineConfig(); config.blacklistHost("localhost"); config.blacklistHost("localhost.localdomain"); config.whitelistHost("google.com"); ThriftMarshaller marshaller = new ThriftMarshaller(); RetryPolicy retryPolicy = new RetryOneTime(1); try (CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), retryPolicy)) { client.start(); String path = "/some/path/to/nodes/hostRules"; ZooKeeperWriteProvider provider = new ZooKeeperWriteProvider(marshaller, client); provider.write(path, config); byte[] data = client.getData().forPath(path); ThriftUnmarshaller unmarshaller = new ThriftUnmarshaller(); HostnameDeterministicRuleEngineConfig read = new HostnameDeterministicRuleEngineConfig(); unmarshaller.unmarshall(read, data); assertEquals(config, read); } } }
); curator.start(); curator.blockUntilConnected(); curator.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath("/container/billy", new byte[]{}); server.stop(); Assert.assertTrue(timing.awaitLatch(latch));
TestingServer server = new TestingServer(); server.start(); String connStr = server.getConnectString(); probeZk.close(); driver.close(); server.stop(); server.close();
@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 createClient() throws Exception { RetryPolicy retryPolicy = ZKUtils.getRetryPolicy(); String zkConnectionString = Services.get().getConf().get("oozie.zookeeper.connection.string", zkServer.getConnectString()); String zkNamespace = Services.get().getConf().get("oozie.zookeeper.namespace", "oozie"); client = CuratorFrameworkFactory.builder() .namespace(zkNamespace) .connectString(zkConnectionString) .retryPolicy(retryPolicy) .build(); client.start(); }