use of org.neo4j.unsafe.impl.batchimport.cache.idmapping.IdMapper 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));
}
use of org.neo4j.unsafe.impl.batchimport.cache.idmapping.IdMapper in project neo4j by neo4j.
the class EncodingIdMapperTest method shouldReturnExpectedValueForNotFound.
@Test
public void shouldReturnExpectedValueForNotFound() throws Exception {
// GIVEN
IdMapper idMapper = mapper(new StringEncoder(), Radix.STRING, NO_MONITOR);
idMapper.prepare(null, mock(Collector.class), NONE);
// WHEN
long id = idMapper.get("123", GLOBAL);
// THEN
assertEquals(ID_NOT_FOUND, id);
}
Aggregations