@Test public void testMetrics() throws Exception{ conf.setVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_QUORUM, "localhost"); conf.setVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_CLIENT_PORT, String.valueOf(server.getPort())); conf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_METRICS_ENABLED, true); conf.setBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, false); conf.setVar(HiveConf.ConfVars.HIVE_METRICS_REPORTER, MetricsReporting.JSON_FILE.name() + "," + MetricsReporting.JMX.name()); MetricsFactory.init(conf); CodahaleMetrics metrics = (CodahaleMetrics) MetricsFactory.getInstance(); HiveLockManagerCtx ctx = new HiveLockManagerCtx(conf); ZooKeeperHiveLockManager zMgr= new ZooKeeperHiveLockManager(); zMgr.setContext(ctx); ZooKeeperHiveLock curLock = zMgr.lock(hiveLock, HiveLockMode.SHARED, false); String json = metrics.dumpJson(); MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.COUNTER, MetricsConstant.ZOOKEEPER_HIVE_SHAREDLOCKS, 1); zMgr.unlock(curLock); json = metrics.dumpJson(); MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.COUNTER, MetricsConstant.ZOOKEEPER_HIVE_SHAREDLOCKS, 0); zMgr.close(); }
public int getPort() { return testingServer.getPort(); }
public static String startZooJVM() { try { @SuppressWarnings("resource") TestingServer zkServer = new TestingServer(); zkServer.start(); return "localhost:" + zkServer.getPort(); } catch (Exception ex) { throw new RuntimeException(ex); } } }
/** Setup a fresh ZooKeeper test server and return a curator client for it. * The test server is added to {@link ZkT#servers}. */ public static CuratorFramework curator() { TestingServer server = localServer(); String connectString = "localhost:" + server.getPort(); return Zk.curator(connectString); } }
private CompletableFuture<Void> startBroker() throws Exception { if(!this.managedZk) { if (zookeeperPort == ALLOCATE_RANDOM_PORT) { zookeeper = new TestingServer(true); zookeeperPort = zookeeper.getPort(); } else { zookeeper = new TestingServer(zookeeperPort, true); } } kafkaPort = kafkaPort == ALLOCATE_RANDOM_PORT ? InstanceSpec.getRandomPort() : kafkaPort; String zookeeperConnectionString = zookeeper.getConnectString(); KafkaConfig kafkaConfig = buildKafkaConfig(zookeeperConnectionString); LOGGER.info("Starting Kafka server with config: {}", kafkaConfig.props()); kafkaServer = new KafkaServerStartable(kafkaConfig); brokerStarted = true; final Integer brokerId = kafkaServer.staticServerConfig().getInt(KafkaConfig.BrokerIdProp()); if(brokerId != null) { /* Avoid warning for missing meta.properties */ Files.write(kafkaLogDir.resolve("meta.properties"), ("version=0\nbroker.id=" + brokerId).getBytes(StandardCharsets.UTF_8)); } return CompletableFuture.runAsync(() -> kafkaServer.startup()); }
private CompletableFuture<Void> startBroker() throws Exception { if(!this.managedZk) { if (zookeeperPort == ALLOCATE_RANDOM_PORT) { zookeeper = new TestingServer(true); zookeeperPort = zookeeper.getPort(); } else { zookeeper = new TestingServer(zookeeperPort, true); } } kafkaPort = kafkaPort == ALLOCATE_RANDOM_PORT ? InstanceSpec.getRandomPort() : kafkaPort; String zookeeperConnectionString = zookeeper.getConnectString(); KafkaConfig kafkaConfig = buildKafkaConfig(zookeeperConnectionString); LOGGER.info("Starting Kafka server with config: {}", kafkaConfig.props()); kafkaServer = new KafkaServerStartable(kafkaConfig); brokerStarted = true; final Integer brokerId = kafkaServer.staticServerConfig().getInt(KafkaConfig.BrokerIdProp()); if(brokerId != null) { /* Avoid warning for missing meta.properties */ Files.write(kafkaLogDir.resolve("meta.properties"), ("version=0\nbroker.id=" + brokerId).getBytes(StandardCharsets.UTF_8)); } return CompletableFuture.runAsync(() -> kafkaServer.startup()); }
@Before public void before() { try { server = ZkT.localServer(); server.start(); } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex); } String connectionString = "localhost:"+server.getPort(); client = Zk.curator(connectionString); try { client.blockUntilConnected(); } catch (InterruptedException e) { e.printStackTrace(); } }
@Override protected PatchLog patchLog() { try { String connectString = "localhost:" + server.getPort(); RetryPolicy policy = new ExponentialBackoffRetry(10000, 5); client = CuratorFrameworkFactory.builder() .connectString(connectString) .retryPolicy(policy) .build(); client.start(); //client.getConnectionStateListenable().addListener((c, newState)->System.out.println("** STATE CHANGED TO : " + newState)); client.blockUntilConnected(); LocalServerConfig config = LocalServers.configZk(connectString); PatchStore ps = new PatchStoreProviderZk().create(config); ps.initialize(new DataRegistry("TestPatchLogZk"), config); DataSourceDescription dsd = new DataSourceDescription(Id.create(), "ABC", "http://example/ABC"); PatchLog patchLog = ps.createLog(dsd); return patchLog; } catch (Exception ex) { ex.printStackTrace(); return null; } }
@BeforeClass public static void startZK() throws Exception { zkServer = new TestingServer(); zkServer.start(); conf.setProperty(LockManagerConfiguration.IS_ENABLED, "true"); conf.setProperty(LockManagerConfiguration.ZK_BASE_PATH, "/////test/////lock_manager////"); conf.setProperty(ZookeeperConfiguration.ZK_QUORUM, zkServer.getConnectString()); conf.setProperty(ZookeeperConfiguration.ZK_PORT, Integer.toString(zkServer.getPort())); conf.setProperty(LockManagerConfiguration.ACQUIRE_LOCK_TIME_MS, Integer.toString(10 * 1000)); conf.setProperty(LockManagerConfiguration.ZK_SESSION_TIMEOUT_MS, Integer.toString(30 * 1000)); conf.setProperty(LockManagerConfiguration.ZK_CONNECTION_TIMEOUT_MS, Integer.toString(12 * 1000)); }
@Before public void beforeEach() throws Exception { zookeeper = new TestingServer(true); exhibitor = buildExhibitor(zookeeper.getPort()); exhibitor.start(); metaDataService = buildMetaDataService(); metaDataService.start(); Config config = ConfigFactory.load("aws-deployment-test") .withValue( "awsDeploymentTest.exhibitor.url", ConfigValueFactory.fromAnyRef(exhibitor.url("/").toString())) .withValue( "awsDeploymentTest.identityUrl", ConfigValueFactory.fromAnyRef(metaDataService.url("/").toString())); awsDeploymentConfig = new AwsDeploymentConfig(config.getConfig("awsDeploymentTest")); awsDeployment = new AwsDeployment(awsDeploymentConfig, 443); }
@Override protected void configure() { binder().requireExplicitBindings(); install(new TestConfigModule(testingServer.getPort())); bind(WorkerAdvertiser.class); install(new CuratorModule()); bind(SliceRunner.class); bind(TaskProgressClient.class).to(NoOpTaskProgressClient.class); install(new TaskPluginRegistryModule()); install(new IpcJsonModule()); } });