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