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