Пример #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 TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRebuildFromLogUpToATx() throws Exception, org.neo4j.consistency.checking.InconsistentStoreException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRebuildFromLogUpToATx()
        {
            // given
            File prototypePath = PrototypePath;
            long txId          = PopulatePrototype(prototypePath);

            File copy = new File(_dir.databaseDir(), "copy");

            FileUtils.copyRecursively(prototypePath, copy);
            GraphDatabaseAPI db = db(copy);

            try
            {
                using (Org.Neo4j.Graphdb.Transaction tx = Db.beginTx())
                {
                    Db.createNode();
                    tx.Success();
                }
            }
            finally
            {
                Db.shutdown();
            }

            // when
            File rebuildPath = RebuilPath;

            (new RebuildFromLogs(_fileSystemRule.get())).rebuild(copy, rebuildPath, txId);

            // then
            assertEquals(GetDbRepresentation(prototypePath), GetDbRepresentation(rebuildPath));
        }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void pageCacheMetrics() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void PageCacheMetrics()
        {
            Label testLabel = Label.label("testLabel");

            using (Transaction transaction = _database.beginTx())
            {
                Node node = _database.createNode(testLabel);
                node.SetProperty("property", "value");
                transaction.Success();
            }

            using (Transaction ignored = _database.beginTx())
            {
                ResourceIterator <Node> nodes = _database.findNodes(testLabel);
                assertEquals(1, nodes.Count());
            }

            AssertMetrics("Metrics report should include page cache pins", PC_PINS, greaterThan(0L));
            AssertMetrics("Metrics report should include page cache unpins", PC_UNPINS, greaterThan(0L));
            AssertMetrics("Metrics report should include page cache evictions", PC_EVICTIONS, greaterThanOrEqualTo(0L));
            AssertMetrics("Metrics report should include page cache page faults", PC_PAGE_FAULTS, greaterThan(0L));
            AssertMetrics("Metrics report should include page cache hits", PC_HITS, greaterThan(0L));
            AssertMetrics("Metrics report should include page cache flushes", PC_FLUSHES, greaterThanOrEqualTo(0L));
            AssertMetrics("Metrics report should include page cache exceptions", PC_EVICTION_EXCEPTIONS, equalTo(0L));

            assertEventually("Metrics report should include page cache hit ratio", () => readDoubleValue(metricsCsv(_metricsDirectory, PC_HIT_RATIO)), lessThanOrEqualTo(1.0), 5, SECONDS);

            assertEventually("Metrics report should include page cache usage ratio", () => readDoubleValue(metricsCsv(_metricsDirectory, PC_USAGE_RATIO)), lessThanOrEqualTo(1.0), 5, SECONDS);
        }
Пример #4
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);
        }
Пример #5
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());
        }
Пример #6
0
 private void AssertInTxNodeWith(Label label, string key, object value)
 {
     using (Transaction tx = _db.beginTx())
     {
         AssertNodeWith(label, key, value);
         tx.Success();
     }
 }
 private static void CreateTestNode(Label marker)
 {
     using (Transaction transaction = _database.beginTx())
     {
         _database.createNode(marker);
         transaction.Success();
     }
 }
Пример #8
0
            internal void ApplyTo(Org.Neo4j.Graphdb.GraphDatabaseService graphDb)
            {
                using (Org.Neo4j.Graphdb.Transaction tx = graphDb.BeginTx())
                {
                    ApplyTx(graphDb);

                    tx.Success();
                }
            }
Пример #9
0
 private void CreateNonUniqueNodes()
 {
     using (Transaction tx = _db.beginTx())
     {
         Node originNode = _db.createNode(LABEL);
         originNode.SetProperty(KEY, _point1);
         Node centerNode = _db.createNode(LABEL);
         centerNode.SetProperty(KEY, _point1);
         tx.Success();
     }
 }
Пример #10
0
 private void CreateUniquenessConstraint()
 {
     using (Transaction tx = _db.beginTx())
     {
         _db.schema().constraintFor(TestLabels.LABEL_ONE).assertPropertyIsUnique(KEY).create();
         tx.Success();
     }
     using (Transaction tx = _db.beginTx())
     {
         _db.schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
         tx.Success();
     }
 }
Пример #11
0
 private void DeleteHumans()
 {
     using (Transaction tx = _db.beginTx())
     {
         using (ResourceIterator <Node> humans = _db.findNodes(_human))
         {
             while (humans.MoveNext())
             {
                 humans.Current.delete();
             }
         }
         tx.Success();
     }
 }
Пример #12
0
 private void CreateAliensAndHumans()
 {
     using (Transaction tx = _db.beginTx())
     {
         for (int i = 0; i < ALIENS; i++)
         {
             _db.createNode(_alien);
         }
         for (int i = 0; i < HUMANS; i++)
         {
             _db.createNode(_human);
         }
         tx.Success();
     }
 }
Пример #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = TEST_TIMEOUT) public void readOwnChangesWithoutIndex()
        public virtual void ReadOwnChangesWithoutIndex()
        {
            // WHEN
            using (Transaction tx = _db.beginTx())
            {
                Node node = _db.createNode(_label);
                node.SetProperty(PROPERTY_KEY, VALUE_1);

                AssertNodeWith(_label, PROPERTY_KEY, VALUE_1);

                tx.Success();
            }

            AssertInTxNodeWith(_label, PROPERTY_KEY, VALUE_1);
        }
