private NodeCommand Node(long nodeId)
        {
            NodeRecord after = new NodeRecord(nodeId, true, false, NO_NEXT_RELATIONSHIP.intValue(), NO_NEXT_PROPERTY.intValue(), 0);

            NodeLabelsField.parseLabelsField(after).add(1, null, null);

            return(new NodeCommand(new NodeRecord(nodeId), after));
        }
Example #2
0
 internal void UpdateCounts(NodeRecord node, int delta)
 {
     Writer.incrementNodeCount(StatementConstants.ANY_LABEL, delta);
     foreach (long label in NodeLabelsField.parseLabelsField(node).get(Nodes))
     {
         Writer.incrementNodeCount(( int )label, delta);
     }
 }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldInlineOneLabelWithHighId()
        public virtual void ShouldInlineOneLabelWithHighId()
        {
            // GIVEN
            long       labelId    = 10000;
            NodeRecord node       = NodeRecordWithInlinedLabels();
            NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);

            // WHEN
            nodeLabels.Add(labelId, null, null);

            // THEN
            assertEquals(InlinedLabelsLongRepresentation(labelId), node.LabelField);
        }
Example #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void maximumOfSevenInlinedLabels()
        public virtual void MaximumOfSevenInlinedLabels()
        {
            // GIVEN
            long[]     labels     = new long[] { 0, 1, 2, 3, 4, 5, 6 };
            NodeRecord node       = NodeRecordWithInlinedLabels(labels);
            NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);

            // WHEN
            IEnumerable <DynamicRecord> changedDynamicRecords = nodeLabels.Add(23, _nodeStore, _nodeStore.DynamicLabelStore);

            // THEN
            assertEquals(DynamicLabelsLongRepresentation(changedDynamicRecords), node.LabelField);
            assertEquals(1, Iterables.count(changedDynamicRecords));
        }
Example #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldInlineTwoSmallLabels()
        public virtual void ShouldInlineTwoSmallLabels()
        {
            // GIVEN
            long       labelId1   = 10;
            long       labelId2   = 30;
            NodeRecord node       = NodeRecordWithInlinedLabels(labelId1);
            NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);

            // WHEN
            nodeLabels.Add(labelId2, null, null);

            // THEN
            assertEquals(InlinedLabelsLongRepresentation(labelId1, labelId2), node.LabelField);
        }
Example #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReallocateAllOfPreviousDynamicRecordsAndThenSome()
        public virtual void ShouldReallocateAllOfPreviousDynamicRecordsAndThenSome()
        {
            // GIVEN
            NodeRecord           node           = nodeRecordWithDynamicLabels(_nodeStore, FourByteLongs(100));
            ISet <DynamicRecord> initialRecords = Iterables.asSet(Cloned(node.DynamicLabelRecords, typeof(DynamicRecord)));
            NodeLabels           nodeLabels     = NodeLabelsField.parseLabelsField(node);

            // WHEN
            ISet <DynamicRecord> reallocatedRecords = Iterables.asUniqueSet(nodeLabels.Put(FourByteLongs(5), _nodeStore, _nodeStore.DynamicLabelStore));

            // THEN
//JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'containsAll' method:
            assertTrue("initial:" + initialRecords + ", reallocated:" + reallocatedRecords, initialRecords.containsAll(Used(reallocatedRecords)));
            assertTrue(Used(reallocatedRecords).Count < initialRecords.Count);
        }
Example #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReallocateSomeOfPreviousDynamicRecords()
        public virtual void ShouldReallocateSomeOfPreviousDynamicRecords()
        {
            // GIVEN
            NodeRecord           node           = nodeRecordWithDynamicLabels(_nodeStore, OneByteLongs(5));
            ISet <DynamicRecord> initialRecords = Iterables.asUniqueSet(node.DynamicLabelRecords);
            NodeLabels           nodeLabels     = NodeLabelsField.parseLabelsField(node);

            // WHEN
            ISet <DynamicRecord> reallocatedRecords = Iterables.asUniqueSet(nodeLabels.Put(FourByteLongs(100), _nodeStore, _nodeStore.DynamicLabelStore));

            // THEN
//JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'containsAll' method:
            assertTrue(reallocatedRecords.containsAll(initialRecords));
            assertTrue(reallocatedRecords.Count > initialRecords.Count);
        }
Example #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void oneDynamicRecordShouldShrinkIntoInlinedWhenRemoving()
        public virtual void OneDynamicRecordShouldShrinkIntoInlinedWhenRemoving()
        {
            // GIVEN
            NodeRecord node = nodeRecordWithDynamicLabels(_nodeStore, OneByteLongs(5));
            ICollection <DynamicRecord> initialRecords = node.DynamicLabelRecords;
            NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);

            // WHEN
            ICollection <DynamicRecord> changedDynamicRecords = Iterables.asCollection(nodeLabels.Remove(255, _nodeStore));

            // THEN
            assertEquals(initialRecords, changedDynamicRecords);
            assertFalse(Iterables.single(changedDynamicRecords).inUse());
            assertEquals(InlinedLabelsLongRepresentation(251, 252, 253, 254), node.LabelField);
        }
