Java Code Examples for org.apache.curator.test.TestingServer#start()

The following examples show how to use org.apache.curator.test.TestingServer#start() . 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: StreamingTestBase.java    From kylin with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: CuratorLeaderSelectorTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@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 3
Source File: CoordinatorTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@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 4
Source File: ResumeCheckpointManuallyITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: ResumeCheckpointManuallyITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalizedFSCheckpointsZookeeper() throws Exception {
	TestingServer zkServer = new TestingServer();
	zkServer.start();
	try {
		final File checkpointDir = temporaryFolder.newFolder();
		testExternalizedCheckpoints(
			checkpointDir,
			zkServer.getConnectString(),
			createFsStateBackend(checkpointDir),
			false);
	} finally {
		zkServer.stop();
	}
}
 
Example 6
Source File: ResumeCheckpointManuallyITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalizedIncrementalRocksDBCheckpointsWithLocalRecoveryZookeeper() throws Exception {
	TestingServer zkServer = new TestingServer();
	zkServer.start();
	try {
		final File checkpointDir = temporaryFolder.newFolder();
		testExternalizedCheckpoints(
			checkpointDir,
			zkServer.getConnectString(),
			createRocksDBStateBackend(checkpointDir, true),
			true);
	} finally {
		zkServer.stop();
	}
}
 
Example 7
Source File: ResumeCheckpointManuallyITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalizedIncrementalRocksDBCheckpointsZookeeper() throws Exception {
	TestingServer zkServer = new TestingServer();
	zkServer.start();
	try {
		final File checkpointDir = temporaryFolder.newFolder();
		testExternalizedCheckpoints(
			checkpointDir,
			zkServer.getConnectString(),
			createRocksDBStateBackend(checkpointDir, true),
			false);
	} finally {
		zkServer.stop();
	}
}
 
Example 8
Source File: ZookeeperDistributedLockTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@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 9
Source File: ResumeCheckpointManuallyITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: ResumeCheckpointManuallyITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: ResumeCheckpointManuallyITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalizedFullRocksDBCheckpointsZookeeper() throws Exception {
	TestingServer zkServer = new TestingServer();
	zkServer.start();
	try {
		final File checkpointDir = temporaryFolder.newFolder();
		testExternalizedCheckpoints(
			checkpointDir,
			zkServer.getConnectString(),
			createRocksDBStateBackend(checkpointDir, false),
			false);
	} finally {
		zkServer.stop();
	}
}
 
Example 12
Source File: Matrix.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
public static String startZooJVM() {
    try {
        zkServer = new TestingServer();
        zkServer.start();
        return "localhost:"+zkServer.getPort();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 13
Source File: ResumeCheckpointManuallyITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 14
Source File: DubboTccProviderStarter.java    From seata-samples with Apache License 2.0 4 votes vote down vote up
private static void mockZKServer() throws Exception {
    //Mock zk server,作为 dubbo 配置中心
    server = new TestingServer(2181, true);
    server.start();
}
 
Example 15
Source File: ZookeeperBackendServiceWithEphemeralAndGuaranteedTest.java    From vertx-service-discovery with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void startZookeeper() throws Exception {
  server = new TestingServer(DEFAULT_PORT);
  server.start();
}
 
Example 16
Source File: ZookeeperDataSourceTest.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
@Test
public void testZooKeeperDataSourceAuthorization() throws Exception {
    TestingServer server = new TestingServer(21812);
    server.start();

    final String remoteAddress = server.getConnectString();
    final String groupId = "sentinel-zk-ds-demo";
    final String dataId = "flow-HK";
    final String path = "/" + groupId + "/" + dataId;
    final String scheme = "digest";
    final String auth = "root:123456";

    AuthInfo authInfo = new AuthInfo(scheme, auth.getBytes());
    List<AuthInfo> authInfoList = Collections.singletonList(authInfo);

    CuratorFramework zkClient = CuratorFrameworkFactory.builder().
            connectString(remoteAddress).
            retryPolicy(new ExponentialBackoffRetry(3, 100)).
            authorization(authInfoList).
            build();
    zkClient.start();
    Stat stat = zkClient.checkExists().forPath(path);
    if (stat == null) {
        ACL acl = new ACL(ZooDefs.Perms.ALL, new Id(scheme, DigestAuthenticationProvider.generateDigest(auth)));
        zkClient.create().creatingParentContainersIfNeeded().withACL(Collections.singletonList(acl)).forPath(path, null);
    }

    ReadableDataSource<String, List<FlowRule>> flowRuleDataSource = new ZookeeperDataSource<List<FlowRule>>(remoteAddress,
            authInfoList, groupId, dataId,
            new Converter<String, List<FlowRule>>() {
                @Override
                public List<FlowRule> convert(String source) {
                    return JSON.parseObject(source, new TypeReference<List<FlowRule>>() {
                    });
                }
            });
    FlowRuleManager.register2Property(flowRuleDataSource.getProperty());


    final String resourceName = "HK";
    publishThenTestFor(zkClient, path, resourceName, 10);
    publishThenTestFor(zkClient, path, resourceName, 15);

    zkClient.close();
    server.stop();
}
 
Example 17
Source File: CassandraStateTest.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
@Before
public void beforeEach() throws Exception {
    server = new TestingServer();

    server.start();

    final ConfigurationFactory<MutableSchedulerConfiguration> factory =
            new ConfigurationFactory<>(
                    MutableSchedulerConfiguration.class,
                    BaseValidator.newValidator(),
                    Jackson.newObjectMapper().registerModule(
                            new GuavaModule())
                            .registerModule(new Jdk8Module()),
                    "dw");

    config = factory.build(
            new SubstitutingSourceProvider(
                    new FileConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false, true)),
            Resources.getResource("scheduler.yml").getFile());

    ServiceConfig initial = config.createConfig().getServiceConfig();

    final CassandraSchedulerConfiguration targetConfig = config.createConfig();
    clusterTaskConfig = targetConfig.getClusterTaskConfig();

    final CuratorFrameworkConfig curatorConfig = config.getCuratorConfig();
    RetryPolicy retryPolicy =
            (curatorConfig.getOperationTimeout().isPresent()) ?
                    new RetryUntilElapsed(
                            curatorConfig.getOperationTimeoutMs()
                                    .get()
                                    .intValue()
                            , (int) curatorConfig.getBackoffMs()) :
                    new RetryForever((int) curatorConfig.getBackoffMs());

    stateStore = new CuratorStateStore(
            targetConfig.getServiceConfig().getName(),
            server.getConnectString(),
            retryPolicy);
    stateStore.storeFrameworkId(Protos.FrameworkID.newBuilder().setValue("1234").build());
    identity = new IdentityManager(
            initial,stateStore);

    identity.register("test_id");

    DefaultConfigurationManager configurationManager =
            new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
            config.createConfig().getServiceConfig().getName(),
            server.getConnectString(),
            config.createConfig(),
            new ConfigValidator(),
            stateStore);

    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    when(mockCapabilities.supportsNamedVips()).thenReturn(true);
    configuration = new ConfigurationManager(
            new CassandraDaemonTask.Factory(mockCapabilities),
            configurationManager);

    cassandraState = new CassandraState(
            configuration,
            clusterTaskConfig,
            stateStore);
}
 
