Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addressed comments and added some IT for the new monitor
- Loading branch information
Showing
7 changed files
with
168 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...java/org/neo4j/unsafe/impl/batchimport/staging/HumanUnderstandableExecutionMonitorIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright (c) 2002-2017 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.unsafe.impl.batchimport.staging; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import java.util.EnumMap; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.neo4j.csv.reader.Extractors; | ||
import org.neo4j.kernel.impl.logging.NullLogService; | ||
import org.neo4j.test.rule.PageCacheAndDependenciesRule; | ||
import org.neo4j.test.rule.RandomRule; | ||
import org.neo4j.test.rule.SuppressOutput; | ||
import org.neo4j.unsafe.impl.batchimport.ParallelBatchImporter; | ||
import org.neo4j.unsafe.impl.batchimport.input.Collector; | ||
import org.neo4j.unsafe.impl.batchimport.input.DataGeneratorInput; | ||
import org.neo4j.unsafe.impl.batchimport.input.Input; | ||
import org.neo4j.unsafe.impl.batchimport.input.SimpleDataGenerator; | ||
import org.neo4j.unsafe.impl.batchimport.input.csv.IdType; | ||
import org.neo4j.unsafe.impl.batchimport.staging.HumanUnderstandableExecutionMonitor.ImportStage; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.fail; | ||
import static org.neo4j.kernel.configuration.Config.defaults; | ||
import static org.neo4j.kernel.impl.store.format.standard.Standard.LATEST_RECORD_FORMATS; | ||
import static org.neo4j.unsafe.impl.batchimport.AdditionalInitialIds.EMPTY; | ||
import static org.neo4j.unsafe.impl.batchimport.Configuration.DEFAULT; | ||
import static org.neo4j.unsafe.impl.batchimport.input.DataGeneratorInput.bareboneNodeHeader; | ||
import static org.neo4j.unsafe.impl.batchimport.input.DataGeneratorInput.bareboneRelationshipHeader; | ||
import static org.neo4j.unsafe.impl.batchimport.input.csv.IdType.INTEGER; | ||
import static org.neo4j.unsafe.impl.batchimport.staging.HumanUnderstandableExecutionMonitor.NO_EXTERNAL_MONITOR; | ||
|
||
public class HumanUnderstandableExecutionMonitorIT | ||
{ | ||
private static final long NODE_COUNT = 1_000; | ||
private static final long RELATIONSHIP_COUNT = 10_000; | ||
|
||
@Rule | ||
public final RandomRule random = new RandomRule(); | ||
|
||
@Rule | ||
public final PageCacheAndDependenciesRule storage = new PageCacheAndDependenciesRule(); | ||
|
||
@Rule | ||
public final SuppressOutput suppressOutput = SuppressOutput.suppressAll(); | ||
|
||
@Test | ||
public void shouldReportProgressOfNodeImport() throws Exception | ||
{ | ||
// given | ||
CapturingMonitor progress = new CapturingMonitor(); | ||
HumanUnderstandableExecutionMonitor monitor = new HumanUnderstandableExecutionMonitor( System.out, progress, NO_EXTERNAL_MONITOR ); | ||
IdType idType = INTEGER; | ||
SimpleDataGenerator generator = new SimpleDataGenerator( bareboneNodeHeader( idType, new Extractors( ';' ) ), | ||
bareboneRelationshipHeader( idType, new Extractors( ';' ) ), random.seed(), NODE_COUNT, 1, 1, idType, 0, 0 ); | ||
Input input = new DataGeneratorInput( NODE_COUNT, RELATIONSHIP_COUNT, generator.nodes(), generator.relationships(), idType, | ||
Collector.EMPTY ); | ||
|
||
// when | ||
new ParallelBatchImporter( storage.directory().absolutePath(), storage.fileSystem(), storage.pageCache(), DEFAULT, | ||
NullLogService.getInstance(), monitor, EMPTY, defaults(), LATEST_RECORD_FORMATS ).doImport( input ); | ||
|
||
// then | ||
progress.assertAllProgressReachedEnd(); | ||
} | ||
|
||
private static class CapturingMonitor implements HumanUnderstandableExecutionMonitor.Monitor | ||
{ | ||
final EnumMap<ImportStage,AtomicInteger> progress = new EnumMap<>( ImportStage.class ); | ||
|
||
@Override | ||
public void progress( ImportStage stage, int percent ) | ||
{ | ||
if ( percent > 100 ) | ||
{ | ||
fail( "Expected percentage to be 0..100% but was " + percent ); | ||
} | ||
|
||
AtomicInteger stageProgress = progress.computeIfAbsent( stage, s -> new AtomicInteger() ); | ||
int previous = stageProgress.getAndSet( percent ); | ||
if ( previous > percent ) | ||
{ | ||
fail( "Progress should go forwards only, but went from " + previous + " to " + percent ); | ||
} | ||
} | ||
|
||
void assertAllProgressReachedEnd() | ||
{ | ||
assertEquals( ImportStage.values().length, progress.size() ); | ||
progress.values().forEach( p -> assertEquals( 100, p.get() ) ); | ||
} | ||
} | ||
} |