Exemple #1
0
        private void AssertThatCommunityCanStartOnNormalConstraint(string constraintCreationQuery)
        {
            // given
            GraphDatabaseService graphDb = (new EnterpriseGraphDatabaseFactory()).newEmbeddedDatabase(Dir.storeDir());

            try
            {
                graphDb.Execute(constraintCreationQuery);
            }
            finally
            {
                graphDb.Shutdown();
            }
            graphDb = null;

            // when
            try
            {
                graphDb = (new TestGraphDatabaseFactory()).newEmbeddedDatabase(Dir.storeDir());
                // Should not get exception
            }
            finally
            {
                if (graphDb != null)
                {
                    graphDb.Shutdown();
                }
            }
        }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void providerGetsFilledInAutomatically()
		 public virtual void ProviderGetsFilledInAutomatically()
		 {
			  IDictionary<string, string> correctConfig = MapUtil.stringMap( "type", "exact", Org.Neo4j.Graphdb.index.IndexManager_Fields.PROVIDER, "lucene" );
			  File storeDir = TestDirectory.storeDir();
			  Neo4jTestCase.deleteFileOrDirectory( storeDir );
			  GraphDatabaseService graphDb = StartDatabase( storeDir );
			  using ( Transaction transaction = graphDb.BeginTx() )
			  {
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("default")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("wo-provider", MapUtil.stringMap("type", "exact"))) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("w-provider", MapUtil.stringMap("type", "exact", Org.Neo4j.Graphdb.index.IndexManager_Fields.PROVIDER, "lucene"))) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("default")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("wo-provider", MapUtil.stringMap("type", "exact"))) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("w-provider", MapUtil.stringMap("type", "exact", Org.Neo4j.Graphdb.index.IndexManager_Fields.PROVIDER, "lucene"))) );
					transaction.Success();
			  }

			  graphDb.Shutdown();

			  RemoveProvidersFromIndexDbFile( TestDirectory.databaseLayout() );
			  graphDb = StartDatabase( storeDir );

			  using ( Transaction ignored = graphDb.BeginTx() )
			  {
					// Getting the index w/o exception means that the provider has been reinstated
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("default")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("wo-provider", MapUtil.stringMap("type", "exact"))) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("w-provider", MapUtil.stringMap("type", "exact", Org.Neo4j.Graphdb.index.IndexManager_Fields.PROVIDER, "lucene"))) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("default")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("wo-provider", MapUtil.stringMap("type", "exact"))) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("w-provider", MapUtil.stringMap("type", "exact", Org.Neo4j.Graphdb.index.IndexManager_Fields.PROVIDER, "lucene"))) );
			  }

			  graphDb.Shutdown();

			  RemoveProvidersFromIndexDbFile( TestDirectory.databaseLayout() );
			  graphDb = StartDatabase( storeDir );

			  using ( Transaction ignored = graphDb.BeginTx() )
			  {
					// Getting the index w/o exception means that the provider has been reinstated
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("default")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("wo-provider")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("w-provider")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("default")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("wo-provider")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("w-provider")) );
			  }

			  graphDb.Shutdown();
		 }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void databaseNotStartInReadOnlyModeWithMissingIndex() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void DatabaseNotStartInReadOnlyModeWithMissingIndex()
        {
            File databaseDir         = TestDirectory.databaseDir();
            FileSystemAbstraction fs = TestDirectory.FileSystem;

            CreateIndex(databaseDir, fs);
            DeleteIndexFolder(databaseDir, fs);
            GraphDatabaseService readGraphDb = null;

            try
            {
                readGraphDb = (new TestGraphDatabaseFactory()).setFileSystem(fs).newImpermanentDatabaseBuilder(databaseDir).setConfig(GraphDatabaseSettings.read_only, Settings.TRUE).newGraphDatabase();
                fail("Should have failed");
            }
            catch (Exception e)
            {
                Exception rootCause = Exceptions.rootCause(e);
                assertTrue(rootCause is System.InvalidOperationException);
                assertTrue(rootCause.Message.contains("Some indexes need to be rebuilt. This is not allowed in read only mode. Please start db in writable mode to rebuild indexes. Indexes " + "needing rebuild:"));
            }
            finally
            {
                if (readGraphDb != null)
                {
                    readGraphDb.Shutdown();
                }
            }
        }
