Search in sources :

Example 36 with TestingCluster

use of org.apache.curator.test.TestingCluster in project knox by apache.

the class RemoteConfigurationRegistryClientServiceUnsecureTest method testMultipleUnsecuredZooKeeperWithSimpleRegistryConfig.

/*
     * Test multiple configurations for an unsecured remote registry.
     */
@Test
public void testMultipleUnsecuredZooKeeperWithSimpleRegistryConfig() throws Exception {
    final String REGISTRY_CLIENT_NAME_1 = "zkclient1";
    final String REGISTRY_CLIENT_NAME_2 = "zkclient2";
    final String PRINCIPAL = null;
    final String PWD = null;
    // Configure and start a secure ZK cluster
    try (TestingCluster zkCluster = setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD)) {
        // Create the setup client for the test cluster, and initialize the test znodes
        CuratorFramework setupClient = initializeTestClientAndZNodes(zkCluster, PRINCIPAL);
        // Mock configuration
        GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class);
        final String registryConfigValue1 = GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString();
        EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME_1)).andReturn(registryConfigValue1).anyTimes();
        final String registryConfigValue2 = GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString();
        EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME_2)).andReturn(registryConfigValue2).anyTimes();
        EasyMock.expect(config.getRemoteRegistryConfigurationNames()).andReturn(Arrays.asList(REGISTRY_CLIENT_NAME_1, REGISTRY_CLIENT_NAME_2)).anyTimes();
        EasyMock.replay(config);
        // Create the client service instance
        RemoteConfigurationRegistryClientService clientService = RemoteConfigurationRegistryClientServiceFactory.newInstance(config);
        assertEquals("Wrong registry client service type.", clientService.getClass(), CuratorClientService.class);
        clientService.setAliasService(null);
        clientService.init(config, null);
        clientService.start();
        RemoteConfigurationRegistryClient client1 = clientService.get(REGISTRY_CLIENT_NAME_1);
        assertNotNull(client1);
        RemoteConfigurationRegistryClient client2 = clientService.get(REGISTRY_CLIENT_NAME_2);
        assertNotNull(client2);
        doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME_1, clientService, false);
        doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME_2, clientService, false);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) TestingCluster(org.apache.curator.test.TestingCluster) RemoteConfigurationRegistryClient(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient) RemoteConfigurationRegistryClientService(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 37 with TestingCluster

use of org.apache.curator.test.TestingCluster in project knox by apache.

the class RemoteConfigurationRegistryClientServiceUnsecureTest method testUnsecuredZooKeeperWithSimpleRegistryConfig.

/*
     * Test a configuration for an unsecured remote registry, included in the gateway configuration.
     */
@Test
public void testUnsecuredZooKeeperWithSimpleRegistryConfig() throws Exception {
    final String REGISTRY_CLIENT_NAME = "unsecured-zk-registry-name";
    final String PRINCIPAL = null;
    final String PWD = null;
    final String CRED_ALIAS = null;
    // Configure and start a secure ZK cluster
    try (TestingCluster zkCluster = setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD)) {
        // Create the setup client for the test cluster, and initialize the test znodes
        CuratorFramework setupClient = initializeTestClientAndZNodes(zkCluster, PRINCIPAL);
        // Mock configuration
        GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class);
        final String registryConfigValue = GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString();
        EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME)).andReturn(registryConfigValue).anyTimes();
        EasyMock.expect(config.getRemoteRegistryConfigurationNames()).andReturn(Collections.singletonList(REGISTRY_CLIENT_NAME)).anyTimes();
        EasyMock.replay(config);
        doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME, config, CRED_ALIAS, PWD);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) TestingCluster(org.apache.curator.test.TestingCluster) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 38 with TestingCluster

use of org.apache.curator.test.TestingCluster in project druid by apache.

the class TestKafkaExtractionCluster method setUp.

