Search in sources :

Example 6 with CoreGraphDatabase

use of org.neo4j.causalclustering.core.CoreGraphDatabase in project neo4j by neo4j.

the class CoreReplicationIT method shouldNotAllowWritesFromAFollower.

@Test
public void shouldNotAllowWritesFromAFollower() throws Exception {
    // given
    cluster.awaitLeader();
    CoreGraphDatabase follower = cluster.getDbWithRole(Role.FOLLOWER).database();
    // when
    try (Transaction tx = follower.beginTx()) {
        follower.createNode();
        tx.success();
        fail("Should have thrown exception");
    } catch (WriteOperationsNotAllowedException ignored) {
        // expected
        assertThat(ignored.getMessage(), containsString("No write operations are allowed"));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Example 7 with CoreGraphDatabase

use of org.neo4j.causalclustering.core.CoreGraphDatabase in project neo4j by neo4j.

the class CoreReplicationIT method shouldNotAllowSchemaChangesFromAFollower.

@Test
public void shouldNotAllowSchemaChangesFromAFollower() throws Exception {
    // given
    cluster.awaitLeader();
    CoreGraphDatabase follower = cluster.getDbWithRole(Role.FOLLOWER).database();
    // when
    try (Transaction tx = follower.beginTx()) {
        follower.schema().constraintFor(Label.label("Foo")).assertPropertyIsUnique("name").create();
        tx.success();
        fail("Should have thrown exception");
    } catch (WriteOperationsNotAllowedException ignored) {
        // expected
        assertThat(ignored.getMessage(), containsString("No write operations are allowed"));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Example 8 with CoreGraphDatabase

use of org.neo4j.causalclustering.core.CoreGraphDatabase in project neo4j by neo4j.

the class BackupReadReplicaIT method makeSureBackupCanBePerformed.

@Test
public void makeSureBackupCanBePerformed() throws Throwable {
    // Run backup
    CoreGraphDatabase leader = createSomeData(cluster);
    ReadReplicaGraphDatabase readReplica = cluster.findAnyReadReplica().database();
    awaitEx(() -> readReplicasUpToDateAsTheLeader(leader, readReplica), 1, TimeUnit.MINUTES);
    DbRepresentation beforeChange = DbRepresentation.of(readReplica);
    String backupAddress = this.backupAddress(readReplica);
    String[] args = backupArguments(backupAddress, backupPath, "readreplica");
    assertEquals(0, runBackupToolFromOtherJvmToGetExitCode(clusterRule.clusterDirectory(), args));
    // Add some new data
    DbRepresentation afterChange = DbRepresentation.of(createSomeData(cluster));
    // Verify that backed up database can be started and compare representation
    DbRepresentation backupRepresentation = DbRepresentation.of(new File(backupPath, "readreplica"), getConfig());
    assertEquals(beforeChange, backupRepresentation);
    assertNotEquals(backupRepresentation, afterChange);
}
Also used : ReadReplicaGraphDatabase(org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) File(java.io.File) DbRepresentation(org.neo4j.test.DbRepresentation) Test(org.junit.Test)

Example 9 with CoreGraphDatabase

use of org.neo4j.causalclustering.core.CoreGraphDatabase in project neo4j by neo4j.

the class ClusterSeedingIT method createBackupUsingAnotherCluster.

private File createBackupUsingAnotherCluster() throws Exception {
    backupCluster.start();
    CoreGraphDatabase db = BackupCoreIT.createSomeData(backupCluster);
    File backup = createBackup(db, "some-backup");
    backupCluster.shutdown();
    return backup;
}
Also used : CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) File(java.io.File)

Example 10 with CoreGraphDatabase

use of org.neo4j.causalclustering.core.CoreGraphDatabase in project neo4j by neo4j.

the class CoreReplicationIT method countNodes.

private long countNodes(CoreClusterMember member) {
    CoreGraphDatabase db = member.database();
    long count;
    try (Transaction tx = db.beginTx()) {
        count = count(db.getAllNodes());
        tx.success();
    }
    return count;
}
Also used : Transaction(org.neo4j.graphdb.Transaction) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase)

Aggregations

CoreGraphDatabase (org.neo4j.causalclustering.core.CoreGraphDatabase)15 Test (org.junit.Test)12 Transaction (org.neo4j.graphdb.Transaction)9 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)7 File (java.io.File)5 Cluster (org.neo4j.causalclustering.discovery.Cluster)5 WriteOperationsNotAllowedException (org.neo4j.graphdb.security.WriteOperationsNotAllowedException)5 Node (org.neo4j.graphdb.Node)3 IOException (java.io.IOException)2 HazelcastDiscoveryServiceFactory (org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory)2 ReadReplica (org.neo4j.causalclustering.discovery.ReadReplica)2 ReadReplicaGraphDatabase (org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase)2 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)2 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)2 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Clock (java.time.Clock)1 Duration.ofSeconds (java.time.Duration.ofSeconds)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1