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();
}
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();
}
}
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();
}
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();
}
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));
}
Aggregations