Java Code Examples for org.apache.curator.test.TestingServer#getConnectString()

The following examples show how to use org.apache.curator.test.TestingServer#getConnectString() . 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: TestConfigBus.java    From eagle with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    server = new TestingServer();
    config = new ZKConfig();
    config.zkQuorum = server.getConnectString();
    config.zkRoot = "/alert";
    config.zkRetryInterval = 1000;
    config.zkRetryTimes = 3;
    config.connectionTimeoutMs = 3000;
    config.zkSessionTimeoutMs = 10000;
    producer = new ConfigBusProducer(config);
    consumer = new ConfigBusConsumer(config, topic, value -> {
        validate.set(value.isValueVersionId());
        configValue.set((String) value.getValue());
        System.out.println("******** get notified of config " + value);
    });
}
 
Example 2
Source File: ZkClientTest.java    From storm-mysql with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    testingServer = new TestingServer();

    String testConnectString = testingServer.getConnectString();
    String testHost = testConnectString.split(":")[0];
    int testPort = testingServer.getPort();

    zkBinLogStateConfig = new ZkBinLogStateConfig.Builder("my-test-spout")
                                                    .servers(Lists.newArrayList(testHost))
                                                    .port(testPort)
                                                    .sessionTimeOutInMs(10000)
                                                    .retryTimes(5)
                                                    .sleepMsBetweenRetries(50)
                                                    .connectionTimeOutInMs(10000)
                                                    .build();

    ZkConf zkConf = new ZkConf(new HashMap<String, Object>(), zkBinLogStateConfig);
    zkClient = new ZkClient(zkConf);
    zkClient.start();
}
 
Example 3
Source File: ConfigurationManagerIntegrationTest.java    From metron with Apache License 2.0 6 votes vote down vote up
@BeforeEach
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();
}
 
Example 4
Source File: ConfigurationManagerTest.java    From dcos-cassandra-service with Apache License 2.0 6 votes vote down vote up
@Before
public void beforeAll() throws Exception {
    server = new TestingServer();
    server.start();
    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    when(mockCapabilities.supportsNamedVips()).thenReturn(true);
    taskFactory = new CassandraDaemonTask.Factory(mockCapabilities);
    configurationFactory = new ConfigurationFactory<>(
                    MutableSchedulerConfiguration.class,
                    BaseValidator.newValidator(),
                    Jackson.newObjectMapper()
                            .registerModule(new GuavaModule())
                            .registerModule(new Jdk8Module()),
                    "dw");
    connectString = server.getConnectString();
}
 
Example 5
Source File: KafkaTestCase.java    From product-cep with Apache License 2.0 6 votes vote down vote up
private void setupKafkaBroker() {
    try {
        // mock zookeeper
        zkTestServer = new TestingServer(2181);
        // mock kafka
        Properties props = new Properties();
        props.put("broker.id", "0");
        props.put("host.name", "localhost");
        props.put("port", "9092");
        props.put("log.dir", "/tmp/tmp_kafka_dir");
        props.put("zookeeper.connect", zkTestServer.getConnectString());
        props.put("replica.socket.timeout.ms", "1500");
        KafkaConfig config = new KafkaConfig(props);
        kafkaServer = new KafkaServerStartable(config);
        kafkaServer.startup();

        // create "sensordata" topic
        ZkClient zkClient = new ZkClient(zkTestServer.getConnectString(), 10000, 10000, ZKStringSerializer$.MODULE$);
        AdminUtils.createTopic(zkClient, "sensordata", 1, 1, new Properties());
        zkClient.close();
    } catch (Exception e) {
        log.error("Error running local Kafka broker / Zookeeper", e);
    }
}
 
Example 6
Source File: ZkDatasetStateStoreTest.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public void setUp() throws Exception {
  ConfigBuilder configBuilder = ConfigBuilder.create();
  testingServer = new TestingServer(-1);
  zkJobStateStore = new ZkStateStore<>(testingServer.getConnectString(), "/STATE_STORE/TEST", false, JobState.class);

  configBuilder.addPrimitive(ZkStateStoreConfigurationKeys.STATE_STORE_ZK_CONNECT_STRING_KEY,
      testingServer.getConnectString());
  configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_ROOT_DIR_KEY, "/STATE_STORE/TEST2");

  ClassAliasResolver<DatasetStateStore.Factory> resolver =
      new ClassAliasResolver<>(DatasetStateStore.Factory.class);
  DatasetStateStore.Factory stateStoreFactory =
      resolver.resolveClass("zk").newInstance();

  zkDatasetStateStore = stateStoreFactory.createStateStore(configBuilder.build());

  // clear data that may have been left behind by a prior test run
  zkJobStateStore.delete(TEST_JOB_NAME);
  zkDatasetStateStore.delete(TEST_JOB_NAME);
  zkJobStateStore.delete(TEST_JOB_NAME2);
  zkDatasetStateStore.delete(TEST_JOB_NAME2);
}
 
