Example #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void execute(java.util.List<Action> load, GBPTree<KEY,VALUE> index) throws java.io.IOException
        private void Execute(IList <Action> load, GBPTree <KEY, VALUE> index)
        {
            foreach (Action action in load)
            {
                action.Execute(index);
            }
        }
Example #2
0
 internal NativeIndexReader(GBPTree <KEY, VALUE> tree, IndexLayout <KEY, VALUE> layout, IndexDescriptor descriptor)
 {
     this.Tree        = tree;
     this.Layout      = layout;
     this.Descriptor  = descriptor;
     this.OpenSeekers = new HashSet <RawCursor <Hit <KEY, VALUE>, IOException> >();
 }
Example #3
0
 internal virtual void InstantiateTree(RecoveryCleanupWorkCollector recoveryCleanupWorkCollector, System.Action <PageCursor> headerWriter)
 {
     EnsureDirectoryExist();
     GBPTree.Monitor monitor = TreeMonitor();
     Tree = new GBPTree <KEY, VALUE>(PageCache, StoreFile, Layout, 0, monitor, NO_HEADER_READER, headerWriter, recoveryCleanupWorkCollector, _readOnly);
     AfterTreeInstantiation(Tree);
 }
Example #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void verifyUpdates(org.neo4j.kernel.api.index.IndexEntryUpdate<org.neo4j.storageengine.api.schema.IndexDescriptor>[] updates) throws java.io.IOException
        internal virtual void VerifyUpdates(IndexEntryUpdate <IndexDescriptor>[] updates)
        {
            Hit <KEY, VALUE>[]        expectedHits = ConvertToHits(updates, Layout);
            IList <Hit <KEY, VALUE> > actualHits   = new List <Hit <KEY, VALUE> >();

            using (GBPTree <KEY, VALUE> tree = Tree, RawCursor <Hit <KEY, VALUE>, IOException> scan = scan(tree))
            {
                while (scan.Next())
                {
                    actualHits.Add(DeepCopy(scan.get()));
                }
            }

            IComparer <Hit <KEY, VALUE> > hitComparator = (h1, h2) =>
            {
                int keyCompare = Layout.compare(h1.key(), h2.key());
                if (keyCompare == 0)
                {
                    return(ValueCreatorUtil.compareIndexedPropertyValue(h1.key(), h2.key()));
                }
                else
                {
                    return(keyCompare);
                }
            };

            AssertSameHits(expectedHits, actualHits.ToArray(), hitComparator);
        }
Example #5
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();
        }
Example #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void randomlyModifyIndex(GBPTree<KEY,VALUE> index, java.util.Map<KEY,VALUE> data, java.util.Random random, double removeProbability) throws java.io.IOException
        private void RandomlyModifyIndex(GBPTree <KEY, VALUE> index, IDictionary <KEY, VALUE> data, Random random, double removeProbability)
        {
            int changeCount = random.Next(10) + 10;

            using (Writer <KEY, VALUE> writer = CreateWriter(index))
            {
                for (int i = 0; i < changeCount; i++)
                {
                    if (random.NextDouble() < removeProbability && data.Count > 0)
                    {                              // remove
                        KEY   key          = RandomKey(data, random);
                        VALUE value        = data.Remove(key);
                        VALUE removedValue = writer.Remove(key);
                        AssertEqualsValue(value, removedValue);
                    }
                    else
                    {                              // put
                        KEY   key   = RandomKey(random);
                        VALUE value = RandomValue(random);
                        writer.Put(key, value);
                        data[key] = value;
                    }
                }
            }
        }
Example #7
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);
            }
        }
Example #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static String readFailureMessage(org.neo4j.io.pagecache.PageCache pageCache, java.io.File indexFile) throws java.io.IOException
        internal static string ReadFailureMessage(PageCache pageCache, File indexFile)
        {
            NativeIndexHeaderReader headerReader = new NativeIndexHeaderReader(NO_HEADER_READER);

            GBPTree.readHeader(pageCache, indexFile, headerReader);
            return(headerReader.FailureMessage);
        }
Example #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private GBPTree<KEY,VALUE> createIndex() throws java.io.IOException
        private GBPTree <KEY, VALUE> CreateIndex()
        {
            // some random padding
            _layout = GetLayout(Random);
            PageCache pageCache = _pageCacheRule.getPageCache(_fs.get(), config().withPageSize(512).withAccessChecks(true));

            return(_index = (new GBPTreeBuilder <KEY, VALUE>(pageCache, _directory.file("index"), _layout)).build());
        }