Example #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void twoDynamicRecordsShouldShrinkToOneWhenRemovingWithoutChangingItsOwner()
        public virtual void TwoDynamicRecordsShouldShrinkToOneWhenRemovingWithoutChangingItsOwner()
        {
            // GIVEN
            // will occupy 61B of data, i.e. just two dynamic records
            long?      nodeId     = 42L;
            NodeRecord node       = nodeRecordWithDynamicLabels(nodeId, _nodeStore, OneByteLongs(57));
            NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);

            IList <DynamicRecord> changedDynamicRecords = Iterables.addToCollection(nodeLabels.Remove(255, _nodeStore), new List <DynamicRecord>());

            // WHEN
            Pair <long, long[]> changedPair = DynamicNodeLabels.getDynamicLabelsArrayAndOwner(changedDynamicRecords, _nodeStore.DynamicLabelStore);

            // THEN
            assertEquals(nodeId, changedPair.First());
        }
Example #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void twoDynamicRecordsShouldShrinkToOneWhenRemoving()
        public virtual void TwoDynamicRecordsShouldShrinkToOneWhenRemoving()
        {
            // GIVEN
            // will occupy 61B of data, i.e. just two dynamic records
            NodeRecord node = nodeRecordWithDynamicLabels(_nodeStore, OneByteLongs(57));
            ICollection <DynamicRecord> initialRecords = node.DynamicLabelRecords;
            NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);

            // WHEN
            IList <DynamicRecord> changedDynamicRecords = Iterables.addToCollection(nodeLabels.Remove(255, _nodeStore), new List <DynamicRecord>());

            // THEN
            assertEquals(initialRecords, changedDynamicRecords);
            assertTrue(changedDynamicRecords[0].InUse());
            assertFalse(changedDynamicRecords[1].InUse());
        }
Example #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void oneDynamicRecordShouldExtendIntoAnAdditionalIfTooManyLabels()
        public virtual void OneDynamicRecordShouldExtendIntoAnAdditionalIfTooManyLabels()
        {
            // GIVEN
            // will occupy 60B of data, i.e. one dynamic record
            NodeRecord node = nodeRecordWithDynamicLabels(_nodeStore, OneByteLongs(56));
            ICollection <DynamicRecord> initialRecords = node.DynamicLabelRecords;
            NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);

            // WHEN
            ISet <DynamicRecord> changedDynamicRecords = Iterables.asSet(nodeLabels.Add(1, _nodeStore, _nodeStore.DynamicLabelStore));

            // THEN
//JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'containsAll' method:
            assertTrue(changedDynamicRecords.containsAll(initialRecords));
            assertEquals(initialRecords.Count + 1, changedDynamicRecords.Count);
        }
Example #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSpillOverToDynamicRecordIfExceedsInlinedSpace()
        public virtual void ShouldSpillOverToDynamicRecordIfExceedsInlinedSpace()
        {
            // GIVEN -- the upper limit for a label ID for 3 labels would be 36b/3 - 1 = 12b - 1 = 4095
            long       labelId1   = 10;
            long       labelId2   = 30;
            long       labelId3   = 4096;
            NodeRecord node       = NodeRecordWithInlinedLabels(labelId1, labelId2);
            NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);

            // WHEN
            ICollection <DynamicRecord> changedDynamicRecords = nodeLabels.Add(labelId3, _nodeStore, _nodeStore.DynamicLabelStore);

            // THEN
            assertEquals(1, Iterables.count(changedDynamicRecords));
            assertEquals(DynamicLabelsLongRepresentation(changedDynamicRecords), node.LabelField);
            assertTrue(Arrays.Equals(new long[] { labelId1, labelId2, labelId3 }, DynamicNodeLabels.getDynamicLabelsArray(changedDynamicRecords, _nodeStore.DynamicLabelStore)));
        }
Example #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void removingNonExistentLabelInDynamicRecordsShouldFail()
        public virtual void RemovingNonExistentLabelInDynamicRecordsShouldFail()
        {
            // GIVEN
            long[]     labels     = OneByteLongs(20);
            NodeRecord node       = nodeRecordWithDynamicLabels(_nodeStore, labels);
            NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);

            // WHEN
            try
            {
                nodeLabels.Remove(123456, _nodeStore);
                fail("Should have thrown exception");
            }
            catch (System.InvalidOperationException)
            {
                // THEN
            }
        }
