Search in sources :

Example 11 with IdMapper

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

the class EncodingIdMapperTest method shouldIncludeSourceLocationsOfCollisions.

@Test
public void shouldIncludeSourceLocationsOfCollisions() throws Exception {
    // GIVEN
    IdMapper mapper = mapper(new StringEncoder(), Radix.STRING, NO_MONITOR);
    final List<Object> idList = Arrays.<Object>asList("10", "9", "10");
    InputIterable<Object> ids = wrap("source", idList);
    Group group = new Group.Adapter(GLOBAL.id(), "global");
    try (ResourceIterator<Object> iterator = ids.iterator()) {
        for (int i = 0; iterator.hasNext(); i++) {
            mapper.put(iterator.next(), i, group);
        }
    }
    // WHEN
    try {
        mapper.prepare(ids, badCollector(new ByteArrayOutputStream(), 0), NONE);
        fail("Should have failed");
    } catch (DuplicateInputIdException e) {
        // THEN
        assertThat(e.getMessage(), containsString("10"));
        assertThat(e.getMessage(), containsString("source:1"));
        assertThat(e.getMessage(), containsString("source:3"));
    }
}
Also used : Group(org.neo4j.unsafe.impl.batchimport.input.Group) IdMapper(org.neo4j.unsafe.impl.batchimport.cache.idmapping.IdMapper) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 12 with IdMapper

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

the class EncodingIdMapperTest method shouldEncodeShortStrings.

@Test
public void shouldEncodeShortStrings() throws Exception {
    // 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(Collector.class), NONE);
    // THEN
    assertEquals(1L, mapper.get("456", GLOBAL));
    assertEquals(0L, mapper.get("123", GLOBAL));
}
Also used : 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 13 with IdMapper

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

the class EncodingIdMapperTest method shouldOnlyFindInputIdsInSpecificGroup.

@Test
public void shouldOnlyFindInputIdsInSpecificGroup() throws Exception {
    // GIVEN
    IdMapper mapper = mapper(new StringEncoder(), Radix.STRING, NO_MONITOR);
    InputIterable<Object> ids = wrap("source", Arrays.<Object>asList("8", "9", "10"));
    Groups groups = new Groups();
    Group firstGroup, secondGroup, thirdGroup;
    try (ResourceIterator<Object> iterator = ids.iterator()) {
        int id = 0;
        mapper.put(iterator.next(), id++, firstGroup = groups.getOrCreate("first"));
        mapper.put(iterator.next(), id++, secondGroup = groups.getOrCreate("second"));
        mapper.put(iterator.next(), id++, thirdGroup = groups.getOrCreate("third"));
    }
    mapper.prepare(ids, mock(Collector.class), 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));
}
Also used : Group(org.neo4j.unsafe.impl.batchimport.input.Group) 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 14 with IdMapper

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

the class EncodingIdMapperTest method shouldEncodeSmallSetOfRandomData.

@Test
public void shouldEncodeSmallSetOfRandomData() throws Throwable {
    // GIVEN
    int size = random.nextInt(10_000) + 2;
    ValueType type = ValueType.values()[random.nextInt(ValueType.values().length)];
    IdMapper mapper = mapper(type.encoder(), type.radix(), NO_MONITOR);
    // WHEN
    InputIterable<Object> values = new ValueGenerator(size, type.data(random.random()));
    {
        int id = 0;
        for (Object value : values) {
            mapper.put(value, id++, GLOBAL);
        }
    }
    mapper.prepare(values, mock(Collector.class), NONE);
    // THEN
    int id = 0;
    for (Object value : values) {
        assertEquals("Expected " + value + " to map to " + id, id++, mapper.get(value, GLOBAL));
    }
}
Also used : 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 15 with IdMapper

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

the class EncodingIdMapperTest method shouldHandleHolesInIdSequence.

@Test
public void shouldHandleHolesInIdSequence() throws Exception {
    // GIVEN
    IdMapper mapper = mapper(new LongEncoder(), Radix.LONG, NO_MONITOR);
    List<Object> ids = new ArrayList<>();
    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(SimpleInputIteratorWrapper.wrap("source", ids), mock(Collector.class), NONE);
    // THEN
    for (Object id : ids) {
        assertEquals(((Long) id).longValue(), mapper.get(id, GLOBAL));
    }
}
Also used : ArrayList(java.util.ArrayList) Matchers.anyLong(org.mockito.Matchers.anyLong) 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)

Aggregations

IdMapper (org.neo4j.unsafe.impl.batchimport.cache.idmapping.IdMapper)17 Test (org.junit.Test)16 Collector (org.neo4j.unsafe.impl.batchimport.input.Collector)15 Collectors.badCollector (org.neo4j.unsafe.impl.batchimport.input.Collectors.badCollector)14 Group (org.neo4j.unsafe.impl.batchimport.input.Group)6 ArrayList (java.util.ArrayList)3 ProgressListener (org.neo4j.helpers.progress.ProgressListener)3 Monitor (org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.EncodingIdMapper.Monitor)3 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Matchers.anyString (org.mockito.Matchers.anyString)2 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)2 Groups (org.neo4j.unsafe.impl.batchimport.input.Groups)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Matchers.anyLong (org.mockito.Matchers.anyLong)1 ResourceIterator (org.neo4j.graphdb.ResourceIterator)1 PrefetchingIterator (org.neo4j.helpers.collection.PrefetchingIterator)1 CountsAccessor (org.neo4j.kernel.impl.api.CountsAccessor)1