Example #10
0
        /// <summary>
        /// Shuts down this store so that no more queries or updates can be accepted.
        /// </summary>
        /// <exception cref="IOException"> on <seealso cref="PageCache"/> exceptions. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void shutdown() throws java.io.IOException
        public override void Shutdown()
        {
            if (_index != null)
            {
                _index.Dispose();
                _index = null;
                _writeMonitor.close();
            }
        }
Example #11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void dropStrict() throws java.io.IOException
        private void DropStrict()
        {
            if (_index != null)
            {
                _index.Dispose();
                _index = null;
            }
            _fileSystem.deleteFileOrThrow(_storeFile);
        }
Example #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void setupIndex() throws java.io.IOException
        private void SetupIndex()
        {
            RecoveryCleanupWorkCollector recoveryCleanupWorkCollector = RecoveryCleanupWorkCollector.Immediate();
            bool readOnly = true;

            // tree = new GBPTree<>( pageCache, indexFile, layout, pageSize, NO_MONITOR, NO_HEADER_READER, NO_HEADER_WRITER,
            //         RecoveryCleanupWorkCollector.immediate() );
            _tree = new GBPTree <MutableLong, MutableLong>(_pageCache, _indexFile, _layout, _pageSize, NO_MONITOR, NO_HEADER_READER, NO_HEADER_WRITER, recoveryCleanupWorkCollector, readOnly);
        }
Example #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static SpaceFillingCurveSettings fromGBPTree(java.io.File indexFile, org.neo4j.io.pagecache.PageCache pageCache, System.Func<ByteBuffer,String> onError) throws java.io.IOException
        public static SpaceFillingCurveSettings FromGBPTree(File indexFile, PageCache pageCache, System.Func <ByteBuffer, string> onError)
        {
            SpaceFillingCurveSettings.SettingsFromIndexHeader settings = new SpaceFillingCurveSettings.SettingsFromIndexHeader();
            GBPTree.readHeader(pageCache, indexFile, settings.HeaderReader(onError));
            if (settings.Failed)
            {
                throw new IOException(settings.FailureMessage);
            }
            return(settings);
        }
Example #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void execute(GBPTree<KEY,VALUE> index) throws java.io.IOException
            public override void Execute(GBPTree <KEY, VALUE> index)
            {
                using (Writer <KEY, VALUE> writer = index.Writer())
                {
                    for (int i = 0; i < DataConflict.Length;)
                    {
                        writer.Put(outerInstance.key(DataConflict[i++]), outerInstance.value(DataConflict[i++]));
                    }
                }
            }
Example #15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void execute(GBPTree<KEY,VALUE> index) throws java.io.IOException
            public override void Execute(GBPTree <KEY, VALUE> index)
            {
                using (Writer <KEY, VALUE> writer = index.Writer())
                {
                    for (int i = 0; i < DataConflict.Length;)
                    {
                        KEY key = key(DataConflict[i++]);
                        i++;                                   // value
                        writer.Remove(key);
                    }
                }
            }
Example #16
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.cursor.RawCursor<org.neo4j.index.internal.gbptree.Hit<KEY,VALUE>, java.io.IOException> scan(org.neo4j.index.internal.gbptree.GBPTree<KEY,VALUE> tree) throws java.io.IOException
        private RawCursor <Hit <KEY, VALUE>, IOException> Scan(GBPTree <KEY, VALUE> tree)
        {
            KEY lowest = Layout.newKey();

            lowest.initialize(long.MinValue);
            lowest.initValueAsLowest(0, ValueGroup.UNKNOWN);
            KEY highest = Layout.newKey();

            highest.initialize(long.MaxValue);
            highest.initValueAsHighest(0, ValueGroup.UNKNOWN);
            return(tree.Seek(lowest, highest));
        }
Example #17
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();
            }
        }