Exemple #4
0
        private static void ExecuteQueryAndShutdown(GraphDatabaseService database, string query, IDictionary <string, object> @params)
        {
            Result execute = database.Execute(query, @params);

            execute.Close();
            database.Shutdown();
        }
Exemple #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void restoreExplicitIndexesFromBackup() throws java.io.IOException, org.neo4j.commandline.admin.CommandFailed
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RestoreExplicitIndexesFromBackup()
        {
            string databaseName = "destination";
            Config config       = ConfigWith(databaseName, Directory.absolutePath().AbsolutePath);
            File   fromPath     = new File(Directory.absolutePath(), "from");
            File   toPath       = config.Get(GraphDatabaseSettings.database_path);

            CreateDbWithExplicitIndexAt(fromPath, 100);

            (new RestoreDatabaseCommand(FileSystemRule.get(), fromPath, config, databaseName, true)).execute();

            GraphDatabaseService restoredDatabase = CreateDatabase(toPath, toPath.AbsolutePath);

            using (Transaction transaction = restoredDatabase.BeginTx())
            {
                IndexManager indexManager           = restoredDatabase.Index();
                string[]     nodeIndexNames         = indexManager.NodeIndexNames();
                string[]     relationshipIndexNames = indexManager.RelationshipIndexNames();

                foreach (string nodeIndexName in nodeIndexNames)
                {
                    CountNodesByKeyValue(indexManager, nodeIndexName, "a", "b");
                    CountNodesByKeyValue(indexManager, nodeIndexName, "c", "d");
                }

                foreach (string relationshipIndexName in relationshipIndexNames)
                {
                    CountRelationshipByKeyValue(indexManager, relationshipIndexName, "x", "y");
                }
            }
            restoredDatabase.Shutdown();
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void createPointPropertyOnLatestDatabase()
        internal virtual void CreatePointPropertyOnLatestDatabase()
        {
            File       storeDir    = _testDirectory.storeDir();
            Label      pointNode   = Label.label("PointNode");
            string     propertyKey = "a";
            PointValue pointValue  = pointValue(Cartesian, 1.0, 2.0);

            GraphDatabaseService database = startDatabaseWithFormat(storeDir, Standard.LATEST_NAME);

            using (Transaction transaction = database.BeginTx())
            {
                Node node = database.CreateNode(pointNode);
                node.SetProperty(propertyKey, pointValue);
                transaction.Success();
            }
            database.Shutdown();

            GraphDatabaseService restartedDatabase = startDatabaseWithFormat(storeDir, Standard.LATEST_NAME);

            using (Transaction ignored = restartedDatabase.BeginTx())
            {
                assertNotNull(restartedDatabase.FindNode(pointNode, propertyKey, pointValue));
            }
            restartedDatabase.Shutdown();
        }
Exemple #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowForcedCopyOverAnExistingDatabase() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowForcedCopyOverAnExistingDatabase()
        {
            // given
            string databaseName = "to";
            Config config       = ConfigWith(databaseName, Directory.absolutePath().AbsolutePath);

            File fromPath      = new File(Directory.absolutePath(), "from");
            File toPath        = config.Get(GraphDatabaseSettings.database_path);
            int  fromNodeCount = 10;
            int  toNodeCount   = 20;

            CreateDbAt(fromPath, fromNodeCount);
            CreateDbAt(toPath, toNodeCount);

            // when
            (new RestoreDatabaseCommand(FileSystemRule.get(), fromPath, config, databaseName, true)).execute();

            // then
            GraphDatabaseService copiedDb = (new GraphDatabaseFactory()).newEmbeddedDatabaseBuilder(toPath).setConfig(OnlineBackupSettings.online_backup_enabled, Settings.FALSE).newGraphDatabase();

            using (Transaction ignored = copiedDb.BeginTx())
            {
                assertEquals(fromNodeCount, Iterables.count(copiedDb.AllNodes));
            }

            copiedDb.Shutdown();
        }
Exemple #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testRegisterUnregisterHandlers()
        public virtual void TestRegisterUnregisterHandlers()
        {
            GraphDatabaseService graphDb  = (new TestGraphDatabaseFactory()).newImpermanentDatabase();
            KernelEventHandler   handler1 = new DummyKernelEventHandlerAnonymousInnerClass(this, _resource1);
            KernelEventHandler   handler2 = new DummyKernelEventHandlerAnonymousInnerClass2(this, _resource2);

            try
            {
                graphDb.UnregisterKernelEventHandler(handler1);
                fail("Shouldn't be able to do unregister on a " + "unregistered handler");
            }
            catch (System.InvalidOperationException)
            {               // Good
            }

            assertSame(handler1, graphDb.RegisterKernelEventHandler(handler1));
            assertSame(handler1, graphDb.RegisterKernelEventHandler(handler1));
            assertSame(handler1, graphDb.UnregisterKernelEventHandler(handler1));

            try
            {
                graphDb.UnregisterKernelEventHandler(handler1);
                fail("Shouldn't be able to do unregister on a " + "unregistered handler");
            }
            catch (System.InvalidOperationException)
            {               // Good
            }

            assertSame(handler1, graphDb.RegisterKernelEventHandler(handler1));
            assertSame(handler2, graphDb.RegisterKernelEventHandler(handler2));
            assertSame(handler1, graphDb.UnregisterKernelEventHandler(handler1));
            assertSame(handler2, graphDb.UnregisterKernelEventHandler(handler2));

            graphDb.Shutdown();
        }
Exemple #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void createPointArrayPropertyOnLatestDatabase()
        internal virtual void CreatePointArrayPropertyOnLatestDatabase()
        {
            File       storeDir    = _testDirectory.storeDir();
            Label      pointNode   = Label.label("PointNode");
            string     propertyKey = "a";
            PointValue pointValue  = pointValue(Cartesian, 1.0, 2.0);

            GraphDatabaseService database = startDatabaseWithFormat(storeDir, Standard.LATEST_NAME);

            using (Transaction transaction = database.BeginTx())
            {
                Node node = database.CreateNode(pointNode);
                node.SetProperty(propertyKey, new PointValue[] { pointValue, pointValue });
                transaction.Success();
            }
            database.Shutdown();

            GraphDatabaseService restartedDatabase = startDatabaseWithFormat(storeDir, Standard.LATEST_NAME);

            using (Transaction ignored = restartedDatabase.BeginTx())
            {
                using (ResourceIterator <Node> nodes = restartedDatabase.FindNodes(pointNode))
                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    Node         node   = nodes.next();
                    PointValue[] points = ( PointValue[] )node.GetProperty(propertyKey);
                    assertThat(points, arrayWithSize(2));
                }
            }
            restartedDatabase.Shutdown();
        }
