Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void backupIndexWithNoCommits()
        public virtual void BackupIndexWithNoCommits()
        {
            int backupPort          = PortAuthority.allocatePort();
            GraphDatabaseService db = null;

            try
            {
                db = GetEmbeddedTestDataBaseService(backupPort);

                using (Transaction transaction = Db.beginTx())
                {
                    Db.index().forNodes("created-no-commits");
                    transaction.Success();
                }

                OnlineBackup backup = OnlineBackup.From("127.0.0.1", backupPort);
                backup.Full(_backupDatabasePath.Path);
                assertTrue("Should be consistent", backup.Consistent);
                assertTrue(backup.Consistent);
            }
            finally
            {
                if (db != null)
                {
                    Db.shutdown();
                }
            }
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testOnByDefault()
        public virtual void TestOnByDefault()
        {
            int port = PortAuthority.allocatePort();

            GraphDatabaseService db = (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(_storeDir).setConfig(OnlineBackupSettings.online_backup_server, "localhost:" + port).newGraphDatabase();

            OnlineBackup.From(HOST_ADDRESS, port).full(_backupDir);
            Db.shutdown();
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testOffByConfig()
        public virtual void TestOffByConfig()
        {
            int port = PortAuthority.allocatePort();

            GraphDatabaseService db = (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(_storeDir).setConfig(OnlineBackupSettings.online_backup_enabled, Settings.FALSE).setConfig(OnlineBackupSettings.online_backup_server, "localhost:" + port).newGraphDatabase();

            try
            {
                OnlineBackup.From(HOST_ADDRESS, port).full(_backupDir);
                fail("Shouldn't be possible");
            }
            catch (Exception)
            {               // Good
            }
            Db.shutdown();
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void multipleIncrementals() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MultipleIncrementals()
        {
            int backupPort          = PortAuthority.allocatePort();
            GraphDatabaseService db = null;

            try
            {
                db = GetEmbeddedTestDataBaseService(backupPort);

                Index <Node> index;
                using (Transaction tx = Db.beginTx())
                {
                    index = Db.index().forNodes("yo");
                    index.Add(Db.createNode(), "justTo", "commitATx");
                    Db.createNode();
                    tx.Success();
                }

                OnlineBackup backup = OnlineBackup.From("127.0.0.1", backupPort);
                backup.Full(_backupDatabasePath.Path);
                assertTrue("Should be consistent", backup.Consistent);
                PageCache pageCache       = _pageCacheRule.getPageCache(_fileSystemRule.get());
                long      lastCommittedTx = GetLastCommittedTx(_backupDatabaseLayout, pageCache);

                for (int i = 0; i < 5; i++)
                {
                    using (Transaction tx = Db.beginTx())
                    {
                        Node node = Db.createNode();
                        index.Add(node, "key", "value" + i);
                        tx.Success();
                    }
                    backup = backup.incremental(_backupDatabasePath.Path);
                    assertTrue("Should be consistent", backup.Consistent);
                    assertEquals(lastCommittedTx + i + 1, GetLastCommittedTx(_backupDatabaseLayout, pageCache));
                }
            }
            finally
            {
                if (db != null)
                {
                    Db.shutdown();
                }
            }
        }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRetainFileLocksAfterFullBackupOnLiveDatabase()
        public virtual void ShouldRetainFileLocksAfterFullBackupOnLiveDatabase()
        {
            int  backupPort = PortAuthority.allocatePort();
            File sourcePath = _testDir.directory("serverdb-lock");

            GraphDatabaseService db = (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(sourcePath).setConfig(OnlineBackupSettings.online_backup_enabled, Settings.TRUE).setConfig(OnlineBackupSettings.online_backup_server, "127.0.0.1:" + backupPort).setConfig(GraphDatabaseSettings.record_format, RecordFormatName).newGraphDatabase();

            try
            {
                AssertStoreIsLocked(sourcePath);
                OnlineBackup.From("127.0.0.1", backupPort).full(_backupDatabasePath.Path);
                AssertStoreIsLocked(sourcePath);
            }
            finally
            {
                Db.shutdown();
            }
        }
Ejemplo n.º 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void makeSureIncrementalFailsWhenNoDb()
        public virtual void MakeSureIncrementalFailsWhenNoDb()
        {
            int backupPort = PortAuthority.allocatePort();

            CreateInitialDataSet(_serverStorePath);
            ServerInterface server = StartServer(_serverStorePath, backupPort);
            OnlineBackup    backup = OnlineBackup.From("127.0.0.1", backupPort);

            try
            {
                backup.incremental(_backupDatabasePath.Path);
                fail("Shouldn't be able to do incremental backup into non-existing db");
            }
            catch (Exception)
            {
                // Good
            }
            ShutdownServer(server);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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();
            }
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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();
            }
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void backupMultipleSchemaIndexes() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void BackupMultipleSchemaIndexes()
        {
            // given
            ExecutorService      executorService = Executors.newSingleThreadExecutor();
            AtomicBoolean        end             = new AtomicBoolean();
            int                  backupPort      = PortAuthority.allocatePort();
            GraphDatabaseService db = GetEmbeddedTestDataBaseService(backupPort);

            try
            {
                int           numberOfIndexedLabels = 10;
                IList <Label> indexedLabels         = CreateIndexes(db, numberOfIndexedLabels);

                // start thread that continuously writes to indexes
                executorService.submit(() =>
                {
                    while (!end.get())
                    {
                        using (Transaction tx = Db.beginTx())
                        {
                            Db.createNode(indexedLabels[_random.Next(numberOfIndexedLabels)]).setProperty("prop", _random.nextValue());
                            tx.success();
                        }
                    }
                });
                executorService.shutdown();

                // create backup
                OnlineBackup backup = OnlineBackup.From("127.0.0.1", backupPort).full(_backupDatabasePath.Path);
                assertTrue("Should be consistent", backup.Consistent);
                end.set(true);
                executorService.awaitTermination(1, TimeUnit.MINUTES);
            }
            finally
            {
                Db.shutdown();
            }
        }
Ejemplo n.º 15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void backedUpDatabaseContainsChecksumOfLastTx() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void BackedUpDatabaseContainsChecksumOfLastTx()
        {
            ServerInterface server = null;

            try
            {
                CreateInitialDataSet(_serverStorePath);
                int backupPort = PortAuthority.allocatePort();
                server = StartServer(_serverStorePath, backupPort);
                OnlineBackup backup = OnlineBackup.From("127.0.0.1", backupPort);
                backup.Full(_backupDatabasePath.Path);
                assertTrue("Should be consistent", backup.Consistent);
                ShutdownServer(server);
                server = null;
                PageCache pageCache = _pageCacheRule.getPageCache(_fileSystemRule.get());

                long firstChecksum = LastTxChecksumOf(_serverStoreLayout, pageCache);
                assertEquals(firstChecksum, LastTxChecksumOf(_backupDatabaseLayout, pageCache));

                AddMoreData(_serverStorePath);
                server = StartServer(_serverStorePath, backupPort);
                backup.incremental(_backupDatabasePath.Path);
                assertTrue("Should be consistent", backup.Consistent);
                ShutdownServer(server);
                server = null;

                long secondChecksum = LastTxChecksumOf(_serverStoreLayout, pageCache);
                assertEquals(secondChecksum, LastTxChecksumOf(_backupDatabaseLayout, pageCache));
                assertTrue(firstChecksum != secondChecksum);
            }
            finally
            {
                if (server != null)
                {
                    ShutdownServer(server);
                }
            }
        }
Ejemplo n.º 16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void makeSureNoLogFileRemains()
        public virtual void MakeSureNoLogFileRemains()
        {
            CreateInitialDataSet(_serverStorePath);
            int             backupPort = PortAuthority.allocatePort();
            ServerInterface server     = StartServer(_serverStorePath, backupPort);
            OnlineBackup    backup     = OnlineBackup.From("127.0.0.1", backupPort);

            // First check full
            backup.Full(_backupDatabasePath.Path);
            assertTrue("Should be consistent", backup.Consistent);
            assertFalse(CheckLogFileExistence(_backupDatabasePath.Path));
            // Then check empty incremental
            backup.incremental(_backupDatabasePath.Path);
            assertTrue("Should be consistent", backup.Consistent);
            assertFalse(CheckLogFileExistence(_backupDatabasePath.Path));
            // Then check real incremental
            ShutdownServer(server);
            AddMoreData(_serverStorePath);
            server = StartServer(_serverStorePath, backupPort);
            backup.incremental(_backupDatabasePath.Path);
            assertTrue("Should be consistent", backup.Consistent);
            assertFalse(CheckLogFileExistence(_backupDatabasePath.Path));
            ShutdownServer(server);
        }