Search in sources :

Example 1 with DbRepresentation

use of org.neo4j.test.DbRepresentation in project neo4j by neo4j.

the class TestReadOnlyNeo4j method testSimple.

@Test
public void testSimple() {
    DbRepresentation someData = createSomeData();
    GraphDatabaseService readGraphDb = new TestGraphDatabaseFactory().setFileSystem(new UncloseableDelegatingFileSystemAbstraction(fs.get())).newImpermanentDatabaseBuilder(PATH).setConfig(GraphDatabaseSettings.read_only, Settings.TRUE).newGraphDatabase();
    assertEquals(someData, DbRepresentation.of(readGraphDb));
    try (Transaction tx = readGraphDb.beginTx()) {
        readGraphDb.createNode();
        tx.success();
    } catch (WriteOperationsNotAllowedException e) {
    // good
    }
    readGraphDb.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) UncloseableDelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction) DbRepresentation(org.neo4j.test.DbRepresentation) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Example 2 with DbRepresentation

use of org.neo4j.test.DbRepresentation in project graphdb by neo4j-attic.

the class TestBackupToolHa method makeSureBackupCanBePerformedFromCluster.

@Test
public void makeSureBackupCanBePerformedFromCluster() throws Exception {
    if (osIsWindows())
        return;
    assertEquals(0, runBackupToolFromOtherJvmToGetExitCode("-full", "-from", "ha://localhost:2181", "-to", BACKUP_PATH));
    assertEquals(representation, DbRepresentation.of(BACKUP_PATH));
    DbRepresentation newRepresentation = createSomeData(instances.get(2));
    assertEquals(0, runBackupToolFromOtherJvmToGetExitCode("-incremental", "-from", "ha://localhost:2182", "-to", BACKUP_PATH));
    assertEquals(newRepresentation, DbRepresentation.of(BACKUP_PATH));
}
Also used : DbRepresentation(org.neo4j.test.DbRepresentation) Test(org.junit.Test)

Example 3 with DbRepresentation

use of org.neo4j.test.DbRepresentation in project neo4j by neo4j.

the class TestBackup method fullThenIncremental.

@Test
public void fullThenIncremental() throws Exception {
    DbRepresentation initialDataSetRepresentation = createInitialDataSet(serverPath);
    ServerInterface server = startServer(serverPath);
    OnlineBackup backup = OnlineBackup.from("127.0.0.1");
    backup.full(backupPath.getPath());
    assertTrue("Should be consistent", backup.isConsistent());
    assertEquals(initialDataSetRepresentation, getDbRepresentation());
    shutdownServer(server);
    DbRepresentation furtherRepresentation = addMoreData(serverPath);
    server = startServer(serverPath);
    backup.incremental(backupPath.getPath());
    assertTrue("Should be consistent", backup.isConsistent());
    assertEquals(furtherRepresentation, getDbRepresentation());
    shutdownServer(server);
}
Also used : DbRepresentation(org.neo4j.test.DbRepresentation) Test(org.junit.Test)

Example 4 with DbRepresentation

use of org.neo4j.test.DbRepresentation in project neo4j by neo4j.

the class TestBackup method shouldIncrementallyBackupDenseNodes.

@Test
public void shouldIncrementallyBackupDenseNodes() throws Exception {
    GraphDatabaseService db = startGraphDatabase(serverPath, true);
    try {
        createInitialDataset(db);
        OnlineBackup backup = OnlineBackup.from("127.0.0.1");
        backup.full(backupPath.getPath());
        DbRepresentation representation = addLotsOfData(db);
        backup.incremental(backupPath.getPath());
        assertEquals(representation, getDbRepresentation());
    } finally {
        db.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) DbRepresentation(org.neo4j.test.DbRepresentation) Test(org.junit.Test)

Example 5 with DbRepresentation

use of org.neo4j.test.DbRepresentation in project neo4j by neo4j.

the class TestBackup method makeSureStoreIdIsEnforced.

@Test
public void makeSureStoreIdIsEnforced() throws Exception {
    // Create data set X on server A
    DbRepresentation initialDataSetRepresentation = createInitialDataSet(serverPath);
    ServerInterface server = startServer(serverPath);
    // Grab initial backup from server A
    OnlineBackup backup = OnlineBackup.from("127.0.0.1");
    backup.full(backupPath.getPath());
    assertTrue("Should be consistent", backup.isConsistent());
    assertEquals(initialDataSetRepresentation, DbRepresentation.of(backupPath));
    shutdownServer(server);
    // Create data set X+Y on server B
    createInitialDataSet(otherServerPath);
    addMoreData(otherServerPath);
    server = startServer(otherServerPath);
    // Data should be OK, but store id check should prevent that.
    try {
        backup.incremental(backupPath.getPath());
        fail("Shouldn't work");
    } catch (RuntimeException e) {
        assertThat(e.getCause(), instanceOf(MismatchingStoreIdException.class));
    }
    shutdownServer(server);
    // Just make sure incremental backup can be received properly from
    // server A, even after a failed attempt from server B
    DbRepresentation furtherRepresentation = addMoreData(serverPath);
    server = startServer(serverPath);
    backup.incremental(backupPath.getPath());
    assertTrue("Should be consistent", backup.isConsistent());
    assertEquals(furtherRepresentation, DbRepresentation.of(backupPath));
    shutdownServer(server);
}
Also used : DbRepresentation(org.neo4j.test.DbRepresentation) Test(org.junit.Test)

Aggregations

DbRepresentation (org.neo4j.test.DbRepresentation)27 Test (org.junit.Test)18 Transaction (org.neo4j.graphdb.Transaction)11 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)10 Node (org.neo4j.graphdb.Node)9 File (java.io.File)7 Relationship (org.neo4j.graphdb.Relationship)4 CoreGraphDatabase (org.neo4j.causalclustering.core.CoreGraphDatabase)2 ReadReplicaGraphDatabase (org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase)2 DynamicRelationshipType (org.neo4j.graphdb.DynamicRelationshipType)2 WriteOperationsNotAllowedException (org.neo4j.graphdb.security.WriteOperationsNotAllowedException)2 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)2 IOException (java.io.IOException)1 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 HashSet (java.util.HashSet)1 Map (java.util.Map)1