//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleLargeAmountsOfDuplicateNodeIds() public virtual void ShouldHandleLargeAmountsOfDuplicateNodeIds() { // GIVEN IdMapper mapper = mapper(new LongEncoder(), Radix.Long, NO_MONITOR); long nodeId = 0; int high = 10; // a list of input ids IList <object> ids = new List <object>(); for (int run = 0; run < 2; run++) { for (long i = 0; i < high / 2; i++) { ids.Add(high - (i + 1)); ids.Add(i); } } // fed to the IdMapper foreach (object inputId in ids) { mapper.Put(inputId, nodeId++, GLOBAL); } // WHEN Collector collector = mock(typeof(Collector)); mapper.Prepare(Values(ids.ToArray()), collector, NONE); // THEN verify(collector, times(high)).collectDuplicateNode(any(typeof(object)), anyLong(), anyString()); assertEquals(high, count(mapper.LeftOverDuplicateNodesIds())); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDetectLargeAmountsOfCollisions() public virtual void ShouldDetectLargeAmountsOfCollisions() { // GIVEN IdMapper mapper = mapper(new StringEncoder(), Radix.String, NO_MONITOR); int count = 20_000; IList <object> ids = new List <object>(); long id = 0; // Generate and add all input ids for (int elements = 0; elements < count; elements++) { string inputId = System.Guid.randomUUID().ToString(); for (int i = 0; i < 2; i++) { ids.Add(inputId); mapper.Put(inputId, id++, GLOBAL); } } // WHEN CountingCollector collector = new CountingCollector(); mapper.Prepare(Values(ids.ToArray()), collector, NONE); // THEN assertEquals(count, collector.Count); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldOnlyFindInputIdsInSpecificGroup() public virtual void ShouldOnlyFindInputIdsInSpecificGroup() { // GIVEN Group firstGroup = _groups.getOrCreate("first"); Group secondGroup = _groups.getOrCreate("second"); Group thirdGroup = _groups.getOrCreate("third"); IdMapper mapper = mapper(new StringEncoder(), Radix.String, NO_MONITOR); System.Func <long, object> ids = Values("8", "9", "10"); int id = 0; mapper.Put(ids(id), id++, firstGroup); mapper.Put(ids(id), id++, secondGroup); mapper.Put(ids(id), id++, thirdGroup); mapper.Prepare(ids, mock(typeof(Collector)), NONE); // WHEN/THEN assertEquals(0L, mapper.Get("8", firstGroup)); assertEquals(ID_NOT_FOUND, mapper.Get("8", secondGroup)); assertEquals(ID_NOT_FOUND, mapper.Get("8", thirdGroup)); assertEquals(ID_NOT_FOUND, mapper.Get("9", firstGroup)); assertEquals(1L, mapper.Get("9", secondGroup)); assertEquals(ID_NOT_FOUND, mapper.Get("9", thirdGroup)); assertEquals(ID_NOT_FOUND, mapper.Get("10", firstGroup)); assertEquals(ID_NOT_FOUND, mapper.Get("10", secondGroup)); assertEquals(2L, mapper.Get("10", thirdGroup)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleHolesInIdSequence() public virtual void ShouldHandleHolesInIdSequence() { // GIVEN IdMapper mapper = mapper(new LongEncoder(), Radix.Long, NO_MONITOR); IList <object> ids = new List <object>(); for (int i = 0; i < 100; i++) { if (Random.nextBoolean()) { // Skip this one } else { long?id = ( long )i; ids.Add(id); mapper.Put(id, i, GLOBAL); } } // WHEN mapper.Prepare(Values(ids.ToArray()), mock(typeof(Collector)), NONE); // THEN foreach (object id in ids) { assertEquals((( long? )id).Value, mapper.Get(id, GLOBAL)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleManyGroups() public virtual void ShouldHandleManyGroups() { // GIVEN int size = 256; // which results in GLOBAL (0) + 1-256 = 257 groups, i.e. requiring two bytes for (int i = 0; i < size; i++) { _groups.getOrCreate("" + i); } IdMapper mapper = mapper(new LongEncoder(), Radix.Long, NO_MONITOR); // WHEN for (int i = 0; i < size; i++) { mapper.Put(i, i, _groups.get("" + i)); } // null since this test should have been set up to not run into collisions mapper.Prepare(null, mock(typeof(Collector)), NONE); // THEN for (int i = 0; i < size; i++) { assertEquals(i, mapper.Get(i, _groups.get("" + i))); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleGreatAmountsOfStuff() public virtual void ShouldHandleGreatAmountsOfStuff() { // GIVEN IdMapper idMapper = Mapper(new StringEncoder(), Radix.String, NO_MONITOR); System.Func <long, object> inputIdLookup = string.valueOf; int count = 300_000; // WHEN for (long nodeId = 0; nodeId < count; nodeId++) { idMapper.Put(inputIdLookup(nodeId), nodeId, GLOBAL); } idMapper.Prepare(inputIdLookup, mock(typeof(Collector)), NONE); // THEN for (long nodeId = 0; nodeId < count; nodeId++) { // the UUIDs here will be generated in the same sequence as above because we reset the random object id = inputIdLookup(nodeId); if (idMapper.Get(id, GLOBAL) == ID_NOT_FOUND) { fail("Couldn't find " + id + " even though I added it just previously"); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBeAbleToHaveDuplicateInputIdButInDifferentGroups() public virtual void ShouldBeAbleToHaveDuplicateInputIdButInDifferentGroups() { // GIVEN Monitor monitor = mock(typeof(Monitor)); Group firstGroup = _groups.getOrCreate("first"); Group secondGroup = _groups.getOrCreate("second"); IdMapper mapper = mapper(new StringEncoder(), Radix.String, monitor); System.Func <long, object> ids = Values("10", "9", "10"); int id = 0; // group 0 mapper.Put(ids(id), id++, firstGroup); mapper.Put(ids(id), id++, firstGroup); // group 1 mapper.Put(ids(id), id++, secondGroup); Collector collector = mock(typeof(Collector)); mapper.Prepare(ids, collector, NONE); // WHEN/THEN verifyNoMoreInteractions(collector); verify(monitor).numberOfCollisions(0); assertEquals(0L, mapper.Get("10", firstGroup)); assertEquals(1L, mapper.Get("9", firstGroup)); assertEquals(2L, mapper.Get("10", secondGroup)); assertFalse(mapper.LeftOverDuplicateNodesIds().hasNext()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCopeWithCollisionsBasedOnDifferentInputIds() public virtual void ShouldCopeWithCollisionsBasedOnDifferentInputIds() { // GIVEN Monitor monitor = mock(typeof(Monitor)); Encoder encoder = mock(typeof(Encoder)); when(encoder.Encode(any())).thenReturn(12345L); IdMapper mapper = mapper(encoder, Radix.String, monitor); System.Func <long, object> ids = Values("10", "9"); for (int i = 0; i < 2; i++) { mapper.Put(ids(i), i, GLOBAL); } // WHEN ProgressListener progress = mock(typeof(ProgressListener)); Collector collector = mock(typeof(Collector)); mapper.Prepare(ids, collector, progress); // THEN verifyNoMoreInteractions(collector); verify(monitor).numberOfCollisions(2); assertEquals(0L, mapper.Get("10", GLOBAL)); assertEquals(1L, mapper.Get("9", GLOBAL)); // 7 times since SPLIT+SORT+DETECT+RESOLVE+SPLIT+SORT,DEDUPLICATE verify(progress, times(7)).started(anyString()); verify(progress, times(7)).done(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnExpectedValueForNotFound() public virtual void ShouldReturnExpectedValueForNotFound() { // GIVEN IdMapper idMapper = Mapper(new StringEncoder(), Radix.String, NO_MONITOR); idMapper.Prepare(null, mock(typeof(Collector)), NONE); // WHEN long id = idMapper.Get("123", GLOBAL); // THEN assertEquals(ID_NOT_FOUND, id); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCopeWithMixedActualAndAccidentalCollisions() public virtual void ShouldCopeWithMixedActualAndAccidentalCollisions() { // GIVEN Monitor monitor = mock(typeof(Monitor)); Encoder encoder = mock(typeof(Encoder)); // Create these explicit instances so that we can use them in mock, even for same values string a = "a"; string b = "b"; string c = "c"; string a2 = "a"; string e = "e"; string f = "f"; when(encoder.Encode(a)).thenReturn(1L); when(encoder.Encode(b)).thenReturn(1L); when(encoder.Encode(c)).thenReturn(3L); when(encoder.Encode(a2)).thenReturn(1L); when(encoder.Encode(e)).thenReturn(2L); when(encoder.Encode(f)).thenReturn(1L); Group groupA = _groups.getOrCreate("A"); Group groupB = _groups.getOrCreate("B"); IdMapper mapper = mapper(encoder, Radix.String, monitor); System.Func <long, object> ids = Values("a", "b", "c", "a", "e", "f"); Group[] groups = new Group[] { groupA, groupA, groupA, groupB, groupB, groupB }; // a/A --> 1 // b/A --> 1 accidental collision with a/A // c/A --> 3 // a/B --> 1 actual collision with a/A // e/B --> 2 // f/B --> 1 accidental collision with a/A // WHEN for (int i = 0; i < 6; i++) { mapper.Put(ids(i), i, groups[i]); } Collector collector = mock(typeof(Collector)); mapper.Prepare(ids, collector, mock(typeof(ProgressListener))); // THEN verify(monitor).numberOfCollisions(4); assertEquals(0L, mapper.Get(a, groupA)); assertEquals(1L, mapper.Get(b, groupA)); assertEquals(2L, mapper.Get(c, groupA)); assertEquals(3L, mapper.Get(a2, groupB)); assertEquals(4L, mapper.Get(e, groupB)); assertEquals(5L, mapper.Get(f, groupB)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldEncodeShortStrings() public virtual void ShouldEncodeShortStrings() { // GIVEN IdMapper mapper = mapper(new StringEncoder(), Radix.String, NO_MONITOR); // WHEN mapper.Put("123", 0, GLOBAL); mapper.Put("456", 1, GLOBAL); mapper.Prepare(null, mock(typeof(Collector)), NONE); // THEN assertEquals(1L, mapper.Get("456", GLOBAL)); assertEquals(0L, mapper.Get("123", GLOBAL)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPutFromMultipleThreads() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldPutFromMultipleThreads() { // GIVEN IdMapper idMapper = Mapper(new StringEncoder(), Radix.String, NO_MONITOR); AtomicLong highNodeId = new AtomicLong(); int batchSize = 1234; Race race = new Race(); System.Func <long, object> inputIdLookup = string.valueOf; int countPerThread = 30_000; race.AddContestants(_processors, () => { int cursor = batchSize; long nextNodeId = 0; for (int j = 0; j < countPerThread; j++) { if (cursor == batchSize) { nextNodeId = highNodeId.getAndAdd(batchSize); cursor = 0; } long nodeId = nextNodeId++; cursor++; idMapper.Put(inputIdLookup(nodeId), nodeId, GLOBAL); } }); // WHEN race.Go(); idMapper.Prepare(inputIdLookup, mock(typeof(Collector)), Org.Neo4j.Helpers.progress.ProgressListener_Fields.None); // THEN int count = _processors * countPerThread; int countWithGapsWorstCase = count + batchSize * _processors; int correctHits = 0; for (long nodeId = 0; nodeId < countWithGapsWorstCase; nodeId++) { long result = idMapper.Get(inputIdLookup(nodeId), GLOBAL); if (result != -1) { assertEquals(nodeId, result); correctHits++; } } assertEquals(count, correctHits); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReportyProgressForSortAndDetect() public virtual void ShouldReportyProgressForSortAndDetect() { // GIVEN IdMapper idMapper = Mapper(new StringEncoder(), Radix.String, NO_MONITOR); ProgressListener progress = mock(typeof(ProgressListener)); idMapper.Prepare(null, mock(typeof(Collector)), progress); // WHEN long id = idMapper.Get("123", GLOBAL); // THEN assertEquals(ID_NOT_FOUND, id); verify(progress, times(3)).started(anyString()); verify(progress, times(3)).done(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReportCollisionsForSameInputId() public virtual void ShouldReportCollisionsForSameInputId() { // GIVEN IdMapper mapper = mapper(new StringEncoder(), Radix.String, NO_MONITOR); System.Func <long, object> values = values("10", "9", "10"); for (int i = 0; i < 3; i++) { mapper.Put(values(i), i, GLOBAL); } // WHEN Collector collector = mock(typeof(Collector)); mapper.Prepare(values, collector, NONE); // THEN verify(collector, times(1)).collectDuplicateNode("10", 2, GLOBAL.name()); verifyNoMoreInteractions(collector); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldEncodeSmallSetOfRandomData() public virtual void ShouldEncodeSmallSetOfRandomData() { // GIVEN int size = Random.Next(10_000) + 2; ValueType type = ValueType.values()[Random.Next(ValueType.values().length)]; IdMapper mapper = mapper(type.encoder(), type.radix(), NO_MONITOR); // WHEN ValueGenerator values = new ValueGenerator(this, type.data(Random.random())); for (int nodeId = 0; nodeId < size; nodeId++) { mapper.Put(values.Apply(nodeId), nodeId, GLOBAL); } mapper.Prepare(values, mock(typeof(Collector)), NONE); // THEN for (int nodeId = 0; nodeId < size; nodeId++) { object value = values.Values[nodeId]; assertEquals("Expected " + value + " to map to " + nodeId, nodeId, mapper.Get(value, GLOBAL)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDetectCorrectDuplicateInputIdsWhereManyAccidentalInManyGroups() public virtual void ShouldDetectCorrectDuplicateInputIdsWhereManyAccidentalInManyGroups() { // GIVEN //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final ControlledEncoder encoder = new ControlledEncoder(new LongEncoder()); ControlledEncoder encoder = new ControlledEncoder(new LongEncoder()); const int idsPerGroup = 20; int groupCount = 5; for (int i = 0; i < groupCount; i++) { _groups.getOrCreate("Group " + i); } IdMapper mapper = mapper(encoder, Radix.Long, NO_MONITOR, ParallelSort.DEFAULT, numberOfCollisions => new LongCollisionValues(NumberArrayFactory.HEAP, numberOfCollisions)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicReference<org.neo4j.unsafe.impl.batchimport.input.Group> group = new java.util.concurrent.atomic.AtomicReference<>(); AtomicReference <Group> group = new AtomicReference <Group>(); System.Func <long, object> ids = nodeId => { int groupId = toIntExact(nodeId / idsPerGroup); if (groupId == groupCount) { return(null); } group.set(_groups.get(groupId)); // Let the first 10% in each group be accidental collisions with each other // i.e. all first 10% in each group collides with all other first 10% in each group if (nodeId % idsPerGroup < 2) { // Let these colliding values encode into the same eId as well, // so that they are definitely marked as collisions encoder.UseThisIdToEncodeNoMatterWhatComesIn(Convert.ToInt64(1234567)); return(Convert.ToInt64(nodeId % idsPerGroup)); } // The other 90% will be accidental collisions for something else encoder.UseThisIdToEncodeNoMatterWhatComesIn(Convert.ToInt64(123456 - group.get().id())); return(Convert.ToInt64(nodeId)); }; // WHEN int count = idsPerGroup * groupCount; for (long nodeId = 0; nodeId < count; nodeId++) { mapper.Put(ids(nodeId), nodeId, group.get()); } Collector collector = mock(typeof(Collector)); mapper.Prepare(ids, collector, NONE); // THEN verifyNoMoreInteractions(collector); for (long nodeId = 0; nodeId < count; nodeId++) { assertEquals(nodeId, mapper.Get(ids(nodeId), group.get())); } verifyNoMoreInteractions(collector); assertFalse(mapper.LeftOverDuplicateNodesIds().hasNext()); }