Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void backupRenamesWork()
        public virtual void BackupRenamesWork()
        {
            // given a prexisting backup from a different store
            string backupName      = "preexistingBackup_" + RecordFormat;
            int    firstBackupPort = PortAuthority.allocatePort();

            StartDb(firstBackupPort);
            CreateSpecificNodePair(_db, "first");

            assertEquals(0, RunSameJvm(_backupDir, backupName, "--from", "127.0.0.1:" + firstBackupPort, "--cc-report-dir=" + _backupDir, "--protocol=common", "--backup-dir=" + _backupDir, "--name=" + backupName));
            DbRepresentation firstDatabaseRepresentation = DbRepresentation.of(_db);

            // and a different database
            int secondBackupPort     = PortAuthority.allocatePort();
            GraphDatabaseService db2 = CreateDb2(secondBackupPort);

            CreateSpecificNodePair(db2, "second");
            DbRepresentation secondDatabaseRepresentation = DbRepresentation.of(db2);

            // when backup is performed
            assertEquals(0, RunSameJvm(_backupDir, backupName, "--from", "127.0.0.1:" + secondBackupPort, "--cc-report-dir=" + _backupDir, "--backup-dir=" + _backupDir, "--protocol=common", "--name=" + backupName));

            // then the new backup has the correct name
            assertEquals(secondDatabaseRepresentation, GetBackupDbRepresentation(backupName));

            // and the old backup is in a renamed location
            assertEquals(firstDatabaseRepresentation, GetBackupDbRepresentation(backupName + ".err.0"));

            // and the data isn't equal (sanity check)
            assertNotEquals(firstDatabaseRepresentation, secondDatabaseRepresentation);
            db2.Shutdown();
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void aReadReplicShouldBeAbleToRejoinTheCluster() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void AReadReplicShouldBeAbleToRejoinTheCluster()
        {
            int readReplicaId = 4;
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
            Cluster <object> 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);

            System.Func <ClusterMember, DbRepresentation> toRep = db => DbRepresentation.of(Db.database());
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            ISet <DbRepresentation> dbs = cluster.CoreMembers().Select(toRep).collect(toSet());

//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            dbs.addAll(cluster.ReadReplicas().Select(toRep).collect(toSet()));

            cluster.Shutdown();

            assertEquals(1, dbs.Count);
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void backupRenamesWork() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void BackupRenamesWork()
        {
            // given a prexisting backup from a different store
            string backupName = "preexistingBackup_" + RecordFormat;
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = startCluster(recordFormat);
            Cluster <object> cluster            = StartCluster(RecordFormat);
            string           firstBackupAddress = CausalClusteringTestHelpers.transactionAddress(ClusterLeader(cluster).database());

            assertEquals(0, RunBackupOtherJvm(firstBackupAddress, backupName));
            DbRepresentation firstDatabaseRepresentation = DbRepresentation.of(ClusterLeader(cluster).database());

            // and a different database
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster2 = startCluster2(recordFormat);
            Cluster <object> cluster2 = StartCluster2(RecordFormat);
            DbRepresentation secondDatabaseRepresentation = DbRepresentation.of(ClusterLeader(cluster2).database());

            assertNotEquals(firstDatabaseRepresentation, secondDatabaseRepresentation);
            string secondBackupAddress = CausalClusteringTestHelpers.transactionAddress(ClusterLeader(cluster2).database());

            // when backup is performed
            assertEquals(0, RunBackupOtherJvm(secondBackupAddress, backupName));
            cluster2.Shutdown();

            // then the new backup has the correct name
            assertEquals(secondDatabaseRepresentation, GetBackupDbRepresentation(backupName, _backupStoreDir));

            // and the old backup is in a renamed location
            assertEquals(firstDatabaseRepresentation, GetBackupDbRepresentation(backupName + ".err.0", _backupStoreDir));

            // and the data isn't equal (sanity check)
            assertNotEquals(firstDatabaseRepresentation, secondDatabaseRepresentation);
        }
Example #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToDownloadToNewInstanceAfterPruning() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToDownloadToNewInstanceAfterPruning()
        {
            // given
            IDictionary <string, string> @params = stringMap(CausalClusteringSettings.state_machine_flush_window_size.name(), "1", CausalClusteringSettings.raft_log_pruning_strategy.name(), "3 entries", CausalClusteringSettings.raft_log_rotation_size.name(), "1K");

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.withSharedCoreParams(params).startCluster();
            Cluster <object> cluster = ClusterRule.withSharedCoreParams(@params).startCluster();

            CoreClusterMember leader = cluster.CoreTx((db, tx) =>
            {
                createData(db, 10000);
                tx.success();
            });

            // when
            foreach (CoreClusterMember coreDb in cluster.CoreMembers())
            {
                coreDb.RaftLogPruner().prune();
            }

            cluster.RemoveCoreMember(leader);                 // to force a change of leader
            leader = cluster.AwaitLeader();

            int newDbId = 3;

            cluster.AddCoreMemberWithId(newDbId).start();
            CoreGraphDatabase newDb = cluster.GetCoreMemberById(newDbId).database();

            // then
            assertEquals(DbRepresentation.of(leader.Database()), DbRepresentation.of(newDb));
        }
Example #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void backupDatabaseWithCustomTransactionLogsLocation() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void BackupDatabaseWithCustomTransactionLogsLocation()
        {
            int backupPort          = PortAuthority.allocatePort();
            GraphDatabaseService db = StartGraphDatabase(_serverStorePath, true, backupPort, "customLogLocation");

            try
            {
                CreateInitialDataSet(db);

                OnlineBackup backup      = OnlineBackup.From("127.0.0.1", backupPort);
                string       backupStore = _backupDatabasePath.Path;
                LogFiles     logFiles    = LogFilesBuilder.logFilesBasedOnlyBuilder(new File(backupStore), _fileSystemRule.get()).build();

                backup.Full(backupStore);
                assertThat(logFiles.LogFilesConflict(), Matchers.arrayWithSize(1));

                DbRepresentation representation = AddLotsOfData(db);
                backup.Incremental(backupStore);
                assertThat(logFiles.LogFilesConflict(), Matchers.arrayWithSize(1));

                assertEquals(representation, DbRepresentation);
            }
            finally
            {
                Db.shutdown();
            }
        }
Example #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void ipv6Enabled() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Ipv6Enabled()
        {
            // given
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = startIpv6Cluster();
            Cluster <object> cluster = StartIpv6Cluster();

            try
            {
                assertNotNull(DbRepresentation.of(ClusterDatabase(cluster)));
                int    port          = ClusterLeader(cluster).config().get(CausalClusteringSettings.transaction_listen_address).Port;
                string customAddress = string.Format("[{0}]:{1:D}", IpFamily.IPV6.localhostAddress(), port);
                string backupName    = "backup_" + RecordFormat;

                // when full backup
                assertEquals(0, RunBackupToolFromOtherJvmToGetExitCode("--from", customAddress, "--protocol=catchup", "--cc-report-dir=" + _backupStoreDir, "--backup-dir=" + _backupStoreDir, "--name=" + backupName));

                // and
                CreateSomeData(cluster);

                // and incremental backup
                assertEquals(0, RunBackupToolFromOtherJvmToGetExitCode("--from", customAddress, "--protocol=catchup", "--cc-report-dir=" + _backupStoreDir, "--backup-dir=" + _backupStoreDir, "--name=" + backupName, Arg(ARG_NAME_FALLBACK_FULL, false)));

                // then
                assertEquals(DbRepresentation.of(ClusterDatabase(cluster)), GetBackupDbRepresentation(backupName, _backupStoreDir));
            }
            finally
            {
                cluster.Shutdown();
            }
        }
Example #7
0
        public static DbRepresentation GetBackupDbRepresentation(string name, File storeDir)
        {
            Config config = Config.defaults();

            config.Augment(OnlineBackupSettings.online_backup_enabled, Settings.FALSE);
            return(DbRepresentation.of(DatabaseLayout.of(storeDir, name).databaseDirectory(), config));
        }
Example #8
0
        private DbRepresentation CreateTransactionWithWeirdRelationshipGroupRecord(File path)
        {
            _db = StartGraphDatabase(path);
            int              i = 0;
            Node             node;
            RelationshipType typeToDelete = RelationshipType.withName("A");
            RelationshipType theOtherType = RelationshipType.withName("B");
            int              defaultDenseNodeThreshold = int.Parse(GraphDatabaseSettings.dense_node_threshold.DefaultValue);

            using (Transaction tx = _db.beginTx())
            {
                node = _db.createNode();
                for ( ; i < defaultDenseNodeThreshold - 1; i++)
                {
                    node.CreateRelationshipTo(_db.createNode(), theOtherType);
                }
                node.CreateRelationshipTo(_db.createNode(), typeToDelete);
                tx.Success();
            }
            using (Transaction tx = _db.beginTx())
            {
                node.CreateRelationshipTo(_db.createNode(), theOtherType);
                foreach (Relationship relationship in node.GetRelationships(Direction.BOTH, typeToDelete))
                {
                    relationship.Delete();
                }
                tx.Success();
            }
            DbRepresentation result = DbRepresentation.of(_db);

            _db.shutdown();
            return(result);
        }
Example #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToDownloadLargerFreshSnapshot() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToDownloadLargerFreshSnapshot()
        {
            // given
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.startCluster();
            Cluster <object> cluster = ClusterRule.startCluster();

            CoreClusterMember source = cluster.CoreTx((db, tx) =>
            {
                createData(db, 1000);
                tx.success();
            });

            // when
            CoreClusterMember follower = cluster.AwaitCoreMemberWithRole(Role.FOLLOWER, 5, TimeUnit.SECONDS);

            // shutdown the follower, remove the store, restart
            follower.Shutdown();
            DeleteDirectoryRecursively(follower.DatabaseDirectory(), follower.ServerId());
            DeleteDirectoryRecursively(follower.ClusterStateDirectory(), follower.ServerId());
            follower.Start();

            // then
            assertEquals(DbRepresentation.of(source.Database()), DbRepresentation.of(follower.Database()));
        }
Example #10
0
        /// <summary>
        /// Waits for <seealso cref="DEFAULT_TIMEOUT_MS"/> for the <code>targetDBs</code> to have the same content as the
        /// <code>member</code>. Changes in the <code>member</code> database contents after this method is called do not get
        /// picked up and are not part of the comparison.
        /// </summary>
        /// <param name="source">  The database to check against </param>
        /// <param name="targets"> The databases expected to match the contents of <code>member</code> </param>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static <T extends ClusterMember> void dataMatchesEventually(org.neo4j.test.DbRepresentation source, java.util.Collection<T> targets) throws java.util.concurrent.TimeoutException
        public static void DataMatchesEventually <T>(DbRepresentation source, ICollection <T> targets) where T : ClusterMember
        {
            foreach (ClusterMember targetDB in targets)
            {
                await(() =>
                {
                    DbRepresentation representation = DbRepresentation.of(targetDB.database());
                    return(source.Equals(representation));
                }, DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
            }
        }
Example #11
0
        private DbRepresentation CreateInitialDataSet(File path)
        {
            GraphDatabaseService db = StartGraphDatabase(path, false, null);

            try
            {
                CreateInitialDataSet(db);
                return(DbRepresentation.of(db));
            }
            finally
            {
                Db.shutdown();
            }
        }
Example #12
0
 private static DbRepresentation AddLotsOfData(GraphDatabaseService db)
 {
     using (Transaction tx = Db.beginTx())
     {
         Node node      = Db.createNode();
         int  threshold = parseInt(dense_node_threshold.DefaultValue);
         for (int i = 0; i < threshold * 2; i++)
         {
             node.CreateRelationshipTo(Db.createNode(), TEST);
         }
         tx.Success();
     }
     return(DbRepresentation.of(db));
 }
Example #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void backupCanBePerformedOverCcWithCustomPort() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void BackupCanBePerformedOverCcWithCustomPort()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = startCluster(recordFormat);
            Cluster <object> cluster       = StartCluster(RecordFormat);
            string           customAddress = CausalClusteringTestHelpers.transactionAddress(ClusterLeader(cluster).database());

            assertEquals(0, RunBackupOtherJvm(customAddress, DATABASE_NAME));
            assertEquals(DbRepresentation.of(ClusterDatabase(cluster)), GetBackupDbRepresentation(DATABASE_NAME, _backupStoreDir));

            CreateSomeData(cluster);
            assertEquals(0, RunBackupOtherJvm(customAddress, DATABASE_NAME));
            assertEquals(DbRepresentation.of(ClusterDatabase(cluster)), GetBackupDbRepresentation(DATABASE_NAME, _backupStoreDir));
        }
Example #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void makeSureBackupCanBePerformedWithCustomPort() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MakeSureBackupCanBePerformedWithCustomPort()
        {
            assumeFalse(SystemUtils.IS_OS_WINDOWS);
            string backupName = "customport" + RecordFormat;               // due to ClassRule not cleaning between tests

            int backupPort = PortAuthority.allocatePort();

            StartDb(backupPort);
            assertEquals("should not be able to do backup when noone is listening", 1, RunBackupTool(_testDirectory.absolutePath(), "--from", "127.0.0.1:" + PortAuthority.allocatePort(), "--cc-report-dir=" + _backupDir, "--backup-dir=" + _backupDir, "--name=" + backupName));
            assertEquals(0, RunBackupTool(_testDirectory.absolutePath(), "--from", "127.0.0.1:" + backupPort, "--cc-report-dir=" + _backupDir, "--backup-dir=" + _backupDir, "--name=" + backupName));
            assertEquals(DbRepresentation.of(_db), GetBackupDbRepresentation(backupName));
            CreateSomeData(_db);
            assertEquals(0, RunBackupTool(_testDirectory.absolutePath(), "--from", "127.0.0.1:" + backupPort, "--cc-report-dir=" + _backupDir, "--backup-dir=" + _backupDir, "--name=" + backupName));
            assertEquals(DbRepresentation.of(_db), GetBackupDbRepresentation(backupName));
        }
Example #15
0
        private DbRepresentation AddMoreData2(File path)
        {
            _db = StartGraphDatabase(path);
            using (Transaction tx = _db.beginTx())
            {
                Node donald    = _db.getNodeById(2);
                Node gladstone = _db.createNode();
                gladstone.SetProperty("name", "Gladstone");
                Relationship hates = donald.CreateRelationshipTo(gladstone, RelationshipType.withName("HATES"));
                hates.SetProperty("since", 1948);
                tx.Success();
            }
            DbRepresentation result = DbRepresentation.of(_db);

            _db.shutdown();
            return(result);
        }
Example #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRebuildDbFromTransactions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRebuildDbFromTransactions()
        {
            // This tests the basic functionality of this tool, there are more things, but it's not as important
            // to test as the functionality of applying transactions.

            // GIVEN
            File from = Directory.directory("from");
            File to   = Directory.directory("to");

            DatabaseWithSomeTransactions(from);
            DatabaseRebuildTool tool = new DatabaseRebuildTool(System.in, NULL_PRINT_STREAM, NULL_PRINT_STREAM);

            // WHEN
            tool.Run("--from", DatabaseDirectory(from).AbsolutePath, "--to", to.AbsolutePath, "apply last");

            // THEN
            assertEquals(DbRepresentation.of(DatabaseDirectory(from)), DbRepresentation.of(DatabaseDirectory(to)));
        }
Example #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void makeSureBackupCanBePerformedFromAnyInstance() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MakeSureBackupCanBePerformedFromAnyInstance()
        {
            foreach (CoreClusterMember db in _cluster.coreMembers())
            {
                // Run backup
                DbRepresentation beforeChange = DbRepresentation.of(CreateSomeData(_cluster));
                string[]         args         = BackupArguments(BackupAddress(_cluster), _backupsDir, "" + Db.serverId());
                assertEventually(() => runBackupToolFromOtherJvmToGetExitCode(ClusterRule.clusterDirectory(), args), equalTo(0), 5, TimeUnit.SECONDS);

                // Add some new data
                DbRepresentation afterChange = DbRepresentation.of(CreateSomeData(_cluster));

                // Verify that old data is back
                DbRepresentation backupRepresentation = DbRepresentation.of(DatabaseLayout.of(_backupsDir, "" + Db.serverId()).databaseDirectory(), Config);
                assertEquals(beforeChange, backupRepresentation);
                assertNotEquals(backupRepresentation, afterChange);
            }
        }
Example #18
0
        private DbRepresentation CreateInitialDataSet(File path)
        {
            _db = StartGraphDatabase(path);
            using (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);
        }
Example #19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void makeSureStoreIdIsEnforced()
        public virtual void MakeSureStoreIdIsEnforced()
        {
            // Create data set X on server A
            DbRepresentation initialDataSetRepresentation = CreateInitialDataSet(_serverStorePath);
            int             backupPort = PortAuthority.allocatePort();
            ServerInterface server     = StartServer(_serverStorePath, backupPort);

            // Grab initial backup from server A
            OnlineBackup backup = OnlineBackup.From("127.0.0.1", backupPort);

            backup.Full(_backupDatabasePath.Path);
            assertTrue("Should be consistent", backup.Consistent);
            assertEquals(initialDataSetRepresentation, DbRepresentation);
            ShutdownServer(server);

            // Create data set X+Y on server B
            CreateInitialDataSet(_otherServerPath);
            AddMoreData(_otherServerPath);
            server = StartServer(_otherServerPath, backupPort);

            // Try to grab incremental backup from server B.
            // Data should be OK, but store id check should prevent that.
            try
            {
                backup.incremental(_backupDatabasePath.Path);
                fail("Shouldn't work");
            }
            catch (Exception e)
            {
                assertThat(rootCause(e), instanceOf(typeof(MismatchingStoreIdException)));
            }
            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(_serverStorePath);

            server = StartServer(_serverStorePath, backupPort);
            backup.incremental(_backupDatabasePath.Path);
            assertTrue("Should be consistent", backup.Consistent);
            assertEquals(furtherRepresentation, DbRepresentation);
            ShutdownServer(server);
        }
Example #20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void backupEmptyIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void BackupEmptyIndex()
        {
            int    backupPort       = PortAuthority.allocatePort();
            string key              = "name";
            string value            = "Neo";
            GraphDatabaseService db = GetEmbeddedTestDataBaseService(backupPort);

            try
            {
                Index <Node> index;
                Node         node;
                using (Transaction tx = Db.beginTx())
                {
                    index = Db.index().forNodes(key);
                    node  = Db.createNode();
                    node.SetProperty(key, value);
                    tx.Success();
                }
                OnlineBackup backup = OnlineBackup.From("127.0.0.1", backupPort).full(_backupDatabasePath.Path);
                assertTrue("Should be consistent", backup.Consistent);
                assertEquals(DbRepresentation.of(db), DbRepresentation);
                FileUtils.deleteDirectory(_backupDatabasePath);
                backup = OnlineBackup.From("127.0.0.1", backupPort).full(_backupDatabasePath.Path);
                assertTrue("Should be consistent", backup.Consistent);
                assertEquals(DbRepresentation.of(db), DbRepresentation);

                using (Transaction tx = Db.beginTx())
                {
                    index.Add(node, key, value);
                    tx.Success();
                }
                FileUtils.deleteDirectory(_backupDatabasePath);
                backup = OnlineBackup.From("127.0.0.1", backupPort).full(_backupDatabasePath.Path);
                assertTrue("Should be consistent", backup.Consistent);
                assertEquals(DbRepresentation.of(db), DbRepresentation);
            }
            finally
            {
                Db.shutdown();
            }
        }
Example #21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDoIncrementalBackup() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDoIncrementalBackup()
        {
            DbRepresentation initialDataSetRepresentation = CreateInitialDataSet(_serverPath);
            int port = PortAuthority.allocatePort();

            _server = StartServer(_serverPath, "127.0.0.1:" + port);

            OnlineBackup backup = OnlineBackup.From("127.0.0.1", port);

            backup.Full(_backupDatabase.Path);

            assertEquals(initialDataSetRepresentation, BackupDbRepresentation);
            ShutdownServer(_server);

            DbRepresentation furtherRepresentation = AddMoreData2(_serverPath);

            _server = StartServer(_serverPath, "127.0.0.1:" + port);
            backup.incremental(_backupDatabase.Path);
            assertEquals(furtherRepresentation, BackupDbRepresentation);
            ShutdownServer(_server);
        }
Example #22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIncrementallyBackupDenseNodes()
        public virtual void ShouldIncrementallyBackupDenseNodes()
        {
            int backupPort          = PortAuthority.allocatePort();
            GraphDatabaseService db = StartGraphDatabase(_serverStorePath, true, backupPort);

            try
            {
                CreateInitialDataSet(db);

                OnlineBackup backup = OnlineBackup.From("127.0.0.1", backupPort);
                backup.Full(_backupDatabasePath.Path);

                DbRepresentation representation = AddLotsOfData(db);
                backup.incremental(_backupDatabasePath.Path);
                assertEquals(representation, DbRepresentation);
            }
            finally
            {
                Db.shutdown();
            }
        }
Example #23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void fullThenIncremental()
        public virtual void FullThenIncremental()
        {
            DbRepresentation initialDataSetRepresentation = CreateInitialDataSet(_serverStorePath);
            int             backupPort = PortAuthority.allocatePort();
            ServerInterface server     = StartServer(_serverStorePath, backupPort);

            OnlineBackup backup = OnlineBackup.From("127.0.0.1", backupPort);

            backup.Full(_backupDatabasePath.Path);
            assertTrue("Should be consistent", backup.Consistent);
            assertEquals(initialDataSetRepresentation, DbRepresentation);
            ShutdownServer(server);

            DbRepresentation furtherRepresentation = AddMoreData(_serverStorePath);

            server = StartServer(_serverStorePath, backupPort);
            backup.incremental(_backupDatabasePath.Path);
            assertTrue("Should be consistent", backup.Consistent);
            assertEquals(furtherRepresentation, DbRepresentation);
            ShutdownServer(server);
        }
Example #24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotServeTransactionsWithInvalidHighIds() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotServeTransactionsWithInvalidHighIds()
        {
            /*
             * This is in effect a high level test for an edge case that happens when a relationship group is
             * created and deleted in the same tx. This can end up causing an IllegalArgumentException because
             * the HighIdApplier used when applying incremental updates (batch transactions in general) will postpone
             * processing of added/altered record ids but deleted ids will be processed on application. This can result
             * in a deleted record causing an IllegalArgumentException even though it is not the highest id in the tx.
             *
             * The way we try to trigger this is:
             * 0. In one tx, create a node with 49 relationships, belonging to two types.
             * 1. In another tx, create another relationship on that node (making it dense) and then delete all
             *    relationships of one type. This results in the tx state having a relationship group record that was
             *    created in this tx and also set to not in use.
             * 2. Receipt of this tx will have the offending rel group command apply its id before the groups that are
             *    altered. This will try to update the high id with a value larger than what has been seen previously and
             *    fail the update.
             * The situation is resolved by a check added in TransactionRecordState which skips the creation of such
             * commands.
             * Note that this problem can also happen in HA slaves.
             */
            DbRepresentation initialDataSetRepresentation = CreateInitialDataSet(_serverPath);
            int port = PortAuthority.allocatePort();

            _server = StartServer(_serverPath, "127.0.0.1:" + port);

            OnlineBackup backup = OnlineBackup.From("127.0.0.1", port);

            backup.Full(_backupDatabase.Path);

            assertEquals(initialDataSetRepresentation, BackupDbRepresentation);
            ShutdownServer(_server);

            DbRepresentation furtherRepresentation = CreateTransactionWithWeirdRelationshipGroupRecord(_serverPath);

            _server = StartServer(_serverPath, "127.0.0.1:" + port);
            backup.incremental(_backupDatabase.Path);
            assertEquals(furtherRepresentation, BackupDbRepresentation);
            ShutdownServer(_server);
        }
Example #25
0
        private DbRepresentation AddMoreData(File path)
        {
            GraphDatabaseService db = StartGraphDatabase(path, false, null);
            DbRepresentation     representation;

            try
            {
                using (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);
        }
Example #26
0
        private DbRepresentation CreateSomeData(File databaseDir, FileSystemAbstraction fs)
        {
            RelationshipType     type = withName("KNOWS");
            GraphDatabaseService db   = (new TestGraphDatabaseFactory()).setFileSystem(fs).newImpermanentDatabase(databaseDir);

            using (Transaction tx = Db.beginTx())
            {
                Node prevNode = Db.createNode();
                for (int i = 0; i < 100; i++)
                {
                    Node         node = Db.createNode();
                    Relationship rel  = prevNode.CreateRelationshipTo(node, type);
                    node.SetProperty("someKey" + i % 10, i % 15);
                    rel.SetProperty("since", DateTimeHelper.CurrentUnixTimeMillis());
                }
                tx.Success();
            }
            DbRepresentation result = DbRepresentation.of(db);

            Db.shutdown();
            return(result);
        }
Example #27
0
        /// <summary>
        /// Waits for <seealso cref="DEFAULT_TIMEOUT_MS"/> for the <code>memberThatChanges</code> to match the contents of
        /// <code>memberToLookLike</code>. After calling this method, changes both in <code>memberThatChanges</code> and
        /// <code>memberToLookLike</code> are picked up.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void dataOnMemberEventuallyLooksLike(CoreClusterMember memberThatChanges, CoreClusterMember memberToLookLike) throws java.util.concurrent.TimeoutException
        public static void DataOnMemberEventuallyLooksLike(CoreClusterMember memberThatChanges, CoreClusterMember memberToLookLike)
        {
            await(() =>
            {
                try
                {
                    // We recalculate the DbRepresentation of both source and target, so changes can be picked up
                    DbRepresentation representationToLookLike  = DbRepresentation.of(memberToLookLike.Database());
                    DbRepresentation representationThatChanges = DbRepresentation.of(memberThatChanges.Database());
                    return(representationToLookLike.Equals(representationThatChanges));
                }
                catch (DatabaseShutdownException)
                {
                    /*
                     * This can happen if the database is still in the process of starting. Yes, the naming
                     * of the exception is unfortunate, since it is thrown when the database lifecycle is not
                     * in RUNNING state and therefore signals general unavailability (e.g still starting) and not
                     * necessarily a database that is shutting down.
                     */
                }
                return(false);
            }, DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
        }
Example #28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void makeSureBackupCanBePerformed() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MakeSureBackupCanBePerformed()
        {
            // Run backup
            ManagedCluster               cluster      = ClusterRule.startCluster();
            DbRepresentation             beforeChange = DbRepresentation.of(cluster.Master);
            HighlyAvailableGraphDatabase hagdb        = cluster.AllMembers.GetEnumerator().next();
            HostnamePort address      = cluster.GetBackupAddress(hagdb);
            string       databaseName = "basic";

            assertEquals(0, runBackupToolFromOtherJvmToGetExitCode(_backupPath, BackupArguments(address.ToString(), _backupPath, databaseName)));

            // Add some new data
            DbRepresentation afterChange = createSomeData(cluster.Master);

            cluster.Sync();

            // Verify that backed up database can be started and compare representation
            Config           config = Config.builder().withSetting(OnlineBackupSettings.online_backup_enabled, Settings.FALSE).withSetting(GraphDatabaseSettings.active_database, databaseName).build();
            DbRepresentation backupRepresentation = DbRepresentation.of(DatabaseLayout.of(_backupPath, databaseName).databaseDirectory(), config);

            assertEquals(beforeChange, backupRepresentation);
            assertNotEquals(backupRepresentation, afterChange);
        }
Example #29
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testSimple()
        public virtual void TestSimple()
        {
            File databaseDir                  = TestDirectory.databaseDir();
            FileSystemAbstraction fs          = TestDirectory.FileSystem;
            DbRepresentation      someData    = CreateSomeData(databaseDir, fs);
            GraphDatabaseService  readGraphDb = (new TestGraphDatabaseFactory()).setFileSystem(fs).newEmbeddedDatabaseBuilder(databaseDir).setConfig(GraphDatabaseSettings.read_only, Settings.TRUE).newGraphDatabase();

            assertEquals(someData, DbRepresentation.of(readGraphDb));

            try
            {
                using (Transaction tx = readGraphDb.BeginTx())
                {
                    readGraphDb.CreateNode();
                    tx.Success();
                    fail("Should have failed");
                }
            }
            catch (WriteOperationsNotAllowedException)
            {
                // good
            }
            readGraphDb.Shutdown();
        }
Example #30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void backupCanBeOptionallySwitchedOnWithTheBackupConfig() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void BackupCanBeOptionallySwitchedOnWithTheBackupConfig()
        {
            // given a cluster with backup switched on
            int[]  backupPorts = new int[] { PortAuthority.allocatePort(), PortAuthority.allocatePort(), PortAuthority.allocatePort() };
            string value       = "localhost:%d";

            _clusterRule = _clusterRule.withSharedCoreParam(OnlineBackupSettings.online_backup_enabled, "true").withInstanceCoreParam(online_backup_server, i => format(value, backupPorts[i]));
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = startCluster(recordFormat);
            Cluster <object> cluster       = StartCluster(RecordFormat);
            string           customAddress = "localhost:" + backupPorts[0];

            // when a full backup is performed
            assertEquals(0, RunBackupOtherJvm(customAddress, DATABASE_NAME));
            assertEquals(DbRepresentation.of(ClusterDatabase(cluster)), GetBackupDbRepresentation(DATABASE_NAME, _backupStoreDir));

            // and an incremental backup is performed
            CreateSomeData(cluster);
            assertEquals(0, RunBackupOtherJvm(customAddress, DATABASE_NAME));
            assertEquals(0, RunBackupToolFromOtherJvmToGetExitCode("--from=" + customAddress, "--cc-report-dir=" + _backupStoreDir, "--backup-dir=" + _backupStoreDir, "--name=defaultport", Arg(ARG_NAME_FALLBACK_FULL, false)));

            // then the data matches
            assertEquals(DbRepresentation.of(ClusterDatabase(cluster)), GetBackupDbRepresentation(DATABASE_NAME, _backupStoreDir));
        }