//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAddLabels() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAddLabels()
        {
            // GIVEN
            ControlledInserter inserter = new ControlledInserter();

            long[] expected = new long[NODE_COUNT];
            using (NativeLabelScanWriter writer = new NativeLabelScanWriter(max(5, NODE_COUNT / 100), NativeLabelScanWriter.EMPTY))
            {
                writer.Initialize(inserter);

                // WHEN
                for (int i = 0; i < NODE_COUNT * 3; i++)
                {
                    NodeLabelUpdate update = RandomUpdate(expected);
                    writer.Write(update);
                }
            }

            // THEN
            for (int i = 0; i < LABEL_COUNT; i++)
            {
                long[] expectedNodeIds = nodesWithLabel(expected, i);
                long[] actualNodeIds   = asArray(new LabelScanValueIterator(inserter.NodesFor(i), new List <RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> >(), NO_ID));
                assertArrayEquals("For label " + i, expectedNodeIds, actualNodeIds);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAcceptUnsortedLabels() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAcceptUnsortedLabels()
        {
            // GIVEN
            ControlledInserter inserter = new ControlledInserter();
            bool failed = false;

            try
            {
                using (NativeLabelScanWriter writer = new NativeLabelScanWriter(1, NativeLabelScanWriter.EMPTY))
                {
                    writer.Initialize(inserter);

                    // WHEN
                    writer.Write(NodeLabelUpdate.labelChanges(0, EMPTY_LONG_ARRAY, new long[] { 2, 1 }));
                    // we can't do the usual "fail( blabla )" here since the actual write will happen
                    // when closing this writer, i.e. in the curly bracket below.
                }
            }
            catch (System.ArgumentException e)
            {
                // THEN
                assertTrue(e.Message.contains("unsorted"));
                failed = true;
            }

            assertTrue(failed);
        }
Esempio n. 3
0
        /// <summary>
        /// Instantiates the underlying <seealso cref="GBPTree"/> and its resources.
        /// </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 init() throws java.io.IOException
        public override void Init()
        {
            _monitor.init();

            bool storeExists = HasStore();
            bool isDirty;

            try
            {
                _needsRebuild = !storeExists;
                if (!storeExists)
                {
                    _monitor.noIndex();
                }

                isDirty = InstantiateTree();
            }
            catch (MetadataMismatchException)
            {
                // GBPTree is corrupt. Try to rebuild.
                isDirty = true;
            }

            _writeMonitor = LabelScanWriteMonitor.Enabled ? new LabelScanWriteMonitor(_fs, _directoryStructure) : NativeLabelScanWriter.EMPTY;
            _singleWriter = new NativeLabelScanWriter(1_000, _writeMonitor);

            if (isDirty)
            {
                _monitor.notValidIndex();
                if (!_readOnly)
                {
                    DropStrict();
                    InstantiateTree();
                }
                _needsRebuild = true;
            }
        }