//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. 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void randomModifications(long[] expected, int count) throws java.io.IOException
        private void RandomModifications(long[] expected, int count)
        {
            BitArray editedNodes = new BitArray();

            using (LabelScanWriter writer = _store.newWriter())
            {
                for (int i = 0; i < count; i++)
                {
                    int nodeId = _random.Next(NODE_COUNT);
                    if (editedNodes.Get(nodeId))
                    {
                        i--;
                        continue;
                    }

                    int    changeSize   = _random.Next(3) + 1;
                    long   labels       = expected[nodeId];
                    long[] labelsBefore = GetLabels(labels);
                    for (int j = 0; j < changeSize; j++)
                    {
                        labels = FlipRandom(labels, LABEL_COUNT, _random.random());
                    }
                    long[] labelsAfter = GetLabels(labels);
                    editedNodes.Set(nodeId, true);

                    NodeLabelUpdate labelChanges = labelChanges(nodeId, labelsBefore, labelsAfter);
                    writer.Write(labelChanges);
                    expected[nodeId] = labels;
                }
            }
        }
Esempio n. 3
0
            public override bool VisitNodeCommand(Command.NodeCommand command)
            {
                // for label store updates
                NodeRecord before = command.Before;
                NodeRecord after  = command.After;

                NodeLabels labelFieldBefore = parseLabelsField(before);
                NodeLabels labelFieldAfter  = parseLabelsField(after);

                if (!(labelFieldBefore.Inlined && labelFieldAfter.Inlined && before.LabelField == after.LabelField))
                {
                    long[] labelsBefore = labelFieldBefore.IfLoaded;
                    long[] labelsAfter  = labelFieldAfter.IfLoaded;
                    if (labelsBefore != null && labelsAfter != null)
                    {
                        if (outerInstance.labelUpdates == null)
                        {
                            outerInstance.labelUpdates = new List <NodeLabelUpdate>();
                        }
                        outerInstance.labelUpdates.Add(NodeLabelUpdate.labelChanges(command.Key, labelsBefore, labelsAfter, outerInstance.txId));
                    }
                }

                // for indexes
                return(IndexUpdatesExtractor.visitNodeCommand(command));
            }
//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 shouldFailOnUnsortedLabelsFromFullStoreChangeStream() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFailOnUnsortedLabelsFromFullStoreChangeStream()
        {
            // given
            PageCache pageCache = _pageCacheRule.getPageCache(_fileSystemRule.get());
            IList <NodeLabelUpdate> existingData = new List <NodeLabelUpdate>();

            existingData.Add(NodeLabelUpdate.labelChanges(1, new long[0], new long[] { 2, 1 }));
            FullStoreChangeStream changeStream         = asStream(existingData);
            NativeLabelScanStore  nativeLabelScanStore = null;

            try
            {
                nativeLabelScanStore = new NativeLabelScanStore(pageCache, _testDirectory.databaseLayout(), _fileSystemRule.get(), changeStream, false, new Monitors(), immediate());
                nativeLabelScanStore.Init();

                // when
                nativeLabelScanStore.Start();
                fail("Expected native label scan store to fail on ");
            }
            catch (System.ArgumentException e)
            {
                // then
                assertThat(e.Message, Matchers.containsString("unsorted label"));
                assertThat(e.Message, Matchers.stringContainsInOrder(Iterables.asIterable("2", "1")));
            }
            finally
            {
                if (nativeLabelScanStore != null)
                {
                    nativeLabelScanStore.Shutdown();
                }
            }
        }
Esempio n. 6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void prepareIndex() throws java.io.IOException
        private void PrepareIndex()
        {
            Start();
            using (LabelScanWriter labelScanWriter = _store.newWriter())
            {
                labelScanWriter.Write(NodeLabelUpdate.labelChanges(1, new long[] {}, new long[] { 1 }));
            }
            _store.shutdown();
        }
