示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailTransactionThatIndexesLargePropertyDuringNodeCreation()
        public virtual void ShouldFailTransactionThatIndexesLargePropertyDuringNodeCreation()
        {
            // GIVEN
            GraphDatabaseService db    = DbRule.GraphDatabaseAPI;
            IndexDefinition      index = Neo4jMatchers.createIndex(db, _label, _propertyKey);

            //We expect this transaction to fail due to the huge property
            ExpectedException.expect(typeof(TransactionFailureException));
            using (Transaction tx = Db.beginTx())
            {
                try
                {
                    Db.execute("CREATE (n:" + _label + " {name: \"" + _longString + "\"})");
                    fail("Argument was illegal");
                }
                catch (System.ArgumentException)
                {
                    //this is expected.
                }
                tx.Success();
            }
            //Check that the database is empty.
            using (Transaction tx = Db.beginTx())
            {
                ResourceIterator <Node> nodes = Db.AllNodes.GetEnumerator();
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse(nodes.hasNext());
            }
            Db.shutdown();
        }
示例#2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException
        public static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                exit(1);
            }

            File storeDir           = new File(args[0]);
            GraphDatabaseService db = (new TestGraphDatabaseFactory()).newEmbeddedDatabase(storeDir);

            using (Transaction tx = Db.beginTx())
            {
                Db.createNode().createRelationshipTo(Db.createNode(), MyRelTypes.TEST);
                tx.Success();
            }

            (( GraphDatabaseAPI )db).DependencyResolver.resolveDependency(typeof(CheckPointer)).forceCheckPoint(new SimpleTriggerInfo("test")
                                                                                                                );

            using (Transaction tx = Db.beginTx())
            {
                Db.index().forNodes("index").add(Db.createNode(), storeDir.AbsolutePath, Db.createNode());
                tx.Success();
            }

            exit(0);
        }
示例#3
0
        protected internal override Traverser InstantiateTraverser(Node start, Node end)
        {
            GraphDatabaseService db       = start.GraphDatabase;
            TraversalDescription sideBase = Db.traversalDescription().breadthFirst().uniqueness(NODE_PATH);

            return(Db.bidirectionalTraversalDescription().mirroredSides(sideBase.Expand(_expander)).sideSelector(LEVEL_STOP_DESCENT_ON_RESULT, _maxDepth).collisionEvaluator(toDepth(_maxDepth)).traverse(start, end));
        }
示例#4
0
        private void SetupDb(GraphDatabaseSettings.SchemaIndex schemaIndex)
        {
            TestGraphDatabaseFactory dbFactory = new TestGraphDatabaseFactory();
            GraphDatabaseBuilder     builder   = dbFactory.NewEmbeddedDatabaseBuilder(_directory.storeDir()).setConfig(GraphDatabaseSettings.default_schema_provider, schemaIndex.providerName());

            _db = builder.NewGraphDatabase();
        }
示例#5
0
        /// <summary>
        /// Tests an issue where loading all relationship types and property indexes after
        /// the neostore data source had been started internally. The db would be in a
        /// state where it would need recovery for the neostore data source, as well as some
        /// other data source. This would fail since eventually TxManager#getTransaction()
        /// would be called, which would fail since it hadn't as of yet recovered fully.
        /// Whereas that failure would happen in a listener and merely be logged, one effect
        /// of it would be that there would seem to be no relationship types in the database.
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void recoverNeoAndIndexHavingAllRelationshipTypesAfterRecovery() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RecoverNeoAndIndexHavingAllRelationshipTypesAfterRecovery()
        {
            // Given (create transactions and kill process, leaving it needing for recovery)
            File storeDir = TestDirectory.storeDir();

//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            assertEquals(0, Runtime.exec(new string[] { JavaExecutable.ToString(), "-Djava.awt.headless=true", "-cp", ClassPath, this.GetType().FullName, storeDir.AbsolutePath }).waitFor());

            // When
            GraphDatabaseService db = (new TestGraphDatabaseFactory()).newEmbeddedDatabase(storeDir);

            // Then
            try
            {
                using (Transaction ignored = Db.beginTx(), ResourceIterator <RelationshipType> typeResourceIterator = Db.AllRelationshipTypes.GetEnumerator())
                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    assertEquals(MyRelTypes.TEST.name(), typeResourceIterator.next().name());
                }
            }
            finally
            {
                Db.shutdown();
            }
        }
示例#6
0
        protected internal override Traverser InstantiateTraverser(Node start, Node end)
        {
            GraphDatabaseService db   = start.GraphDatabase;
            TraversalDescription side = Db.traversalDescription().breadthFirst().uniqueness(_uniqueness).order((startSource, _expander) => new LiteDepthFirstSelector(startSource, _startThreshold, _expander));

            return(Db.bidirectionalTraversalDescription().startSide(side.Expand(_expander).evaluator(toDepth(_onDepth / 2))).endSide(side.Expand(_expander.reverse()).evaluator(toDepth(_onDepth - _onDepth / 2))).collisionEvaluator(atDepth(_onDepth)).traverse(start, end));
        }
