Search in sources :

Example 6 with Group

use of org.neo4j.unsafe.impl.batchimport.input.Group in project neo4j by neo4j.

the class CsvInputTest method shouldHaveRelationshipsSpecifyStartEndNodeIdGroupsInHeader.

@Test
public void shouldHaveRelationshipsSpecifyStartEndNodeIdGroupsInHeader() throws Exception {
    // GIVEN
    IdType idType = IdType.ACTUAL;
    Iterable<DataFactory<InputRelationship>> data = dataIterable(data("123,TYPE,234\n" + "345,TYPE,456"));
    Groups groups = new Groups();
    Group startNodeGroup = groups.getOrCreate("StartGroup");
    Group endNodeGroup = groups.getOrCreate("EndGroup");
    Input input = new CsvInput(null, null, data, header(entry(null, Type.START_ID, startNodeGroup.name(), idType.extractor(extractors)), entry(null, Type.TYPE, extractors.string()), entry(null, Type.END_ID, endNodeGroup.name(), idType.extractor(extractors))), idType, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN/THEN
    try (InputIterator<InputRelationship> relationships = input.relationships().iterator()) {
        assertRelationship(relationships.next(), startNodeGroup, 123L, endNodeGroup, 234L, "TYPE", properties());
        assertRelationship(relationships.next(), startNodeGroup, 345L, endNodeGroup, 456L, "TYPE", properties());
        assertFalse(relationships.hasNext());
    }
}
Also used : Group(org.neo4j.unsafe.impl.batchimport.input.Group) Input(org.neo4j.unsafe.impl.batchimport.input.Input) Groups(org.neo4j.unsafe.impl.batchimport.input.Groups) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) Test(org.junit.Test)

Example 7 with Group

use of org.neo4j.unsafe.impl.batchimport.input.Group 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 8 with Group

use of org.neo4j.unsafe.impl.batchimport.input.Group 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 9 with Group

use of org.neo4j.unsafe.impl.batchimport.input.Group 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

Group (org.neo4j.unsafe.impl.batchimport.input.Group)9 Test (org.junit.Test)7 IdMapper (org.neo4j.unsafe.impl.batchimport.cache.idmapping.IdMapper)5 Collector (org.neo4j.unsafe.impl.batchimport.input.Collector)4 Collectors.badCollector (org.neo4j.unsafe.impl.batchimport.input.Collectors.badCollector)4 Groups (org.neo4j.unsafe.impl.batchimport.input.Groups)4 SimpleInputIterator (org.neo4j.unsafe.impl.batchimport.input.SimpleInputIterator)3 Random (java.util.Random)2 Randoms (org.neo4j.test.Randoms)2 Monitor (org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.EncodingIdMapper.Monitor)2 Input (org.neo4j.unsafe.impl.batchimport.input.Input)2 InputNode (org.neo4j.unsafe.impl.batchimport.input.InputNode)2 InputRelationship (org.neo4j.unsafe.impl.batchimport.input.InputRelationship)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Iterator (java.util.Iterator)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 MutableLong (org.apache.commons.lang3.mutable.MutableLong)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.anyString (org.mockito.Matchers.anyString)1 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)1