//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = TEST_TIMEOUT) public void timeoutOnAcquiringSharedLock() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TimeoutOnAcquiringSharedLock()
        {
            ExpectedException.expect(new RootCauseMatcher <>(typeof(LockAcquisitionTimeoutException), "The transaction has been terminated. " + "Retry your operation in a new transaction, and you should see a successful result. " + "Unable to acquire lock within configured timeout (dbms.lock.acquisition.timeout). " + "Unable to acquire lock for resource: LABEL with id: 1 within 2000 millis."));

            using (Transaction ignored = _database.beginTx())
            {
                Locks lockManger = LockManager;
                lockManger.NewClient().acquireExclusive(LockTracer.NONE, ResourceTypes.LABEL, 1);

                Future <Void> propertySetFuture = _secondTransactionExecutor.executeDontWait(state =>
                {
                    using (Transaction nestedTransaction = _database.beginTx())
                    {
                        ResourceIterator <Node> nodes = _database.findNodes(_marker);
                        Node node = nodes.next();
                        node.addLabel(Label.label("anotherLabel"));
                        nestedTransaction.success();
                    }
                    return(null);
                });

                _secondTransactionExecutor.waitUntilWaiting(SharedLockWaitingPredicate());
                _clockExecutor.execute((OtherThreadExecutor.WorkerCommand <Void, Void>)state =>
                {
                    _fakeClock.forward(3, TimeUnit.SECONDS);
                    return(null);
                });
                propertySetFuture.get();

                fail("Should throw termination exception.");
            }
        }
示例#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
//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();
        }
示例#4
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));
        }
示例#5
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 readOwnChangesFromRacingIndexNoBlock() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ReadOwnChangesFromRacingIndexNoBlock()
        {
            Future <Void> t2Future = T2.execute(state =>
            {
                using (Transaction tx = _db.beginTx())
                {
                    CreateNodeWithProperty(_label, PROPERTY_KEY, VALUE_1);
                    AssertNodeWith(_label, PROPERTY_KEY, VALUE_1);

                    tx.success();
                }
                return(null);
            });

            Future <Void> t3Future = T3.execute(state =>
            {
                using (Transaction tx = _db.beginTx())
                {
                    CreateAndAwaitIndex(_label, PROPERTY_KEY);
                    tx.success();
                }
                return(null);
            });

            t3Future.get();
            t2Future.get();

            AssertInTxNodeWith(_label, PROPERTY_KEY, VALUE_1);
        }
示例#6
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);
        }
示例#7
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();
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = TEST_TIMEOUT) public void timeoutOnAcquiringExclusiveLock() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TimeoutOnAcquiringExclusiveLock()
        {
            ExpectedException.expect(new RootCauseMatcher <>(typeof(LockAcquisitionTimeoutException), "The transaction has been terminated. " + "Retry your operation in a new transaction, and you should see a successful result. " + "Unable to acquire lock within configured timeout (dbms.lock.acquisition.timeout). " + "Unable to acquire lock for resource: NODE with id: 0 within 2000 millis."));

            using (Transaction ignored = _database.beginTx())
            {
                ResourceIterator <Node> nodes = _database.findNodes(_marker);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                Node node = nodes.next();
                node.SetProperty(TEST_PROPERTY_NAME, "b");

                Future <Void> propertySetFuture = _secondTransactionExecutor.executeDontWait(state =>
                {
                    using (Transaction transaction1 = _database.beginTx())
                    {
                        node.SetProperty(TEST_PROPERTY_NAME, "b");
                        transaction1.success();
                    }
                    return(null);
                });

                _secondTransactionExecutor.waitUntilWaiting(ExclusiveLockWaitingPredicate());
                _clockExecutor.execute((OtherThreadExecutor.WorkerCommand <Void, Void>)state =>
                {
                    _fakeClock.forward(3, TimeUnit.SECONDS);
                    return(null);
                });
                propertySetFuture.get();

                fail("Should throw termination exception.");
            }
        }
示例#9
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());
        }
示例#10
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();
     }
 }
示例#12
0
        private int LabelId(Label alien)
        {
            ThreadToStatementContextBridge contextBridge = (( GraphDatabaseAPI )_db).DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge));

            using (Transaction tx = _db.beginTx())
            {
                return(contextBridge.GetKernelTransactionBoundToThisThread(true).tokenRead().nodeLabel(alien.Name()));
            }
        }
示例#13
0
            internal void ApplyTo(Org.Neo4j.Graphdb.GraphDatabaseService graphDb)
            {
                using (Org.Neo4j.Graphdb.Transaction tx = graphDb.BeginTx())
                {
                    ApplyTx(graphDb);

                    tx.Success();
                }
            }
示例#14
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();
     }
 }
示例#15
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()
        {
            CreateGraph("A TO B", "B TO C", "C TO D", "D TO E");

            _tx = BeginTx();

            _a = GetNodeWithName("A");
            _b = GetNodeWithName("B");
            _c = GetNodeWithName("C");
            _d = GetNodeWithName("D");
            _e = GetNodeWithName("E");
        }
示例#16
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();
     }
 }
示例#17
0
 private void DeleteHumans()
 {
     using (Transaction tx = _db.beginTx())
     {
         using (ResourceIterator <Node> humans = _db.findNodes(_human))
         {
             while (humans.MoveNext())
             {
                 humans.Current.delete();
             }
         }
         tx.Success();
     }
 }
示例#18
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();
     }
 }
示例#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 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);
        }
示例#20
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);
        }
示例#21
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: private org.neo4j.test.OtherThreadExecutor.WorkerCommand<Void,Void> createAndAwaitIndex(final org.neo4j.graphdb.Label label, final String key)
        private WorkerCommand <Void, Void> CreateAndAwaitIndex(Label label, string key)
        {
            return(state =>
            {
                using (Transaction tx = _db.beginTx())
                {
                    _db.schema().indexFor(label).on(key).create();
                    tx.success();
                }
                using (Transaction ignore = _db.beginTx())
                {
                    _db.schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
                }
                return null;
            });
        }
示例#22
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();
            }
        }
示例#23
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();
            }
        }
示例#24
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();
            }
        }
示例#25
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();
            }
        }
示例#26
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());
        }
示例#27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void init()
        public virtual void Init()
        {
            _tx = BeginTx();
        }