Esempio n. 1
0
//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()));
        }
Esempio n. 2
0
//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());
        }
Esempio n. 3
0
//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());
        }