Search in sources :

Example 11 with IdMapper

use of org.neo4j.internal.batchimport.cache.idmapping.IdMapper in project neo4j by neo4j.

the class EncodingIdMapperTest method shouldDetectLargeAmountsOfCollisions.

@Test
public void shouldDetectLargeAmountsOfCollisions() {
    // GIVEN
    IdMapper mapper = mapper(new StringEncoder(), Radix.STRING, EncodingIdMapper.NO_MONITOR);
    int count = 20_000;
    List<Object> ids = new ArrayList<>();
    long id = 0;
    // Generate and add all input ids
    for (int elements = 0; elements < count; elements++) {
        String inputId = UUID.randomUUID().toString();
        for (int i = 0; i < 2; i++) {
            ids.add(inputId);
            mapper.put(inputId, id++, Group.GLOBAL);
        }
    }
    // WHEN
    CountingCollector collector = new CountingCollector();
    mapper.prepare(values(ids.toArray()), collector, NONE);
    // THEN
    assertEquals(count, collector.count);
}
Also used : ArrayList(java.util.ArrayList) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 12 with IdMapper

use of org.neo4j.internal.batchimport.cache.idmapping.IdMapper in project neo4j by neo4j.

the class EncodingIdMapperTest method shouldReturnExpectedValueForNotFound.

@Test
public void shouldReturnExpectedValueForNotFound() {
    // GIVEN
    IdMapper idMapper = mapper(new StringEncoder(), Radix.STRING, EncodingIdMapper.NO_MONITOR);
    idMapper.prepare(null, mock(Collector.class), NONE);
    // WHEN
    long id = idMapper.get("123", Group.GLOBAL);
    // THEN
    assertEquals(IdMapper.ID_NOT_FOUND, id);
}
Also used : Collector(org.neo4j.internal.batchimport.input.Collector) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) Test(org.junit.Test)

Example 13 with IdMapper

use of org.neo4j.internal.batchimport.cache.idmapping.IdMapper in project neo4j by neo4j.

the class EncodingIdMapperTest method shouldCopeWithCollisionsBasedOnDifferentInputIds.

@Test
public void shouldCopeWithCollisionsBasedOnDifferentInputIds() {
    // GIVEN
    EncodingIdMapper.Monitor monitor = mock(EncodingIdMapper.Monitor.class);
    Encoder encoder = mock(Encoder.class);
    when(encoder.encode(any())).thenReturn(12345L);
    IdMapper mapper = mapper(encoder, Radix.STRING, monitor);
    PropertyValueLookup ids = values("10", "9");
    for (int i = 0; i < 2; i++) {
        mapper.put(ids.lookupProperty(i, NULL), i, Group.GLOBAL);
    }
    // WHEN
    ProgressListener progress = mock(ProgressListener.class);
    Collector collector = mock(Collector.class);
    mapper.prepare(ids, collector, progress);
    // THEN
    verifyNoMoreInteractions(collector);
    verify(monitor).numberOfCollisions(2);
    assertEquals(0L, mapper.get("10", Group.GLOBAL));
    assertEquals(1L, mapper.get("9", Group.GLOBAL));
    // 7 times since SPLIT+SORT+DETECT+RESOLVE+SPLIT+SORT,DEDUPLICATE
    verify(progress, times(7)).started(anyString());
    verify(progress, times(7)).done();
}
Also used : ProgressListener(org.neo4j.internal.helpers.progress.ProgressListener) PropertyValueLookup(org.neo4j.internal.batchimport.PropertyValueLookup) Collector(org.neo4j.internal.batchimport.input.Collector) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) Test(org.junit.Test)

Example 14 with IdMapper

use of org.neo4j.internal.batchimport.cache.idmapping.IdMapper in project neo4j by neo4j.

the class EncodingIdMapperTest method shouldEncodeSmallSetOfRandomData.

@Test
public void shouldEncodeSmallSetOfRandomData() {
    // GIVEN
    int size = random.nextInt(10_000) + 2;
    ValueType type = ValueType.values()[random.nextInt(ValueType.values().length)];
    IdMapper mapper = mapper(type.encoder(), type.radix(), EncodingIdMapper.NO_MONITOR);
    // WHEN
    ValueGenerator values = new ValueGenerator(type.data(random.random()));
    for (int nodeId = 0; nodeId < size; nodeId++) {
        mapper.put(values.lookupProperty(nodeId, NULL), nodeId, Group.GLOBAL);
    }
    mapper.prepare(values, mock(Collector.class), NONE);
    // THEN
    for (int nodeId = 0; nodeId < size; nodeId++) {
        Object value = values.values.get(nodeId);
        assertEquals("Expected " + value + " to map to " + nodeId, nodeId, mapper.get(value, Group.GLOBAL));
    }
}
Also used : Collector(org.neo4j.internal.batchimport.input.Collector) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) Test(org.junit.Test)

Example 15 with IdMapper

use of org.neo4j.internal.batchimport.cache.idmapping.IdMapper in project neo4j by neo4j.

the class EncodingIdMapperTest method shouldCopeWithMixedActualAndAccidentalCollisions.

@Test
public void shouldCopeWithMixedActualAndAccidentalCollisions() {
    // GIVEN
    EncodingIdMapper.Monitor monitor = mock(EncodingIdMapper.Monitor.class);
    Encoder encoder = mock(Encoder.class);
    // 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);
    PropertyValueLookup ids = values("a", "b", "c", "a", "e", "f");
    Group[] groups = new Group[] { groupA, groupA, groupA, groupB, groupB, groupB };
    // WHEN
    for (int i = 0; i < 6; i++) {
        mapper.put(ids.lookupProperty(i, NULL), i, groups[i]);
    }
    Collector collector = mock(Collector.class);
    mapper.prepare(ids, collector, mock(ProgressListener.class));
    // 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));
}
Also used : Group(org.neo4j.internal.batchimport.input.Group) ProgressListener(org.neo4j.internal.helpers.progress.ProgressListener) PropertyValueLookup(org.neo4j.internal.batchimport.PropertyValueLookup) Collector(org.neo4j.internal.batchimport.input.Collector) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

IdMapper (org.neo4j.internal.batchimport.cache.idmapping.IdMapper)21 Test (org.junit.Test)19 Collector (org.neo4j.internal.batchimport.input.Collector)16 PropertyValueLookup (org.neo4j.internal.batchimport.PropertyValueLookup)9 ArrayList (java.util.ArrayList)7 MutableLong (org.apache.commons.lang3.mutable.MutableLong)7 Group (org.neo4j.internal.batchimport.input.Group)7 ProgressListener (org.neo4j.internal.helpers.progress.ProgressListener)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)5 Math.toIntExact (java.lang.Math.toIntExact)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Random (java.util.Random)4 Set (java.util.Set)4 UUID (java.util.UUID)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 LongFunction (java.util.function.LongFunction)4