Search in sources :

Example 6 with TestingServer

use of org.apache.curator.test.TestingServer in project curator by Netflix.

the class ZkPathUtilTest method testToString.

public void testToString() throws Exception {
    _zkServer = new TestingServer(4711);
    _client = ZkTestSystem.createZkClient("localhost:4711");
    final String file1 = "/files/file1";
    final String file2 = "/files/file2";
    final String file3 = "/files/file2/file3";
    _client.createPersistent(file1, true);
    _client.createPersistent(file2, true);
    _client.createPersistent(file3, true);
    String stringRepresentation = ZkPathUtil.toString(_client);
    System.out.println(stringRepresentation);
    System.out.println("-------------------------");
    assertTrue(stringRepresentation.contains("file1"));
    assertTrue(stringRepresentation.contains("file2"));
    assertTrue(stringRepresentation.contains("file3"));
    // path filtering
    stringRepresentation = ZkPathUtil.toString(_client, "/", new ZkPathUtil.PathFilter() {

        @Override
        public boolean showChilds(String path) {
            return !file2.equals(path);
        }
    });
    assertTrue(stringRepresentation.contains("file1"));
    assertTrue(stringRepresentation.contains("file2"));
    assertFalse(stringRepresentation.contains("file3"));
    // start path
    stringRepresentation = ZkPathUtil.toString(_client, file2, ZkPathUtil.PathFilter.ALL);
    assertFalse(stringRepresentation.contains("file1"));
    assertTrue(stringRepresentation.contains("file2"));
    assertTrue(stringRepresentation.contains("file3"));
    _zkServer.close();
}
Also used : TestingServer(org.apache.curator.test.TestingServer)

Example 7 with TestingServer

use of org.apache.curator.test.TestingServer in project pinpoint by naver.

the class ZookeeperClusterTest method createZookeeperServer.

private static TestingServer createZookeeperServer(int port) throws Exception {
    TestingServer mockZookeeperServer = new TestingServer(port);
    mockZookeeperServer.start();
    return mockZookeeperServer;
}
Also used : TestingServer(org.apache.curator.test.TestingServer)

Example 8 with TestingServer

use of org.apache.curator.test.TestingServer in project helios by spotify.

the class DeploymentGroupTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    zkServer = new TestingServer(true);
    final CuratorFramework curatorFramework = CuratorFrameworkFactory.builder().connectString(zkServer.getConnectString()).retryPolicy(new ExponentialBackoffRetry(100, 3)).build();
    client = new DefaultZooKeeperClient(curatorFramework);
    client.start();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) DefaultZooKeeperClient(com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient) Before(org.junit.Before)

Example 9 with TestingServer

use of org.apache.curator.test.TestingServer in project helios by spotify.

the class ZooKeeperTestingServerManager method start.

@Override
public void start() {
    log.info("starting zookeeper TestingServer at port={}, dataDir={}", port, dataDir);
    try {
        server = new TestingServer(port, dataDir);
        awaitUp(2, MINUTES);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : TestingServer(org.apache.curator.test.TestingServer) KeeperException(org.apache.zookeeper.KeeperException) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 10 with TestingServer

use of org.apache.curator.test.TestingServer in project opennms by OpenNMS.

the class JUnitKafkaServer method before.

@Override
public void before() throws Exception {
    zkServer = new TestingServer();
    // Start ZooKeeper, this method will block until the service has started
    zkServer.start();
    getAvailablePort(kafkaPort, 9192);
    // Delete any existing Kafka log directory
    FileUtils.deleteDirectory(new File("target/kafka-log"));
    localhost = getLocalhost();
    final Properties properties = new Properties();
    properties.put("broker.id", "1");
    properties.put("auto.create.topics.enable", "true");
    properties.put("num.partitions", "100");
    properties.put("enable.zookeeper", "true");
    properties.put("host.name", localhost);
    properties.put("log.dir", "target/kafka-log");
    properties.put("port", String.valueOf(kafkaPort.get()));
    properties.put("zookeeper.connect", zkServer.getConnectString());
    System.err.println("Kafka server properties: " + properties);
    kafkaConfig = new KafkaConfig(properties);
    final List<KafkaMetricsReporter> kmrList = new ArrayList<>();
    final Buffer<KafkaMetricsReporter> metricsList = scala.collection.JavaConversions.asScalaBuffer(kmrList);
    kafkaServer = new KafkaServer(kafkaConfig, new SystemTime(), Option.<String>empty(), metricsList);
    kafkaServer.startup();
    await().atMost(1, MINUTES).until(() -> getBrokerMetadatas(), hasSize(greaterThanOrEqualTo(1)));
    System.err.println("Kafka Address: " + getKafkaConnectString());
    System.err.println("Zookeeper Address: " + getZookeeperConnectString());
}
Also used : TestingServer(org.apache.curator.test.TestingServer) KafkaServer(kafka.server.KafkaServer) ArrayList(java.util.ArrayList) Properties(java.util.Properties) File(java.io.File) KafkaMetricsReporter(kafka.metrics.KafkaMetricsReporter) KafkaConfig(kafka.server.KafkaConfig)

Aggregations

TestingServer (org.apache.curator.test.TestingServer)42 Before (org.junit.Before)17 Test (org.junit.Test)7 File (java.io.File)6 RetryOneTime (org.apache.curator.retry.RetryOneTime)6 BeforeClass (org.junit.BeforeClass)6 IOException (java.io.IOException)5 CuratorFramework (org.apache.curator.framework.CuratorFramework)5 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)5 HashMap (java.util.HashMap)4 Configuration (org.apache.hadoop.conf.Configuration)4 Properties (java.util.Properties)3 ActorSystem (akka.actor.ActorSystem)2 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)2 SocketTimeoutException (java.net.SocketTimeoutException)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 SimpleConsumer (kafka.javaapi.consumer.SimpleConsumer)2 ZkClient (org.I0Itec.zkclient.ZkClient)2 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)2