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

The following examples show how to use org.apache.curator.test.TestingServer#stop() . 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: 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 2
Source File: ResumeCheckpointManuallyITCase.java    From flink 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 3
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 4
Source File: ZookeeperDataSourceTest.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
@Test
public void testZooKeeperDataSource() throws Exception {
    TestingServer server = new TestingServer(21812);
    server.start();

    final String remoteAddress = server.getConnectString();
    final String path = "/sentinel-zk-ds-demo/flow-HK";

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

    CuratorFramework zkClient = CuratorFrameworkFactory.newClient(remoteAddress,
            new ExponentialBackoffRetry(3, 1000));
    zkClient.start();
    Stat stat = zkClient.checkExists().forPath(path);
    if (stat == null) {
        zkClient.create().creatingParentContainersIfNeeded().withMode(CreateMode.PERSISTENT).forPath(path, null);
    }

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

    zkClient.close();
    server.stop();
}
 
Example 5
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 6
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 7
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 8
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 9
Source File: ResumeCheckpointManuallyITCase.java    From flink 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 10
Source File: ZookeeperDataSourceTest.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
@Test
public void testZooKeeperDataSource() throws Exception {
    TestingServer server = new TestingServer(21812);
    server.start();

    final String remoteAddress = server.getConnectString();
    final String path = "/sentinel-zk-ds-demo/flow-HK";

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

    CuratorFramework zkClient = CuratorFrameworkFactory.newClient(remoteAddress,
            new ExponentialBackoffRetry(3, 1000));
    zkClient.start();
    Stat stat = zkClient.checkExists().forPath(path);
    if (stat == null) {
        zkClient.create().creatingParentContainersIfNeeded().withMode(CreateMode.PERSISTENT).forPath(path, null);
    }

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

    zkClient.close();
    server.stop();
}
 
Example 11
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 12
Source File: ResumeCheckpointManuallyITCase.java    From Flink-CEPplus 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 13
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 14
Source File: ResumeCheckpointManuallyITCase.java    From Flink-CEPplus 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 15
Source File: ResumeCheckpointManuallyITCase.java    From flink 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 16
Source File: ResumeCheckpointManuallyITCase.java    From Flink-CEPplus 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 17
Source File: ZooKeeperClusterServiceTest.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void testClusterService() throws Exception {
    final int zkPort =  AvailablePortFinder.getNextAvailable();
    final File zkDir =  temporaryFolder.newFolder();

    final TestingServer zkServer = new TestingServer(zkPort, zkDir);
    zkServer.start();

    try {
        new ApplicationContextRunner()
            .withUserConfiguration(TestConfiguration.class)
            .withPropertyValues(
                "debug=false",
                "spring.main.banner-mode=OFF",
                "spring.application.name=" + UUID.randomUUID().toString(),
                "camel.component.zookeeper.cluster.service.enabled=true",
                "camel.component.zookeeper.cluster.service.nodes=localhost:" + zkPort,
                "camel.component.zookeeper.cluster.service.id=" + UUID.randomUUID().toString(),
                "camel.component.zookeeper.cluster.service.base-path=" + SERVICE_PATH)
            .run(
                context -> {
                    assertThat(context).hasSingleBean(CamelContext.class);
                    assertThat(context).hasSingleBean(CamelClusterService.class);

                    final CamelContext camelContext = context.getBean(CamelContext.class);
                    final CamelClusterService clusterService = camelContext.hasService(CamelClusterService.class);

                    assertThat(clusterService).isNotNull();
                    assertThat(clusterService).isInstanceOf(ZooKeeperClusterService.class);
                }
            );
    } finally {
        zkServer.stop();
    }
}
 
Example 18
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 19
Source File: ZooKeeperServiceRegistryTest.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Test
public void testServiceRegistry() throws Exception {
    final int zkPort =  AvailablePortFinder.getNextAvailable();
    final File zkDir =  temporaryFolder.newFolder();

    final TestingServer zkServer = new TestingServer(zkPort, zkDir);
    zkServer.start();

    final ZooKeeperTestClient zkClient = new ZooKeeperTestClient("localhost:" + zkPort);
    zkClient.start();

    try {
        new ApplicationContextRunner()
            .withUserConfiguration(TestConfiguration.class)
            .withPropertyValues(
                "debug=false",
                "spring.main.banner-mode=OFF",
                "spring.application.name=" + UUID.randomUUID().toString(),
                "camel.component.zookeeper.service-registry.enabled=true",
                "camel.component.zookeeper.service-registry.nodes=localhost:" + zkPort,
                "camel.component.zookeeper.service-registry.id=" + UUID.randomUUID().toString(),
                "camel.component.zookeeper.service-registry.base-path=" + SERVICE_PATH,
                "camel.component.zookeeper.service-registry.service-host=localhost")
            .run(
                context -> {
                    assertThat(context).hasSingleBean(CamelContext.class);
                    assertThat(context).hasSingleBean(ServiceRegistry.class);

                    final CamelContext camelContext = context.getBean(CamelContext.class);
                    final ServiceRegistry serviceRegistry = camelContext.hasService(ServiceRegistry.class);

                    assertThat(serviceRegistry).isNotNull();

                    serviceRegistry.register(
                        DefaultServiceDefinition.builder()
                            .withHost(SERVICE_HOST)
                            .withPort(SERVICE_PORT)
                            .withName(SERVICE_NAME)
                            .withId(SERVICE_ID)
                            .build()
                    );

                    final Collection<ServiceInstance<ZooKeeperServiceRegistry.MetaData>> services = zkClient.discovery().queryForInstances(SERVICE_NAME);

                    assertThat(services).hasSize(1);
                    assertThat(services).first().hasFieldOrPropertyWithValue("id", SERVICE_ID);
                    assertThat(services).first().hasFieldOrPropertyWithValue("name", SERVICE_NAME);
                    assertThat(services).first().hasFieldOrPropertyWithValue("address", SERVICE_HOST);
                    assertThat(services).first().hasFieldOrPropertyWithValue("port", SERVICE_PORT);
                }
            );
    } finally {
        zkClient.stop();
        zkServer.stop();
    }
}
 
Example 20
Source File: ZookeeperDataSourceTest.java    From Sentinel 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();
}