Search in sources :

Example 46 with TestingServer

use of org.apache.curator.test.TestingServer in project drill by axbaretto.

the class TestZkRegistry method testCycle.

/**
 * Test a typical life cycle: existing Drillbit on AM start, add a Drilbit
 * (simulates a drillbit starting), and remove a drillbit (simulates a
 * Drillbit ending).
 *
 * @throws Exception
 */
@Test
public void testCycle() throws Exception {
    TestingServer server = new TestingServer();
    server.start();
    String connStr = server.getConnectString();
    CuratorFramework probeZk = connectToZk(connStr);
    addDrillbit(probeZk, FRED_HOST);
    ZKClusterCoordinatorDriver driver = new ZKClusterCoordinatorDriver().setConnect(connStr, ZK_ROOT, CLUSTER_ID).build();
    List<DrillbitEndpoint> bits = driver.getInitialEndpoints();
    assertEquals(1, bits.size());
    assertEquals(makeKey(FRED_HOST), ZKClusterCoordinatorDriver.asString(bits.get(0)));
    TestDrillbitStatusListener listener = new TestDrillbitStatusListener();
    driver.addDrillbitListener(listener);
    addDrillbit(probeZk, WILMA_HOST);
    Thread.sleep(50);
    assertNull(listener.removed);
    assertNotNull(listener.added);
    assertEquals(1, listener.added.size());
    for (DrillbitEndpoint dbe : listener.added) {
        assertEquals(makeKey(WILMA_HOST), ZKClusterCoordinatorDriver.asString(dbe));
    }
    listener.clear();
    removeDrillbit(probeZk, FRED_HOST);
    Thread.sleep(50);
    assertNull(listener.added);
    assertNotNull(listener.removed);
    assertEquals(1, listener.removed.size());
    for (DrillbitEndpoint dbe : listener.removed) {
        assertEquals(makeKey(FRED_HOST), ZKClusterCoordinatorDriver.asString(dbe));
    }
    probeZk.close();
    driver.close();
    server.stop();
    server.close();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) CuratorFramework(org.apache.curator.framework.CuratorFramework) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) Test(org.junit.Test)

Example 47 with TestingServer

use of org.apache.curator.test.TestingServer in project vespa by vespa-engine.

the class CuratorTest method setupServers.

@Before
public void setupServers() throws Exception {
    port1 = allocatePort();
    port2 = allocatePort();
    test1 = new TestingServer(port1);
    test2 = new TestingServer(port2);
    spec1 = localhost + ":" + port1;
    spec2 = localhost + ":" + port2;
}
Also used : TestingServer(org.apache.curator.test.TestingServer) Before(org.junit.Before)

Example 48 with TestingServer

use of org.apache.curator.test.TestingServer in project vespa by vespa-engine.

the class ZookeeperStatusServiceTest method setUp.

@Before
public void setUp() throws Exception {
    Logger.getLogger("").setLevel(LogLevel.WARNING);
    testingServer = new TestingServer();
    curator = createConnectedCurator(testingServer);
    zookeeperStatusService = new ZookeeperStatusService(curator);
}
Also used : TestingServer(org.apache.curator.test.TestingServer) Before(org.junit.Before)

Example 49 with TestingServer

use of org.apache.curator.test.TestingServer in project testcases by coheigea.

the class KafkaTest method setup.

@org.junit.BeforeClass
public static void setup() throws Exception {
    zkServer = new TestingServer();
    tempDir = Files.createTempDirectory("kafka");
    port = Integer.parseInt(System.getProperty("kafka.port"));
    Properties props = new Properties();
    props.put("broker.id", 1);
    props.put("host.name", "localhost");
    props.put("port", port);
    props.put("log.dir", tempDir.toString());
    props.put("zookeeper.connect", zkServer.getConnectString());
    props.put("replica.socket.timeout.ms", "1500");
    props.put("controlled.shutdown.enable", Boolean.TRUE.toString());
    props.put("offsets.topic.replication.factor", (short) 1);
    props.put("offsets.topic.num.partitions", 1);
    KafkaConfig config = new KafkaConfig(props);
    kafkaServer = new KafkaServerStartable(config);
    kafkaServer.startup();
    // Create a "test" topic
    ZkClient zkClient = new ZkClient(zkServer.getConnectString(), 30000, 30000, ZKStringSerializer$.MODULE$);
    final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zkServer.getConnectString()), false);
    AdminUtils.createTopic(zkUtils, "test", 1, 1, new Properties(), RackAwareMode.Enforced$.MODULE$);
}
Also used : TestingServer(org.apache.curator.test.TestingServer) ZkClient(org.I0Itec.zkclient.ZkClient) KafkaServerStartable(kafka.server.KafkaServerStartable) ZkUtils(kafka.utils.ZkUtils) Properties(java.util.Properties) ZkConnection(org.I0Itec.zkclient.ZkConnection) KafkaConfig(kafka.server.KafkaConfig)

