use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.
the class TestSlaveOnlyCluster method testMasterElectionAfterMasterRecoversInSlaveOnlyCluster.
@Test
public void testMasterElectionAfterMasterRecoversInSlaveOnlyCluster() throws Throwable {
ManagedCluster cluster = clusterRule.startCluster();
assertThat(cluster.getServerId(cluster.getMaster()), equalTo(new InstanceId(3)));
HighlyAvailableGraphDatabase master = cluster.getMaster();
CountDownLatch masterFailedLatch = createMasterFailLatch(cluster);
RepairKit repairKit = cluster.fail(master);
try {
assertTrue(masterFailedLatch.await(60, TimeUnit.SECONDS));
} finally {
repairKit.repair();
}
cluster.await(allSeesAllAsAvailable());
long nodeId = createNodeWithPropertyOn(cluster.getAnySlave(), PROPERTY, VALUE);
try (Transaction ignore = master.beginTx()) {
assertThat(master.getNodeById(nodeId).getProperty(PROPERTY), equalTo(VALUE));
}
}
use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.
the class HACountsPropagationTest method shouldPropagateRelationshipCountsInHA.
@Test
public void shouldPropagateRelationshipCountsInHA() throws Throwable {
ManagedCluster cluster = clusterRule.startCluster();
HighlyAvailableGraphDatabase master = cluster.getMaster();
try (Transaction tx = master.beginTx()) {
Node left = master.createNode();
Node right = master.createNode(Label.label("A"));
left.createRelationshipTo(right, RelationshipType.withName("Type"));
tx.success();
}
cluster.sync();
for (HighlyAvailableGraphDatabase db : cluster.getAllMembers()) {
CountsTracker counts = counts(db);
assertEquals(1, counts.relationshipCount(-1, -1, -1, newDoubleLongRegister()).readSecond());
assertEquals(1, counts.relationshipCount(-1, -1, 0, newDoubleLongRegister()).readSecond());
assertEquals(1, counts.relationshipCount(-1, 0, -1, newDoubleLongRegister()).readSecond());
assertEquals(1, counts.relationshipCount(-1, 0, 0, newDoubleLongRegister()).readSecond());
}
}
use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.
the class HACountsPropagationTest method shouldPropagateNodeCountsInHA.
@Test
public void shouldPropagateNodeCountsInHA() throws Throwable {
ManagedCluster cluster = clusterRule.startCluster();
HighlyAvailableGraphDatabase master = cluster.getMaster();
try (Transaction tx = master.beginTx()) {
master.createNode();
master.createNode(Label.label("A"));
tx.success();
}
cluster.sync();
for (HighlyAvailableGraphDatabase db : cluster.getAllMembers()) {
CountsTracker counts = counts(db);
assertEquals(2, counts.nodeCount(-1, newDoubleLongRegister()).readSecond());
assertEquals(1, counts.nodeCount(0, /* A */
newDoubleLongRegister()).readSecond());
}
}
use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.
the class TransactionThroughMasterSwitchStressIT method oneRound.
private void oneRound() throws Throwable {
// GIVEN a cluster and a node
final String key = "key";
ManagedCluster cluster = clusterRule.startCluster();
final GraphDatabaseService master = cluster.getMaster();
final long nodeId = createNode(master);
cluster.sync();
// and a bunch of workers contending on that node, each changing it
Workers<Runnable> transactors = new Workers<>("Transactors");
final AtomicInteger successes = new AtomicInteger();
final AtomicBoolean end = new AtomicBoolean();
for (int i = 0; i < 10; i++) {
transactors.start(new Runnable() {
@Override
public void run() {
Random random = ThreadLocalRandom.current();
while (!end.get()) {
boolean committed = true;
try (Transaction tx = master.beginTx()) {
Node node = master.getNodeById(nodeId);
// Acquiring lock, read int property value, increment, set incremented int property
// should not break under any circumstances.
tx.acquireWriteLock(node);
node.setProperty(key, (Integer) node.getProperty(key, 0) + 1);
// Throw in relationship for good measure
node.createRelationshipTo(master.createNode(), TEST);
Thread.sleep(random.nextInt(1_000));
tx.success();
} catch (Throwable e) {
// It's OK
committed = false;
}
if (committed) {
successes.incrementAndGet();
}
}
}
});
}
// WHEN entering a period of induced cluster instabilities
reelectTheSameMasterMakingItGoToPendingAndBack(cluster);
// ... letting transactions run a bit after the role switch as well.
long targetSuccesses = successes.get() + 20;
while (successes.get() < targetSuccesses) {
Thread.sleep(100);
}
end.set(true);
transactors.awaitAndThrowOnError(RuntimeException.class);
// THEN verify that the count is equal to the number of successful transactions
assertEquals(successes.get(), getNodePropertyValue(master, nodeId, key));
}
use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.
the class AutoIndexConfigIT method programmaticConfigShouldSurviveMasterSwitches.
@Test
public void programmaticConfigShouldSurviveMasterSwitches() throws Throwable {
String propertyToIndex = "programmatic-property";
// Given
ManagedCluster cluster = clusterRule.startCluster();
HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
AutoIndexer<Node> originalAutoIndex = slave.index().getNodeAutoIndexer();
originalAutoIndex.setEnabled(true);
originalAutoIndex.startAutoIndexingProperty(propertyToIndex);
// When
cluster.shutdown(cluster.getMaster());
cluster.await(masterAvailable());
// Then
AutoIndexer<Node> newAutoIndex = slave.index().getNodeAutoIndexer();
assertThat(newAutoIndex.isEnabled(), is(true));
assertThat(newAutoIndex.getAutoIndexedProperties(), hasItem(propertyToIndex));
}
Aggregations