### Question:
ImportLogic implements Closeable { static int nextSetOfTypesThatFitInMemory( DataStatistics typeDistribution, int startingFromType, long freeMemoryForDenseNodeCache, long numberOfDenseNodes ) { assert startingFromType >= 0 : startingFromType; long currentSetOfRelationshipsMemoryUsage = 0; int numberOfTypes = typeDistribution.getNumberOfRelationshipTypes(); int toType = startingFromType; for ( ; toType < numberOfTypes; toType++ ) { RelationshipTypeCount type = typeDistribution.get( toType ); long relationshipCountForThisType = type.getCount(); long memoryUsageForThisType = calculateMaxMemoryUsage( numberOfDenseNodes, relationshipCountForThisType ); long memoryUsageUpToAndIncludingThisType = currentSetOfRelationshipsMemoryUsage + memoryUsageForThisType; if ( memoryUsageUpToAndIncludingThisType > freeMemoryForDenseNodeCache && currentSetOfRelationshipsMemoryUsage > 0 ) { break; } currentSetOfRelationshipsMemoryUsage += memoryUsageForThisType; } return toType; } ImportLogic( File storeDir, FileSystemAbstraction fileSystem, BatchingNeoStores neoStore,
            Configuration config, LogService logService, ExecutionMonitor executionMonitor,
            RecordFormats recordFormats, Monitor monitor ); void initialize( Input input ); T getState( Class<T> type ); void putState( T state ); void importNodes(); void prepareIdMapper(); void importRelationships(); void calculateNodeDegrees(); int linkRelationships( int startingFromType ); void linkRelationshipsOfAllTypes(); void defragmentRelationshipGroups(); void buildCountsStore(); void success(); @Override void close(); static BatchingNeoStores instantiateNeoStores( FileSystemAbstraction fileSystem, File storeDir,
            PageCache externalPageCache, RecordFormats recordFormats, Configuration config,
            LogService logService, AdditionalInitialIds additionalInitialIds, Config dbConfig, JobScheduler scheduler ); static final Monitor NO_MONITOR; }### Answer:
@Test public void shouldSplitUpRelationshipTypesInBatches() { int denseNodeThreshold = 5; int numberOfNodes = 100; int numberOfTypes = 10; NodeRelationshipCache cache = new NodeRelationshipCache( NumberArrayFactory.HEAP, denseNodeThreshold ); cache.setNodeCount( numberOfNodes + 1 ); Direction[] directions = Direction.values(); for ( int i = 0; i < numberOfNodes; i++ ) { int count = random.nextInt( 1, denseNodeThreshold * 2 ); cache.setCount( i, count, random.nextInt( numberOfTypes ), random.among( directions ) ); } cache.countingCompleted(); List<RelationshipTypeCount> types = new ArrayList<>(); int numberOfRelationships = 0; for ( int i = 0; i < numberOfTypes; i++ ) { int count = random.nextInt( 1, 100 ); types.add( new RelationshipTypeCount( i, count ) ); numberOfRelationships += count; } types.sort( ( t1, t2 ) -> Long.compare( t2.getCount(), t1.getCount() ) ); DataStatistics typeDistribution = new DataStatistics( 0, 0, types.toArray( new RelationshipTypeCount[types.size()] ) ); { long memory = cache.calculateMaxMemoryUsage( numberOfRelationships ) * numberOfTypes; int upToType = ImportLogic.nextSetOfTypesThatFitInMemory( typeDistribution, 0, memory, cache.getNumberOfDenseNodes() ); assertEquals( types.size(), upToType ); } { long memory = cache.calculateMaxMemoryUsage( numberOfRelationships ) * numberOfTypes / 3; int startingFromType = 0; int rounds = 0; while ( startingFromType < types.size() ) { rounds++; startingFromType = ImportLogic.nextSetOfTypesThatFitInMemory( typeDistribution, startingFromType, memory, cache.getNumberOfDenseNodes() ); } assertEquals( types.size(), startingFromType ); assertThat( rounds, greaterThan( 1 ) ); } }