Exemplo n.º 1
0
        public override AllEntriesLabelScanReader AllNodeLabelRanges()
        {
            System.Func <int, RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> > seekProvider = labelId =>
            {
                try
                {
                    return(_index.seek((new LabelScanKey()).Set(labelId, 0), (new LabelScanKey()).Set(labelId, long.MaxValue)));
                }
                catch (IOException e)
                {
                    throw new Exception(e);
                }
            };

            int highestLabelId = -1;

            try
            {
                using (RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> cursor = _index.seek((new LabelScanKey()).Set(int.MaxValue, long.MaxValue), (new LabelScanKey()).Set(0, -1)))
                {
                    if (cursor.Next())
                    {
                        highestLabelId = cursor.get().key().labelId;
                    }
                }
            }
            catch (IOException e)
            {
                throw new Exception(e);
            }
            return(new NativeAllEntriesLabelScanReader(seekProvider, highestLabelId));
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCloseUnexhaustedCursorsOnReaderClose() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCloseUnexhaustedCursorsOnReaderClose()
        {
            // GIVEN
            GBPTree <LabelScanKey, LabelScanValue> index = mock(typeof(GBPTree));
            RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> cursor1 = mock(typeof(RawCursor));

            when(cursor1.Next()).thenReturn(false);
            RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> cursor2 = mock(typeof(RawCursor));

            when(cursor2.Next()).thenReturn(false);
            when(index.Seek(any(typeof(LabelScanKey)), any(typeof(LabelScanKey)))).thenReturn(cursor1, cursor2);

            // WHEN
            using (NativeLabelScanReader reader = new NativeLabelScanReader(index))
            {
                // first check test invariants
                reader.NodesWithLabel(LABEL_ID);
                reader.NodesWithLabel(LABEL_ID);
                verify(cursor1, never()).close();
                verify(cursor2, never()).close();
            }

            // THEN
            verify(cursor1, times(1)).close();
            verify(cursor2, times(1)).close();
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void assertHit(org.neo4j.cursor.RawCursor<Hit<org.apache.commons.lang3.mutable.MutableLong,org.apache.commons.lang3.mutable.MutableLong>,java.io.IOException> cursor, System.Nullable<long> expectedKey) throws java.io.IOException
		 private static void AssertHit( RawCursor<Hit<MutableLong, MutableLong>, IOException> cursor, long? expectedKey )
		 {
			  assertTrue( "Had no next when expecting key " + expectedKey, cursor.Next() );
			  Hit<MutableLong, MutableLong> hit = cursor.get();
			  assertEquals( expectedKey.Value, hit.Key().longValue() );
			  assertEquals( Value( expectedKey.Value ), hit.Value().longValue() );
		 }
Exemplo n.º 4
0
 private void StartSeekForRange(Org.Neo4j.Storageengine.Api.schema.IndexProgressor_NodeValueClient client, IndexQuery.GeometryRangePredicate rangePredicate, IndexQuery[] query)
 {
     try
     {
         BridgingIndexProgressor multiProgressor = new BridgingIndexProgressor(client, descriptor.schema().PropertyIds);
         client.Initialize(descriptor, multiProgressor, query, IndexOrder.NONE, false);
         SpaceFillingCurve curve = _spatial.SpaceFillingCurve;
         double[]          from  = rangePredicate.From() == null ? null : rangePredicate.From().coordinate();
         double[]          to    = rangePredicate.To() == null ? null : rangePredicate.To().coordinate();
         IList <SpaceFillingCurve.LongRange> ranges = curve.GetTilesIntersectingEnvelope(from, to, _configuration);
         foreach (SpaceFillingCurve.LongRange range in ranges)
         {
             SpatialIndexKey treeKeyFrom = layout.newKey();
             SpatialIndexKey treeKeyTo   = layout.newKey();
             InitializeKeys(treeKeyFrom, treeKeyTo);
             treeKeyFrom.FromDerivedValue(long.MinValue, range.Min);
             treeKeyTo.FromDerivedValue(long.MaxValue, range.Max + 1);
             RawCursor <Hit <SpatialIndexKey, VALUE>, IOException> seeker = makeIndexSeeker(treeKeyFrom, treeKeyTo, IndexOrder.NONE);
             IndexProgressor hitProgressor = new NativeHitIndexProgressor <>(seeker, client, openSeekers);
             multiProgressor.Initialize(descriptor, hitProgressor, query, IndexOrder.NONE, false);
         }
     }
     catch (System.ArgumentException)
     {
         // Invalid query ranges will cause this state (eg. min>max)
         client.Initialize(descriptor, IndexProgressor.EMPTY, query, IndexOrder.NONE, false);
     }
     catch (IOException e)
     {
         throw new UncheckedIOException(e);
     }
 }
Exemplo n.º 5
0
        // Timeout because test verify no infinite loop
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = 10_000L) public void shouldHandleDescendingWithEmptyRange() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleDescendingWithEmptyRange()
        {
            long[] seeds = new long[] { 0, 1, 4 };
            using (GBPTree <KEY, VALUE> index = CreateIndex())
            {
                // Write
                using (Writer <KEY, VALUE> writer = CreateWriter(index))
                {
                    foreach (long seed in seeds)
                    {
                        KEY   key   = _layout.key(seed);
                        VALUE value = _layout.value(0);
                        writer.Put(key, value);
                    }
                }

                KEY from = _layout.key(3);
                KEY to   = _layout.key(1);
                using (RawCursor <Hit <KEY, VALUE>, IOException> seek = index.Seek(from, to))
                {
                    assertFalse(seek.Next());
                }
                index.Checkpoint(Org.Neo4j.Io.pagecache.IOLimiter_Fields.Unlimited);
            }
        }
Exemplo n.º 6
0
        public override long CountIndexedNodes(long nodeId, int[] propertyKeyIds, params Value[] propertyValues)
        {
            KEY treeKeyFrom = Layout.newKey();
            KEY treeKeyTo   = Layout.newKey();

            treeKeyFrom.initialize(nodeId);
            treeKeyTo.initialize(nodeId);
            for (int i = 0; i < propertyValues.Length; i++)
            {
                treeKeyFrom.initFromValue(i, propertyValues[i], NEUTRAL);
                treeKeyTo.initFromValue(i, propertyValues[i], NEUTRAL);
            }
            try
            {
                using (RawCursor <Hit <KEY, VALUE>, IOException> seeker = Tree.seek(treeKeyFrom, treeKeyTo))
                {
                    long count = 0;
                    while (seeker.Next())
                    {
                        if (seeker.get().key().EntityId == nodeId)
                        {
                            count++;
                        }
                    }
                    return(count);
                }
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
Exemplo n.º 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPerformSuccessfulStoreCopyProcess() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPerformSuccessfulStoreCopyProcess()
        {
            // given
            StoreStreamingProcess process = new StoreStreamingProcess(_protocol, _checkPointerSupplier, _mutex, _resourceStream);

            // mocked behaviour
            ImmediateEventExecutor eventExecutor     = ImmediateEventExecutor.INSTANCE;
            Promise <Void>         completionPromise = eventExecutor.newPromise();
            long lastCheckpointedTxId = 1000L;
            RawCursor <StoreResource, IOException> resources = rawCursorOf();

            when(_checkPointer.tryCheckPoint(any())).thenReturn(lastCheckpointedTxId);
            when(_checkPointer.lastCheckPointedTransactionId()).thenReturn(lastCheckpointedTxId);
            when(_protocol.end(_ctx, SUCCESS)).thenReturn(completionPromise);
            when(_resourceStream.create()).thenReturn(resources);

            // when
            process.Perform(_ctx);

            // then
            InOrder inOrder = Mockito.inOrder(_protocol, _checkPointer);

            inOrder.verify(_checkPointer).tryCheckPoint(any());
            inOrder.verify(_protocol).end(_ctx, SUCCESS);
            inOrder.verifyNoMoreInteractions();

            assertEquals(1, @lock.ReadLockCount);

            // when
            completionPromise.Success = null;

            // then
            assertEquals(0, @lock.ReadLockCount);
        }
Exemplo n.º 8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void perform(io.netty.channel.ChannelHandlerContext ctx) throws java.io.IOException
        internal virtual void Perform(ChannelHandlerContext ctx)
        {
            CheckPointer checkPointer   = _checkPointerSupplier.get();
            Resource     checkPointLock = _mutex.storeCopy(() => checkPointer.TryCheckPoint(new SimpleTriggerInfo("Store copy")));

            Future <Void> completion = null;

            try
            {
                using (RawCursor <StoreResource, IOException> resources = _resourceStreamFactory.create())
                {
                    while (resources.Next())
                    {
                        StoreResource resource = resources.get();
                        _protocol.stream(ctx, resource);
                    }
                    completion = _protocol.end(ctx, SUCCESS);
                }
            }
            finally
            {
                if (completion != null)
                {
                    completion.addListener(f => checkPointLock.close());
                }
                else
                {
                    checkPointLock.Close();
                }
            }
        }
Exemplo n.º 9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void closeSeeker() throws java.io.IOException
        private void CloseSeeker()
        {
            if (_seeker != null)
            {
                _seeker.close();
                _seeker = null;
            }
        }
Exemplo n.º 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleRemoveEntireTree() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleRemoveEntireTree()
        {
            // given
            using (GBPTree <KEY, VALUE> index = CreateIndex())
            {
                int numberOfNodes = 200_000;
                using (Writer <KEY, VALUE> writer = CreateWriter(index))
                {
                    for (int i = 0; i < numberOfNodes; i++)
                    {
                        writer.Put(Key(i), Value(i));
                    }
                }

                // when
                BitArray removed = new BitArray();
                using (Writer <KEY, VALUE> writer = CreateWriter(index))
                {
                    for (int i = 0; i < numberOfNodes - numberOfNodes / 10; i++)
                    {
                        int candidate;
                        do
                        {
                            candidate = Random.Next(max(1, Random.Next(numberOfNodes)));
                        } while (removed.Get(candidate));
                        removed.Set(candidate, true);

                        writer.Remove(Key(candidate));
                    }
                }

                int next = 0;
                using (Writer <KEY, VALUE> writer = CreateWriter(index))
                {
                    for (int i = 0; i < numberOfNodes / 10; i++)
                    {
                        next = removed.nextClearBit(next);
                        removed.Set(next, true);
                        writer.Remove(Key(next));
                    }
                }

                // then
                using (RawCursor <Hit <KEY, VALUE>, IOException> seek = index.Seek(Key(0), Key(numberOfNodes)))
                {
                    assertFalse(seek.Next());
                }

                // and finally
                index.ConsistencyCheck();
            }
        }
Exemplo n.º 11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: org.neo4j.cursor.RawCursor<org.neo4j.index.internal.gbptree.Hit<KEY,VALUE>,java.io.IOException> makeIndexSeeker(KEY treeKeyFrom, KEY treeKeyTo, org.neo4j.internal.kernel.api.IndexOrder indexOrder) throws java.io.IOException
        internal virtual RawCursor <Hit <KEY, VALUE>, IOException> MakeIndexSeeker(KEY treeKeyFrom, KEY treeKeyTo, IndexOrder indexOrder)
        {
            if (indexOrder == IndexOrder.DESCENDING)
            {
                KEY tmpKey = treeKeyFrom;
                treeKeyFrom = treeKeyTo;
                treeKeyTo   = tmpKey;
            }
            RawCursor <Hit <KEY, VALUE>, IOException> seeker = Tree.seek(treeKeyFrom, treeKeyTo);

            OpenSeekers.Add(seeker);
            return(seeker);
        }
Exemplo n.º 12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyUniqueSeek(org.neo4j.cursor.RawCursor<org.neo4j.index.internal.gbptree.Hit<KEY,VALUE>,java.io.IOException> seek) throws java.io.IOException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
        private void VerifyUniqueSeek(RawCursor <Hit <KEY, VALUE>, IOException> seek)
        {
            if (seek != null)
            {
                if (seek.Next())
                {
                    long firstEntityId = seek.get().key().EntityId;
                    if (seek.Next())
                    {
                        long secondEntityId = seek.get().key().EntityId;
                        throw new IndexEntryConflictException(firstEntityId, secondEntityId, seek.get().key().asValues());
                    }
                }
            }
        }
Exemplo n.º 13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static <E extends Exception> int count(org.neo4j.cursor.RawCursor<?,E> cursor) throws E
        public static int Count <E, T1>(RawCursor <T1> cursor) where E : Exception
        {
            try
            {
                int count = 0;
                while (cursor.Next())
                {
                    count++;
                }
                return(count);
            }
            finally
            {
                cursor.Close();
            }
        }
Exemplo n.º 14
0
        public override IndexSample Result()
        {
            KEY lowest = _layout.newKey();

            lowest.initialize(long.MinValue);
            lowest.initValuesAsLowest();
            KEY highest = _layout.newKey();

            highest.initialize(long.MaxValue);
            highest.initValuesAsHighest();
            KEY prev = _layout.newKey();

            try
            {
                using (RawCursor <Hit <KEY, VALUE>, IOException> seek = _gbpTree.seek(lowest, highest))
                {
                    long sampledValues = 0;
                    long uniqueValues  = 0;

                    // Get the first one so that prev gets initialized
                    if (seek.Next())
                    {
                        prev = _layout.copyKey(seek.get().key(), prev);
                        sampledValues++;
                        uniqueValues++;

                        // Then do the rest
                        while (seek.Next())
                        {
                            Hit <KEY, VALUE> hit = seek.get();
                            if (_layout.compareValue(prev, hit.Key()) != 0)
                            {
                                uniqueValues++;
                                _layout.copyKey(hit.Key(), prev);
                            }
                            // else this is a duplicate of the previous one
                            sampledValues++;
                        }
                    }
                    return(new IndexSample(sampledValues, uniqueValues, sampledValues));
                }
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
Exemplo n.º 15
0
        /* Randomized tests */

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSplitCorrectly() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSplitCorrectly()
        {
            // GIVEN
            using (GBPTree <KEY, VALUE> index = index())
            {
                // WHEN
                int         count = 1_000;
                IList <KEY> seen  = new List <KEY>(count);
                using (Writer <KEY, VALUE> writer = index.Writer())
                {
                    for (int i = 0; i < count; i++)
                    {
                        KEY key;
                        do
                        {
                            key = key(_random.Next(100_000));
                        } while (ListContains(seen, key));
                        VALUE value = value(i);
                        writer.Put(key, value);
                        seen.Add(key);
                    }
                }

                // THEN
                using (RawCursor <Hit <KEY, VALUE>, IOException> cursor = index.Seek(Key(0), Key(long.MaxValue)))
                {
                    long prev = -1;
                    while (cursor.Next())
                    {
                        KEY  hit     = cursor.get().key();
                        long hitSeed = _layout.keySeed(hit);
                        if (hitSeed < prev)
                        {
                            fail(hit + " smaller than prev " + prev);
                        }
                        prev = hitSeed;
                        assertTrue(RemoveFromList(seen, hit));
                    }

                    if (seen.Count > 0)
                    {
                        fail("expected hits " + seen);
                    }
                }
            }
        }
Exemplo n.º 16
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void shouldWriteAndReadEntriesOfRandomSizes(int minKeySize, int maxKeySize, int minValueSize, int maxValueSize) throws java.io.IOException
        private void ShouldWriteAndReadEntriesOfRandomSizes(int minKeySize, int maxKeySize, int minValueSize, int maxValueSize)
        {
            // given
            using (GBPTree <RawBytes, RawBytes> tree = CreateIndex(Layout()))
            {
                // when
                ISet <string> generatedStrings             = new HashSet <string>();
                IList <Pair <RawBytes, RawBytes> > entries = new List <Pair <RawBytes, RawBytes> >();
                using (Writer <RawBytes, RawBytes> writer = tree.Writer())
                {
                    for (int i = 0; i < 1_000; i++)
                    {
                        // value, based on i
                        RawBytes value = new RawBytes();
                        value.Bytes = new sbyte[Random.Next(minValueSize, maxValueSize)];
                        Random.NextBytes(value.Bytes);

                        // key, randomly generated
                        string @string;
                        do
                        {
                            @string = Random.nextAlphaNumericString(minKeySize, maxKeySize);
                        } while (!generatedStrings.Add(@string));
                        RawBytes key = new RawBytes();
                        key.Bytes = UTF8.encode(@string);
                        entries.Add(Pair.of(key, value));

                        // write
                        writer.Put(key, value);
                    }
                }

                // then
                foreach (Pair <RawBytes, RawBytes> entry in entries)
                {
                    using (RawCursor <Hit <RawBytes, RawBytes>, IOException> seek = tree.Seek(entry.First(), entry.First()))
                    {
                        assertTrue(seek.Next());
                        assertArrayEquals(entry.First().Bytes, seek.get().key().bytes);
                        assertArrayEquals(entry.Other().Bytes, seek.get().value().bytes);
                        assertFalse(seek.Next());
                    }
                }
            }
        }
Exemplo n.º 17
0
 internal virtual void StartSeekForInitializedRange(Org.Neo4j.Storageengine.Api.schema.IndexProgressor_NodeValueClient client, KEY treeKeyFrom, KEY treeKeyTo, IndexQuery[] query, IndexOrder indexOrder, bool needFilter, bool needsValues)
 {
     if (IsEmptyRange(treeKeyFrom, treeKeyTo))
     {
         client.Initialize(Descriptor, IndexProgressor.EMPTY, query, indexOrder, needsValues);
         return;
     }
     try
     {
         RawCursor <Hit <KEY, VALUE>, IOException> seeker = MakeIndexSeeker(treeKeyFrom, treeKeyTo, indexOrder);
         IndexProgressor hitProgressor = GetIndexProgressor(seeker, client, needFilter, query);
         client.Initialize(Descriptor, hitProgressor, query, indexOrder, needsValues);
     }
     catch (IOException e)
     {
         throw new UncheckedIOException(e);
     }
 }
Exemplo n.º 18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") @Test public void shouldFindMultipleNodesInEachRange() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFindMultipleNodesInEachRange()
        {
            // GIVEN
            GBPTree <LabelScanKey, LabelScanValue> index = mock(typeof(GBPTree));
            RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> cursor = mock(typeof(RawCursor));

            when(cursor.Next()).thenReturn(true, true, true, false);
            when(cursor.get()).thenReturn(Hit(0, 0b1000_1000__1100_0010L), Hit(1, 0b0000_0010__0000_1000L), Hit(3, 0b0010_0000__1010_0001L), null);
            when(index.Seek(any(typeof(LabelScanKey)), any(typeof(LabelScanKey)))).thenReturn(cursor);
            using (NativeLabelScanReader reader = new NativeLabelScanReader(index))
            {
                // WHEN
                LongIterator iterator = reader.NodesWithLabel(LABEL_ID);

                // THEN
                assertArrayEquals(new long[] { 1, 6, 7, 11, 15, 64 + 3, 64 + 9, 192 + 0, 192 + 5, 192 + 7, 192 + 13 }, asArray(iterator));
            }
        }
Exemplo n.º 19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldStartFromGivenId() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldStartFromGivenId()
        {
            // given
            GBPTree <LabelScanKey, LabelScanValue> index = mock(typeof(GBPTree));
            RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> cursor = mock(typeof(RawCursor));

            when(cursor.Next()).thenReturn(true, true, false);
            when(cursor.get()).thenReturn(Hit(1, 0b0001_1000__0101_1110L), Hit(3, 0b0010_0000__1010_0001L), null);
            when(index.Seek(any(typeof(LabelScanKey)), any(typeof(LabelScanKey)))).thenReturn(cursor);

            // when
            long fromId = LabelScanValue.RangeSize + 3;

            using (NativeLabelScanReader reader = new NativeLabelScanReader(index), PrimitiveLongResourceIterator iterator = reader.NodesWithAnyOfLabels(fromId, LABEL_ID))
            {
                // then
                assertArrayEquals(new long[] { 64 + 4, 64 + 6, 64 + 11, 64 + 12, 192 + 0, 192 + 5, 192 + 7, 192 + 13 }, asArray(iterator));
            }
        }
Exemplo n.º 20
0
        private IList <PrimitiveLongResourceIterator> IteratorsForLabels(long fromId, int[] labelIds)
        {
            IList <PrimitiveLongResourceIterator> iterators = new List <PrimitiveLongResourceIterator>();

            try
            {
                foreach (int labelId in labelIds)
                {
                    RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> cursor = SeekerForLabel(fromId, labelId);
                    _openCursors.Add(cursor);
                    iterators.Add(new LabelScanValueIterator(cursor, _openCursors, fromId));
                }
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
            return(iterators);
        }
Exemplo n.º 21
0
        public override void DistinctValues(Org.Neo4j.Storageengine.Api.schema.IndexProgressor_NodeValueClient client, NodePropertyAccessor propertyAccessor, bool needsValues)
        {
            KEY lowest = Layout.newKey();

            lowest.initialize(long.MinValue);
            lowest.initValuesAsLowest();
            KEY highest = Layout.newKey();

            highest.initialize(long.MaxValue);
            highest.initValuesAsHighest();
            try
            {
                RawCursor <Hit <KEY, VALUE>, IOException> seeker = Tree.seek(lowest, highest);
                client.Initialize(Descriptor, new NativeDistinctValuesProgressor <>(seeker, client, OpenSeekers, Layout, Layout.compareValue), new IndexQuery[0], IndexOrder.NONE, needsValues);
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
Exemplo n.º 22
0
        public override IEnumerator <long> Iterator()
        {
            KEY from = _layout.newKey();

            from.initialize(long.MinValue);
            from.initValuesAsLowest();
            KEY to = _layout.newKey();

            to.initialize(long.MaxValue);
            to.initValuesAsHighest();
            try
            {
                CloseSeeker();
                _seeker = _tree.seek(from, to);
                return(new PrefetchingIteratorAnonymousInnerClass(this));
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
Exemplo n.º 23
0
        internal override void StartSeekForInitializedRange(Org.Neo4j.Storageengine.Api.schema.IndexProgressor_NodeValueClient client, SpatialIndexKey treeKeyFrom, SpatialIndexKey treeKeyTo, IndexQuery[] query, IndexOrder indexOrder, bool needFilter, bool needsValues)
        {
            // Spatial does not support providing values
            Debug.Assert(!needsValues);

            if (layout.compare(treeKeyFrom, treeKeyTo) > 0)
            {
                client.Initialize(descriptor, IndexProgressor.EMPTY, query, IndexOrder.NONE, false);
                return;
            }
            try
            {
                RawCursor <Hit <SpatialIndexKey, VALUE>, IOException> seeker = makeIndexSeeker(treeKeyFrom, treeKeyTo, indexOrder);
                IndexProgressor hitProgressor = new NativeHitIndexProgressor <>(seeker, client, openSeekers);
                client.Initialize(descriptor, hitProgressor, query, IndexOrder.NONE, false);
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
Exemplo n.º 24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecoverFromCrashBeforeFirstCheckpoint() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRecoverFromCrashBeforeFirstCheckpoint()
        {
            // GIVEN
            // a tree with only small amount of data that has not yet seen checkpoint from outside
            KEY   key   = key(1L);
            VALUE value = value(10L);
            File  file  = _directory.file("index");

            {
                using (PageCache pageCache = CreatePageCache(), GBPTree <KEY, VALUE> index = CreateIndex(pageCache, file), Writer <KEY, VALUE> writer = index.Writer())
                {
                    writer.Put(key, value);
                    pageCache.FlushAndForce();
                    // No checkpoint
                }
            }

            // WHEN
            using (PageCache pageCache = CreatePageCache(), GBPTree <KEY, VALUE> index = CreateIndex(pageCache, file))
            {
                using (Writer <KEY, VALUE> writer = index.Writer())
                {
                    writer.Put(key, value);
                }

                // THEN
                // we should end up with a consistent index
                index.ConsistencyCheck();

                // ... containing all the stuff load says
                using (RawCursor <Hit <KEY, VALUE>, IOException> cursor = index.Seek(key(long.MinValue), key(long.MaxValue)))
                {
                    assertTrue(cursor.Next());
                    Hit <KEY, VALUE> hit = cursor.get();
                    AssertEqualsKey(key, hit.Key());
                    AssertEqualsValue(value, hit.Value());
                }
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCloseExhaustedCursors() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCloseExhaustedCursors()
        {
            // GIVEN
            RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> cursor = mock(typeof(RawCursor));

            when(cursor.Next()).thenReturn(false);
            ICollection <RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> > toRemoveFrom = new HashSet <RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> >();
            LabelScanValueIndexProgressor iterator = new LabelScanValueIndexProgressor(cursor, toRemoveFrom, mock(typeof(Org.Neo4j.Storageengine.Api.schema.IndexProgressor_NodeLabelClient)));

            verify(cursor, never()).close();

            // WHEN
            Exhaust(iterator);
            verify(cursor, times(1)).close();

            // retrying to get more items from the first one should not close it again
            iterator.Next();
            verify(cursor, times(1)).close();

            // and set should be empty
            assertTrue(toRemoveFrom.Count == 0);
        }
        public override IEnumerator <NodeLabelRange> Iterator()
        {
            try
            {
                long lowestRange = long.MaxValue;
                CloseCursors();
                for (int labelId = 0; labelId <= _highestLabelId; labelId++)
                {
                    RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> cursor = _seekProvider.apply(labelId);

                    // Bootstrap the cursor, which also provides a great opportunity to exclude if empty
                    if (cursor.Next())
                    {
                        lowestRange = min(lowestRange, cursor.get().key().idRange);
                        _cursors.Add(cursor);
                    }
                }
                return(new NodeLabelRangeIterator(this, lowestRange));
            }
            catch (IOException e)
            {
                throw new Exception(e);
            }
        }
Exemplo n.º 27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSupportMultipleOpenCursorsConcurrently() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSupportMultipleOpenCursorsConcurrently()
        {
            // GIVEN
            GBPTree <LabelScanKey, LabelScanValue> index = mock(typeof(GBPTree));
            RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> cursor1 = mock(typeof(RawCursor));

            when(cursor1.Next()).thenReturn(false);
            RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> cursor2 = mock(typeof(RawCursor));

            when(cursor2.Next()).thenReturn(false);
            when(index.Seek(any(typeof(LabelScanKey)), any(typeof(LabelScanKey)))).thenReturn(cursor1, cursor2);

            // WHEN
            using (NativeLabelScanReader reader = new NativeLabelScanReader(index))
            {
                // first check test invariants
                verify(cursor1, never()).close();
                verify(cursor2, never()).close();
                LongIterator first  = reader.NodesWithLabel(LABEL_ID);
                LongIterator second = reader.NodesWithLabel(LABEL_ID);

                // getting the second iterator should not have closed the first one
                verify(cursor1, never()).close();
                verify(cursor2, never()).close();

                // exhausting the first one should have closed only the first one
                Exhaust(first);
                verify(cursor1, times(1)).close();
                verify(cursor2, never()).close();

                // exhausting the second one should close it
                Exhaust(second);
                verify(cursor1, times(1)).close();
                verify(cursor2, times(1)).close();
            }
        }
Exemplo n.º 28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldStreamResources() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldStreamResources()
        {
            // given
            StoreFileStreamingProtocol protocol = new StoreFileStreamingProtocol();
            ChannelHandlerContext      ctx      = mock(typeof(ChannelHandlerContext));

            Fs.mkdir(new File("dirA"));
            Fs.mkdir(new File("dirB"));

            string[] files = new string[] { "dirA/one", "dirA/two", "dirB/one", "dirB/two", "one", "two", "three" };

            IList <StoreResource> resourceList = new List <StoreResource>();

            foreach (string file in files)
            {
                resourceList.Add(CreateResource(new File(file), ThreadLocalRandom.current().Next(1, 4096)));
            }
            RawCursor <StoreResource, IOException> resources = rawCursorOf(resourceList);

            // when
            while (resources.Next())
            {
                protocol.Stream(ctx, resources.get());
            }

            // then
            InOrder inOrder = Mockito.inOrder(ctx);

            foreach (StoreResource resource in resourceList)
            {
                inOrder.verify(ctx).write(ResponseMessageType.FILE);
                inOrder.verify(ctx).write(new FileHeader(resource.Path(), resource.RecordSize()));
                inOrder.verify(ctx).write(new FileSender(resource));
            }
            verifyNoMoreInteractions(ctx);
        }
Exemplo n.º 29
0
        public override void DistinctValues(Org.Neo4j.Storageengine.Api.schema.IndexProgressor_NodeValueClient client, NodePropertyAccessor propertyAccessor, bool needsValues)
        {
            // This is basically a version of the basic implementation, but with added consulting of the PropertyAccessor
            // since these are lossy spatial values.
            SpatialIndexKey lowest = layout.newKey();

            lowest.initialize(long.MinValue);
            lowest.initValuesAsLowest();
            SpatialIndexKey highest = layout.newKey();

            highest.initialize(long.MaxValue);
            highest.initValuesAsHighest();
            try
            {
                RawCursor <Hit <SpatialIndexKey, VALUE>, IOException> seeker = tree.seek(lowest, highest);
                IComparer <SpatialIndexKey> comparator = new PropertyLookupFallbackComparator <SpatialIndexKey>(layout, propertyAccessor, descriptor.schema().PropertyId);
                NativeDistinctValuesProgressor <SpatialIndexKey, VALUE> progressor = new NativeDistinctValuesProgressorAnonymousInnerClass(this, seeker, client, openSeekers, layout, comparator, propertyAccessor);
                client.Initialize(descriptor, progressor, new IndexQuery[0], IndexOrder.NONE, false);
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
Exemplo n.º 30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeSimpleInsertions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeSimpleInsertions()
        {
            using (GBPTree <KEY, VALUE> index = index())
            {
                int count = 1000;
                using (Writer <KEY, VALUE> writer = index.Writer())
                {
                    for (int i = 0; i < count; i++)
                    {
                        writer.Put(Key(i), Value(i));
                    }
                }

                using (RawCursor <Hit <KEY, VALUE>, IOException> cursor = index.Seek(Key(0), Key(long.MaxValue)))
                {
                    for (int i = 0; i < count; i++)
                    {
                        assertTrue(cursor.Next());
                        AssertEqualsKey(Key(i), cursor.get().key());
                    }
                    assertFalse(cursor.Next());
                }
            }
        }