Example 7
Source File: ConfigurationFunctionsTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@BeforeAll
public static void setupZookeeper() throws Exception {

  // zookeeper server
  testZkServer = new TestingServer(true);
  zookeeperUrl = testZkServer.getConnectString();

  // zookeeper client
  client = ConfigurationsUtils.getClient(zookeeperUrl);
  client.start();
}
 
Example 8
Source File: ConfigurationsUtilsTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@BeforeEach
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);
}
 
Example 9
Source File: ZKServerComponent.java    From metron with Apache License 2.0 5 votes vote down vote up
@Override
public void start() throws UnableToStartException {
  try {
    testZkServer = new TestingServer(true);
    zookeeperUrl = testZkServer.getConnectString();
    if(postStartCallback.isPresent()) {
      postStartCallback.get().accept(this);
    }
  }catch(Exception e){
    throw new UnableToStartException("Unable to start TestingServer",e);
  }
}
 
Example 10
Source File: ZooKeeperServerResource.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
protected void before() throws Throwable {
  testingServer = new TestingServer(true);
  zkClient = new CuratorZookeeperClient(testingServer.getConnectString(), 5000, 5000, null, new RetryOneTime(1000));
  zkClient.start();
  zkClient.blockUntilConnectedOrTimedOut();
}
 
Example 11
Source File: ServiceDiscoveryIntegrationTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@BeforeEach
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();
}
 
Example 12
Source File: CuratorFrameworkFactoryBeanTests.java    From spring-cloud-cluster with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
	TestingServer testingServer = new TestingServer();
	CuratorFrameworkFactoryBean fb = new CuratorFrameworkFactoryBean(testingServer.getConnectString());
	CuratorFramework client = fb.getObject();
	fb.start();
	assertTrue(client.getState().equals(CuratorFrameworkState.STARTED));
	fb.stop();
	assertTrue(client.getState().equals(CuratorFrameworkState.STOPPED));
	testingServer.close();
}
 
Example 13
Source File: ZookeeperDataSourceTest.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
@Test
public void testZooKeeperDataSource() throws Exception {
    TestingServer server = new TestingServer(21812);
    server.start();

    final String remoteAddress = server.getConnectString();
    final String path = "/sentinel-zk-ds-demo/flow-HK";

    ReadableDataSource<String, List<FlowRule>> flowRuleDataSource = new ZookeeperDataSource<List<FlowRule>>(remoteAddress, path,
            new Converter<String, List<FlowRule>>() {
                @Override
                public List<FlowRule> convert(String source) {
                    return JSON.parseObject(source, new TypeReference<List<FlowRule>>() {
                    });
                }
            });
    FlowRuleManager.register2Property(flowRuleDataSource.getProperty());

    CuratorFramework zkClient = CuratorFrameworkFactory.newClient(remoteAddress,
            new ExponentialBackoffRetry(3, 1000));
    zkClient.start();
    Stat stat = zkClient.checkExists().forPath(path);
    if (stat == null) {
        zkClient.create().creatingParentContainersIfNeeded().withMode(CreateMode.PERSISTENT).forPath(path, null);
    }

    final String resourceName = "HK";
    publishThenTestFor(zkClient, path, resourceName, 10);
    publishThenTestFor(zkClient, path, resourceName, 15);

    zkClient.close();
    server.stop();
}
 
Example 14
Source File: ServiceConfigResourceTest.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeAll() throws Exception {

    server = new TestingServer();

    server.start();

    final ConfigurationFactory<MutableSchedulerConfiguration> factory =
            new ConfigurationFactory<>(
                    MutableSchedulerConfiguration.class,
                    BaseValidator.newValidator(),
                    Jackson.newObjectMapper().registerModule(
                            new GuavaModule())
                            .registerModule(new Jdk8Module()),
                    "dw");

    config = factory.build(
            new SubstitutingSourceProvider(
                    new FileConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false, true)),
            Resources.getResource("scheduler.yml").getFile());

    final CuratorFrameworkConfig curatorConfig = config.getCuratorConfig();
    RetryPolicy retryPolicy =
            (curatorConfig.getOperationTimeout().isPresent()) ?
                    new RetryUntilElapsed(
                            curatorConfig.getOperationTimeoutMs()
                                    .get()
                                    .intValue()
                            , (int) curatorConfig.getBackoffMs()) :
                    new RetryForever((int) curatorConfig.getBackoffMs());

    stateStore = new CuratorStateStore(
            config.createConfig().getServiceConfig().getName(),
            server.getConnectString(),
            retryPolicy);

    final CassandraSchedulerConfiguration configuration = config.createConfig();
    try {
        final ConfigValidator configValidator = new ConfigValidator();
        final DefaultConfigurationManager defaultConfigurationManager =
                new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
                configuration.getServiceConfig().getName(),
                server.getConnectString(),
                configuration,
                configValidator,
                stateStore);
        Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
        when(mockCapabilities.supportsNamedVips()).thenReturn(true);
        configurationManager = new ConfigurationManager(
                new CassandraDaemonTask.Factory(mockCapabilities),
                defaultConfigurationManager);
    } catch (ConfigStoreException e) {
        throw new RuntimeException(e);
    }
}
 
