public String getZKConnectionString() { return zkServer.getConnectionStr(); }
private Properties generateKafkaConfig() throws IOException { Properties properties = new Properties(); properties.setProperty("broker.id", "1"); properties.setProperty("host.name", InetAddress.getLoopbackAddress().getHostAddress()); properties.setProperty("port", "0"); properties.setProperty("num.network.threads", "2"); properties.setProperty("num.io.threads", "2"); properties.setProperty("socket.send.buffer.bytes", "1048576"); properties.setProperty("socket.receive.buffer.bytes", "1048576"); properties.setProperty("socket.request.max.bytes", "104857600"); properties.setProperty("log.dir", tmpFolder.newFolder().getAbsolutePath()); properties.setProperty("num.partitions", String.valueOf(numPartitions)); properties.setProperty("log.flush.interval.messages", "10000"); properties.setProperty("log.flush.interval.ms", "1000"); properties.setProperty("log.retention.hours", "1"); properties.setProperty("log.segment.bytes", "536870912"); properties.setProperty("log.cleanup.interval.mins", "1"); properties.setProperty("zookeeper.connect", zkServer.getConnectionStr()); properties.setProperty("zookeeper.connection.timeout.ms", "1000000"); return properties; }
/** * Creates a topic with the given number of partitions. */ public void createTopic(String topic, int partitions) { AdminUtils.createTopic(new ZkClient(zkServer.getConnectionStr(), 20000, 2000, ZKStringSerializer$.MODULE$), topic, partitions, 1, new Properties()); } }
@Override protected void startUp() throws Exception { ZooKeeperServer zkServer = new ZooKeeperServer(); FileTxnSnapLog ftxn = new FileTxnSnapLog(dataDir, dataDir); zkServer.setTxnLogFactory(ftxn); zkServer.setTickTime(tickTime); factory = ServerCnxnFactory.createFactory(); factory.configure(getAddress(port), -1); factory.startup(zkServer); LOG.info("In memory ZK started: " + getConnectionStr()); }
@Override protected void startUp() throws Exception { ZooKeeperServer zkServer = new ZooKeeperServer(); FileTxnSnapLog ftxn = new FileTxnSnapLog(dataDir, dataDir); zkServer.setTxnLogFactory(ftxn); zkServer.setTickTime(tickTime); factory = ServerCnxnFactory.createFactory(); factory.configure(getAddress(port), -1); factory.startup(zkServer); LOG.info("In memory ZK started: " + getConnectionStr()); }
private void initializeCConf() throws IOException { cConf.unset(KafkaConstants.ConfigKeys.ZOOKEEPER_NAMESPACE_CONFIG); cConf.set(Constants.CFG_LOCAL_DATA_DIR, tmpFolder.newFolder().getAbsolutePath()); cConf.set(Constants.Zookeeper.QUORUM, zkServer.getConnectionStr()); for (Map.Entry<String, String> entry : extraConfigs.entrySet()) { cConf.set(entry.getKey(), entry.getValue()); } }
/** * Creates an unstarted instance of {@link org.apache.twill.api.TwillRunnerService}. */ public TwillRunnerService createTwillRunnerService() throws IOException { YarnTwillRunnerService runner = new YarnTwillRunnerService(config, zkServer.getConnectionStr() + "/twill", createLocationFactory()); // disable tests stealing focus runner.setJVMOptions("-Djava.awt.headless=true"); return runner; }
private ZKClientService createZKClient() { ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); zkClient.startAndWait(); return zkClient; } }
@Test public void testCreateOrSet() throws Exception { String path = "/parent/testCreateOrSet"; ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); zkClient.startAndWait(); // Create with "1" Assert.assertEquals(1, ZKExtOperations.createOrSet(zkClient, path, Suppliers.ofInstance(1), INT_CODEC, 0).get().intValue()); // Should get "1" back Assert.assertEquals(1, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue()); // Set with "2" Assert.assertEquals(2, ZKExtOperations.createOrSet(zkClient, path, Suppliers.ofInstance(2), INT_CODEC, 0).get().intValue()); // Should get "2" back Assert.assertEquals(2, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue()); zkClient.stopAndWait(); }
@Test public void testSetOrCreate() throws Exception { String path = "/parent/testSetOrCreate"; ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); zkClient.startAndWait(); // Create with "1" Assert.assertEquals(1, ZKExtOperations.setOrCreate(zkClient, path, Suppliers.ofInstance(1), INT_CODEC, 0).get().intValue()); // Should get "1" back Assert.assertEquals(1, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue()); // Set with "2" Assert.assertEquals(2, ZKExtOperations.setOrCreate(zkClient, path, Suppliers.ofInstance(2), INT_CODEC, 0).get().intValue()); // Should get "2" back Assert.assertEquals(2, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue()); zkClient.stopAndWait(); }
@Override protected void before() throws Throwable { tmpFolder.create(); zkServer = InMemoryZKServer.builder().setDataDir(tmpFolder.newFolder()).build(); zkServer.startAndWait(); LOG.info("In memory ZK started on {}", zkServer.getConnectionStr()); kafkaServer = new EmbeddedKafkaServer(generateKafkaConfig()); kafkaServer.startAndWait(); initializeCConf(); injector = createInjector(); zkClient = injector.getInstance(ZKClientService.class); zkClient.startAndWait(); kafkaClient = injector.getInstance(KafkaClientService.class); kafkaClient.startAndWait(); brokerService = injector.getInstance(BrokerService.class); brokerService.startAndWait(); String brokerList = updateKafkaBrokerList(injector.getInstance(CConfiguration.class), brokerService); LOG.info("Waiting for Kafka server to startup..."); waitForKafkaStartup(); LOG.info("Kafka server started with broker list {}", brokerList); }
@BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(TMP_FOLDER.newFolder()).build(); zkServer.startAndWait(); CConfiguration cConf = CConfiguration.create(); cConf.set(Constants.Zookeeper.QUORUM, zkServer.getConnectionStr()); Injector injector = Guice.createInjector(new ConfigModule(cConf), new ZKClientModule()); zkClientService = injector.getInstance(ZKClientService.class); zkClientService.startAndWait(); }
@BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(TEMP_FOLDER.newFolder()).build(); zkServer.startAndWait(); cConf = CConfiguration.create(); cConf.set(Constants.Zookeeper.QUORUM, zkServer.getConnectionStr()); cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath()); }
@BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(TEMP_FOLDER.newFolder()).build(); zkServer.startAndWait(); cConf = CConfiguration.create(); cConf.set(Constants.Zookeeper.QUORUM, zkServer.getConnectionStr()); cConf.setInt(Constants.Zookeeper.CFG_SESSION_TIMEOUT_MILLIS, 2000); cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath()); cConf.set(Constants.MessagingSystem.HTTP_SERVER_BIND_ADDRESS, InetAddress.getLocalHost().getHostName()); cConf.set(Constants.MessagingSystem.SYSTEM_TOPICS, "topic"); cConf.setLong(Constants.MessagingSystem.HA_FENCING_DELAY_SECONDS, 0L); namespaceQueryAdmin = new InMemoryNamespaceAdmin(); levelDBTableFactory = new LevelDBTableFactory(cConf); }
@Before public void beforeTest() throws Exception { zkServer = InMemoryZKServer.builder().setDataDir(TEMP_FOLDER.newFolder()).build(); zkServer.startAndWait(); CConfiguration cConf = CConfiguration.create(); String kafkaZKNamespace = cConf.get(KafkaConstants.ConfigKeys.ZOOKEEPER_NAMESPACE_CONFIG); kafkaZKConnect = zkServer.getConnectionStr(); if (kafkaZKNamespace != null) { ZKClientService zkClient = new DefaultZKClientService(zkServer.getConnectionStr(), 2000, null, ImmutableMultimap.<String, byte[]>of()); zkClient.startAndWait(); zkClient.create("/" + kafkaZKNamespace, null, CreateMode.PERSISTENT); zkClient.stopAndWait(); kafkaZKConnect += "/" + kafkaZKNamespace; } kafkaServer = createKafkaServer(kafkaZKConnect, TEMP_FOLDER.newFolder()); kafkaServer.startAndWait(); }
@Before public void before() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(tmpFolder.newFolder()).setTickTime(30000).build(); zkServer.startAndWait(); zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); zkClient.startAndWait(); Injector injector = Guice.createInjector( new ZookeeperModule(zkClient), new QueueModule(zkClient) ); zkQueueGroupService = injector.getInstance(ZKQueueService.class); zkQueueGroupService.startAndWait(); }
@BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(tmpFolder.newFolder()).build(); zkServer.startAndWait(); zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); zkClient.startAndWait(); }
@BeforeClass public static void beforeClass() throws SQLException, ClassNotFoundException, IOException { zkServer = InMemoryZKServer.builder().setDataDir(tmpFolder.newFolder()).setTickTime(1000).build(); zkServer.startAndWait(); zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); zkClient.startAndWait(); }
@Before public void before() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(tmpFolder.newFolder()).setTickTime(1000).build(); zkServer.startAndWait(); zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); zkClient.startAndWait(); }
@Before public void before() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(tmpFolder.newFolder()).setTickTime(1000).build(); zkServer.startAndWait(); zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); zkClient.startAndWait(); }