Exemple #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReportMissingSchemaIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReportMissingSchemaIndex()
        {
            // given
            DatabaseLayout       databaseLayout = _testDirectory.databaseLayout();
            GraphDatabaseService gds            = GetGraphDatabaseService(databaseLayout.DatabaseDirectory());

            Label  label   = Label.label("label");
            string propKey = "propKey";

            CreateIndex(gds, label, propKey);

            gds.Shutdown();

            // when
            File schemaDir = FindFile(databaseLayout, "schema");

            FileUtils.deleteRecursively(schemaDir);

            ConsistencyCheckService service = new ConsistencyCheckService();
            Config configuration            = Config.defaults(Settings());
            Result result = RunFullConsistencyCheck(service, configuration, databaseLayout);

            // then
            assertTrue(result.Successful);
            File reportFile = result.ReportFile();

            assertTrue("Consistency check report file should be generated.", reportFile.exists());
            assertThat("Expected to see report about schema index not being online", Files.readAllLines(reportFile.toPath()).ToString(), allOf(containsString("schema rule"), containsString("not online")));
        }
Exemple #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void createDateArrayOnLatestDatabase()
        internal virtual void CreateDateArrayOnLatestDatabase()
        {
            File      storeDir    = _testDirectory.storeDir();
            Label     label       = Label.label("DateNode");
            string    propertyKey = "a";
            LocalDate date        = DateValue.date(1991, 5, 3).asObjectCopy();

            GraphDatabaseService database = startDatabaseWithFormat(storeDir, Standard.LATEST_NAME);

            using (Transaction transaction = database.BeginTx())
            {
                Node node = database.CreateNode(label);
                node.SetProperty(propertyKey, new LocalDate[] { date, date });
                transaction.Success();
            }
            database.Shutdown();

            GraphDatabaseService restartedDatabase = startDatabaseWithFormat(storeDir, Standard.LATEST_NAME);

            using (Transaction ignored = restartedDatabase.BeginTx())
            {
                using (ResourceIterator <Node> nodes = restartedDatabase.FindNodes(label))
                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    Node        node   = nodes.next();
                    LocalDate[] points = ( LocalDate[] )node.GetProperty(propertyKey);
                    assertThat(points, arrayWithSize(2));
                }
            }
            restartedDatabase.Shutdown();
        }
