use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class UniquenessConstraintValidationHAIT method shouldPreventConcurrentCreationOfConflictingNonStringPropertyOnMasterAndSlave.
@Test
public void shouldPreventConcurrentCreationOfConflictingNonStringPropertyOnMasterAndSlave() throws Exception {
// given
ClusterManager.ManagedCluster cluster = clusterRule.startCluster();
HighlyAvailableGraphDatabase master = cluster.getMaster();
HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
// when
Future<Boolean> created;
try (Transaction tx = master.beginTx()) {
master.createNode(LABEL).setProperty(PROPERTY_KEY, 0x0099CC);
created = otherThread.execute(createNode(slave, LABEL.name(), PROPERTY_KEY, 0x0099CC));
assertThat(otherThread, isWaiting());
tx.success();
}
// then
assertFalse("creating violating data should fail", created.get());
}
use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class UniquenessConstraintValidationHAIT method shouldPreventConcurrentCreationOfConflictingDataOnSeparateHosts.
@Test
public void shouldPreventConcurrentCreationOfConflictingDataOnSeparateHosts() throws Exception {
// given
ClusterManager.ManagedCluster cluster = clusterRule.startCluster();
HighlyAvailableGraphDatabase slave1 = cluster.getAnySlave();
HighlyAvailableGraphDatabase slave2 = cluster.getAnySlave(/*except:*/
slave1);
// when
Future<Boolean> created;
try (Transaction tx = slave1.beginTx()) {
slave1.createNode(LABEL).setProperty(PROPERTY_KEY, "value3");
created = otherThread.execute(createNode(slave2, LABEL.name(), PROPERTY_KEY, "value3"));
assertThat(otherThread, isWaiting());
tx.success();
}
// then
assertFalse("creating violating data should fail", created.get());
}
use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class UpdatePullerSwitchIT method createLabeledNodeOnMaster.
private void createLabeledNodeOnMaster(ClusterManager.ManagedCluster cluster, Label label) {
HighlyAvailableGraphDatabase master = cluster.getMaster();
try (Transaction transaction = master.beginTx()) {
Node masterNode = master.createNode();
masterNode.addLabel(label);
transaction.success();
}
}
use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class ConstraintsInHAIT method creatingConstraintOnSlaveIsNotAllowed.
@Test
public void creatingConstraintOnSlaveIsNotAllowed() throws Exception {
// given
ClusterManager.ManagedCluster cluster = clusterRule.startCluster();
HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
slave.beginTx();
try {
ConstraintCreator constraintCreator = slave.schema().constraintFor(Label.label("LabelName")).assertPropertyIsUnique("PropertyName");
// when
constraintCreator.create();
fail("should have thrown exception");
} catch (InvalidTransactionTypeException e) {
assertThat(e.getMessage(), equalTo("Modifying the database schema can only be done on the master server, " + "this server is a slave. Please issue schema modification commands directly to the master."));
}
}
use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase 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));
}
}
Aggregations