use of org.neo4j.driver.internal.net.BoltServerAddress in project neo4j by neo4j.
the class BoltCausalClusteringIT method shouldSendRequestsToNewlyAddedReadReplicas.
@Test
public void shouldSendRequestsToNewlyAddedReadReplicas() throws Throwable {
// given
cluster = clusterRule.withNumberOfReadReplicas(1).withSharedCoreParams(stringMap(CausalClusteringSettings.cluster_routing_ttl.name(), "1s")).startCluster();
CoreClusterMember leader = cluster.awaitLeader();
Driver driver = GraphDatabase.driver(leader.routingURI(), AuthTokens.basic("neo4j", "neo4j"));
String bookmark = inExpirableSession(driver, (d) -> d.session(AccessMode.WRITE), (session) -> {
try (Transaction tx = session.beginTransaction()) {
tx.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Jim"));
tx.success();
}
return session.lastBookmark();
});
// when
Set<String> readReplicas = new HashSet<>();
for (ReadReplica readReplica : cluster.readReplicas()) {
readReplicas.add(readReplica.boltAdvertisedAddress());
}
for (int i = 10; i <= 13; i++) {
ReadReplica newReadReplica = cluster.addReadReplicaWithId(i);
readReplicas.add(newReadReplica.boltAdvertisedAddress());
newReadReplica.start();
}
assertEventually("Failed to send requests to all servers", () -> {
for (// don't care about cores
int i = 0; // don't care about cores
i < cluster.readReplicas().size(); // don't care about cores
i++) {
try (Session session = driver.session(AccessMode.READ)) {
BoltServerAddress boltServerAddress = ((RoutingNetworkSession) session).address();
executeReadQuery(bookmark, session);
readReplicas.remove(boltServerAddress.toString());
} catch (Throwable throwable) {
return false;
}
}
// have sent something to all replicas
return readReplicas.size() == 0;
}, is(true), 30, SECONDS);
}
use of org.neo4j.driver.internal.net.BoltServerAddress in project neo4j by neo4j.
the class BoltCausalClusteringIT method shouldPickANewServerToWriteToOnLeaderSwitch.
@Test
public void shouldPickANewServerToWriteToOnLeaderSwitch() throws Throwable {
// given
cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
CoreClusterMember leader = cluster.awaitLeader();
LeaderSwitcher leaderSwitcher = new LeaderSwitcher(cluster);
Config config = Config.build().withLogging(new JULogging(Level.OFF)).toConfig();
Set<BoltServerAddress> seenAddresses = new HashSet<>();
try (Driver driver = GraphDatabase.driver(leader.routingURI(), AuthTokens.basic("neo4j", "neo4j"), config)) {
boolean success = false;
long deadline = System.currentTimeMillis() + (30 * 1000);
while (!success) {
if (System.currentTimeMillis() > deadline) {
fail("Failed to write to the new leader in time. Addresses seen: " + seenAddresses);
}
try (Session session = driver.session(AccessMode.WRITE)) {
BoltServerAddress boltServerAddress = ((RoutingNetworkSession) session).address();
session.run("CREATE (p:Person)");
seenAddresses.add(boltServerAddress);
success = seenAddresses.size() >= 2;
} catch (Exception e) {
Thread.sleep(100);
}
/*
* Having the latch release here ensures that we've done at least one pass through the loop, which means
* we've completed a connection before the forced master switch.
*/
if (seenAddresses.size() >= 1) {
leaderSwitcher.start();
}
}
} finally {
leaderSwitcher.stop();
assertTrue(leaderSwitcher.hadLeaderSwitch());
assertThat(seenAddresses.size(), greaterThanOrEqualTo(2));
}
}
Aggregations