Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test @Resources.Life(STARTED) public void shouldNotEndUpInBrokenStateAfterRotationFailure() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotEndUpInBrokenStateAfterRotationFailure()
        {
            // GIVEN
            FakeClock         clock             = Clocks.fakeClock();
            CallTrackingClock callTrackingClock = new CallTrackingClock(clock);
            CountsTracker     tracker           = ResourceManager.managed(NewTracker(callTrackingClock, EmptyVersionContextSupplier.EMPTY));
            int labelId = 1;

            using (Org.Neo4j.Kernel.Impl.Api.CountsAccessor_Updater tx = tracker.Apply(2).get())
            {
                tx.IncrementNodeCount(labelId, 1);                           // now at 1
            }

            // WHEN
            System.Predicate <Thread> arrived  = thread => stackTraceContains(thread, all(classNameContains("Rotation"), methodIs("rotate")));
            Future <object>           rotation = Threading.executeAndAwait(t => t.rotate(4), tracker, arrived, 1, SECONDS);

            using (Org.Neo4j.Kernel.Impl.Api.CountsAccessor_Updater tx = tracker.Apply(3).get())
            {
                tx.IncrementNodeCount(labelId, 1);                           // now at 2
            }
            while (callTrackingClock.CallsToNanos() == 0)
            {
                Thread.Sleep(10);
            }
            clock.Forward(Config.defaults().get(GraphDatabaseSettings.counts_store_rotation_timeout).toMillis() * 2, MILLISECONDS);
            try
            {
                rotation.get();
                fail("Should've failed rotation due to timeout");
            }
            catch (ExecutionException e)
            {
                // good
                assertTrue(e.InnerException is RotationTimeoutException);
            }

            // THEN
            Org.Neo4j.Register.Register_DoubleLongRegister register = Registers.newDoubleLongRegister();
            tracker.Get(CountsKeyFactory.nodeKey(labelId), register);
            assertEquals(2, register.ReadSecond());

            // and WHEN later attempting rotation again
            using (Org.Neo4j.Kernel.Impl.Api.CountsAccessor_Updater tx = tracker.Apply(4).get())
            {
                tx.IncrementNodeCount(labelId, 1);                           // now at 3
            }
            tracker.Rotate(4);

            // THEN
            tracker.Get(CountsKeyFactory.nodeKey(labelId), register);
            assertEquals(3, register.ReadSecond());
        }
Пример #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static java.util.List<java.util.Map<String,Object>> indexes(org.neo4j.internal.kernel.api.TokenRead tokens, org.neo4j.internal.kernel.api.SchemaRead schemaRead, Anonymizer anonymizer) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
        private static IList <IDictionary <string, object> > Indexes(TokenRead tokens, SchemaRead schemaRead, Anonymizer anonymizer)
        {
            IList <IDictionary <string, object> > indexes = new List <IDictionary <string, object> >();

            SilentTokenNameLookup tokenLookup = new SilentTokenNameLookup(tokens);

            IEnumerator <IndexReference> iterator = schemaRead.IndexesGetAll();

            while (iterator.MoveNext())
            {
                IndexReference index = iterator.Current;

                IDictionary <string, object> data = new Dictionary <string, object>();
                data["labels"] = Map(index.Schema().EntityTokenIds, id => anonymizer.Label(tokenLookup.LabelGetName(id), id));

                data["properties"] = Map(index.Schema().PropertyIds, id => anonymizer.PropertyKey(tokenLookup.PropertyKeyGetName(id), id));

                Org.Neo4j.Register.Register_DoubleLongRegister register = Registers.newDoubleLongRegister();
                schemaRead.IndexUpdatesAndSize(index, register);
                data["totalSize"] = register.ReadSecond();
                data["updatesSinceEstimation"] = register.ReadFirst();
                schemaRead.IndexSample(index, register);
                data["estimatedUniqueSize"] = register.ReadFirst();

                indexes.Add(data);
            }

            return(indexes);
        }
Пример #3
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());
        }
Пример #4
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());
        }
Пример #5
0
        private static void AssertDoubleLongEquals(int expectedFirst, int expectedSecond, Register_DoubleLongRegister actualValues)
        {
            string msg = string.Format("Expected ({0:D},{1:D}) but was ({2:D},{3:D})", expectedFirst, expectedSecond, actualValues.ReadFirst(), actualValues.ReadSecond());

            assertTrue(msg, actualValues.HasValues(expectedFirst, expectedSecond));
        }
Пример #6
0
 private void AssertEqualRegisters(string message, Register_DoubleLongRegister expected, Register_DoubleLongRegister actual)
 {
     assertEquals(message + " (first part of register)", expected.ReadFirst(), actual.ReadFirst());
     assertEquals(message + " (second part of register)", expected.ReadSecond(), actual.ReadSecond());
 }
Пример #7
0
 public void visitIndexSample(long indexId, long unique, long size)
 {
     Org.Neo4j.Register.Register_DoubleLongRegister output = _tracker.indexSample(indexId, newDoubleLongRegister());
     assertEquals("Should be able to read visited state.", output.ReadFirst(), unique);
     assertEquals("Should be able to read visited state.", output.ReadSecond(), size);
 }
Пример #8
0
 public void visitIndexStatistics(long indexId, long updates, long size)
 {
     Org.Neo4j.Register.Register_DoubleLongRegister output = _tracker.indexUpdatesAndSize(indexId, newDoubleLongRegister());
     assertEquals("Should be able to read visited state.", output.ReadFirst(), updates);
     assertEquals("Should be able to read visited state.", output.ReadSecond(), size);
 }