Example #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void addingAnAlreadyAddedLabelWhenLabelsAreInDynamicRecordsShouldFail()
        public virtual void AddingAnAlreadyAddedLabelWhenLabelsAreInDynamicRecordsShouldFail()
        {
            // GIVEN
            long[]     labels     = OneByteLongs(20);
            NodeRecord node       = nodeRecordWithDynamicLabels(_nodeStore, labels);
            NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);

            // WHEN
            try
            {
                nodeLabels.Add(safeCastLongToInt(labels[0]), _nodeStore, _nodeStore.DynamicLabelStore);
                fail("Should have thrown exception");
            }
            catch (System.InvalidOperationException)
            {
                // THEN
            }
        }
Example #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void addingAnAlreadyAddedLabelWhenLabelsAreInlinedShouldFail()
        public virtual void AddingAnAlreadyAddedLabelWhenLabelsAreInlinedShouldFail()
        {
            // GIVEN
            int        labelId    = 1;
            NodeRecord node       = NodeRecordWithInlinedLabels(labelId);
            NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);

            // WHEN
            try
            {
                nodeLabels.Add(labelId, _nodeStore, _nodeStore.DynamicLabelStore);
                fail("Should have thrown exception");
            }
            catch (System.InvalidOperationException)
            {
                // THEN
            }
        }
Example #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void removingNonExistentInlinedLabelShouldFail()
        public virtual void RemovingNonExistentInlinedLabelShouldFail()
        {
            // GIVEN
            int        labelId1   = 1;
            int        labelId2   = 2;
            NodeRecord node       = NodeRecordWithInlinedLabels(labelId1);
            NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);

            // WHEN
            try
            {
                nodeLabels.Remove(labelId2, _nodeStore);
                fail("Should have thrown exception");
            }
            catch (System.InvalidOperationException)
            {
                // THEN
            }
        }
Example #17
0
        private Ids CreateNode(DataImporter.Monitor monitor, NeoStores neoStores, int propertyCount, int labelCount)
        {
            PropertyStore propertyStore = neoStores.PropertyStore;
            RecordAccess <PropertyRecord, PrimitiveRecord> propertyRecordAccess = new DirectRecordAccess <PropertyRecord, PrimitiveRecord>(propertyStore, (new Loaders(neoStores)).propertyLoader());
            NodeStore  nodeStore  = neoStores.NodeStore;
            NodeRecord nodeRecord = nodeStore.NewRecord();

            nodeRecord.Id    = nodeStore.NextId();
            nodeRecord.InUse = true;
            NodeLabelsField.parseLabelsField(nodeRecord).put(LabelIds(labelCount), nodeStore, nodeStore.DynamicLabelStore);
            long nextProp = (new PropertyCreator(propertyStore, new PropertyTraverser())).createPropertyChain(nodeRecord, Properties(propertyStore, propertyCount), propertyRecordAccess);

            nodeRecord.NextProp = nextProp;
            nodeStore.UpdateRecord(nodeRecord);
            PropertyRecord[] propertyRecords = ExtractPropertyRecords(propertyRecordAccess, nextProp);
            propertyRecordAccess.Close();
            monitor.NodesImported(1);
            monitor.PropertiesImported(propertyCount);
            return(new Ids(nodeRecord, propertyRecords));
        }
Example #18
0
        /*
         * There was this issue that DynamicNodeLabels#add would consider even unused dynamic records when
         * reading existing label ids before making the change. Previously this would create a duplicate
         * last label id (the one formerly being in the second record).
         *
         * This randomized test found this issue every time when it existed and it will potentially find other
         * unforeseen issues as well.
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleRandomAddsAndRemoves()
        public virtual void ShouldHandleRandomAddsAndRemoves()
        {
            // GIVEN
            ISet <int> key  = new HashSet <int>();
            NodeRecord node = new NodeRecord(0);

            node.InUse = true;

            // WHEN
            for (int i = 0; i < 100_000; i++)
            {
                NodeLabels labels  = NodeLabelsField.parseLabelsField(node);
                int        labelId = Random.Next(200);
                if (Random.nextBoolean())
                {
                    if (!key.Contains(labelId))
                    {
                        labels.Add(labelId, _nodeStore, _nodeStore.DynamicLabelStore);
                        key.Add(labelId);
                    }
                }
                else
                {
                    if (key.remove(labelId))
                    {
                        labels.Remove(labelId, _nodeStore);
                    }
                }
            }

            // THEN
            NodeLabels labels = NodeLabelsField.parseLabelsField(node);

            long[] readLabelIds = labels.Get(_nodeStore);
            foreach (long labelId in readLabelIds)
            {
                assertTrue("Found an unexpected label " + labelId, key.remove(( int )labelId));
            }
            assertTrue(key.Count == 0);
        }