Example #18
0
		 /// <summary>
		 /// Throws <seealso cref="FormatViolationException"/> if format has changed.
		 /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("EmptyTryBlock") @Override protected void verifyFormat(java.io.File storeFile) throws java.io.IOException, FormatViolationException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
		 protected internal override void VerifyFormat( File storeFile )
		 {
			  PageCache pageCache = _pageCacheRule.getPageCache( GlobalFs.get() );
			  try
			  {
					  using ( GBPTree<MutableLong, MutableLong> ignored = ( new GBPTreeBuilder<MutableLong, MutableLong>( pageCache, storeFile, Layout ) ).build() )
					  {
					  }
			  }
			  catch ( MetadataMismatchException e )
			  {
					throw new FormatViolationException( this, e );
			  }
		 }
Example #19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustStayCorrectWhenInsertingValuesOfIncreasingLength() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MustStayCorrectWhenInsertingValuesOfIncreasingLength()
        {
            Layout <RawBytes, RawBytes> layout = layout();

            using (GBPTree <RawBytes, RawBytes> index = CreateIndex(layout), Writer <RawBytes, RawBytes> writer = index.Writer())
            {
                RawBytes emptyValue = layout.NewValue();
                emptyValue.Bytes = new sbyte[0];
                for (int keySize = 1; keySize < index.KeyValueSizeCap(); keySize++)
                {
                    RawBytes key = layout.NewKey();
                    key.Bytes = new sbyte[keySize];
                    writer.Put(key, emptyValue);
                }
            }
        }
Example #20
0
 private static LayoutBootstrapper GenericLayout()
 {
     return((indexFile, pageCache, meta, targetLayout) =>
     {
         if (targetLayout.contains("generic"))
         {
             string numberOfSlotsString = targetLayout.replace("generic", "");
             int numberOfSlots = int.Parse(numberOfSlotsString);
             IDictionary <CoordinateReferenceSystem, SpaceFillingCurveSettings> settings = new Dictionary <CoordinateReferenceSystem, SpaceFillingCurveSettings>();
             GBPTree.readHeader(pageCache, indexFile, new NativeIndexHeaderReader(new SpaceFillingCurveSettingsReader(settings)));
             ConfiguredSpaceFillingCurveSettingsCache configuredSettings = new ConfiguredSpaceFillingCurveSettingsCache(Config.defaults());
             return new GenericLayout(numberOfSlots, new IndexSpecificSpaceFillingCurveSettingsCache(configuredSettings, settings));
         }
         return null;
     });
 }
Example #21
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void createStoreFile(java.io.File storeFile) throws java.io.IOException
		 protected internal override void CreateStoreFile( File storeFile )
		 {
			  IList<long> initialKeys = initialKeys();
			  PageCache pageCache = _pageCacheRule.getPageCache( GlobalFs.get() );
			  using ( GBPTree<MutableLong, MutableLong> tree = ( new GBPTreeBuilder<MutableLong, MutableLong>( pageCache, storeFile, Layout ) ).build() )
			  {
					using ( Writer<MutableLong, MutableLong> writer = tree.Writer() )
					{
						 foreach ( long? key in initialKeys )
						 {
							  Put( writer, key.Value );
						 }
					}
					tree.Checkpoint( Org.Neo4j.Io.pagecache.IOLimiter_Fields.Unlimited );
			  }
		 }
Example #22
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void shouldReadCorrectlyWithConcurrentUpdates(TestCoordinator testCoordinator) throws Throwable
        private void ShouldReadCorrectlyWithConcurrentUpdates(TestCoordinator testCoordinator)
        {
            // Readers config
            int readers = max(1, Runtime.Runtime.availableProcessors() - 1);

            // Thread communication
            System.Threading.CountdownEvent readerReadySignal = new System.Threading.CountdownEvent(readers);
            System.Threading.CountdownEvent readerStartSignal = new System.Threading.CountdownEvent(1);
            AtomicBoolean endSignal = testCoordinator.EndSignal();
            AtomicBoolean failHalt  = new AtomicBoolean();              // Readers signal to writer that there is a failure
            AtomicReference <Exception> readerError = new AtomicReference <Exception>();

            // GIVEN
            _index = CreateIndex();
            testCoordinator.Prepare(_index);

            // WHEN starting the readers
            RunnableReader readerTask = new RunnableReader(this, testCoordinator, readerReadySignal, readerStartSignal, endSignal, failHalt, readerError);

            for (int i = 0; i < readers; i++)
            {
                _threadPool.submit(readerTask);
            }

            // and starting the checkpointer
            _threadPool.submit(CheckpointThread(endSignal, readerError, failHalt));

            // and starting the writer
            try
            {
                Write(testCoordinator, readerReadySignal, readerStartSignal, endSignal, failHalt);
            }
            finally
            {
                // THEN no reader should have failed by the time we have finished all the scheduled updates.
                // A successful read means that all results were ordered and we saw all inserted values and
                // none of the removed values at the point of making the seek call.
                endSignal.set(true);
                _threadPool.shutdown();
                _threadPool.awaitTermination(10, TimeUnit.SECONDS);
                if (readerError.get() != null)
                {
                    //noinspection ThrowFromFinallyBlock
                    throw readerError.get();
                }
            }
        }
