use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class ClusterLocksIT method locksFailingOnSlavesMustHaveDescriptiveMessage.
@Test
public void locksFailingOnSlavesMustHaveDescriptiveMessage() throws Throwable {
HighlyAvailableGraphDatabase master = cluster.getMaster();
Node masterA = createNodeOnMaster(testLabel, master);
Node masterB = createNodeOnMaster(testLabel, master);
HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
try (Transaction transaction = slave.beginTx()) {
Node slaveA = slave.getNodeById(masterA.getId());
Node slaveB = slave.getNodeById(masterB.getId());
CountDownLatch latch = new CountDownLatch(1);
transaction.acquireWriteLock(slaveB);
Thread masterTx = new Thread(() -> {
try (Transaction tx = master.beginTx()) {
tx.acquireWriteLock(masterA);
latch.countDown();
tx.acquireWriteLock(masterB);
}
});
masterTx.setDaemon(true);
masterTx.start();
latch.await();
// This should deadlock
expectedException.expect(DeadlockDetectedException.class);
transaction.acquireWriteLock(slaveA);
}
}
use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class ClusterLocksIT method aPendingMemberShouldBeAbleToServeReads.
@Test
public void aPendingMemberShouldBeAbleToServeReads() throws Throwable {
// given
createNodeOnMaster(testLabel, cluster.getMaster());
cluster.sync();
HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
cluster.fail(slave, ClusterManager.NetworkFlag.values());
cluster.await(instanceEvicted(slave));
assertEquals(PENDING, slave.getInstanceState());
// when
for (int i = 0; i < 10; i++) {
try (Transaction tx = slave.beginTx()) {
Node single = Iterables.single(slave.getAllNodes());
Label label = Iterables.single(single.getLabels());
assertEquals(testLabel, label);
tx.success();
break;
} catch (TransactionTerminatedException e) {
// Race between going to pending and reading, try again in a little while
Thread.sleep(1_000);
}
}
// then no exceptions thrown
}
use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class ClusterTest method testInstancesWithConflictingHaPorts.
@Test
public void testInstancesWithConflictingHaPorts() throws Throwable {
HighlyAvailableGraphDatabase first = null;
try {
File storeDir = testDirectory.directory("testConflictingHaPorts");
first = (HighlyAvailableGraphDatabase) new TestHighlyAvailableGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir).setConfig(ClusterSettings.initial_hosts, "127.0.0.1:5001").setConfig(ClusterSettings.cluster_server, "127.0.0.1:5001").setConfig(ClusterSettings.server_id, "1").setConfig(HaSettings.ha_server, "127.0.0.1:6666").newGraphDatabase();
try {
HighlyAvailableGraphDatabase failed = (HighlyAvailableGraphDatabase) new TestHighlyAvailableGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir).setConfig(ClusterSettings.initial_hosts, "127.0.0.1:5001").setConfig(ClusterSettings.cluster_server, "127.0.0.1:5002").setConfig(ClusterSettings.server_id, "2").setConfig(HaSettings.ha_server, "127.0.0.1:6666").newGraphDatabase();
failed.shutdown();
fail("Should not start when ports conflict");
} catch (Exception e) {
// good
}
} finally {
if (first != null) {
first.shutdown();
}
}
}
use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class ReadOnlySlaveTest method givenClusterWithReadOnlySlaveWhenChangePropertyOnSlaveThenThrowException.
@Test
public void givenClusterWithReadOnlySlaveWhenChangePropertyOnSlaveThenThrowException() throws Throwable {
// Given
ManagedCluster cluster = clusterRule.startCluster();
Node node;
HighlyAvailableGraphDatabase master = cluster.getMaster();
try (Transaction tx = master.beginTx()) {
node = master.createNode();
tx.success();
}
// When
HighlyAvailableGraphDatabase readOnlySlave = cluster.getMemberByServerId(new InstanceId(2));
try (Transaction tx = readOnlySlave.beginTx()) {
Node slaveNode = readOnlySlave.getNodeById(node.getId());
// Then
slaveNode.setProperty("foo", "bar");
tx.success();
fail("Should have thrown exception");
} catch (WriteOperationsNotAllowedException ex) {
// Ok!
}
}
use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class TestInstanceJoin method start.
private static HighlyAvailableGraphDatabase start(File storeDir, int i, Map<String, String> additionalConfig) {
HighlyAvailableGraphDatabase db = (HighlyAvailableGraphDatabase) new TestHighlyAvailableGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir).setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + (5001 + i)).setConfig(ClusterSettings.server_id, i + "").setConfig(HaSettings.ha_server, "127.0.0.1:" + (6666 + i)).setConfig(HaSettings.pull_interval, "0ms").setConfig(additionalConfig).newGraphDatabase();
awaitStart(db);
return db;
}
Aggregations