Пример #14
0
        private Pair <long, long> CreateUniqueNodes()
        {
            Pair <long, long> nodeIds;

            using (Transaction tx = _db.beginTx())
            {
                Node originNode = _db.createNode(LABEL);
                originNode.SetProperty(KEY, _point1);
                Node centerNode = _db.createNode(LABEL);
                centerNode.SetProperty(KEY, _point2);

                nodeIds = Pair.of(originNode.Id, centerNode.Id);
                tx.Success();
            }
            return(nodeIds);
        }
Пример #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = TEST_TIMEOUT) public void firstRemoveSecondChangeProperty() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void FirstRemoveSecondChangeProperty()
        {
            // GIVEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.Barrier_Control barrier = new org.neo4j.test.Barrier_Control();
            Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Node node;
            Node node;

            using (Transaction tx = _db.beginTx())
            {
                node = _db.createNode();
                node.SetProperty(PROPERTY_KEY, VALUE_1);
                tx.Success();
            }

            // WHEN
            Future <Void> future = T2.execute(state =>
            {
                using (Transaction tx = _db.beginTx())
                {
                    node.RemoveProperty(PROPERTY_KEY);
                    tx.Success();
                    barrier.Reached();
                }
                return(null);
            });

            using (Transaction tx = _db.beginTx())
            {
                barrier.Await();
                node.SetProperty(PROPERTY_KEY, VALUE_2);
                tx.Success();
                barrier.Release();
            }

            future.get();
            using (Transaction tx = _db.beginTx())
            {
                assertEquals(VALUE_2, node.GetProperty(PROPERTY_KEY, VALUE_2));
                tx.Success();
            }
        }
Пример #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = TEST_TIMEOUT) public void shouldNotFreakOutIfTwoTransactionsDecideToEachAddTheSameProperty() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotFreakOutIfTwoTransactionsDecideToEachAddTheSameProperty()
        {
            // GIVEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.Barrier_Control barrier = new org.neo4j.test.Barrier_Control();
            Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Node node;
            Node node;

            using (Transaction tx = _db.beginTx())
            {
                node = _db.createNode();
                tx.Success();
            }

            // WHEN
            T2.execute((WorkerCommand <Void, Void>)state =>
            {
                using (Transaction tx = _db.beginTx())
                {
                    node.SetProperty(PROPERTY_KEY, VALUE_1);
                    tx.Success();
                    barrier.Reached();
                }
                return(null);
            });
            using (Transaction tx = _db.beginTx())
            {
                barrier.Await();
                node.SetProperty(PROPERTY_KEY, VALUE_2);
                tx.Success();
                barrier.Release();
            }

            using (Transaction tx = _db.beginTx())
            {
                assertEquals(1, count(node.PropertyKeys));
                tx.Success();
            }
        }
Пример #17
0
        private void AssertBothNodesArePresent(Pair <long, long> nodeIds)
        {
            using (Transaction tx = _db.beginTx())
            {
                ResourceIterator <Node> origin = _db.findNodes(LABEL, KEY, _point1);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue(origin.hasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals(nodeIds.First(), origin.next().Id);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse(origin.hasNext());

                ResourceIterator <Node> center = _db.findNodes(LABEL, KEY, _point2);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue(center.hasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals(nodeIds.Other(), center.next().Id);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse(center.hasNext());

                tx.Success();
            }
        }
Пример #18
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());
        }
Пример #19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = TEST_TIMEOUT) public void removeNodeChangeNodeProperty() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RemoveNodeChangeNodeProperty()
        {
            // GIVEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.Barrier_Control barrier = new org.neo4j.test.Barrier_Control();
            Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long nodeId;
            long nodeId;

            using (Transaction tx = _db.beginTx())
            {
                Node node = _db.createNode();
                nodeId = node.Id;
                node.SetProperty(PROPERTY_KEY, VALUE_1);
                tx.Success();
            }

            // WHEN
            Future <Void> future = T2.execute(state =>
            {
                using (Transaction tx = _db.beginTx())
                {
                    _db.getNodeById(nodeId).delete();
                    tx.Success();
                    barrier.Reached();
                }
                return(null);
            });

            try
            {
                using (Transaction tx = _db.beginTx())
                {
                    barrier.Await();
                    _db.getNodeById(nodeId).setProperty(PROPERTY_KEY, VALUE_2);
                    tx.Success();
                    barrier.Release();
                }
            }
            catch (TransactionFailureException e)
            {
                // Node was already deleted, fine.
                assertThat(e.InnerException, instanceOf(typeof(InvalidRecordException)));
            }

            future.get();
            using (Transaction tx = _db.beginTx())
            {
                try
                {
                    _db.getNodeById(nodeId);
                    assertEquals(VALUE_2, _db.getNodeById(nodeId).getProperty(PROPERTY_KEY, VALUE_2));
                }
                catch (NotFoundException)
                {
                    // Fine, its gone
                }
                tx.Success();
            }
        }