use of org.neo4j.internal.batchimport.PropertyValueLookup in project neo4j by neo4j.
the class EncodingIdMapperTest method shouldOnlyFindInputIdsInSpecificGroup.
@Test
public void shouldOnlyFindInputIdsInSpecificGroup() {
// GIVEN
Group firstGroup = groups.getOrCreate("first");
Group secondGroup = groups.getOrCreate("second");
Group thirdGroup = groups.getOrCreate("third");
IdMapper mapper = mapper(new StringEncoder(), Radix.STRING, EncodingIdMapper.NO_MONITOR);
PropertyValueLookup ids = values("8", "9", "10");
int id = 0;
mapper.put(ids.lookupProperty(id, NULL), id++, firstGroup);
mapper.put(ids.lookupProperty(id, NULL), id++, secondGroup);
mapper.put(ids.lookupProperty(id, NULL), id, thirdGroup);
mapper.prepare(ids, mock(Collector.class), NONE);
// WHEN/THEN
assertEquals(0L, mapper.get("8", firstGroup));
assertEquals(IdMapper.ID_NOT_FOUND, mapper.get("8", secondGroup));
assertEquals(IdMapper.ID_NOT_FOUND, mapper.get("8", thirdGroup));
assertEquals(IdMapper.ID_NOT_FOUND, mapper.get("9", firstGroup));
assertEquals(1L, mapper.get("9", secondGroup));
assertEquals(IdMapper.ID_NOT_FOUND, mapper.get("9", thirdGroup));
assertEquals(IdMapper.ID_NOT_FOUND, mapper.get("10", firstGroup));
assertEquals(IdMapper.ID_NOT_FOUND, mapper.get("10", secondGroup));
assertEquals(2L, mapper.get("10", thirdGroup));
}
use of org.neo4j.internal.batchimport.PropertyValueLookup in project neo4j by neo4j.
the class EncodingIdMapperTest method shouldHandleGreatAmountsOfStuff.
@Test
public void shouldHandleGreatAmountsOfStuff() {
// GIVEN
IdMapper idMapper = mapper(new StringEncoder(), Radix.STRING, EncodingIdMapper.NO_MONITOR);
PropertyValueLookup inputIdLookup = (id, cursorContext) -> String.valueOf(id);
int count = 300_000;
// WHEN
for (long nodeId = 0; nodeId < count; nodeId++) {
idMapper.put(inputIdLookup.lookupProperty(nodeId, NULL), nodeId, Group.GLOBAL);
}
idMapper.prepare(inputIdLookup, mock(Collector.class), NONE);
// THEN
for (long nodeId = 0; nodeId < count; nodeId++) {
// the UUIDs here will be generated in the same sequence as above because we reset the random
Object id = inputIdLookup.lookupProperty(nodeId, NULL);
if (idMapper.get(id, Group.GLOBAL) == IdMapper.ID_NOT_FOUND) {
fail("Couldn't find " + id + " even though I added it just previously");
}
}
}
use of org.neo4j.internal.batchimport.PropertyValueLookup in project neo4j by neo4j.
the class EncodingIdMapperTest method tracePageCacheAccessOnCollisions.
@Test
public void tracePageCacheAccessOnCollisions() {
EncodingIdMapper.Monitor monitor = mock(EncodingIdMapper.Monitor.class);
Encoder encoder = mock(Encoder.class);
when(encoder.encode(any())).thenReturn(12345L);
var pageCacheTracer = new DefaultPageCacheTracer();
IdMapper mapper = mapper(encoder, Radix.STRING, monitor, pageCacheTracer);
PropertyValueLookup ids = (nodeId, cursorContext) -> {
cursorContext.getCursorTracer().beginPin(false, 1, null).done();
return nodeId + "";
};
int expectedCollisions = 2;
for (int i = 0; i < expectedCollisions; i++) {
mapper.put(ids.lookupProperty(i, NULL), i, Group.GLOBAL);
}
ProgressListener progress = mock(ProgressListener.class);
Collector collector = mock(Collector.class);
mapper.prepare(ids, collector, progress);
verifyNoMoreInteractions(collector);
verify(monitor).numberOfCollisions(expectedCollisions);
assertEquals(expectedCollisions, pageCacheTracer.pins());
assertEquals(expectedCollisions, pageCacheTracer.unpins());
}
use of org.neo4j.internal.batchimport.PropertyValueLookup in project neo4j by neo4j.
the class EncodingIdMapperTest method shouldPutFromMultipleThreads.
@Test
public void shouldPutFromMultipleThreads() throws Throwable {
// GIVEN
IdMapper idMapper = mapper(new StringEncoder(), Radix.STRING, EncodingIdMapper.NO_MONITOR);
AtomicLong highNodeId = new AtomicLong();
int batchSize = 1234;
Race race = new Race();
PropertyValueLookup inputIdLookup = (id, cursorContext) -> String.valueOf(id);
int countPerThread = 30_000;
race.addContestants(processors, () -> {
int cursor = batchSize;
long nextNodeId = 0;
for (int j = 0; j < countPerThread; j++) {
if (cursor == batchSize) {
nextNodeId = highNodeId.getAndAdd(batchSize);
cursor = 0;
}
long nodeId = nextNodeId++;
cursor++;
idMapper.put(inputIdLookup.lookupProperty(nodeId, NULL), nodeId, Group.GLOBAL);
}
});
// WHEN
race.go();
idMapper.prepare(inputIdLookup, mock(Collector.class), ProgressListener.NONE);
// THEN
int count = processors * countPerThread;
int countWithGapsWorstCase = count + batchSize * processors;
int correctHits = 0;
for (long nodeId = 0; nodeId < countWithGapsWorstCase; nodeId++) {
long result = idMapper.get(inputIdLookup.lookupProperty(nodeId, NULL), Group.GLOBAL);
if (result != -1) {
assertEquals(nodeId, result);
correctHits++;
}
}
assertEquals(count, correctHits);
}
Aggregations