Exemple #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void failToCreateDateArrayOnOldDatabase()
        internal virtual void FailToCreateDateArrayOnOldDatabase()
        {
            File storeDir = _testDirectory.storeDir();
            GraphDatabaseService        nonUpgradedStore = startNonUpgradableDatabaseWithFormat(storeDir, StandardV3_2.NAME);
            LocalDate                   date             = DateValue.date(1991, 5, 3).asObjectCopy();
            TransactionFailureException failureException = assertThrows(typeof(TransactionFailureException), () =>
            {
                using (Transaction transaction = nonUpgradedStore.BeginTx())
                {
                    Node node = nonUpgradedStore.CreateNode();
                    node.setProperty("a", new LocalDate[] { date, date });
                    transaction.success();
                }
            });

            assertEquals("Current record format does not support TEMPORAL_PROPERTIES. Please upgrade your store " + "to the format that support requested capability.", Exceptions.rootCause(failureException).Message);
            nonUpgradedStore.Shutdown();

            GraphDatabaseService restartedOldFormatDatabase = startNonUpgradableDatabaseWithFormat(storeDir, StandardV3_2.NAME);

            using (Transaction transaction = restartedOldFormatDatabase.BeginTx())
            {
                Node node = restartedOldFormatDatabase.CreateNode();
                node.SetProperty("c", "d");
                transaction.success();
            }
            restartedOldFormatDatabase.Shutdown();
        }
Exemple #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void createDatePropertyOnLatestDatabase()
        internal virtual void CreateDatePropertyOnLatestDatabase()
        {
            File      storeDir    = _testDirectory.storeDir();
            Label     label       = Label.label("DateNode");
            string    propertyKey = "a";
            LocalDate date        = DateValue.date(1991, 5, 3).asObjectCopy();

            GraphDatabaseService database = startDatabaseWithFormat(storeDir, Standard.LATEST_NAME);

            using (Transaction transaction = database.BeginTx())
            {
                Node node = database.CreateNode(label);
                node.SetProperty(propertyKey, date);
                transaction.Success();
            }
            database.Shutdown();

            GraphDatabaseService restartedDatabase = startDatabaseWithFormat(storeDir, Standard.LATEST_NAME);

            using (Transaction ignored = restartedDatabase.BeginTx())
            {
                assertNotNull(restartedDatabase.FindNode(label, propertyKey, date));
            }
            restartedDatabase.Shutdown();
        }
Exemple #14
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();
        }