Example #23
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);
                    }
                }
            }
        }
Example #24
0
        /// <returns> true if instantiated tree needs to be rebuilt. </returns>
        private bool InstantiateTree()
        {
            _monitors.addMonitorListener(TreeMonitor());
            GBPTree.Monitor monitor      = _monitors.newMonitor(typeof(GBPTree.Monitor));
            MutableBoolean  isRebuilding = new MutableBoolean();

            Header.Reader readRebuilding = headerData => isRebuilding.setValue(headerData.get() == _needsRebuilding);
            try
            {
                _index = new GBPTree <LabelScanKey, LabelScanValue>(_pageCache, _storeFile, new LabelScanLayout(), _pageSize, monitor, readRebuilding, _needsRebuildingWriter, _recoveryCleanupWorkCollector, _readOnly);
                return(isRebuilding.Value);
            }
            catch (TreeFileNotFoundException e)
            {
                throw new System.InvalidOperationException("Label scan store file could not be found, most likely this database needs to be recovered, file:" + _storeFile, e);
            }
        }
Example #25
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());
                    }
                }
            }
        }
Example #26
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));
            }
        }
Example #27
0
 internal override GenericLayout Layout(StoreIndexDescriptor descriptor, File storeFile)
 {
     try
     {
         int numberOfSlots = descriptor.Properties().Length;
         IDictionary <CoordinateReferenceSystem, SpaceFillingCurveSettings> settings = new Dictionary <CoordinateReferenceSystem, SpaceFillingCurveSettings>();
         if (storeFile != null && Fs.fileExists(storeFile))
         {
             // The index file exists and is sane so use it to read header information from.
             GBPTree.readHeader(PageCache, storeFile, new NativeIndexHeaderReader(new SpaceFillingCurveSettingsReader(settings)));
         }
         return(new GenericLayout(numberOfSlots, new IndexSpecificSpaceFillingCurveSettingsCache(_configuredSettings, settings)));
     }
     catch (IOException e)
     {
         throw new UncheckedIOException(e);
     }
 }
Example #28
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));
            }
        }
Example #29
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static org.neo4j.internal.kernel.api.InternalIndexState readState(org.neo4j.io.pagecache.PageCache pageCache, java.io.File indexFile) throws java.io.IOException
        public static InternalIndexState ReadState(PageCache pageCache, File indexFile)
        {
            NativeIndexHeaderReader headerReader = new NativeIndexHeaderReader(NO_HEADER_READER);

            GBPTree.readHeader(pageCache, indexFile, headerReader);
            switch (headerReader.State)
            {
            case BYTE_FAILED:
                return(InternalIndexState.FAILED);

            case BYTE_ONLINE:
                return(InternalIndexState.ONLINE);

            case BYTE_POPULATING:
                return(InternalIndexState.POPULATING);

            default:
                throw new System.InvalidOperationException("Unexpected initial state byte value " + headerReader.State);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIncludeAllValuesInTree() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldIncludeAllValuesInTree()
        {
            // GIVEN
            Value[] values = GenerateNumberValues();
            BuildTree(values);

            // WHEN
            IndexSample sample;

            using (GBPTree <NumberIndexKey, NativeIndexValue> gbpTree = Tree)
            {
                FullScanNonUniqueIndexSampler <NumberIndexKey, NativeIndexValue> sampler = new FullScanNonUniqueIndexSampler <NumberIndexKey, NativeIndexValue>(gbpTree, Layout);
                sample = sampler.Result();
            }

            // THEN
            assertEquals(values.Length, sample.SampleSize());
            assertEquals(countUniqueValues(values), sample.UniqueValues());
            assertEquals(values.Length, sample.IndexSize());
        }