Search in sources :

Example 56 with TestingServer

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

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) BaseTest(org.apache.drill.test.BaseTest)

Example 57 with TestingServer

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

the class TestAmRegistration method testAMRegistry.

@Test
public void testAMRegistry() throws Exception {
    try (TestingServer server = new TestingServer()) {
        server.start();
        String connStr = server.getConnectString();
        ZKClusterCoordinatorDriver driver = new ZKClusterCoordinatorDriver().setConnect(connStr, TEST_ZK_ROOT, TEST_CLUSTER_ID).build();
        // Register an AM using the above.
        driver.register(TEST_AM_HOST, TEST_AM_PORT, TEST_APP_ID);
        // Simulate a second AM for the same cluster.
        {
            ZKClusterCoordinatorDriver driver2 = new ZKClusterCoordinatorDriver().setConnect(connStr, TEST_ZK_ROOT, TEST_CLUSTER_ID).build();
            try {
                driver.register(PROBE_AM_HOST, PROBE_AM_PORT, PROBE_APP_ID);
                fail();
            } catch (AMRegistrationException e) {
                String msg = e.getMessage();
                assertTrue(msg.contains("Application Master already exists"));
                assertTrue(msg.contains(" " + TEST_ZK_ROOT + "/" + TEST_CLUSTER_ID + " "));
                assertTrue(msg.contains(" host: " + TEST_AM_HOST));
                assertTrue(msg.contains(" Application ID: " + TEST_APP_ID));
            }
            driver2.close();
        }
        {
            ZKClusterCoordinatorDriver driver2 = new ZKClusterCoordinatorDriver().setConnect(connStr, TEST_ZK_ROOT, PROBE_CLUSTER_ID).build();
            try {
                driver2.register(PROBE_AM_HOST, PROBE_AM_PORT, PROBE_APP_ID);
            } catch (AMRegistrationException e) {
                fail("Registration should be OK");
            }
            driver2.close();
        }
        {
            ZKClusterCoordinatorDriver driver2 = new ZKClusterCoordinatorDriver().setConnect(connStr, PROBE_ZK_ROOT, TEST_CLUSTER_ID).build();
            try {
                driver2.register(PROBE_AM_HOST, PROBE_AM_PORT, PROBE_APP_ID);
            } catch (AMRegistrationException e) {
                fail("Registration should be OK");
            }
            driver2.close();
        }
        // First AM exits.
        driver.close();
        {
            // Should be able to register an AM for the same cluster.
            ZKClusterCoordinatorDriver driver2 = new ZKClusterCoordinatorDriver().setConnect(connStr, TEST_ZK_ROOT, TEST_CLUSTER_ID).build();
            try {
                driver2.register(PROBE_AM_HOST, PROBE_AM_PORT, PROBE_APP_ID);
            } catch (AMRegistrationException e) {
                fail("Registration should be OK");
            }
            driver2.close();
        }
        server.stop();
    }
}
Also used : TestingServer(org.apache.curator.test.TestingServer) AMRegistrationException(org.apache.drill.yarn.appMaster.AMRegistrar.AMRegistrationException) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Example 58 with TestingServer

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

the class TestEphemeralStore method setUp.

@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    ZookeeperTestUtil.setZookeeperSaslTestConfigProps();
    server = new TestingServer();
    final RetryPolicy policy = new RetryNTimes(2, 1000);
    curator = CuratorFrameworkFactory.newClient(server.getConnectString(), policy);
    config = Mockito.mock(TransientStoreConfig.class);
    Mockito.when(config.getName()).thenReturn(root);
    Mockito.when(config.getSerializer()).thenReturn(new InstanceSerializer<String>() {

        @Override
        public byte[] serialize(final String instance) throws IOException {
            if (instance == null) {
                return null;
            }
            return instance.getBytes();
        }

        @Override
        public String deserialize(final byte[] raw) throws IOException {
            if (raw == null) {
                return null;
            }
            return new String(raw);
        }
    });
    store = new ZkEphemeralStore<>(config, curator);
    server.start();
    curator.start();
    store.start();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) RetryNTimes(org.apache.curator.retry.RetryNTimes) TransientStoreConfig(org.apache.drill.exec.coord.store.TransientStoreConfig) IOException(java.io.IOException) RetryPolicy(org.apache.curator.RetryPolicy) Before(org.junit.Before)

Example 59 with TestingServer

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

the class TestZKACL method setUp.

@Before
public void setUp() throws Exception {
    System.setProperty("zookeeper.authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider");
    String configPath = (ClassLoader.getSystemResource("zkacltest.conf")).getPath();
    System.setProperty("java.security.auth.login.config", configPath);
    server = new TestingServer();
    final DrillConfig config = new DrillConfig(DrillConfig.create().withValue(ExecConstants.ZK_ACL_PROVIDER, ConfigValueFactory.fromAnyRef("creator-all")).withValue(ExecConstants.ZK_APPLY_SECURE_ACL, ConfigValueFactory.fromAnyRef(true)));
    final ScanResult result = ClassPathScanner.fromPrescan(config);
    final BootStrapContext bootStrapContext = new BootStrapContext(config, SystemOptionManager.createDefaultOptionDefinitions(), result);
    aclProviderDelegate = ZKACLProviderFactory.getACLProvider(config, drillClusterPath, bootStrapContext);
    server.start();
    client = CuratorFrameworkFactory.builder().retryPolicy(retryPolicy).connectString(server.getConnectString()).aclProvider(aclProviderDelegate).build();
    client.start();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) ScanResult(org.apache.drill.common.scanner.persistence.ScanResult) DrillConfig(org.apache.drill.common.config.DrillConfig) BootStrapContext(org.apache.drill.exec.server.BootStrapContext) Before(org.junit.Before)

Example 60 with TestingServer

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

the class KafkaUnit method setUp.

public void setUp() throws Exception {
    // setup ZK
    zookeeper = new TestingServer(true);
    // setup Broker
    kafkaDir = new TmpPath(Files.createTempDirectory("kafka-").toAbsolutePath().toString());
    Properties brokerProps = new Properties();
    brokerProps.setProperty("zookeeper.connect", zookeeper.getConnectString());
    brokerProps.setProperty("broker.id", "0");
    brokerProps.setProperty("log.dirs", kafkaDir.getPath());
    brokerProps.setProperty("listeners", String.format("PLAINTEXT://%s:%d", KAFKA_HOST, KAFKA_PORT));
    brokerProps.setProperty("offsets.topic.replication.factor", "1");
    KafkaConfig config = new KafkaConfig(brokerProps);
    MockTime mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);
    // setup default Producer
    createProducer();
    kafkaAdminClient = AdminClient.create(Collections.singletonMap(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, KAFKA_HOST + ":" + KAFKA_PORT));
}
Also used : TestingServer(org.apache.curator.test.TestingServer) TmpPath(org.apache.storm.testing.TmpPath) Properties(java.util.Properties) MockTime(kafka.utils.MockTime) 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