Search in sources :

Example 6 with DbRepresentation

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

the class TestBackup method addMoreData.

private DbRepresentation addMoreData(File path) {
    GraphDatabaseService db = startGraphDatabase(path, false);
    DbRepresentation representation;
    try (Transaction tx = db.beginTx()) {
        Node node = db.createNode();
        node.setProperty("backup", "Is great");
        db.createNode().createRelationshipTo(node, RelationshipType.withName("LOVES"));
        tx.success();
    } finally {
        representation = DbRepresentation.of(db);
        db.shutdown();
    }
    return representation;
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) DbRepresentation(org.neo4j.test.DbRepresentation)

Example 7 with DbRepresentation

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

the class IncrementalBackupTests method shouldDoIncrementalBackup.

@Test
public void shouldDoIncrementalBackup() throws Exception {
    DbRepresentation initialDataSetRepresentation = createInitialDataSet(serverPath);
    server = startServer(serverPath, "127.0.0.1:6362");
    OnlineBackup backup = OnlineBackup.from("127.0.0.1");
    backup.full(backupPath.getPath());
    assertEquals(initialDataSetRepresentation, getBackupDbRepresentation());
    shutdownServer(server);
    DbRepresentation furtherRepresentation = addMoreData2(serverPath);
    server = startServer(serverPath, null);
    backup.incremental(backupPath.getPath());
    assertEquals(furtherRepresentation, getBackupDbRepresentation());
    shutdownServer(server);
}
Also used : DbRepresentation(org.neo4j.test.DbRepresentation) Test(org.junit.Test)

Example 8 with DbRepresentation

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

the class IncrementalBackupTests method createInitialDataSet.

private DbRepresentation createInitialDataSet(File path) {
    db = startGraphDatabase(path);
    try (Transaction tx = db.beginTx()) {
        db.createNode().setProperty("name", "Goofy");
        Node donald = db.createNode();
        donald.setProperty("name", "Donald");
        Node daisy = db.createNode();
        daisy.setProperty("name", "Daisy");
        Relationship knows = donald.createRelationshipTo(daisy, RelationshipType.withName("LOVES"));
        knows.setProperty("since", 1940);
        tx.success();
    }
    DbRepresentation result = DbRepresentation.of(db);
    db.shutdown();
    return result;
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) DbRepresentation(org.neo4j.test.DbRepresentation)

Example 9 with DbRepresentation

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

the class ReadReplicaReplicationIT method aReadReplicShouldBeAbleToRejoinTheCluster.

@Test
public void aReadReplicShouldBeAbleToRejoinTheCluster() throws Exception {
    int readReplicaId = 4;
    Cluster cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
    cluster.coreTx(createSomeData);
    cluster.addReadReplicaWithId(readReplicaId).start();
    // let's spend some time by adding more data
    cluster.coreTx(createSomeData);
    awaitEx(() -> readReplicasUpToDateAsTheLeader(cluster.awaitLeader(), cluster.readReplicas()), 1, TimeUnit.MINUTES);
    cluster.removeReadReplicaWithMemberId(readReplicaId);
    // let's spend some time by adding more data
    cluster.coreTx(createSomeData);
    cluster.addReadReplicaWithId(readReplicaId).start();
    awaitEx(() -> readReplicasUpToDateAsTheLeader(cluster.awaitLeader(), cluster.readReplicas()), 1, TimeUnit.MINUTES);
    Function<ClusterMember, DbRepresentation> toRep = db -> DbRepresentation.of(db.database());
    Set<DbRepresentation> dbs = cluster.coreMembers().stream().map(toRep).collect(toSet());
    dbs.addAll(cluster.readReplicas().stream().map(toRep).collect(toSet()));
    cluster.shutdown();
    assertEquals(1, dbs.size());
}
Also used : ResourceIterator(org.neo4j.graphdb.ResourceIterator) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) Log(org.neo4j.logging.Log) CausalClusteringSettings(org.neo4j.causalclustering.core.CausalClusteringSettings) ReadReplicaGraphDatabase(org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) ThrowingSupplier(org.neo4j.function.ThrowingSupplier) HighLimit(org.neo4j.kernel.impl.store.format.highlimit.HighLimit) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Assert.fail(org.junit.Assert.fail) Transaction(org.neo4j.graphdb.Transaction) Path(java.nio.file.Path) Collectors.toSet(java.util.stream.Collectors.toSet) Standard(org.neo4j.kernel.impl.store.format.standard.Standard) PageCache(org.neo4j.io.pagecache.PageCache) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Collection(java.util.Collection) Set(java.util.Set) BinaryOperator(java.util.function.BinaryOperator) UnsatisfiedDependencyException(org.neo4j.kernel.impl.util.UnsatisfiedDependencyException) Cluster(org.neo4j.causalclustering.discovery.Cluster) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) TransactionIdTracker(org.neo4j.kernel.api.txtracking.TransactionIdTracker) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Predicates.awaitEx(org.neo4j.function.Predicates.awaitEx) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) SortedMap(java.util.SortedMap) Mockito.mock(org.mockito.Mockito.mock) Role(org.neo4j.causalclustering.core.consensus.roles.Role) ClusterMember(org.neo4j.causalclustering.discovery.ClusterMember) Label(org.neo4j.graphdb.Label) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) Iterables.count(org.neo4j.helpers.collection.Iterables.count) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Monitors(org.neo4j.kernel.monitoring.Monitors) MINUTES(java.util.concurrent.TimeUnit.MINUTES) ClusterRule(org.neo4j.test.causalclustering.ClusterRule) LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) Duration.ofSeconds(java.time.Duration.ofSeconds) Function(java.util.function.Function) Node(org.neo4j.graphdb.Node) HashSet(java.util.HashSet) CatchupPollingProcess(org.neo4j.causalclustering.catchup.tx.CatchupPollingProcess) LifecycleException(org.neo4j.kernel.lifecycle.LifecycleException) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TIME(org.neo4j.kernel.impl.store.MetaDataStore.Position.TIME) BiConsumer(java.util.function.BiConsumer) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) FileNames(org.neo4j.causalclustering.core.consensus.log.segmented.FileNames) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) FileCopyMonitor(org.neo4j.causalclustering.catchup.tx.FileCopyMonitor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Assert.assertEventually(org.neo4j.test.assertion.Assert.assertEventually) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) SampleData.createData(org.neo4j.causalclustering.scenarios.SampleData.createData) Rule(org.junit.Rule) Paths(java.nio.file.Paths) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) DbRepresentation(org.neo4j.test.DbRepresentation) Clock(java.time.Clock) ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) ClusterMember(org.neo4j.causalclustering.discovery.ClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) DbRepresentation(org.neo4j.test.DbRepresentation) Test(org.junit.Test)

Example 10 with DbRepresentation

use of org.neo4j.test.DbRepresentation 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)

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