@Before
public void setUp() throws Exception {
    zkServer = new TestingCluster(1);
    zkServer.start();
    closer.register(() -> {
        zkServer.stop();
    });
    kafkaServer = new KafkaServer(getBrokerProperties(), Time.SYSTEM, Some.apply(StringUtils.format("TestingBroker[%d]-", 1)), false);
    kafkaServer.startup();
    closer.register(() -> {
        kafkaServer.shutdown();
        kafkaServer.awaitShutdown();
    });
    log.info("---------------------------Started Kafka Broker ---------------------------");
    log.info("---------------------------Publish Messages to topic-----------------------");
    publishRecordsToKafka();
    System.setProperty("druid.extensions.searchCurrentClassloader", "false");
    injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bindConstant().annotatedWith(Names.named("serviceName")).to("test");
            binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
            binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1);
        }
    }, // These injections fail under IntelliJ but are required for maven
    new NamespaceExtractionModule(), new KafkaExtractionNamespaceModule()));
    mapper = injector.getInstance(ObjectMapper.class);
    log.info("--------------------------- placed default item via producer ---------------------------");
    final Map<String, String> consumerProperties = getConsumerProperties();
    final KafkaLookupExtractorFactory kafkaLookupExtractorFactory = new KafkaLookupExtractorFactory(null, TOPIC_NAME, consumerProperties);
    factory = (KafkaLookupExtractorFactory) mapper.readValue(mapper.writeValueAsString(kafkaLookupExtractorFactory), LookupExtractorFactory.class);
    Assert.assertEquals(kafkaLookupExtractorFactory.getKafkaTopic(), factory.getKafkaTopic());
    Assert.assertEquals(kafkaLookupExtractorFactory.getKafkaProperties(), factory.getKafkaProperties());
    factory.start();
    closer.register(() -> factory.close());
    log.info("--------------------------- started rename manager ---------------------------");
}
Also used : KafkaServer(kafka.server.KafkaServer) NamespaceExtractionModule(org.apache.druid.server.lookup.namespace.NamespaceExtractionModule) Binder(com.google.inject.Binder) TestingCluster(org.apache.curator.test.TestingCluster) Module(com.google.inject.Module) NamespaceExtractionModule(org.apache.druid.server.lookup.namespace.NamespaceExtractionModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 39 with TestingCluster

use of org.apache.curator.test.TestingCluster in project druid by apache.

the class KafkaIndexTaskTest method setupClass.

@BeforeClass
public static void setupClass() throws Exception {
    emitter = new ServiceEmitter("service", "host", new NoopEmitter());
    emitter.start();
    EmittingLogger.registerEmitter(emitter);
    zkServer = new TestingCluster(1);
    zkServer.start();
    kafkaServer = new TestBroker(zkServer.getConnectString(), null, 1, ImmutableMap.of("num.partitions", "2"));
    kafkaServer.start();
    taskExec = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool(Execs.makeThreadFactory("kafka-task-test-%d")));
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) TestingCluster(org.apache.curator.test.TestingCluster) TestBroker(org.apache.druid.indexing.kafka.test.TestBroker) NoopEmitter(org.apache.druid.java.util.emitter.core.NoopEmitter) BeforeClass(org.junit.BeforeClass)

Example 40 with TestingCluster

use of org.apache.curator.test.TestingCluster in project druid by apache.

the class KafkaRecordSupplierTest method setupClass.

@BeforeClass
public static void setupClass() throws Exception {
    zkServer = new TestingCluster(1);
    zkServer.start();
    kafkaServer = new TestBroker(zkServer.getConnectString(), null, 1, ImmutableMap.of("num.partitions", "2"));
    kafkaServer.start();
}
Also used : TestingCluster(org.apache.curator.test.TestingCluster) TestBroker(org.apache.druid.indexing.kafka.test.TestBroker) BeforeClass(org.junit.BeforeClass)

Aggregations

TestingCluster (org.apache.curator.test.TestingCluster)97 CuratorFramework (org.apache.curator.framework.CuratorFramework)48 InstanceSpec (org.apache.curator.test.InstanceSpec)41 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)39 Before (org.junit.Before)30 Timing (org.apache.curator.test.Timing)21 Test (org.junit.jupiter.api.Test)21 CountDownLatch (java.util.concurrent.CountDownLatch)20 ConnectionState (org.apache.curator.framework.state.ConnectionState)16 RetryOneTime (org.apache.curator.retry.RetryOneTime)15 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)12 HashMap (java.util.HashMap)10 PotentiallyGzippedCompressionProvider (org.apache.druid.curator.PotentiallyGzippedCompressionProvider)10 BeforeClass (org.junit.BeforeClass)10 Test (org.junit.Test)10 Test (org.testng.annotations.Test)10 ArrayList (java.util.ArrayList)9 TestBroker (org.apache.druid.indexing.kafka.test.TestBroker)8 ZkPathsConfig (org.apache.druid.server.initialization.ZkPathsConfig)8 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)8