Search in sources :

Example 31 with ManagedCluster

use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.

the class HaBeanIT method shouldAccessHaBeans.

@Test
public void shouldAccessHaBeans() throws Throwable {
    ManagedCluster cluster = clusterRule.startCluster();
    // High Availability bean
    HighAvailability ha = ha(cluster.getMaster());
    assertNotNull("could not get ha bean", ha);
    assertMasterInformation(ha);
    assertMasterAndSlaveInformation(ha.getInstancesInCluster());
    for (ClusterMemberInfo info : ha.getInstancesInCluster()) {
        assertTrue(info.isAlive());
        assertTrue(info.isAvailable());
    }
    // Branched data bean
    BranchedStore bs = beans(cluster.getMaster()).getBranchedStoreBean();
    assertNotNull("could not get branched store bean", bs);
}
Also used : ClusterMemberInfo(org.neo4j.management.ClusterMemberInfo) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) HighAvailability(org.neo4j.management.HighAvailability) BranchedStore(org.neo4j.management.BranchedStore) Test(org.junit.Test)

Example 32 with ManagedCluster

use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.

the class BackupHaIT method makeSureBackupCanBePerformed.

@Test
public void makeSureBackupCanBePerformed() throws Throwable {
    // Run backup
    ManagedCluster cluster = clusterRule.startCluster();
    DbRepresentation beforeChange = DbRepresentation.of(cluster.getMaster());
    assertEquals(0, runBackupToolFromOtherJvmToGetExitCode(backupPath, backupArguments("localhost:4445", backupPath, "basic")));
    // Add some new data
    DbRepresentation afterChange = createSomeData(cluster.getMaster());
    cluster.sync();
    // Verify that backed up database can be started and compare representation
    DbRepresentation backupRepresentation = DbRepresentation.of(new File(backupPath, "basic"));
    assertEquals(beforeChange, backupRepresentation);
    assertNotEquals(backupRepresentation, afterChange);
}
Also used : ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) File(java.io.File) DbRepresentation(org.neo4j.test.DbRepresentation) Test(org.junit.Test)

Example 33 with ManagedCluster

use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.

the class BackupHaIT method makeSureBackupCanBePerformedFromAnyInstance.

@Test
public void makeSureBackupCanBePerformedFromAnyInstance() throws Throwable {
    ManagedCluster cluster = clusterRule.startCluster();
    Integer[] backupPorts = { 4445, 4446, 4447 };
    for (Integer port : backupPorts) {
        // Run backup
        DbRepresentation beforeChange = DbRepresentation.of(cluster.getMaster());
        assertEquals(0, runBackupToolFromOtherJvmToGetExitCode(backupPath, backupArguments("localhost:" + port, backupPath, "anyinstance")));
        // Add some new data
        DbRepresentation afterChange = createSomeData(cluster.getMaster());
        cluster.sync();
        // Verify that old data is back
        DbRepresentation backupRepresentation = DbRepresentation.of(new File(backupPath, "anyinstance"));
        assertEquals(beforeChange, backupRepresentation);
        assertNotEquals(backupRepresentation, afterChange);
    }
}
Also used : ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) File(java.io.File) DbRepresentation(org.neo4j.test.DbRepresentation) Test(org.junit.Test)

Example 34 with ManagedCluster

use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster 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!
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) InstanceId(org.neo4j.cluster.InstanceId) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Node(org.neo4j.graphdb.Node) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Aggregations

ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)34 Test (org.junit.Test)32 HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)16 Transaction (org.neo4j.graphdb.Transaction)15 Node (org.neo4j.graphdb.Node)13 InstanceId (org.neo4j.cluster.InstanceId)6 File (java.io.File)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 WriteOperationsNotAllowedException (org.neo4j.graphdb.security.WriteOperationsNotAllowedException)4 ClusterManager (org.neo4j.kernel.impl.ha.ClusterManager)4 RepairKit (org.neo4j.kernel.impl.ha.ClusterManager.RepairKit)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CountsTracker (org.neo4j.kernel.impl.store.counts.CountsTracker)2 DbRepresentation (org.neo4j.test.DbRepresentation)2 Random (java.util.Random)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1