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());
}
}
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"));
}
}
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));
}
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));
}
Aggregations