Search in sources :

Example 66 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class TransactionConstraintsIT method getSlaveOnlySlave.

private HighlyAvailableGraphDatabase getSlaveOnlySlave() {
    HighlyAvailableGraphDatabase db = cluster.getMemberByServerId(new InstanceId(SLAVE_ONLY_ID));
    assertEquals(SLAVE_ONLY_ID, cluster.getServerId(db).toIntegerIndex());
    assertFalse(db.isMaster());
    return db;
}
Also used : HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) InstanceId(org.neo4j.cluster.InstanceId)

Example 67 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class TransactionConstraintsIT method masterShouldNotBeAbleToProduceAnInvalidTransaction.

@Test
public void masterShouldNotBeAbleToProduceAnInvalidTransaction() throws Exception {
    // GIVEN
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    Node node = createMiniTree(master);
    Transaction tx = master.beginTx();
    // Deleting this node isn't allowed since it still has relationships
    node.delete();
    tx.success();
    // EXPECT
    exception.expect(ConstraintViolationException.class);
    // WHEN
    tx.close();
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 68 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class UniquenessConstraintValidationHAIT method shouldAllowOtherHostToCompleteIfFirstHostRollsBackTransaction.

@Test
public void shouldAllowOtherHostToCompleteIfFirstHostRollsBackTransaction() 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, "value4");
        created = otherThread.execute(createNode(slave2, LABEL.name(), PROPERTY_KEY, "value4"));
        assertThat(otherThread, isWaiting());
        tx.failure();
    }
    // then
    assertTrue("creating data that conflicts only with rolled back data should pass", created.get());
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Test(org.junit.Test)

Example 69 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class UniquenessConstraintValidationHAIT method shouldAllowCreationOfNonConflictingDataOnSeparateHosts.

@Test
public void shouldAllowCreationOfNonConflictingDataOnSeparateHosts() 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, "value1");
        created = otherThread.execute(createNode(slave2, LABEL.name(), PROPERTY_KEY, "value2"));
        tx.success();
    }
    // then
    assertTrue("creating non-conflicting data should pass", created.get());
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Test(org.junit.Test)

Example 70 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class UpdatePullerSwitchIT method checkLabeledNodeExistanceOnSlave.

private void checkLabeledNodeExistanceOnSlave(ClusterManager.ManagedCluster cluster, Label label) {
    HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
    try (Transaction transaction = slave.beginTx()) {
        ResourceIterator<Node> slaveNodes = slave.findNodes(label);
        assertEquals(1, Iterators.asList(slaveNodes).size());
        transaction.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Node(org.neo4j.graphdb.Node)

Aggregations

HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)80 Test (org.junit.Test)68 Transaction (org.neo4j.graphdb.Transaction)38 ClusterManager (org.neo4j.kernel.impl.ha.ClusterManager)24 Node (org.neo4j.graphdb.Node)22 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)16 File (java.io.File)12 InstanceId (org.neo4j.cluster.InstanceId)10 Response (javax.ws.rs.core.Response)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 TransientTransactionFailureException (org.neo4j.graphdb.TransientTransactionFailureException)5 TestHighlyAvailableGraphDatabaseFactory (org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory)5 RepairKit (org.neo4j.kernel.impl.ha.ClusterManager.RepairKit)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 ClusterClient (org.neo4j.cluster.client.ClusterClient)4 TransactionTerminatedException (org.neo4j.graphdb.TransactionTerminatedException)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 IOException (java.io.IOException)3 URI (java.net.URI)3 ExecutionException (java.util.concurrent.ExecutionException)3