示例#7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSampleUniqueIndex() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSampleUniqueIndex()
        {
            GraphDatabaseService db = null;
            long deletedNodes       = 0;

            try
            {
                // Given
                db = (new TestGraphDatabaseFactory()).newEmbeddedDatabase(TestDirectory.storeDir());
                using (Transaction tx = Db.beginTx())
                {
                    Db.schema().constraintFor(_label).assertPropertyIsUnique(_property).create();
                    tx.Success();
                }

                using (Transaction tx = Db.beginTx())
                {
                    for (int i = 0; i < _nodes; i++)
                    {
                        Db.createNode(_label).setProperty(_property, "" + i);
                        tx.Success();
                    }
                }

                using (Transaction tx = Db.beginTx())
                {
                    for (int i = 0; i < _nodes; i++)
                    {
                        if (i % 10 == 0)
                        {
                            deletedNodes++;
                            Db.findNode(_label, _property, "" + i).delete();
                            tx.Success();
                        }
                    }
                }
            }
            finally
            {
                if (db != null)
                {
                    Db.shutdown();
                }
            }

            // When
            TriggerIndexResamplingOnNextStartup();

            // Then
            Register_DoubleLongRegister indexSampleRegister = FetchIndexSamplingValues(db);

            assertEquals(_nodes - deletedNodes, indexSampleRegister.ReadFirst());
            assertEquals(_nodes - deletedNodes, indexSampleRegister.ReadSecond());

            Register_DoubleLongRegister indexSizeRegister = FetchIndexSizeValues(db);

            assertEquals(0, indexSizeRegister.ReadFirst());
            assertEquals(_nodes - deletedNodes, indexSizeRegister.ReadSecond());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @BeforeClass public static void setUp()
        public static void SetUp()
        {
            CustomClockFacadeFactory facadeFactory = new CustomClockFacadeFactory();

            _database = (new CustomClockTestGraphDatabaseFactory(facadeFactory)).NewEmbeddedDatabaseBuilder(Directory.storeDir()).setConfig(GraphDatabaseSettings.lock_acquisition_timeout, "2s").setConfig("dbms.backup.enabled", "false").newGraphDatabase();

            CreateTestNode(_marker);
        }
示例#9
0
        protected internal override Traverser InstantiateTraverser(Node start, Node end)
        {
            // Bidirectional traversal
            GraphDatabaseService db    = start.GraphDatabase;
            TraversalDescription @base = Db.traversalDescription().depthFirst().uniqueness(Uniqueness());

            return(Db.bidirectionalTraversalDescription().startSide(@base.Expand(_expander).evaluator(toDepth(_maxDepth / 2))).endSide(@base.Expand(_expander.reverse()).evaluator(toDepth(_maxDepth - _maxDepth / 2))).traverse(start, end));
        }
示例#10
0
            internal void ApplyTo(Org.Neo4j.Graphdb.GraphDatabaseService graphDb)
            {
                using (Org.Neo4j.Graphdb.Transaction tx = graphDb.BeginTx())
                {
                    ApplyTx(graphDb);

                    tx.Success();
                }
            }
示例#11
0
 internal override void RemoveOffendingDataInRunningTx(GraphDatabaseService db)
 {
     using (ResourceIterator <Node> nodes = Db.findNodes(Label.label(KEY)))
     {
         while (nodes.MoveNext())
         {
             nodes.Current.delete();
         }
     }
 }
示例#12
0
 private void DoCleanShutdown()
 {
     try
     {
         _db.shutdown();
     }
     finally
     {
         _db = null;
     }
 }
示例#13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void restart(org.neo4j.io.fs.FileSystemAbstraction fs) throws java.io.IOException
        private void Restart(FileSystemAbstraction fs)
        {
            if (_db != null)
            {
                _db.shutdown();
            }

            fs.Mkdirs(_storeDir);
            TestGraphDatabaseFactory dbFactory = new TestGraphDatabaseFactory();

            _db = dbFactory.setUserLogProvider(_userLogProvider).setInternalLogProvider(_internalLogProvider).setFileSystem(new UncloseableDelegatingFileSystemAbstraction(fs)).newImpermanentDatabaseBuilder(_storeDir).setConfig(index_background_sampling_enabled, "false").newGraphDatabase();
        }
示例#14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.register.Register_DoubleLongRegister fetchIndexSizeValues(org.neo4j.graphdb.GraphDatabaseService db) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException, org.neo4j.internal.kernel.api.exceptions.TransactionFailureException
        private Register_DoubleLongRegister FetchIndexSizeValues(GraphDatabaseService db)
        {
            try
            {
                // Then
                db = (new TestGraphDatabaseFactory()).newEmbeddedDatabase(TestDirectory.storeDir());
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("deprecation") org.neo4j.kernel.internal.GraphDatabaseAPI api = (org.neo4j.kernel.internal.GraphDatabaseAPI) db;
                GraphDatabaseAPI api = ( GraphDatabaseAPI )db;
                using ([email protected] tx = api.DependencyResolver.resolveDependency(typeof(Kernel)).beginTransaction(@explicit, AUTH_DISABLED))
                {
                    return(tx.SchemaRead().indexUpdatesAndSize(IndexId(tx), Registers.newDoubleLongRegister()));
                }
            }
            finally
            {
                if (db != null)
                {
                    Db.shutdown();
                }
            }
        }
示例#15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void initDb()
        public virtual void InitDb()
        {
            DbRule.withSetting(DeferringStatementLocksFactory.DeferredLocksEnabled, Settings.TRUE);
            _db = DbRule.GraphDatabaseAPI;
        }
示例#16
0
 internal override void CreateConstraintInRunningTx(GraphDatabaseService db, string type, string property)
 {
     SchemaHelper.createNodeKeyConstraint(db, type, property);
 }
示例#17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSampleNotUniqueIndex() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSampleNotUniqueIndex()
        {
            GraphDatabaseService db = null;
            long deletedNodes       = 0;

            try
            {
                // Given
                db = (new TestGraphDatabaseFactory()).newEmbeddedDatabase(TestDirectory.storeDir());
                IndexDefinition indexDefinition;
                using (Transaction tx = Db.beginTx())
                {
                    indexDefinition = Db.schema().indexFor(_label).on(_property).create();
                    tx.Success();
                }

                using (Transaction tx = Db.beginTx())
                {
                    Db.schema().awaitIndexOnline(indexDefinition, 10, TimeUnit.SECONDS);
                    tx.Success();
                }

                using (Transaction tx = Db.beginTx())
                {
                    for (int i = 0; i < _nodes; i++)
                    {
                        Db.createNode(_label).setProperty(_property, _names[i % _names.Length]);
                        tx.Success();
                    }
                }

                using (Transaction tx = Db.beginTx())
                {
                    for (int i = 0; i < (_nodes / 10); i++)
                    {
                        using (ResourceIterator <Node> nodes = Db.findNodes(_label, _property, _names[i % _names.Length]))
                        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                            nodes.next().delete();
                        }
                        deletedNodes++;
                        tx.Success();
                    }
                }
            }
            finally
            {
                if (db != null)
                {
                    Db.shutdown();
                }
            }

            // When
            TriggerIndexResamplingOnNextStartup();

            // Then

            // lucene will consider also the delete nodes, native won't
            Register_DoubleLongRegister register = FetchIndexSamplingValues(db);

            assertEquals(_names.Length, register.ReadFirst());
            assertThat(register.ReadSecond(), allOf(greaterThanOrEqualTo(nodes - deletedNodes), lessThanOrEqualTo(nodes)));

            // but regardless, the deleted nodes should not be considered in the index size value
            Register_DoubleLongRegister indexSizeRegister = FetchIndexSizeValues(db);

            assertEquals(0, indexSizeRegister.ReadFirst());
            assertEquals(nodes - deletedNodes, indexSizeRegister.ReadSecond());
        }
示例#18
0
 internal override void CreateOffendingDataInRunningTx(GraphDatabaseService db)
 {
     Db.createNode(Label.label(KEY));
 }
示例#19
0
 internal static Org.Neo4j.Graphdb.Node FirstNode(Org.Neo4j.Graphdb.GraphDatabaseService graphDb)
 {
     return(Iterables.firstOrNull(graphDb.AllNodes));
 }
示例#20
0
 internal void ApplyTx(Org.Neo4j.Graphdb.GraphDatabaseService graphDb)
 {
 }
示例#21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp()
        public virtual void SetUp()
        {
            _metricsDirectory = TestDirectory.directory("metrics");
            _database         = (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(TestDirectory.storeDir()).setConfig(MetricsSettings.MetricsEnabled, Settings.FALSE).setConfig(MetricsSettings.NeoPageCacheEnabled, Settings.TRUE).setConfig(MetricsSettings.CsvEnabled, Settings.TRUE).setConfig(MetricsSettings.CsvInterval, "100ms").setConfig(MetricsSettings.CsvPath, _metricsDirectory.AbsolutePath).setConfig(OnlineBackupSettings.online_backup_enabled, Settings.FALSE).newGraphDatabase();
        }