Example 18
Source File: TestBase.java    From sofa-dashboard-client with Apache License 2.0 4 votes vote down vote up
@Before
public void setupZkServer() throws Exception {
    testServer = new TestingServer(22181, true);
    testServer.start();
}
 
Example 19
Source File: AbstractTestWithDbProvider.java    From incubator-sentry with Apache License 2.0 4 votes vote down vote up
public static void createContext() throws Exception {
  conf = new Configuration(false);
  policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
  properties.put(HiveServerFactory.AUTHZ_PROVIDER_BACKEND, SimpleDBProviderBackend.class.getName());
  properties.put(ConfVars.HIVE_AUTHORIZATION_TASK_FACTORY.varname,
      SentryHiveAuthorizationTaskFactoryImpl.class.getName());
  properties.put(ServerConfig.SECURITY_MODE, ServerConfig.SECURITY_MODE_NONE);
  properties.put(ServerConfig.ADMIN_GROUPS, ADMINGROUP);
  properties.put(ServerConfig.RPC_ADDRESS, SERVER_HOST);
  properties.put(ServerConfig.RPC_PORT, String.valueOf(0));
  dbDir = new File(Files.createTempDir(), "sentry_policy_db");
  properties.put(ServerConfig.SENTRY_STORE_JDBC_URL,
      "jdbc:derby:;databaseName=" + dbDir.getPath() + ";create=true");
  properties.put(ServerConfig.SENTRY_STORE_JDBC_PASS, "dummy");
  properties.put(ServerConfig.SENTRY_VERIFY_SCHEM_VERSION, "false");
  properties.put(ServerConfig.SENTRY_STORE_GROUP_MAPPING,
      ServerConfig.SENTRY_STORE_LOCAL_GROUP_MAPPING);
  policyFilePath = new File(Files.createTempDir(), "sentry-policy-file.ini");
  properties.put(ServerConfig.SENTRY_STORE_GROUP_MAPPING_RESOURCE,
      policyFilePath.getPath());
  if (haEnabled) {
    zkServer = new TestingServer();
    zkServer.start();
    properties.put(ServerConfig.SENTRY_HA_ENABLED, "true");
    properties.put(ServerConfig.SENTRY_HA_ZOOKEEPER_NAMESPACE, "sentry-test");
    properties.put(ServerConfig.SENTRY_HA_ZOOKEEPER_QUORUM, zkServer.getConnectString());
  }
  for (Map.Entry<String, String> entry : properties.entrySet()) {
    conf.set(entry.getKey(), entry.getValue());
  }
  for (int i = 0; i < sentryServerCount; i++) {
    SentryService server = new SentryServiceFactory().create(new Configuration(conf));
    servers.add(server);
    properties.put(ClientConfig.SERVER_RPC_ADDRESS, server.getAddress()
        .getHostName());
    properties.put(ClientConfig.SERVER_RPC_PORT,
        String.valueOf(server.getAddress().getPort()));
  }

  context = AbstractTestWithHiveServer.createContext(properties);
  policyFile
      .setUserGroupMapping(StaticUserGroup.getStaticMapping())
      .write(context.getPolicyFile(), policyFilePath);

  startSentryService();
}
 
Example 20
Source File: DubboSagaProviderStarter.java    From seata-samples with Apache License 2.0 4 votes vote down vote up
private static void mockZKServer() throws Exception {
    //Mock zk server,作为 dubbo 配置中心
    server = new TestingServer(2181, true);
    server.start();
}