use of com.alibaba.nacos.config.server.service.repository.embedded.DistributedDatabaseOperateImpl in project nacos by alibaba.
the class BaseClusterTest method run.
private static void run(final int index, final CountDownLatch latch, final Class<?> cls) {
Runnable runnable = () -> {
try {
EnvUtil.setIsStandalone(false);
final String path = Paths.get(System.getProperty("user.home"), "/nacos-" + index + "/").toString();
DiskUtils.deleteDirectory(path);
System.setProperty("nacos.home", path);
System.out.println("nacos.home is : [" + path + "]");
Map<String, Object> properties = new HashMap<>();
properties.put("server.port", "884" + (7 + index));
properties.put("nacos.home", path);
properties.put("nacos.logs.path", Paths.get(System.getProperty("user.home"), "nacos-" + index, "/logs/").toString());
properties.put("spring.jmx.enabled", false);
properties.put("nacos.core.snowflake.worker-id", index + 1);
MapPropertySource propertySource = new MapPropertySource("nacos_cluster_test", properties);
ConfigurableEnvironment environment = new StandardServletEnvironment();
environment.getPropertySources().addFirst(propertySource);
SpringApplication cluster = new SpringApplicationBuilder(cls).web(WebApplicationType.SERVLET).environment(environment).properties(clusterInfo).properties("embeddedStorage=true").build();
ConfigurableApplicationContext context = cluster.run();
DistributedDatabaseOperateImpl operate = context.getBean(DistributedDatabaseOperateImpl.class);
CPProtocol protocol = context.getBean(CPProtocol.class);
protocol.protocolMetaData().subscribe(operate.group(), MetadataKey.LEADER_META_DATA, o -> {
ProtocolMetaData.ValueItem item = (ProtocolMetaData.ValueItem) o;
System.out.println("node : 884" + (7 + index) + "-> select leader is : " + item.getData());
if (FINISHED[index].compareAndSet(false, true)) {
latch.countDown();
}
});
new Thread(() -> {
try {
Thread.sleep(5000L);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (FINISHED[index].compareAndSet(false, true)) {
latch.countDown();
}
}
});
applications.put(String.valueOf(properties.get("server.port")), context);
} catch (Throwable e) {
e.printStackTrace();
} finally {
latch.countDown();
}
};
runnable.run();
}
Aggregations