Esempio n. 7
0
        /// <summary>
        /// Queues a <seealso cref="NodeLabelUpdate"/> to this writer for applying when batch gets full,
        /// or when <seealso cref="close() closing"/>.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void write(org.neo4j.kernel.api.labelscan.NodeLabelUpdate update) throws java.io.IOException
        public override void Write(NodeLabelUpdate update)
        {
            if (_pendingUpdatesCursor == _pendingUpdates.Length)
            {
                FlushPendingChanges();
            }

            _pendingUpdates[_pendingUpdatesCursor++] = update;
            PhysicalToLogicalLabelChanges.ConvertToAdditionsAndRemovals(update);
            CheckNextLabelId(update.LabelsBefore);
            CheckNextLabelId(update.LabelsAfter);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void checkLabelScanStoreAccessible(org.neo4j.kernel.api.labelscan.LabelScanStore labelScanStore) throws java.io.IOException
        private static void CheckLabelScanStoreAccessible(LabelScanStore labelScanStore)
        {
            int labelId = 1;

            using (LabelScanWriter labelScanWriter = labelScanStore.NewWriter())
            {
                labelScanWriter.Write(NodeLabelUpdate.labelChanges(1, new long[] {}, new long[] { labelId }));
            }
            using (LabelScanReader labelScanReader = labelScanStore.NewReader())
            {
                assertEquals(1, labelScanReader.NodesWithLabel(labelId).next());
            }
        }
        private NodeLabelUpdate RandomUpdate(long[] expected)
        {
            int  nodeId = Random.Next(expected.Length);
            long labels = expected[nodeId];

            long[] before      = getLabels(labels);
            int    changeCount = Random.Next(4) + 1;

            for (int i = 0; i < changeCount; i++)
            {
                labels = flipRandom(labels, LABEL_COUNT, Random.random());
            }
            expected[nodeId] = labels;
            return(NodeLabelUpdate.labelChanges(nodeId, before, getLabels(labels)));
        }
Esempio n. 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldWorkWithAFullRange()
        public virtual void ShouldWorkWithAFullRange()
        {
            // given
            long labelId = 0;
            IList <NodeLabelUpdate> updates = new List <NodeLabelUpdate>();
            ISet <long>             nodes   = new HashSet <long>();

            for (int i = 0; i < 34; i++)
            {
                updates.Add(NodeLabelUpdate.labelChanges(i, new long[] {}, new long[] { labelId }));
                nodes.Add(( long )i);
            }

            Start(updates);

            // when
            LabelScanReader reader         = _store.newReader();
            ISet <long>     nodesWithLabel = PrimitiveLongCollections.toSet(reader.NodesWithLabel(( int )labelId));

            // then
            assertEquals(nodes, nodesWithLabel);
        }
Esempio n. 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeEntriesWhenOnlyLowestIsPresent()
        public virtual void ShouldSeeEntriesWhenOnlyLowestIsPresent()
        {
            // given
            long labelId = 0;
            IList <NodeLabelUpdate> labelUpdates = new List <NodeLabelUpdate>();

            labelUpdates.Add(NodeLabelUpdate.labelChanges(0L, new long[] {}, new long[] { labelId }));

            Start(labelUpdates);

            // when
            MutableInt count = new MutableInt();
            AllEntriesLabelScanReader nodeLabelRanges = _store.allNodeLabelRanges();

            nodeLabelRanges.forEach(nlr =>
            {
                foreach (long nodeId in nlr.nodes())
                {
                    count.add(nlr.labels(nodeId).length);
                }
            });
            assertThat(count.intValue(), @is(1));
        }
Esempio n. 12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void flushPendingChanges() throws java.io.IOException
        private void FlushPendingChanges()
        {
            Arrays.sort(_pendingUpdates, 0, _pendingUpdatesCursor, _updateSorter);
            _monitor.flushPendingUpdates();
            long currentLabelId = _lowestLabelId;

            _value.clear();
            _key.clear();
            while (currentLabelId != long.MaxValue)
            {
                long nextLabelId = long.MaxValue;
                for (int i = 0; i < _pendingUpdatesCursor; i++)
                {
                    NodeLabelUpdate update = _pendingUpdates[i];
                    long            nodeId = update.NodeId;
                    nextLabelId = ExtractChange(update.LabelsAfter, currentLabelId, nodeId, nextLabelId, true, update.TxId);
                    nextLabelId = ExtractChange(update.LabelsBefore, currentLabelId, nodeId, nextLabelId, false, update.TxId);
                }
                currentLabelId = nextLabelId;
            }
            FlushPendingRange();
            _pendingUpdatesCursor = 0;
        }
 public override void Write(NodeLabelUpdate update)
 {
     assertEquals(ExpectedNodeIds[Cursor], update.NodeId);
     Cursor++;
 }