Example 15
Source File: CassandraDaemonStepTest.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
@Before
public void beforeEach() throws Exception {
    MockitoAnnotations.initMocks(this);
    server = new TestingServer();
    server.start();

    Capabilities mockCapabilities = mock(Capabilities.class);
    when(mockCapabilities.supportsNamedVips()).thenReturn(true);
    taskFactory = new CassandraDaemonTask.Factory(mockCapabilities);

    final ConfigurationFactory<MutableSchedulerConfiguration> factory =
            new ConfigurationFactory<>(
                    MutableSchedulerConfiguration.class,
                    BaseValidator.newValidator(),
                    Jackson.newObjectMapper().registerModule(
                            new GuavaModule())
                            .registerModule(new Jdk8Module()),
                    "dw");

    config = factory.build(
            new SubstitutingSourceProvider(
                    new FileConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false, true)),
            Resources.getResource("scheduler.yml").getFile());

    final CassandraSchedulerConfiguration targetConfig = config.createConfig();
    clusterTaskConfig = targetConfig.getClusterTaskConfig();

    final CuratorFrameworkConfig curatorConfig = config.getCuratorConfig();
    RetryPolicy retryPolicy =
            (curatorConfig.getOperationTimeout().isPresent()) ?
                    new RetryUntilElapsed(
                            curatorConfig.getOperationTimeoutMs()
                                    .get()
                                    .intValue()
                            , (int) curatorConfig.getBackoffMs()) :
                    new RetryForever((int) curatorConfig.getBackoffMs());

    stateStore = new CuratorStateStore(
            targetConfig.getServiceConfig().getName(),
            server.getConnectString(),
            retryPolicy);
    stateStore.storeFrameworkId(Protos.FrameworkID.newBuilder().setValue("1234").build());

    configurationManager = new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
                    config.createConfig().getServiceConfig().getName(),
                    server.getConnectString(),
                    config.createConfig(),
                    new ConfigValidator(),
                    stateStore);

    cassandraState = new CassandraState(
            new ConfigurationManager(taskFactory, configurationManager),
            clusterTaskConfig,
            stateStore);
}
 
Example 16
Source File: ClusterTaskOfferRequirementProviderTest.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeAll() throws Exception {

    server = new TestingServer();

    server.start();

    final ConfigurationFactory<MutableSchedulerConfiguration> factory =
            new ConfigurationFactory<>(
                    MutableSchedulerConfiguration.class,
                    BaseValidator.newValidator(),
                    Jackson.newObjectMapper().registerModule(
                            new GuavaModule())
                            .registerModule(new Jdk8Module()),
                    "dw");

    MutableSchedulerConfiguration mutable = factory.build(
            new SubstitutingSourceProvider(
                    new FileConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false, true)),
            Resources.getResource("scheduler.yml").getFile());

    config = mutable.createConfig();
    ServiceConfig initial = config.getServiceConfig();

    clusterTaskConfig = config.getClusterTaskConfig();

    final CuratorFrameworkConfig curatorConfig = mutable.getCuratorConfig();
    RetryPolicy retryPolicy =
            (curatorConfig.getOperationTimeout().isPresent()) ?
                    new RetryUntilElapsed(
                            curatorConfig.getOperationTimeoutMs()
                                    .get()
                                    .intValue()
                            , (int) curatorConfig.getBackoffMs()) :
                    new RetryForever((int) curatorConfig.getBackoffMs());

    stateStore = new CuratorStateStore(
            config.getServiceConfig().getName(),
            server.getConnectString(),
            retryPolicy);
    stateStore.storeFrameworkId(Protos.FrameworkID.newBuilder().setValue("1234").build());

    identity = new IdentityManager(
            initial,stateStore);

    identity.register("test_id");

    DefaultConfigurationManager configurationManager =
            new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
            config.getServiceConfig().getName(),
            server.getConnectString(),
            config,
            new ConfigValidator(),
            stateStore);
    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    when(mockCapabilities.supportsNamedVips()).thenReturn(true);
    configuration = new ConfigurationManager(
            new CassandraDaemonTask.Factory(mockCapabilities),
            configurationManager);

    provider = new ClusterTaskOfferRequirementProvider();
}
 
