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)); }
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); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReadNullDynamicRecordFromInlineLabelsField() public virtual void ShouldReadNullDynamicRecordFromInlineLabelsField() { // GIVEN NodeRecord node = NodeRecordWithInlinedLabels(23L); // WHEN bool isDynamicReference = NodeLabelsField.fieldPointsToDynamicRecordOfLabels(node.LabelField); // THEN assertFalse(isDynamicReference); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDedupLabelIds() public virtual void ShouldDedupLabelIds() { // GIVEN BatchingLabelTokenRepository repo = new BatchingLabelTokenRepository(mock(typeof(TokenStore))); // WHEN long[] ids = repo.GetOrCreateIds(new string[] { "One", "Two", "One" }); // THEN assertTrue(NodeLabelsField.isSane(ids)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReadIdOfDynamicRecordFromDynamicLabelsField() public virtual void ShouldReadIdOfDynamicRecordFromDynamicLabelsField() { // GIVEN NodeRecord node = nodeRecordWithDynamicLabels(_nodeStore, OneByteLongs(5)); DynamicRecord dynamicRecord = node.DynamicLabelRecords.GetEnumerator().next(); // WHEN long dynRecordId = NodeLabelsField.firstDynamicLabelRecordId(node.LabelField); // THEN assertEquals(dynamicRecord.Id, dynRecordId); }
//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); }
//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)); }
//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); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldSortLabelIds() public virtual void ShouldSortLabelIds() { // GIVEN BatchingLabelTokenRepository repo = new BatchingLabelTokenRepository(mock(typeof(TokenStore))); long[] expected = new long[] { repo.GetOrCreateId("One"), repo.GetOrCreateId("Two"), repo.GetOrCreateId("Three") }; // WHEN long[] ids = repo.GetOrCreateIds(new string[] { "Two", "One", "Three" }); // THEN assertArrayEquals(expected, ids); assertTrue(NodeLabelsField.isSane(ids)); }
//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); }
//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); }
//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); }
//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()); }
//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()); }
//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); }
//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))); }
//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 } }
//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 } }
//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 } }
//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 } }
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)); }
/* * 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); }
public override void Check(RelationshipRecord record, CheckerEngine <RelationshipRecord, ConsistencyReport_RelationshipConsistencyReport> engine, RecordAccess records) { if (CountUpdateCondition.test(record)) { if (record.InUse()) { Org.Neo4j.Consistency.checking.cache.CacheAccess_Client cacheAccess = records.CacheAccess().client(); ISet <long> firstNodeLabels; ISet <long> secondNodeLabels; long firstLabelsField = cacheAccess.GetFromCache(record.FirstNode, SLOT_LABEL_FIELD); if (NodeLabelsField.fieldPointsToDynamicRecordOfLabels(firstLabelsField)) { firstNodeLabels = LabelsFor(NodeStore, engine, records, record.FirstNode); } else { firstNodeLabels = NodeLabelReader.GetListOfLabels(firstLabelsField); } long secondLabelsField = cacheAccess.GetFromCache(record.SecondNode, SLOT_LABEL_FIELD); if (NodeLabelsField.fieldPointsToDynamicRecordOfLabels(secondLabelsField)) { secondNodeLabels = LabelsFor(NodeStore, engine, records, record.SecondNode); } else { secondNodeLabels = NodeLabelReader.GetListOfLabels(secondLabelsField); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int type = record.getType(); int type = record.Type; lock ( Counts ) { Counts.addToValue(relationshipKey(WILDCARD, WILDCARD, WILDCARD), 1); Counts.addToValue(relationshipKey(WILDCARD, type, WILDCARD), 1); if (firstNodeLabels != null) { foreach (long firstLabel in firstNodeLabels) { Counts.addToValue(relationshipKey(( int )firstLabel, WILDCARD, WILDCARD), 1); Counts.addToValue(relationshipKey(( int )firstLabel, type, WILDCARD), 1); } } if (secondNodeLabels != null) { foreach (long secondLabel in secondNodeLabels) { Counts.addToValue(relationshipKey(WILDCARD, WILDCARD, ( int )secondLabel), 1); Counts.addToValue(relationshipKey(WILDCARD, type, ( int )secondLabel), 1); } } if (COMPUTE_DOUBLE_SIDED_RELATIONSHIP_COUNTS) { foreach (long firstLabel in firstNodeLabels) { foreach (long secondLabel in secondNodeLabels) { Counts.addToValue(relationshipKey(( int )firstLabel, WILDCARD, ( int )secondLabel), 1); Counts.addToValue(relationshipKey(( int )firstLabel, type, ( int )secondLabel), 1); } } } } } } Inner.check(record, engine, records); }