Example 50 with TestingServer

use of org.apache.curator.test.TestingServer in project testcases by coheigea.

the class KafkaAuthorizerSASLSSLTest method setup.

@org.junit.BeforeClass
public static void setup() throws Exception {
    // JAAS Config file
    String basedir = System.getProperty("basedir");
    if (basedir == null) {
        basedir = new File(".").getCanonicalPath();
    }
    File f = new File(basedir + "/src/test/resources/kafka_plain.jaas");
    System.setProperty("java.security.auth.login.config", f.getPath());
    zkServer = new TestingServer();
    // Get a random port
    ServerSocket serverSocket = new ServerSocket(0);
    port = serverSocket.getLocalPort();
    serverSocket.close();
    final Properties props = new Properties();
    props.put("broker.id", 1);
    props.put("host.name", "localhost");
    props.put("port", port);
    props.put("log.dir", "/tmp/kafka");
    props.put("zookeeper.connect", zkServer.getConnectString());
    props.put("replica.socket.timeout.ms", "1500");
    props.put("controlled.shutdown.enable", Boolean.TRUE.toString());
    // Enable SASL_SSL
    props.put("listeners", "SASL_SSL://localhost:" + port);
    props.put("security.inter.broker.protocol", "SASL_SSL");
    props.put("sasl.enabled.mechanisms", "PLAIN");
    props.put("sasl.mechanism.inter.broker.protocol", "PLAIN");
    props.put("ssl.keystore.location", KafkaAuthorizerTest.class.getResource("/brokerstore.jks").getPath());
    props.put("ssl.keystore.password", "bspass");
    props.put("ssl.key.password", "bkpass");
    props.put("ssl.truststore.location", KafkaAuthorizerTest.class.getResource("/truststore.jks").getPath());
    props.put("ssl.truststore.password", "security");
    // Plug in custom authorizer
    props.put("authorizer.class.name", "org.apache.coheigea.bigdata.kafka.CustomSASLSSLAuthorizer");
    KafkaConfig config = new KafkaConfig(props);
    kafkaServer = new KafkaServerStartable(config);
    kafkaServer.startup();
    // Create some topics
    ZkClient zkClient = new ZkClient(zkServer.getConnectString(), 30000, 30000, ZKStringSerializer$.MODULE$);
    final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zkServer.getConnectString()), false);
    AdminUtils.createTopic(zkUtils, "test", 1, 1, new Properties(), RackAwareMode.Enforced$.MODULE$);
    AdminUtils.createTopic(zkUtils, "dev", 1, 1, new Properties(), RackAwareMode.Enforced$.MODULE$);
}
Also used : TestingServer(org.apache.curator.test.TestingServer) ZkClient(org.I0Itec.zkclient.ZkClient) ServerSocket(java.net.ServerSocket) KafkaServerStartable(kafka.server.KafkaServerStartable) ZkUtils(kafka.utils.ZkUtils) Properties(java.util.Properties) File(java.io.File) ZkConnection(org.I0Itec.zkclient.ZkConnection) KafkaConfig(kafka.server.KafkaConfig)

Aggregations

TestingServer (org.apache.curator.test.TestingServer)150 Before (org.junit.Before)38 Test (org.junit.Test)30 CuratorFramework (org.apache.curator.framework.CuratorFramework)28 File (java.io.File)27 Properties (java.util.Properties)18 KafkaConfig (kafka.server.KafkaConfig)15 RetryOneTime (org.apache.curator.retry.RetryOneTime)15 Test (org.testng.annotations.Test)15 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)14 IOException (java.io.IOException)13 Timing (org.apache.curator.test.Timing)13 HashMap (java.util.HashMap)12 ZkClient (org.I0Itec.zkclient.ZkClient)12 ServerSocket (java.net.ServerSocket)11 KafkaServerStartable (kafka.server.KafkaServerStartable)11 ZkUtils (kafka.utils.ZkUtils)11 ZkConnection (org.I0Itec.zkclient.ZkConnection)11 BeforeClass (org.junit.BeforeClass)11 TestingServerStarter (io.pravega.test.common.TestingServerStarter)9