Search in sources :

Example 1 with Monitor

use of org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.EncodingIdMapper.Monitor in project neo4j by neo4j.

the class EncodingIdMapperTest method shouldBeAbleToHaveDuplicateInputIdButInDifferentGroups.

@Test
public void shouldBeAbleToHaveDuplicateInputIdButInDifferentGroups() throws Exception {
    // GIVEN
    Monitor monitor = mock(Monitor.class);
    IdMapper mapper = mapper(new StringEncoder(), Radix.STRING, monitor);
    InputIterable<Object> ids = wrap("source", Arrays.<Object>asList("10", "9", "10"));
    Groups groups = new Groups();
    Group firstGroup = groups.getOrCreate("first"), secondGroup = groups.getOrCreate("second");
    try (ResourceIterator<Object> iterator = ids.iterator()) {
        int id = 0;
        // group 0
        mapper.put(iterator.next(), id++, firstGroup);
        mapper.put(iterator.next(), id++, firstGroup);
        // group 1
        mapper.put(iterator.next(), id++, secondGroup);
    }
    Collector collector = mock(Collector.class);
    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));
}
Also used : Group(org.neo4j.unsafe.impl.batchimport.input.Group) Monitor(org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.EncodingIdMapper.Monitor) Groups(org.neo4j.unsafe.impl.batchimport.input.Groups) Collector(org.neo4j.unsafe.impl.batchimport.input.Collector) Collectors.badCollector(org.neo4j.unsafe.impl.batchimport.input.Collectors.badCollector) IdMapper(org.neo4j.unsafe.impl.batchimport.cache.idmapping.IdMapper) Test(org.junit.Test)

Example 2 with Monitor

use of org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.EncodingIdMapper.Monitor in project neo4j by neo4j.

the class EncodingIdMapperTest method shouldCopeWithCollisionsBasedOnDifferentInputIds.

@Test
public void shouldCopeWithCollisionsBasedOnDifferentInputIds() throws Exception {
    // GIVEN
    Monitor monitor = mock(Monitor.class);
    Encoder encoder = mock(Encoder.class);
    when(encoder.encode(any())).thenReturn(12345L);
    IdMapper mapper = mapper(encoder, Radix.STRING, monitor);
    InputIterable<Object> ids = wrap("source", Arrays.<Object>asList("10", "9"));
    try (ResourceIterator<Object> iterator = ids.iterator()) {
        for (int i = 0; iterator.hasNext(); i++) {
            mapper.put(iterator.next(), i, 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", 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();
}
Also used : Monitor(org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.EncodingIdMapper.Monitor) ProgressListener(org.neo4j.helpers.progress.ProgressListener) Collector(org.neo4j.unsafe.impl.batchimport.input.Collector) Collectors.badCollector(org.neo4j.unsafe.impl.batchimport.input.Collectors.badCollector) IdMapper(org.neo4j.unsafe.impl.batchimport.cache.idmapping.IdMapper) Test(org.junit.Test)

Example 3 with Monitor

use of org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.EncodingIdMapper.Monitor in project neo4j by neo4j.

the class EncodingIdMapperTest method shouldCopeWithMixedActualAndAccidentalCollisions.

@Test
public void shouldCopeWithMixedActualAndAccidentalCollisions() throws Exception {
    // GIVEN
    Monitor monitor = mock(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 = new String("a");
    String b = new String("b");
    String c = new String("c");
    String a2 = new String("a");
    String e = new String("e");
    String f = new String("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);
    IdMapper mapper = mapper(encoder, Radix.STRING, monitor);
    InputIterable<Object> ids = wrap("source", Arrays.<Object>asList("a", "b", "c", "a", "e", "f"));
    Group.Adapter groupA = new Group.Adapter(1, "A");
    Group.Adapter groupB = new Group.Adapter(2, "B");
    Group[] groups = new Group[] { groupA, groupA, groupA, groupB, groupB, groupB };
    // WHEN
    try (ResourceIterator<Object> iterator = ids.iterator()) {
        for (int i = 0; iterator.hasNext(); i++) {
            mapper.put(iterator.next(), 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.unsafe.impl.batchimport.input.Group) IdMapper(org.neo4j.unsafe.impl.batchimport.cache.idmapping.IdMapper) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Monitor(org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.EncodingIdMapper.Monitor) ProgressListener(org.neo4j.helpers.progress.ProgressListener) Collector(org.neo4j.unsafe.impl.batchimport.input.Collector) Collectors.badCollector(org.neo4j.unsafe.impl.batchimport.input.Collectors.badCollector) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 IdMapper (org.neo4j.unsafe.impl.batchimport.cache.idmapping.IdMapper)3 Monitor (org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.EncodingIdMapper.Monitor)3 Collector (org.neo4j.unsafe.impl.batchimport.input.Collector)3 Collectors.badCollector (org.neo4j.unsafe.impl.batchimport.input.Collectors.badCollector)3 ProgressListener (org.neo4j.helpers.progress.ProgressListener)2 Group (org.neo4j.unsafe.impl.batchimport.input.Group)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Groups (org.neo4j.unsafe.impl.batchimport.input.Groups)1