Exemple #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void failToCreatePointOnOldDatabase()
        internal virtual void FailToCreatePointOnOldDatabase()
        {
            File storeDir = _testDirectory.storeDir();
            GraphDatabaseService        nonUpgradedStore = startNonUpgradableDatabaseWithFormat(storeDir, StandardV3_2.NAME);
            TransactionFailureException exception        = assertThrows(typeof(TransactionFailureException), () =>
            {
                using (Transaction transaction = nonUpgradedStore.BeginTx())
                {
                    Node node = nonUpgradedStore.CreateNode();
                    node.setProperty("a", pointValue(Cartesian, 1.0, 2.0));
                    transaction.success();
                }
            });

            assertEquals("Current record format does not support POINT_PROPERTIES. Please upgrade your store to the format that support requested capability.", Exceptions.rootCause(exception).Message);
            nonUpgradedStore.Shutdown();

            GraphDatabaseService restartedOldFormatDatabase = startNonUpgradableDatabaseWithFormat(storeDir, StandardV3_2.NAME);

            using (Transaction transaction = restartedOldFormatDatabase.BeginTx())
            {
                Node node = restartedOldFormatDatabase.CreateNode();
                node.SetProperty("c", "d");
                transaction.success();
            }
            restartedOldFormatDatabase.Shutdown();
        }
