Search in sources :

Example 6 with PropertyValueLookup

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));
}
Also used : Group(org.neo4j.internal.batchimport.input.Group) PropertyValueLookup(org.neo4j.internal.batchimport.PropertyValueLookup) Collector(org.neo4j.internal.batchimport.input.Collector) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) Test(org.junit.Test)

Example 7 with PropertyValueLookup

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");
        }
    }
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) NO_MONITOR(org.neo4j.internal.batchimport.cache.idmapping.string.EncodingIdMapper.NO_MONITOR) NumberArrayFactories(org.neo4j.internal.batchimport.cache.NumberArrayFactories) Collector(org.neo4j.internal.batchimport.input.Collector) CursorContext(org.neo4j.io.pagecache.context.CursorContext) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) Groups(org.neo4j.internal.batchimport.input.Groups) Random(java.util.Random) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RandomRule(org.neo4j.test.rule.RandomRule) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) MutableLong(org.apache.commons.lang3.mutable.MutableLong) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) Assert.fail(org.junit.Assert.fail) Math.toIntExact(java.lang.Math.toIntExact) ProgressListener(org.neo4j.internal.helpers.progress.ProgressListener) NONE(org.neo4j.internal.helpers.progress.ProgressListener.NONE) Parameterized(org.junit.runners.Parameterized) LongFunction(java.util.function.LongFunction) PropertyValueLookup(org.neo4j.internal.batchimport.PropertyValueLookup) Collection(java.util.Collection) Set(java.util.Set) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) AtomicLong(java.util.concurrent.atomic.AtomicLong) Factory(org.neo4j.function.Factory) GLOBAL(org.neo4j.internal.batchimport.input.Group.GLOBAL) List(java.util.List) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) Rule(org.junit.Rule) Group(org.neo4j.internal.batchimport.input.Group) Assert.assertFalse(org.junit.Assert.assertFalse) Race(org.neo4j.test.Race) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) PrimitiveLongCollections.count(org.neo4j.collection.PrimitiveLongCollections.count) PropertyValueLookup(org.neo4j.internal.batchimport.PropertyValueLookup) Collector(org.neo4j.internal.batchimport.input.Collector) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) Test(org.junit.Test)

Example 8 with PropertyValueLookup

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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) NO_MONITOR(org.neo4j.internal.batchimport.cache.idmapping.string.EncodingIdMapper.NO_MONITOR) NumberArrayFactories(org.neo4j.internal.batchimport.cache.NumberArrayFactories) Collector(org.neo4j.internal.batchimport.input.Collector) CursorContext(org.neo4j.io.pagecache.context.CursorContext) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) Groups(org.neo4j.internal.batchimport.input.Groups) Random(java.util.Random) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RandomRule(org.neo4j.test.rule.RandomRule) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) MutableLong(org.apache.commons.lang3.mutable.MutableLong) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) Assert.fail(org.junit.Assert.fail) Math.toIntExact(java.lang.Math.toIntExact) ProgressListener(org.neo4j.internal.helpers.progress.ProgressListener) NONE(org.neo4j.internal.helpers.progress.ProgressListener.NONE) Parameterized(org.junit.runners.Parameterized) LongFunction(java.util.function.LongFunction) PropertyValueLookup(org.neo4j.internal.batchimport.PropertyValueLookup) Collection(java.util.Collection) Set(java.util.Set) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) AtomicLong(java.util.concurrent.atomic.AtomicLong) Factory(org.neo4j.function.Factory) GLOBAL(org.neo4j.internal.batchimport.input.Group.GLOBAL) List(java.util.List) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) Rule(org.junit.Rule) Group(org.neo4j.internal.batchimport.input.Group) Assert.assertFalse(org.junit.Assert.assertFalse) Race(org.neo4j.test.Race) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) PrimitiveLongCollections.count(org.neo4j.collection.PrimitiveLongCollections.count) ProgressListener(org.neo4j.internal.helpers.progress.ProgressListener) PropertyValueLookup(org.neo4j.internal.batchimport.PropertyValueLookup) Collector(org.neo4j.internal.batchimport.input.Collector) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.Test)

Example 9 with PropertyValueLookup

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);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) NO_MONITOR(org.neo4j.internal.batchimport.cache.idmapping.string.EncodingIdMapper.NO_MONITOR) NumberArrayFactories(org.neo4j.internal.batchimport.cache.NumberArrayFactories) Collector(org.neo4j.internal.batchimport.input.Collector) CursorContext(org.neo4j.io.pagecache.context.CursorContext) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) Groups(org.neo4j.internal.batchimport.input.Groups) Random(java.util.Random) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RandomRule(org.neo4j.test.rule.RandomRule) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) MutableLong(org.apache.commons.lang3.mutable.MutableLong) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) Assert.fail(org.junit.Assert.fail) Math.toIntExact(java.lang.Math.toIntExact) ProgressListener(org.neo4j.internal.helpers.progress.ProgressListener) NONE(org.neo4j.internal.helpers.progress.ProgressListener.NONE) Parameterized(org.junit.runners.Parameterized) LongFunction(java.util.function.LongFunction) PropertyValueLookup(org.neo4j.internal.batchimport.PropertyValueLookup) Collection(java.util.Collection) Set(java.util.Set) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) AtomicLong(java.util.concurrent.atomic.AtomicLong) Factory(org.neo4j.function.Factory) GLOBAL(org.neo4j.internal.batchimport.input.Group.GLOBAL) List(java.util.List) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) Rule(org.junit.Rule) Group(org.neo4j.internal.batchimport.input.Group) Assert.assertFalse(org.junit.Assert.assertFalse) Race(org.neo4j.test.Race) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) PrimitiveLongCollections.count(org.neo4j.collection.PrimitiveLongCollections.count) AtomicLong(java.util.concurrent.atomic.AtomicLong) Race(org.neo4j.test.Race) PropertyValueLookup(org.neo4j.internal.batchimport.PropertyValueLookup) Collector(org.neo4j.internal.batchimport.input.Collector) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 PropertyValueLookup (org.neo4j.internal.batchimport.PropertyValueLookup)9 IdMapper (org.neo4j.internal.batchimport.cache.idmapping.IdMapper)9 Collector (org.neo4j.internal.batchimport.input.Collector)9 Group (org.neo4j.internal.batchimport.input.Group)7 ProgressListener (org.neo4j.internal.helpers.progress.ProgressListener)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 Math.toIntExact (java.lang.Math.toIntExact)4 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Random (java.util.Random)4 Set (java.util.Set)4 UUID (java.util.UUID)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 LongFunction (java.util.function.LongFunction)4 MutableLong (org.apache.commons.lang3.mutable.MutableLong)4 Assert.assertEquals (org.junit.Assert.assertEquals)4