use of org.neo4j.cluster.client.ClusterClientModule in project neo4j by neo4j.
the class ClusterTopologyChangesIT method newClusterClient.
private ClusterClientModule newClusterClient(LifeSupport life, InstanceId id) {
Config config = Config.embeddedDefaults(MapUtil.stringMap(ClusterSettings.initial_hosts.name(), cluster.getInitialHostsConfigString(), ClusterSettings.server_id.name(), String.valueOf(id.toIntegerIndex()), ClusterSettings.cluster_server.name(), "0.0.0.0:8888"));
FormattedLogProvider logProvider = FormattedLogProvider.toOutputStream(System.out);
SimpleLogService logService = new SimpleLogService(logProvider, logProvider);
return new ClusterClientModule(life, new Dependencies(), new Monitors(), config, logService, new NotElectableElectionCredentialsProvider());
}
use of org.neo4j.cluster.client.ClusterClientModule in project neo4j by neo4j.
the class ClusterTopologyChangesIT method failedInstanceShouldReceiveCorrectCoordinatorIdUponRejoiningCluster.
@Test
public void failedInstanceShouldReceiveCorrectCoordinatorIdUponRejoiningCluster() throws Throwable {
// Given
HighlyAvailableGraphDatabase initialMaster = cluster.getMaster();
// When
cluster.shutdown(initialMaster);
cluster.await(masterAvailable(initialMaster));
cluster.await(masterSeesSlavesAsAvailable(1));
// create node on new master to ensure that it has the greatest tx id
createNodeOn(cluster.getMaster());
cluster.sync();
LifeSupport life = new LifeSupport();
ClusterClientModule clusterClient = newClusterClient(life, new InstanceId(1));
cleanup.add(life);
final AtomicReference<InstanceId> coordinatorIdWhenReJoined = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
clusterClient.clusterClient.addClusterListener(new ClusterListener.Adapter() {
@Override
public void enteredCluster(ClusterConfiguration clusterConfiguration) {
coordinatorIdWhenReJoined.set(clusterConfiguration.getElected(COORDINATOR));
latch.countDown();
}
});
life.start();
// Then
assertTrue(latch.await(20, SECONDS));
assertEquals(new InstanceId(2), coordinatorIdWhenReJoined.get());
}
use of org.neo4j.cluster.client.ClusterClientModule in project neo4j by neo4j.
the class ArbiterBootstrapper method start.
@SafeVarargs
@Override
public final int start(File homeDir, Optional<File> configFile, Pair<String, String>... configOverrides) {
Config config = getConfig(configFile, configOverrides);
try {
DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
life.add(new FileSystemLifecycleAdapter(fileSystem));
life.add(new Neo4jJobScheduler());
new ClusterClientModule(life, new Dependencies(), new Monitors(), config, logService(fileSystem, config), new NotElectableElectionCredentialsProvider());
} catch (LifecycleException e) {
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "unchecked" }) Throwable cause = peel(e, Predicates.<Throwable>instanceOf(LifecycleException.class));
if (cause instanceof ChannelException) {
System.err.println("ERROR: " + cause.getMessage() + (cause.getCause() != null ? ", caused by:" + cause.getCause().getMessage() : ""));
} else {
System.err.println("ERROR: Unknown error");
throw e;
}
}
addShutdownHook();
life.start();
return 0;
}
use of org.neo4j.cluster.client.ClusterClientModule in project neo4j by neo4j.
the class ArbiterBootstrapperIT method before.
@Before
public void before() throws Exception {
directory = testDirectory.directory("temp");
life = new LifeSupport();
// So that the clients get started as they are added
life.start();
clients = new ClusterClient[2];
for (int i = 1; i <= clients.length; i++) {
Map<String, String> config = stringMap();
config.put(cluster_server.name(), ":" + (5000 + i));
config.put(server_id.name(), "" + i);
config.put(initial_hosts.name(), ":5001");
LifeSupport moduleLife = new LifeSupport();
ClusterClientModule clusterClientModule = new ClusterClientModule(moduleLife, new Dependencies(), new Monitors(), Config.embeddedDefaults(config), NullLogService.getInstance(), new ServerIdElectionCredentialsProvider());
ClusterClient client = clusterClientModule.clusterClient;
CountDownLatch latch = new CountDownLatch(1);
client.addClusterListener(new ClusterListener.Adapter() {
@Override
public void enteredCluster(ClusterConfiguration configuration) {
latch.countDown();
client.removeClusterListener(this);
}
});
life.add(moduleLife);
clients[i - 1] = client;
assertTrue("Didn't join the cluster", latch.await(20, SECONDS));
}
}
Aggregations