Exemple #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void uniqueIndexWithoutOwningConstraintIsIgnoredDuringCheck() throws ConsistencyCheckTool.ToolFailureException, java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void UniqueIndexWithoutOwningConstraintIsIgnoredDuringCheck()
        {
            File   databaseDir = TestDirectory.databaseDir();
            Label  marker      = Label.label("MARKER");
            string property    = "property";

            GraphDatabaseService database = (new EnterpriseGraphDatabaseFactory()).newEmbeddedDatabase(databaseDir);

            try
            {
                CreateNodes(marker, property, database);
                AddIndex(database);
                WaitForIndexPopulationFailure(database);
            }
            catch (SchemaKernelException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            finally
            {
                database.Shutdown();
            }

            ConsistencyCheckService.Result checkResult = ConsistencyCheckTool.RunConsistencyCheckTool(new string[] { databaseDir.AbsolutePath }, EmptyPrintStream(), EmptyPrintStream());
            assertTrue(string.join(Environment.NewLine, Files.readAllLines(checkResult.ReportFile().toPath())), checkResult.Successful);
        }
Exemple #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void startCommunityDatabaseOnProvidedNonAbsoluteFile()
        internal virtual void StartCommunityDatabaseOnProvidedNonAbsoluteFile()
        {
            File directory = new File("notAbsoluteDirectory");
            EphemeralCommunityFacadeFactory factory         = new EphemeralCommunityFacadeFactory();
            GraphDatabaseFactory            databaseFactory = new EphemeralGraphDatabaseFactory(factory);
            GraphDatabaseService            service         = databaseFactory.NewEmbeddedDatabase(directory);

            service.Shutdown();
        }
Exemple #18
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void cleanup(org.neo4j.graphdb.GraphDatabaseService gdb) throws java.io.IOException
        private void Cleanup(GraphDatabaseService gdb)
        {
            if (gdb != null)
            {
                GraphDatabaseAPI db = ( GraphDatabaseAPI )gdb;
                gdb.Shutdown();
                FileUtils.deleteDirectory(Db.databaseLayout().databaseDirectory());
            }
        }
Exemple #19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void failToRecoverFirstCorruptedTransactionSingleFileNoCheckpointIfFailOnCorruption() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void FailToRecoverFirstCorruptedTransactionSingleFileNoCheckpointIfFailOnCorruption()
        {
            AddCorruptedCommandsToLastLogFile();

            _expectedException.expectCause(new RootCauseMatcher <>(typeof(NegativeArraySizeException)));

            GraphDatabaseService recoveredDatabase = _databaseFactory.newEmbeddedDatabase(_storeDir);

            recoveredDatabase.Shutdown();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUpgradeAutomaticallyOnDatabaseStartup() throws org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldUpgradeAutomaticallyOnDatabaseStartup()
        {
            // when
            GraphDatabaseService database = CreateGraphDatabaseService();

            database.Shutdown();

            // then
            assertTrue("Some store files did not have the correct version", checkNeoStoreHasDefaultFormatVersion(_check, _workingDatabaseLayout));
            assertConsistentStore(_workingDatabaseLayout);
        }
Exemple #21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testShutdownEvents()
        public virtual void TestShutdownEvents()
        {
            GraphDatabaseService    graphDb  = (new TestGraphDatabaseFactory()).newImpermanentDatabase();
            DummyKernelEventHandler handler1 = new DummyKernelEventHandlerAnonymousInnerClass3(this, _resource1);
            DummyKernelEventHandler handler2 = new DummyKernelEventHandlerAnonymousInnerClass4(this, _resource1);

            graphDb.RegisterKernelEventHandler(handler1);
            graphDb.RegisterKernelEventHandler(handler2);

            graphDb.Shutdown();

            assertEquals(Convert.ToInt32(0), handler2.BeforeShutdownConflict);
            assertEquals(Convert.ToInt32(1), handler1.BeforeShutdownConflict);
        }
Exemple #22
0
 private static void ShutdownDatabaseSilently(GraphDatabaseService databaseService)
 {
     if (databaseService != null)
     {
         try
         {
             databaseService.Shutdown();
         }
         catch (Exception)
         {
             // ignored
         }
     }
 }
Exemple #23
0
        private void AssertThatCommunityCannotStartOnEnterpriseOnlyConstraint(string constraintCreationQuery, string errorMessage)
        {
            // given
            GraphDatabaseService graphDb = (new EnterpriseGraphDatabaseFactory()).newEmbeddedDatabase(Dir.storeDir());

            try
            {
                graphDb.Execute(constraintCreationQuery);
            }
            finally
            {
                graphDb.Shutdown();
            }
            graphDb = null;

            // when
            try
            {
                graphDb = (new TestGraphDatabaseFactory()).newEmbeddedDatabase(Dir.storeDir());
                fail("should have failed to start!");
            }
            // then
            catch (Exception e)
            {
                Exception error = Exceptions.rootCause(e);
                assertThat(error, instanceOf(typeof(System.InvalidOperationException)));
                assertEquals(errorMessage, error.Message);
            }
            finally
            {
                if (graphDb != null)
                {
                    graphDb.Shutdown();
                }
            }
        }
Exemple #24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void failToDowngradeFormatWhenUpgradeNotAllowed()
        internal virtual void FailToDowngradeFormatWhenUpgradeNotAllowed()
        {
            GraphDatabaseService database = StartDatabaseWithFormatUnspecifiedUpgrade(_storeDir, StandardV3_4.NAME);

            using (Transaction transaction = database.BeginTx())
            {
                Node node = database.CreateNode();
                node.SetProperty("a", "b");
                transaction.Success();
            }
            database.Shutdown();
            Exception throwable = assertThrows(typeof(Exception), () => StartDatabaseWithFormatUnspecifiedUpgrade(_storeDir, StandardV3_2.NAME));

            assertSame(typeof(UpgradeNotAllowedByConfigurationException), Exceptions.rootCause(throwable).GetType());
        }
Exemple #25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void failToDowngradeFormatWheUpgradeAllowed()
        internal virtual void FailToDowngradeFormatWheUpgradeAllowed()
        {
            GraphDatabaseService database = StartDatabaseWithFormatUnspecifiedUpgrade(_storeDir, StandardV3_4.NAME);

            using (Transaction transaction = database.BeginTx())
            {
                Node node = database.CreateNode();
                node.SetProperty("a", "b");
                transaction.Success();
            }
            database.Shutdown();
            Exception throwable = assertThrows(typeof(Exception), () => (new GraphDatabaseFactory()).newEmbeddedDatabaseBuilder(_storeDir).setConfig(record_format, StandardV3_2.NAME).setConfig(allow_upgrade, Settings.TRUE).newGraphDatabase());

            assertSame(typeof(StoreUpgrader.AttemptedDowngradeException), Exceptions.rootCause(throwable).GetType());
        }
Exemple #26
0
        private static void PerformTransactions(string txPath, File storeDir)
        {
            GraphDatabaseService database = (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(storeDir).setConfig(GraphDatabaseSettings.logical_logs_location, txPath).newGraphDatabase();

            for (int i = 0; i < 10; i++)
            {
                using (Transaction transaction = database.BeginTx())
                {
                    Node node = database.CreateNode();
                    node.SetProperty("a", "b");
                    node.SetProperty("c", "d");
                    transaction.Success();
                }
            }
            database.Shutdown();
        }
Exemple #27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void latestRecordNotMigratedWhenFormatBumped()
        internal virtual void LatestRecordNotMigratedWhenFormatBumped()
        {
            GraphDatabaseService database = StartDatabaseWithFormatUnspecifiedUpgrade(_storeDir, StandardV3_2.NAME);

            using (Transaction transaction = database.BeginTx())
            {
                Node node = database.CreateNode();
                node.SetProperty("a", "b");
                transaction.Success();
            }
            database.Shutdown();

            Exception exception = assertThrows(typeof(Exception), () => StartDatabaseWithFormatUnspecifiedUpgrade(_storeDir, Standard.LATEST_NAME));

            assertSame(typeof(UpgradeNotAllowedByConfigurationException), Exceptions.rootCause(exception).GetType());
        }
Exemple #28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void failToOpenStoreWithPointPropertyUsingOldFormat()
        internal virtual void FailToOpenStoreWithPointPropertyUsingOldFormat()
        {
            File storeDir = _testDirectory.storeDir();
            GraphDatabaseService database = startDatabaseWithFormat(storeDir, StandardV3_4.NAME);

            using (Transaction transaction = database.BeginTx())
            {
                Node node = database.CreateNode();
                node.SetProperty("a", pointValue(Cartesian, 1.0, 2.0));
                transaction.Success();
            }
            database.Shutdown();

            Exception throwable = assertThrows(typeof(Exception), () => startDatabaseWithFormat(storeDir, StandardV3_2.NAME));

            assertSame(typeof(StoreUpgrader.AttemptedDowngradeException), Exceptions.rootCause(throwable).GetType());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAbortOnNonCleanlyShutdown() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAbortOnNonCleanlyShutdown()
        {
            // given
            removeCheckPointFromTxLog(_fileSystem, _workingDatabaseLayout.databaseDirectory());
            try
            {
                // when
                GraphDatabaseService database = CreateGraphDatabaseService();
                database.Shutdown();                         // shutdown db in case test fails
                fail("Should have been unable to start upgrade on old version");
            }
            catch (Exception e)
            {
                // then
                assertThat(Exceptions.rootCause(e), Matchers.instanceOf(typeof(StoreUpgrader.UnableToUpgradeException)));
            }
        }
Exemple #30
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void run(String[] args) throws java.io.IOException
        protected internal virtual void Run(string[] args)
        {
            if (args.Length != 2 && args.Length != 3)
            {
                Console.Error.WriteLine("arguments: <generated class name> [<output source root>] <database dir>");
                Environment.Exit(1);
            }

            bool   writeToFile = args.Length == 3;
            string generatedClassWithPackage = args[0];
            string dbDir = writeToFile ? args[2] : args[1];

            Pair <string, string> parsedGenerated = ParseClassNameWithPackage(generatedClassWithPackage);
            string generatedClassPackage          = parsedGenerated.First();
            string generatedClassName             = parsedGenerated.Other();

//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getCanonicalName method:
            string generator = format("%s %s [<output source root>] <db-dir>", this.GetType().FullName, generatedClassWithPackage);

            GraphDatabaseService graph = InstantiateGraphDatabase(dbDir);

            try
            {
                if (writeToFile)
                {
                    File   sourceRoot       = new File(args[1]);
                    string outputPackageDir = generatedClassPackage.Replace('.', Path.DirectorySeparatorChar);
                    string outputFileName   = generatedClassName + ".java";
                    File   outputDir        = new File(sourceRoot, outputPackageDir);
                    File   outputFile       = new File(outputDir, outputFileName);
                    using (PrintWriter writer = new PrintWriter(outputFile))
                    {
                        TraceDb(generator, generatedClassPackage, generatedClassName, graph, writer);
                    }
                }
                else
                {
                    TraceDb(generator, generatedClassPackage, generatedClassName, graph, System.out);
                }
            }
            finally
            {
                graph.Shutdown();
            }
        }