Java Code Examples for org.apache.curator.test.TestingCluster#start()
The following examples show how to use
org.apache.curator.test.TestingCluster#start() .
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: ZooKeeperTestingClusterManager.java From helios with Apache License 2.0 | 6 votes |
private void start0() { zkPeers = createPeers(3); zkAddresses = allocateAddresses(zkPeers); peerCurators = createCurators(zkAddresses); System.setProperty("zookeeper.jmx.log4j.disable", "true"); cluster = new TestingCluster(zkPeers); zkServers = cluster.getServers(); try { cluster.start(); } catch (Exception e) { stop(); Throwables.throwIfUnchecked(e); throw new RuntimeException(e); } }
Example 2
Source File: SOLRZookeeperURLManagerTest.java From knox with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { cluster = new TestingCluster(1); cluster.start(); try(CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(cluster.getConnectString()) .retryPolicy(new ExponentialBackoffRetry(1000, 3)).build()) { zooKeeperClient.start(); assertTrue(zooKeeperClient.blockUntilConnected(10, TimeUnit.SECONDS)); zooKeeperClient.create().forPath("/live_nodes"); zooKeeperClient.create().forPath("/live_nodes/host1:8983_solr"); zooKeeperClient.create().forPath("/live_nodes/host2:8983_solr"); zooKeeperClient.create().forPath("/live_nodes/host3:8983_solr"); } manager = new SOLRZookeeperURLManager(); HaServiceConfig config = new DefaultHaServiceConfig("SOLR"); config.setEnabled(true); config.setZookeeperEnsemble(cluster.getConnectString()); manager.setConfig(config); }
Example 3
Source File: TestZookeeperConfigProvider.java From exhibitor with Apache License 2.0 | 5 votes |
@BeforeMethod public void setup() throws Exception { timing = new Timing(); cluster = new TestingCluster(3); cluster.start(); client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); client.start(); }
Example 4
Source File: TestDisruptedScheduler.java From workflow with Apache License 2.0 | 5 votes |
@BeforeMethod public void setup() throws Exception { cluster = new TestingCluster(3); cluster.start(); clients = Lists.newArrayList(); executedTasks = Sets.newConcurrentHashSet(); executedTasksLatch = new CountDownLatch(6); }
Example 5
Source File: AtlasZookeeperURLManagerTest.java From knox with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { cluster = new TestingCluster(1); cluster.start(); try(CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(cluster.getConnectString()) .retryPolicy(new ExponentialBackoffRetry(1000, 3)) .build()) { zooKeeperClient.start(); assertTrue(zooKeeperClient.blockUntilConnected(10, TimeUnit.SECONDS)); zooKeeperClient.create().forPath("/apache_atlas"); zooKeeperClient.create().forPath("/apache_atlas/active_server_info"); zooKeeperClient.setData().forPath("/apache_atlas/active_server_info", atlasNode1.getBytes(StandardCharsets.UTF_8)); } setAtlasActiveHostURLInZookeeper(atlasNode1); manager = new AtlasZookeeperURLManager(); HaServiceConfig config = new DefaultHaServiceConfig("ATLAS-API"); config.setEnabled(true); config.setZookeeperEnsemble(cluster.getConnectString()); config.setZookeeperNamespace("apache_atlas"); manager.setConfig(config); }
Example 6
Source File: HS2ZookeeperURLManagerTest.java From knox with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { cluster = new TestingCluster(1); cluster.start(); try(CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(cluster.getConnectString()) .retryPolicy(new ExponentialBackoffRetry(1000, 3)).build()) { String host1 = "hive.server2.authentication=NONE;hive.server2.transport.mode=http;hive.server2.thrift.http.path=cliservice;" + "hive.server2.thrift.http.port=10001;hive.server2.thrift.bind.host=host1;hive.server2.use.SSL=true"; String host2 = "hive.server2.authentication=NONE;hive.server2.transport.mode=http;hive.server2.thrift.http.path=foobar;" + "hive.server2.thrift.http.port=10002;hive.server2.thrift.bind.host=host2;hive.server2.use.SSL=false"; String host3 = "hive.server2.authentication=NONE;hive.server2.transport.mode=http;hive.server2.thrift.http.path=cliservice;" + "hive.server2.thrift.http.port=10003;hive.server2.thrift.bind.host=host3;hive.server2.use.SSL=false"; String host4 = "hive.server2.authentication=NONE;hive.server2.transport.mode=http;hive.server2.thrift.http.path=cliservice;" + "hive.server2.thrift.http.port=10004;hive.server2.thrift.bind.host=host4;hive.server2.use.SSL=true"; zooKeeperClient.start(); assertTrue(zooKeeperClient.blockUntilConnected(10, TimeUnit.SECONDS)); zooKeeperClient.create().forPath("/hiveServer2"); zooKeeperClient.create().forPath("/hiveServer2/host1", host1.getBytes(StandardCharsets.UTF_8)); zooKeeperClient.create().forPath("/hiveServer2/host2", host2.getBytes(StandardCharsets.UTF_8)); zooKeeperClient.create().forPath("/hiveServer2/host3", host3.getBytes(StandardCharsets.UTF_8)); zooKeeperClient.create().forPath("/hiveServer2/host4", host4.getBytes(StandardCharsets.UTF_8)); } manager = new HS2ZookeeperURLManager(); HaServiceConfig config = new DefaultHaServiceConfig("HIVE"); config.setEnabled(true); config.setZookeeperEnsemble(cluster.getConnectString()); config.setZookeeperNamespace("hiveServer2"); manager.setConfig(config); }
Example 7
Source File: KafkaZookeeperURLManagerTest.java From knox with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { cluster = new TestingCluster(1); cluster.start(); try (CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder() .connectString(cluster.getConnectString()) .retryPolicy(new ExponentialBackoffRetry(1000, 3)).build()) { zooKeeperClient.start(); assertTrue(zooKeeperClient.blockUntilConnected(10, TimeUnit.SECONDS)); zooKeeperClient.create().forPath("/brokers"); zooKeeperClient.create().forPath("/brokers/ids"); } }
Example 8
Source File: ServiceProviderIntegrationTest.java From ranger with Apache License 2.0 | 5 votes |
@Before public void startTestCluster() throws Exception { objectMapper = new ObjectMapper(); testingCluster = new TestingCluster(3); testingCluster.start(); /* registering 3 with RotationMonitor on file and 1 on anotherFile */ registerService("localhost-1", 9000, 1, file); registerService("localhost-2", 9000, 1, file); registerService("localhost-3", 9000, 2, file); registerService("localhost-4", 9000, 2, anotherFile); serviceFinder = ServiceFinderBuilders.unshardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") .withDeserializer(new Deserializer<UnshardedClusterInfo>() { @Override public ServiceNode<UnshardedClusterInfo> deserialize(byte[] data) { try { return objectMapper.readValue(data, new TypeReference<ServiceNode<UnshardedClusterInfo>>() { }); } catch (IOException e) { e.printStackTrace(); } return null; } }) .build(); serviceFinder.start(); }
Example 9
Source File: SimpleServiceProviderTest.java From ranger with Apache License 2.0 | 5 votes |
@Before public void startTestCluster() throws Exception { objectMapper = new ObjectMapper(); testingCluster = new TestingCluster(3); testingCluster.start(); registerService("localhost-1", 9000, 1); registerService("localhost-2", 9000, 1); registerService("localhost-3", 9000, 2); }
Example 10
Source File: ServiceProviderExtCuratorTest.java From ranger with Apache License 2.0 | 5 votes |
@Before public void startTestCluster() throws Exception { objectMapper = new ObjectMapper(); testingCluster = new TestingCluster(3); testingCluster.start(); curatorFramework = CuratorFrameworkFactory.builder() .namespace("test") .connectString(testingCluster.getConnectString()) .retryPolicy(new ExponentialBackoffRetry(1000, 100)).build(); curatorFramework.start(); registerService("localhost-1", 9000, 1); registerService("localhost-2", 9000, 1); registerService("localhost-3", 9000, 2); }
Example 11
Source File: CustomShardSelectorTest.java From ranger with Apache License 2.0 | 5 votes |
@Before public void startTestCluster() throws Exception { objectMapper = new ObjectMapper(); testingCluster = new TestingCluster(3); testingCluster.start(); registerService("localhost-1", 9000, 1, 2); registerService("localhost-2", 9000, 1, 3); registerService("localhost-3", 9000, 2, 3); }
Example 12
Source File: ServiceProviderTest.java From ranger with Apache License 2.0 | 5 votes |
@Before public void startTestCluster() throws Exception { objectMapper = new ObjectMapper(); testingCluster = new TestingCluster(3); testingCluster.start(); registerService("localhost-1", 9000, 1); registerService("localhost-2", 9000, 1); registerService("localhost-3", 9000, 1); registerService("localhost-4", 9000, 2); }
Example 13
Source File: ServiceProviderHealthcheckTest.java From ranger with Apache License 2.0 | 5 votes |
@Before public void startTestCluster() throws Exception { objectMapper = new ObjectMapper(); testingCluster = new TestingCluster(3); testingCluster.start(); registerService("localhost-1", 9000, 1); //registerService("localhost-2", 9000, 1); registerService("localhost-3", 9000, 2); }
Example 14
Source File: ServiceNoProviderTest.java From ranger with Apache License 2.0 | 5 votes |
@Before public void startTestCluster() throws Exception { objectMapper = new ObjectMapper(); testingCluster = new TestingCluster(3); testingCluster.start(); //registerService("localhost-1", 9000, 1); //registerService("localhost-2", 9000, 1); //registerService("localhost-3", 9000, 2); }
Example 15
Source File: TestWithCluster.java From xian with Apache License 2.0 | 5 votes |
@Test public void testSessionSurvives() throws Exception { Timing timing = new Timing(); CuratorFramework client = null; TestingCluster cluster = new TestingCluster(3); cluster.start(); try { client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), timing.session(), timing.connection(), new ExponentialBackoffRetry(100, 3)); client.start(); client.create().withMode(CreateMode.EPHEMERAL).forPath("/temp", "value".getBytes()); Assert.assertNotNull(client.checkExists().forPath("/temp")); for ( InstanceSpec spec : cluster.getInstances() ) { cluster.killServer(spec); timing.forWaiting().sleepABit(); cluster.restartServer(spec); timing.sleepABit(); } timing.sleepABit(); Assert.assertNotNull(client.checkExists().forPath("/temp")); } finally { CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(cluster); } }
Example 16
Source File: ServiceProviderBuilderTest.java From ranger with Apache License 2.0 | 4 votes |
@Before public void startTestCluster() throws Exception { objectMapper = new ObjectMapper(); testingCluster = new TestingCluster(3); testingCluster.start(); }
Example 17
Source File: RemoteConfigurationMonitorTest.java From knox with Apache License 2.0 | 4 votes |
/** * Configure and start the ZooKeeper test cluster, and create the znodes monitored by the RemoteConfigurationMonitor. */ private void configureAndStartZKCluster() throws Exception { // Configure security for the ZK cluster instances Map<String, Object> customInstanceSpecProps = new HashMap<>(); customInstanceSpecProps.put("authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider"); customInstanceSpecProps.put("requireClientAuthScheme", "sasl"); customInstanceSpecProps.put("admin.enableServer", false); // Define the test cluster List<InstanceSpec> instanceSpecs = new ArrayList<>(); for (int i = 0 ; i < 1 ; i++) { InstanceSpec is = new InstanceSpec(null, -1, -1, -1, false, (i+1), -1, -1, customInstanceSpecProps); instanceSpecs.add(is); } zkCluster = new TestingCluster(instanceSpecs); // Configure auth for the ZooKeeper servers and the clients File saslConfigFile = setupDigestSaslConfig(ZK_USERNAME, ZK_PASSWORD); // This system property is used by the ZooKeeper cluster instances, the test driver client, and the // RemoteConfigurationMonitor implementation for SASL authentication/authorization System.setProperty("java.security.auth.login.config", saslConfigFile.getAbsolutePath()); // Start the cluster zkCluster.start(); // Create the client for the test cluster client = CuratorFrameworkFactory.builder() .connectString(zkCluster.getConnectString()) .retryPolicy(new ExponentialBackoffRetry(100, 3)) .build(); assertNotNull(client); client.start(); assertTrue(client.blockUntilConnected(10, TimeUnit.SECONDS)); // Create test config nodes with an ACL for a sasl user that is NOT configured for the test client List<ACL> acls = Arrays.asList(new ACL(ZooDefs.Perms.ALL, new Id("sasl", ALT_USERNAME)), new ACL(ZooDefs.Perms.READ, ZooDefs.Ids.ANYONE_ID_UNSAFE)); client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).withACL(acls).forPath(PATH_AUTH_TEST); assertNotNull("Failed to create node:" + PATH_AUTH_TEST, client.checkExists().forPath(PATH_AUTH_TEST)); }
Example 18
Source File: RemoteConfigurationRegistryClientServiceTest.java From knox with Apache License 2.0 | 4 votes |
private TestingCluster setupAndStartSecureTestZooKeeper(String principal, String digestPassword) throws Exception { final boolean applyAuthentication = (principal != null); // Configure security for the ZK cluster instances Map<String, Object> customInstanceSpecProps = new HashMap<>(); customInstanceSpecProps.put("admin.enableServer", false); if (applyAuthentication) { customInstanceSpecProps.put("authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider"); customInstanceSpecProps.put("requireClientAuthScheme", "sasl"); } // Define the test cluster List<InstanceSpec> instanceSpecs = new ArrayList<>(); for (int i = 0 ; i < 1 ; i++) { InstanceSpec is = new InstanceSpec(null, -1, -1, -1, false, (i+1), -1, -1, customInstanceSpecProps); instanceSpecs.add(is); } TestingCluster zkCluster = new TestingCluster(instanceSpecs); if (applyAuthentication) { // Setup ZooKeeper server SASL Map<String, String> digestOptions = new HashMap<>(); digestOptions.put("user_" + principal, digestPassword); final AppConfigurationEntry[] serverEntries = {new AppConfigurationEntry("org.apache.zookeeper.server.auth.DigestLoginModule", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, digestOptions)}; Configuration.setConfiguration(new Configuration() { @Override public AppConfigurationEntry[] getAppConfigurationEntry(String name) { return ("Server".equalsIgnoreCase(name)) ? serverEntries : null; } }); } // Start the cluster zkCluster.start(); return zkCluster; }
Example 19
Source File: HBaseZookeeperURLManagerTest.java From knox with Apache License 2.0 | 4 votes |
@Before public void setUp() throws Exception { cluster = new TestingCluster(1); cluster.start(); }
Example 20
Source File: ZookeeperRemoteAliasMonitorTest.java From knox with Apache License 2.0 | 4 votes |
@BeforeClass public static void setupSuite() throws Exception { // Configure security for the ZK cluster instances Map<String, Object> customInstanceSpecProps = new HashMap<>(); customInstanceSpecProps.put("authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider"); customInstanceSpecProps.put("requireClientAuthScheme", "sasl"); customInstanceSpecProps.put("admin.enableServer", false); // Define the test cluster List<InstanceSpec> instanceSpecs = new ArrayList<>(); for (int i = 0; i < 1; i++) { InstanceSpec is = new InstanceSpec(null, -1, -1, -1, false, (i + 1), -1, -1, customInstanceSpecProps); instanceSpecs.add(is); } zkNodes = new TestingCluster(instanceSpecs); zkNodes.start(); // Create the client for the test cluster client = CuratorFrameworkFactory.builder() .connectString(zkNodes.getConnectString()) .retryPolicy(new ExponentialBackoffRetry(100, 3)).build(); assertNotNull(client); client.start(); assertTrue(client.blockUntilConnected(10, TimeUnit.SECONDS)); // Create the knox config paths with an ACL for the sasl user configured for the client List<ACL> acls = new ArrayList<>(); acls.add(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.ANYONE_ID_UNSAFE)); client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT) .withACL(acls).forPath( ZookeeperRemoteAliasService.PATH_KNOX_ALIAS_STORE_TOPOLOGY + ZookeeperRemoteAliasService. PATH_SEPARATOR + expectedClusterName); assertNotNull("Failed to create node:" + ZookeeperRemoteAliasService.PATH_KNOX_ALIAS_STORE_TOPOLOGY + ZookeeperRemoteAliasService. PATH_SEPARATOR + expectedClusterName, client.checkExists().forPath( ZookeeperRemoteAliasService.PATH_KNOX_ALIAS_STORE_TOPOLOGY + ZookeeperRemoteAliasService. PATH_SEPARATOR + expectedClusterName)); client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT) .withACL(acls).forPath( ZookeeperRemoteAliasService.PATH_KNOX_ALIAS_STORE_TOPOLOGY + ZookeeperRemoteAliasService. PATH_SEPARATOR + expectedClusterNameDev); assertNotNull("Failed to create node:" + ZookeeperRemoteAliasService.PATH_KNOX_ALIAS_STORE_TOPOLOGY + ZookeeperRemoteAliasService. PATH_SEPARATOR + expectedClusterNameDev, client.checkExists().forPath( ZookeeperRemoteAliasService.PATH_KNOX_ALIAS_STORE_TOPOLOGY + ZookeeperRemoteAliasService. PATH_SEPARATOR + expectedClusterNameDev)); /* Start Zookeeper with an existing alias */ client.create().withMode(CreateMode.PERSISTENT). forPath(ZookeeperRemoteAliasService.PATH_KNOX_ALIAS_STORE_TOPOLOGY + ZookeeperRemoteAliasService. PATH_SEPARATOR + expectedClusterName + ZookeeperRemoteAliasService.PATH_SEPARATOR + preferRemoteAlias, preferRemoteAliasEncryptedPassword.getBytes(StandardCharsets.UTF_8)); }