org.apache.curator.test.TestingServer Java Examples
The following examples show how to use
org.apache.curator.test.TestingServer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KafkaTestServerImpl.java From eagle with Apache License 2.0 | 6 votes |
@Override public void start() throws Exception { zkServer = new TestingServer(zookeeperPort, logDir); ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3); curatorClient = CuratorFrameworkFactory.newClient(zkServer.getConnectString(), retryPolicy); curatorClient.start(); Properties props = new Properties(); props.setProperty("zookeeper.connect", zkServer.getConnectString()); props.setProperty("broker.id", "0"); props.setProperty("port", "" + kafkaPort); props.setProperty("log.dirs", logDir.getAbsolutePath()); props.setProperty("auto.create.topics.enable", "true"); kafkaServer = new KafkaServerStartable(new KafkaConfig(props)); kafkaServer.startup(); }
Example #2
Source File: TestZooKeeperOutput.java From envelope with Apache License 2.0 | 6 votes |
@BeforeClass public static void setup() throws Exception { zk = new TestingServer(-1, true); Map<String, Object> configMap = Maps.newHashMap(); configMap.put(ZooKeeperConnection.CONNECTION_CONFIG, "127.0.0.1:" + zk.getPort()); configMap.put(ZooKeeperOutput.SCHEMA_CONFIG + ".type", "com.cloudera.labs.envelope.zookeeper.DummyFlatSchema"); configMap.put(ZooKeeperOutput.SCHEMA_CONFIG + ".field.names", fieldNames); configMap.put(ZooKeeperOutput.SCHEMA_CONFIG + ".field.types", fieldTypes); configMap.put(ZooKeeperOutput.KEY_FIELD_NAMES_CONFIG, keyFieldNames); config = ConfigFactory.parseMap(configMap); List<StructField> fields = Lists.newArrayList(); for (int fieldNum = 0; fieldNum < fieldNames.size(); fieldNum++) { fields.add(DataTypes.createStructField(fieldNames.get(fieldNum), ConfigurationDataTypes.getSparkDataType(fieldTypes.get(fieldNum)), true)); } schema = DataTypes.createStructType(fields); keySchema = SchemaUtils.subsetSchema(schema, keyFieldNames); }
Example #3
Source File: ServiceCacheLeakTester.java From curator with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { TestingServer testingServer = new TestingServer(); final CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(testingServer.getConnectString(), new RetryOneTime(1)); try { curatorFramework.start(); doWork(curatorFramework); System.gc(); System.out.println("Done - get dump"); Thread.currentThread().join(); } finally { CloseableUtils.closeQuietly(curatorFramework); CloseableUtils.closeQuietly(testingServer); } }
Example #4
Source File: TestRoundRobinJedisPool.java From jodis with MIT License | 6 votes |
@Before public void setUp() throws Exception { deleteDirectory(testDir); testDir.mkdirs(); zkServer = new TestingServer(-1, testDir, true); zkPort = zkServer.getPort(); redisPort1 = probeFreePort(); redis1 = new RedisServer(redisPort1); redis1.start(); waitUntilRedisStarted(redisPort1); redisPort2 = probeFreePort(); redis2 = new RedisServer(redisPort2); redis2.start(); waitUntilRedisStarted(redisPort2); jedis1 = new Jedis("localhost", redisPort1); jedis2 = new Jedis("localhost", redisPort2); addNode("node1", redisPort1, "online"); jodisPool = RoundRobinJedisPool.create().curatorClient("localhost:" + zkPort, 5000) .zkProxyDir(zkProxyDir).build(); }
Example #5
Source File: TransactionExample.java From ZKRecipesByExample with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { TestingServer server = new TestingServer(); CuratorFramework client = null; try { client = createSimple(server.getConnectString()); client.start(); ZKPaths.mkdirs(client.getZookeeperClient().getZooKeeper(),"/a"); ZKPaths.mkdirs(client.getZookeeperClient().getZooKeeper(),"/another/path"); ZKPaths.mkdirs(client.getZookeeperClient().getZooKeeper(),"/yet/another/path"); transaction(client); } catch (Exception ex) { ex.printStackTrace(); } finally { CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(server); } }
Example #6
Source File: ZookeeperBridgeTest.java From vertx-service-discovery with Apache License 2.0 | 6 votes |
@Before public void startZookeeper() throws Exception { zkTestServer = new TestingServer(2181); cli = CuratorFrameworkFactory.newClient(zkTestServer.getConnectString(), new RetryOneTime(2000)); cli.start(); discovery = ServiceDiscoveryBuilder.builder(String.class) .client(cli) .basePath("/discovery") .watchInstances(true) .build(); discovery.start(); vertx = Vertx.vertx(); sd = io.vertx.servicediscovery.ServiceDiscovery.create(vertx); }
Example #7
Source File: ZooKeeperLeaderRetrievalTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Before public void before() throws Exception { testingServer = new TestingServer(); config = new Configuration(); config.setString(HighAvailabilityOptions.HA_MODE, "zookeeper"); config.setString(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM, testingServer.getConnectString()); CuratorFramework client = ZooKeeperUtils.startCuratorFramework(config); highAvailabilityServices = new ZooKeeperHaServices( client, TestingUtils.defaultExecutor(), config, new VoidBlobStore()); }
Example #8
Source File: StreamingTestBase.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
@Before public void init() { logger.debug("Start zk and prepare meatdata."); staticCreateTestMetadata(); int realPort = port; for (int i = 0; i <= retryTimes; i++) { try { testingServer = new TestingServer(realPort, false); testingServer.start(); } catch (Exception e) { // maybe caused by port occupy logger.error("Failed start zookeeper server at " + realPort, e); realPort++; continue; } break; } Assume.assumeTrue(realPort - port < retryTimes); connectStr = "localhost:" + realPort; System.setProperty("kylin.env.zookeeper-connect-string", connectStr); metadataStore = StreamMetadataStoreFactory.getZKStreamMetaDataStore(); initZookeeperMetadataStore(); }
Example #9
Source File: ZkDatasetStateStoreTest.java From incubator-gobblin with Apache License 2.0 | 6 votes |
@BeforeClass public void setUp() throws Exception { ConfigBuilder configBuilder = ConfigBuilder.create(); testingServer = new TestingServer(-1); zkJobStateStore = new ZkStateStore<>(testingServer.getConnectString(), "/STATE_STORE/TEST", false, JobState.class); configBuilder.addPrimitive(ZkStateStoreConfigurationKeys.STATE_STORE_ZK_CONNECT_STRING_KEY, testingServer.getConnectString()); configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_ROOT_DIR_KEY, "/STATE_STORE/TEST2"); ClassAliasResolver<DatasetStateStore.Factory> resolver = new ClassAliasResolver<>(DatasetStateStore.Factory.class); DatasetStateStore.Factory stateStoreFactory = resolver.resolveClass("zk").newInstance(); zkDatasetStateStore = stateStoreFactory.createStateStore(configBuilder.build()); // clear data that may have been left behind by a prior test run zkJobStateStore.delete(TEST_JOB_NAME); zkDatasetStateStore.delete(TEST_JOB_NAME); zkJobStateStore.delete(TEST_JOB_NAME2); zkDatasetStateStore.delete(TEST_JOB_NAME2); }
Example #10
Source File: ZooKeeperLeaderRetrievalTest.java From flink with Apache License 2.0 | 6 votes |
@Before public void before() throws Exception { testingServer = new TestingServer(); config = new Configuration(); config.setString(HighAvailabilityOptions.HA_MODE, "zookeeper"); config.setString(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM, testingServer.getConnectString()); CuratorFramework client = ZooKeeperUtils.startCuratorFramework(config); highAvailabilityServices = new ZooKeeperHaServices( client, TestingUtils.defaultExecutor(), config, new VoidBlobStore()); }
Example #11
Source File: LocalRegistryServerHATest.java From registry with Apache License 2.0 | 6 votes |
@Before public void startZooKeeper() throws Exception { testingServer = new TestingServer(true); File serverYAMLFile = new File(SCHEMA_REGISTRY_TEST_CONFIGURATION.getServerYAMLPath()); String fileContent = FileUtils.readFileToString(serverYAMLFile,"UTF-8" ); File registryConfigFile = File.createTempFile("ha-", ".yaml"); registryConfigFile.deleteOnExit(); try (FileWriter writer = new FileWriter(registryConfigFile)) { IOUtils.write(fileContent.replace("__zk_connect_url__", testingServer.getConnectString()), writer); } SchemaRegistryTestConfiguration testConfiguration = new SchemaRegistryTestConfiguration(registryConfigFile.getAbsolutePath(), SCHEMA_REGISTRY_TEST_CONFIGURATION.getClientYAMLPath()); List<SchemaRegistryTestServerClientWrapper> schemaRegistryServers = new ArrayList<>(); for (int i = 1; i < 4; i++) { SchemaRegistryTestServerClientWrapper server = new SchemaRegistryTestServerClientWrapper(testConfiguration); schemaRegistryServers.add(server); server.startTestServer(); } registryServers = Collections.unmodifiableList(schemaRegistryServers); }
Example #12
Source File: KafkaTestUtil.java From siddhi-io-kafka with Apache License 2.0 | 6 votes |
public static void setupKafkaBroker() { try { log.info("#############################################################################################"); log.info("################################# ZOOKEEPER STARTED ######################################"); log.info("#############################################################################################"); // mock zookeeper zkTestServer = new TestingServer(2181); // mock kafka Properties props = new Properties(); props.put("broker.id", "0"); props.put("host.name", "localhost"); props.put("port", "9092"); props.put("log.dir", kafkaLogDir); props.put("zookeeper.connect", zkTestServer.getConnectString()); props.put("replica.socket.timeout.ms", "30000"); props.put("delete.topic.enable", "true"); props.put("log.cleaner.dedupe.buffer.size", CLEANER_BUFFER_SIZE); KafkaConfig config = new KafkaConfig(props); kafkaServer = new KafkaServerStartable(config); kafkaServer.startup(); } catch (Exception e) { log.error("Error running local Kafka broker / Zookeeper", e); } }
Example #13
Source File: CuratorServiceResource.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Override protected void before() throws Throwable { zkServer = new TestingServer(true); ZookeeperConfiguration zookeeperConfiguration = ZookeeperTestUtils.withEmbeddedZookeeper(Mockito.mock(ZookeeperConfiguration.class), zkServer.getConnectString()); zkPaths = new ZookeeperPaths(zookeeperConfiguration); ZookeeperClusterResolver clusterResolver = new DefaultZookeeperClusterResolver(zookeeperConfiguration); curatorService = new CuratorServiceImpl(zookeeperConfiguration, clusterResolver, titusRuntime.getRegistry()); curatorService.start(); }
Example #14
Source File: TestZooKeeperStateProvider.java From localization_nifi with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { zkServer = new TestingServer(true); zkServer.start(); final Map<PropertyDescriptor, String> properties = new HashMap<>(defaultProperties); properties.put(ZooKeeperStateProvider.CONNECTION_STRING, zkServer.getConnectString()); this.provider = createProvider(properties); }
Example #15
Source File: ResumeCheckpointManuallyITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testExternalizedFSCheckpointsWithLocalRecoveryZookeeper() throws Exception { TestingServer zkServer = new TestingServer(); zkServer.start(); try { final File checkpointDir = temporaryFolder.newFolder(); testExternalizedCheckpoints( checkpointDir, zkServer.getConnectString(), createFsStateBackend(checkpointDir), true); } finally { zkServer.stop(); } }
Example #16
Source File: BaseZkTest.java From sofa-rpc with Apache License 2.0 | 5 votes |
@BeforeClass public static void adBeforeClass() { RpcRunningState.setUnitTestMode(true); try { server = new TestingServer(2181, true); server.start(); } catch (Exception e) { e.printStackTrace(); } }
Example #17
Source File: MetaServerBaseTest.java From hermes with Apache License 2.0 | 5 votes |
protected void startZKServer(int port) throws Exception { try { m_zkServer = new TestingServer(port); m_zkServer.restart(); logger.info("==Start ZKServer== on port {} Success.", port); } catch (java.net.BindException e) { logger.warn("==Start ZKServer== on port {} failed. BindException.", port); } }
Example #18
Source File: ZookeeperLocalCluster.java From hadoop-mini-clusters with Apache License 2.0 | 5 votes |
@Override public void start() throws Exception { LOG.info("ZOOKEEPER: Starting Zookeeper on port: {}", port); InstanceSpec spec = new InstanceSpec(new File(tempDir), port, electionPort, quorumPort, deleteDataDirectoryOnClose, serverId, tickTime, maxClientCnxns, customProperties); testingServer = new TestingServer(spec, true); }
Example #19
Source File: S3T.java From rdf-delta with Apache License 2.0 | 5 votes |
public static Pair<PatchStore, S3Mock> setup() { TestingServer server = ZkT.localServer(); String connectString = "localhost:" + server.getPort(); int port = WebLib.choosePort(); S3Mock api = new S3Mock.Builder() .withPort(port) .withInMemoryBackend().build(); // Must start so provider.create works. api.start(); // AWSCredentials credentials = new AnonymousAWSCredentials(); // AmazonS3ClientBuilder // .standard() // .withPathStyleAccessEnabled(true) // .withEndpointConfiguration(endpoint) // .withCredentials(new AWSStaticCredentialsProvider(credentials)) // .build(); EndpointConfiguration endpointCfg = new EndpointConfiguration("http://localhost:"+port+"/", REGION); String endpoint = endpointCfg.getServiceEndpoint(); S3Config cfg = S3Config.create() .bucketName(BUCKET_NAME) .region(REGION) .endpoint(endpoint) .build(); LocalServerConfig config = S3.configZkS3(connectString, cfg); PatchStoreProvider provider = new PatchStoreProviderZkS3(); PatchStore patchStore = provider.create(config); patchStore.initialize(new DataSourceRegistry("X"), config); return Pair.create(patchStore, api); }
Example #20
Source File: TestModule.java From dcos-cassandra-service with Apache License 2.0 | 5 votes |
public static TestingServer createTestingServerQuietly() { try { return new TestingServer(40000); } catch (Exception ex) { return null; } }
Example #21
Source File: TestSentryServiceDiscovery.java From incubator-sentry with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { server = new TestingServer(); // HA conf Configuration conf = new Configuration(false); conf.set(ServerConfig.SENTRY_HA_ENABLED, "true"); conf.set(ServerConfig.SENTRY_HA_ZOOKEEPER_NAMESPACE, "sentry-test"); conf.set(ServerConfig.SENTRY_HA_ZOOKEEPER_QUORUM, server.getConnectString()); haContext = HAContext.getHAContext(conf); }
Example #22
Source File: TestChildReaper.java From big-c with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { while(this.server == null) { try { this.server = new TestingServer(); } catch (BindException var2) { System.err.println("Getting bind exception - retrying to allocate server"); this.server = null; } } }
Example #23
Source File: ResumeCheckpointManuallyITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testExternalizedFullRocksDBCheckpointsWithLocalRecoveryZookeeper() throws Exception { TestingServer zkServer = new TestingServer(); zkServer.start(); try { final File checkpointDir = temporaryFolder.newFolder(); testExternalizedCheckpoints( checkpointDir, zkServer.getConnectString(), createRocksDBStateBackend(checkpointDir, false), true); } finally { zkServer.stop(); } }
Example #24
Source File: CuratorLeaderSelectorTest.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { zkTestServer = new TestingServer(); zkTestServer.start(); System.setProperty("kylin.env.zookeeper-connect-string", zkTestServer.getConnectString()); System.setProperty("kylin.server.mode", "all"); createTestMetadata(); }
Example #25
Source File: CloudConfigSample.java From cloud-config with MIT License | 5 votes |
private static void prepare(TestingServer server) throws Exception { CuratorFramework zkRootClient = null; try { zkRootClient = CuratorFrameworkFactory.builder() .connectString(server.getConnectString()) .retryPolicy(new BoundedExponentialBackoffRetry(10, 100, 7)) .build(); zkRootClient.start(); ZooKeeper zk = zkRootClient.getZookeeperClient().getZooKeeper(); ZKPaths.mkdirs(zk, "/" + CloudConfigCommon.CONFIG_ROOT); ZKPaths.mkdirs(zk, "/"+CloudConfigCommon.PROPERTY_ROOT); CuratorFramework zkConfigClient = zkRootClient.usingNamespace(CloudConfigCommon.CONFIG_ROOT); // CuratorFramework zkPropsClient = zkRootClient.usingNamespace(CloudConfigCommon.PROPERTY_ROOT); String config = "{\n" + " \"driverClassName\" : \"com.mysql.jdbc.Driver\",\n" + " \"userName\" : \"root\",\n" + " \"password\" : \"1111\", \n"+ " \"jdbcUrl\" : \"jdbc:mysql://127.0.0.1:3306/a?characterEncoding=utf8&createDatabaseIfNotExist=true\"\n"+ "}"; zkConfigClient.create().creatingParentsIfNeeded().forPath("/database/mydb", config.getBytes()); } finally { if(zkRootClient!=null) { zkRootClient.close(); } } }
Example #26
Source File: CuratorSchedulerTest.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { zkTestServer = new TestingServer(); zkTestServer.start(); System.setProperty("kylin.env.zookeeper-connect-string", zkTestServer.getConnectString()); System.setProperty("kylin.server.mode", "query"); createTestMetadata(); }
Example #27
Source File: ZookeeperDistributedLockTest.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { zkTestServer = new TestingServer(); zkTestServer.start(); System.setProperty("kylin.env.zookeeper-connect-string", zkTestServer.getConnectString()); createTestMetadata(); factory = new ZookeeperDistributedLock.Factory(); }
Example #28
Source File: JobHistorySpoutTest.java From eagle with Apache License 2.0 | 5 votes |
private void createZk() throws Exception { int port = 2111; File logFile = new File(System.getProperty("java.io.tmpdir"), "zk/logs/zookeeper-test-" + port); FileUtils.deleteQuietly(logFile); server = new TestingServer(port, logFile); ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3); zookeeper = CuratorFrameworkFactory.newClient(server.getConnectString(), retryPolicy); }
Example #29
Source File: CoordinatorTest.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { logger.info("Setup coordinator test env."); staticCreateTestMetadata(); testingServer = new TestingServer(12181, false); testingServer.start(); System.setProperty("kylin.env.zookeeper-connect-string", "localhost:12181"); metadataStore = StreamMetadataStoreFactory.getZKStreamMetaDataStore(); initZookeeperMetadataStore(); mockCube(); }
Example #30
Source File: ZookeeperClusterTest.java From pinpoint with Apache License 2.0 | 5 votes |
private static void closeZookeeperServer(TestingServer mockZookeeperServer) throws Exception { try { if (mockZookeeperServer != null) { mockZookeeperServer.close(); } } catch (Exception e) { e.printStackTrace(); } }