Search in sources :

Example 6 with IdMapper

use of org.neo4j.internal.batchimport.cache.idmapping.IdMapper in project neo4j by neo4j.

the class EncodingIdMapperTest method shouldBeAbleToHaveDuplicateInputIdButInDifferentGroups.

@Test
public void shouldBeAbleToHaveDuplicateInputIdButInDifferentGroups() {
    // GIVEN
    EncodingIdMapper.Monitor monitor = mock(EncodingIdMapper.Monitor.class);
    Group firstGroup = groups.getOrCreate("first");
    Group secondGroup = groups.getOrCreate("second");
    IdMapper mapper = mapper(new StringEncoder(), Radix.STRING, monitor);
    PropertyValueLookup ids = values("10", "9", "10");
    int id = 0;
    // group 0
    mapper.put(ids.lookupProperty(id, NULL), id++, firstGroup);
    mapper.put(ids.lookupProperty(id, NULL), id++, firstGroup);
    // group 1
    mapper.put(ids.lookupProperty(id, NULL), id, secondGroup);
    Collector collector = mock(Collector.class);
    mapper.prepare(ids, collector, NONE);
    // WHEN/THEN
    verifyNoMoreInteractions(collector);
    verify(monitor).numberOfCollisions(0);
    assertEquals(0L, mapper.get("10", firstGroup));
    assertEquals(1L, mapper.get("9", firstGroup));
    assertEquals(2L, mapper.get("10", secondGroup));
    assertFalse(mapper.leftOverDuplicateNodesIds().hasNext());
}
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 IdMapper

use of org.neo4j.internal.batchimport.cache.idmapping.IdMapper in project neo4j by neo4j.

the class EncodingIdMapperTest method shouldHandleHolesInIdSequence.

@Test
public void shouldHandleHolesInIdSequence() {
    // GIVEN
    IdMapper mapper = mapper(new LongEncoder(), Radix.LONG, EncodingIdMapper.NO_MONITOR);
    List<Object> ids = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        if (!random.nextBoolean()) {
            Long id = (long) i;
            ids.add(id);
            mapper.put(id, i, Group.GLOBAL);
        }
    }
    // WHEN
    mapper.prepare(values(ids.toArray()), mock(Collector.class), NONE);
    // THEN
    for (Object id : ids) {
        assertEquals(((Long) id).longValue(), mapper.get(id, Group.GLOBAL));
    }
}
Also used : ArrayList(java.util.ArrayList) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) MutableLong(org.apache.commons.lang3.mutable.MutableLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) Collector(org.neo4j.internal.batchimport.input.Collector) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) Test(org.junit.Test)

Example 8 with IdMapper

use of org.neo4j.internal.batchimport.cache.idmapping.IdMapper in project neo4j by neo4j.

the class EncodingIdMapperTest method shouldReportyProgressForSortAndDetect.

@Test
public void shouldReportyProgressForSortAndDetect() {
    // GIVEN
    IdMapper idMapper = mapper(new StringEncoder(), Radix.STRING, EncodingIdMapper.NO_MONITOR);
    ProgressListener progress = mock(ProgressListener.class);
    idMapper.prepare(null, mock(Collector.class), progress);
    // WHEN
    long id = idMapper.get("123", Group.GLOBAL);
    // THEN
    assertEquals(IdMapper.ID_NOT_FOUND, id);
    verify(progress, times(3)).started(anyString());
    verify(progress, times(3)).done();
}
Also used : ProgressListener(org.neo4j.internal.helpers.progress.ProgressListener) Collector(org.neo4j.internal.batchimport.input.Collector) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) Test(org.junit.Test)

Example 9 with IdMapper

use of org.neo4j.internal.batchimport.cache.idmapping.IdMapper in project neo4j by neo4j.

the class EncodingIdMapperTest method shouldReportCollisionsForSameInputId.

@Test
public void shouldReportCollisionsForSameInputId() {
    // GIVEN
    IdMapper mapper = mapper(new StringEncoder(), Radix.STRING, EncodingIdMapper.NO_MONITOR);
    PropertyValueLookup values = values("10", "9", "10");
    for (int i = 0; i < 3; i++) {
        mapper.put(values.lookupProperty(i, NULL), i, Group.GLOBAL);
    }
    // WHEN
    Collector collector = mock(Collector.class);
    mapper.prepare(values, collector, NONE);
    // THEN
    verify(collector).collectDuplicateNode("10", 2, Group.GLOBAL.name());
    verifyNoMoreInteractions(collector);
}
Also used : 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 10 with IdMapper

use of org.neo4j.internal.batchimport.cache.idmapping.IdMapper in project neo4j by neo4j.

the class HumanUnderstandableExecutionMonitor method initialize.

@Override
public void initialize(DependencyResolver dependencyResolver) {
    this.dependencyResolver = dependencyResolver;
    Input.Estimates estimates = dependencyResolver.resolveDependency(Input.Estimates.class);
    BatchingNeoStores neoStores = dependencyResolver.resolveDependency(BatchingNeoStores.class);
    IdMapper idMapper = dependencyResolver.resolveDependency(IdMapper.class);
    pageCacheArrayFactoryMonitor = dependencyResolver.resolveDependency(PageCacheArrayFactoryMonitor.class);
    long biggestCacheMemory = estimatedCacheSize(neoStores, NodeRelationshipCache.memoryEstimation(estimates.numberOfNodes()), idMapper.memoryEstimation(estimates.numberOfNodes()));
    System.out.println();
    printStageHeader("Import starting", ESTIMATED_NUMBER_OF_NODES, count(estimates.numberOfNodes()), ESTIMATED_NUMBER_OF_NODE_PROPERTIES, count(estimates.numberOfNodeProperties()), ESTIMATED_NUMBER_OF_RELATIONSHIPS, count(estimates.numberOfRelationships()), ESTIMATED_NUMBER_OF_RELATIONSHIP_PROPERTIES, count(estimates.numberOfRelationshipProperties()), ESTIMATED_DISK_SPACE_USAGE, bytesToString(nodesDiskUsage(estimates, neoStores) + relationshipsDiskUsage(estimates, neoStores) + estimates.sizeOfNodeProperties() + estimates.sizeOfRelationshipProperties()), ESTIMATED_REQUIRED_MEMORY_USAGE, bytesToString(biggestCacheMemory));
    System.out.println();
}
Also used : Input(org.neo4j.internal.batchimport.input.Input) BatchingNeoStores(org.neo4j.internal.batchimport.store.BatchingNeoStores) PageCacheArrayFactoryMonitor(org.neo4j.internal.batchimport.cache.PageCacheArrayFactoryMonitor) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper)

Aggregations

IdMapper (org.neo4j.internal.batchimport.cache.idmapping.IdMapper)21 Test (org.junit.Test)19 Collector (org.neo4j.internal.batchimport.input.Collector)16 PropertyValueLookup (org.neo4j.internal.batchimport.PropertyValueLookup)9 ArrayList (java.util.ArrayList)7 MutableLong (org.apache.commons.lang3.mutable.MutableLong)7 Group (org.neo4j.internal.batchimport.input.Group)7 ProgressListener (org.neo4j.internal.helpers.progress.ProgressListener)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)5 Math.toIntExact (java.lang.Math.toIntExact)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 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 LongFunction (java.util.function.LongFunction)4