Example 17
Source File: CassandraTaskFactoryTest.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
@Before
public void beforeEach() throws Exception {
    MockitoAnnotations.initMocks(this);
    server = new TestingServer();
    server.start();

    final ConfigurationFactory<MutableSchedulerConfiguration> factory =
            new ConfigurationFactory<>(
                    MutableSchedulerConfiguration.class,
                    BaseValidator.newValidator(),
                    Jackson.newObjectMapper().registerModule(
                            new GuavaModule())
                            .registerModule(new Jdk8Module()),
                    "dw");

    config = factory.build(
            new SubstitutingSourceProvider(
                    new FileConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false, true)),
            Resources.getResource("scheduler.yml").getFile());

    ServiceConfig initial = config.createConfig().getServiceConfig();

    final CassandraSchedulerConfiguration targetConfig = config.createConfig();
    clusterTaskConfig = targetConfig.getClusterTaskConfig();

    final CuratorFrameworkConfig curatorConfig = config.getCuratorConfig();
    RetryPolicy retryPolicy =
            (curatorConfig.getOperationTimeout().isPresent()) ?
                    new RetryUntilElapsed(
                            curatorConfig.getOperationTimeoutMs()
                                    .get()
                                    .intValue()
                            , (int) curatorConfig.getBackoffMs()) :
                    new RetryForever((int) curatorConfig.getBackoffMs());

    stateStore = new CuratorStateStore(
            targetConfig.getServiceConfig().getName(),
            server.getConnectString(),
            retryPolicy);
    stateStore.storeFrameworkId(Protos.FrameworkID.newBuilder().setValue("1234").build());
    identity = new IdentityManager(initial,stateStore);

    identity.register("test_id");

    DefaultConfigurationManager configurationManager =
            new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
                    config.createConfig().getServiceConfig().getName(),
                    server.getConnectString(),
                    config.createConfig(),
                    new ConfigValidator(),
                    stateStore);

    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    when(mockCapabilities.supportsNamedVips()).thenReturn(true);
    configuration = new ConfigurationManager(
            new CassandraDaemonTask.Factory(mockCapabilities),
            configurationManager);

    cassandraState = new CassandraState(
            configuration,
            clusterTaskConfig,
            stateStore);

    taskFactory = new CassandraTaskFactory(executorDriver);
}
 
Example 18
Source File: ZookeeperAutoConfigurationTests.java    From spring-cloud-zookeeper with Apache License 2.0 4 votes vote down vote up
@Bean
EnsembleProvider ensembleProvider(TestingServer testingServer) {
	return new FixedEnsembleProvider(testingServer.getConnectString());
}
 
Example 19
Source File: StellarMaaSIntegrationTest.java    From metron with Apache License 2.0 4 votes vote down vote up
@BeforeAll
public static void setup() throws Exception {
  UnitTestHelper.setJavaLoggingLevel(WebApplicationImpl.class, Level.WARNING);
  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)
          .build();
  MaaSConfig config = ConfigUtil.INSTANCE.read(client, "/metron/maas/config", new MaaSConfig(), MaaSConfig.class);
  discoverer = new ServiceDiscoverer(client, config.getServiceRoot());
  discoverer.start();
  endpointUrl = new URL("http://localhost:8282");
  ModelEndpoint endpoint = new ModelEndpoint();
  {
    endpoint.setName("dga");
    endpoint.setContainerId("0");
    Endpoint ep = new Endpoint();
    ep.setUrl(endpointUrl.toString());
    endpoint.setEndpoint(ep);
    endpoint.setVersion("1.0");
  }
  ;

  ServiceInstanceBuilder<ModelEndpoint> builder = ServiceInstance.<ModelEndpoint>builder()
          .address(endpointUrl.getHost())
          .id("0")
          .name("dga")
          .port(endpointUrl.getPort())
          .registrationTimeUTC(System.currentTimeMillis())
          .serviceType(ServiceType.STATIC)
          .payload(endpoint);
  final ServiceInstance<ModelEndpoint> instance = builder.build();
  discoverer.getServiceDiscovery().registerService(instance);
  //wait til the endpoint is installed...
  for(int i = 0;i < 10;++i) {
    try {
      Object o = discoverer.getEndpoint("dga");
      if(o != null) {
        break;
      }
    }
    catch(Exception e) {

    }
    Thread.sleep(1000);
  }
}
 
Example 20
Source File: KafkaMetadataServiceTest.java    From streamline with Apache License 2.0 4 votes vote down vote up
public void startZk() throws Exception {
    final TestingServer server = new TestingServer();
    final String connectionString = server.getConnectString();
    zkCli = ZookeeperClient.newInstance(connectionString);
    zkCli.start();
}