From e14374d9a29eeb8348a7379d25586be5ec726b80 Mon Sep 17 00:00:00 2001 From: Mikhaylo Demianenko Date: Mon, 29 Jun 2015 11:58:27 +0200 Subject: [PATCH] Add specific exceptions for import relationships errors, update id for 'ID Spaces' section to be specific instead of generated, rename Mute to SuppressOutput, add possiblity to check output messages in SuppressOutput rule --- .../AdvancedVersionAndEditionServiceIT.java | 6 +- .../src/docs/ops/import-tool.asciidoc | 1 + .../java/org/neo4j/tooling/ImportTool.java | 63 +++++- .../org/neo4j/tooling/ImportToolTest.java | 198 +++++++++++------- .../batchimport/EntityStoreUpdaterStep.java | 4 +- .../batchimport/IdMapperPreparationStage.java | 2 +- .../batchimport/IdMapperPreparationStep.java | 2 +- .../impl/batchimport/PropertyEncoderStep.java | 2 +- .../batchimport/cache/idmapping/IdMapper.java | 23 +- .../idmapping/string/EncodingIdMapper.java | 9 +- .../unsafe/impl/batchimport/input/Groups.java | 1 - .../MissingRelationshipDataException.java | 38 ++++ .../impl/batchimport/input/csv/CsvInput.java | 11 +- .../batchimport/input/csv/DataFactories.java | 4 +- .../input/csv/InputNodeDeserialization.java | 8 +- .../helpers/progress/ProgressMonitorTest.java | 4 +- .../test/{Mute.java => SuppressOutput.java} | 97 ++++++--- .../java/org/neo4j/harness/FixturesTest.java | 4 +- .../neo4j/harness/InProcessBuilderTest.java | 4 +- .../java/org/neo4j/harness/JUnitRuleTest.java | 4 +- .../harness/doc/ExtensionTestingDocTest.java | 4 +- .../org/neo4j/harness/doc/JUnitDocTest.java | 4 +- .../neo4j/server/BaseBootstrapperTest.java | 4 +- .../PropertyFileConfiguratorTest.java | 6 +- .../TestLifecycleManagedDatabase.java | 6 +- .../neo4j/server/modules/DBMSModuleTest.java | 5 +- .../server/preflight/TestPreflightTasks.java | 6 +- .../rest/paging/PagedTraverserDocIT.java | 6 +- .../rest/web/CollectUserAgentFilterTest.java | 6 +- .../org/neo4j/server/rrd/RrdFactoryTest.java | 6 +- .../server/web/JettyThreadLimitTest.java | 6 +- .../neo4j/server/web/TestJetty9WebServer.java | 7 +- ...ommunityVersionAndEditionServiceDocIT.java | 6 +- .../test/server/ExclusiveServerTestBase.java | 9 +- .../test/server/SharedServerTestBase.java | 10 +- .../org/neo4j/backup/BackupServiceIT.java | 8 +- .../EnterpriseVersionAndEditionServiceIT.java | 6 +- 37 files changed, 387 insertions(+), 203 deletions(-) create mode 100644 community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/MissingRelationshipDataException.java rename community/kernel/src/test/java/org/neo4j/test/{Mute.java => SuppressOutput.java} (72%) diff --git a/advanced/server-advanced/src/test/java/org/neo4j/server/webadmin/rest/AdvancedVersionAndEditionServiceIT.java b/advanced/server-advanced/src/test/java/org/neo4j/server/webadmin/rest/AdvancedVersionAndEditionServiceIT.java index ef5703ac9940a..8836366108286 100644 --- a/advanced/server-advanced/src/test/java/org/neo4j/server/webadmin/rest/AdvancedVersionAndEditionServiceIT.java +++ b/advanced/server-advanced/src/test/java/org/neo4j/server/webadmin/rest/AdvancedVersionAndEditionServiceIT.java @@ -43,7 +43,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; -import static org.neo4j.test.Mute.muteAll; +import static org.neo4j.test.SuppressOutput.suppressAll; /* Note that when running this test from within an IDE, the version field will be an empty string. This is because the @@ -78,7 +78,7 @@ public static void setupServer() throws Exception .withClock( clock ) .build(); - muteAll().call( new Callable() + suppressAll().call( new Callable() { @Override public Void call() throws Exception @@ -99,7 +99,7 @@ public void setupTheDatabase() throws Exception @AfterClass public static void stopServer() throws Exception { - muteAll().call( new Callable() + suppressAll().call( new Callable() { @Override public Void call() throws Exception diff --git a/community/import-tool/src/docs/ops/import-tool.asciidoc b/community/import-tool/src/docs/ops/import-tool.asciidoc index e62a5026401a5..97bc19e37bbea 100644 --- a/community/import-tool/src/docs/ops/import-tool.asciidoc +++ b/community/import-tool/src/docs/ops/import-tool.asciidoc @@ -71,6 +71,7 @@ START_ID:: END_ID:: The id of the end node of the relationship to create. +[[import-tool-id-spaces]] === ID Spaces The import tool assumes that node identifiers are unique across node files. diff --git a/community/import-tool/src/main/java/org/neo4j/tooling/ImportTool.java b/community/import-tool/src/main/java/org/neo4j/tooling/ImportTool.java index e421ab7b993bb..91afa24089f6f 100644 --- a/community/import-tool/src/main/java/org/neo4j/tooling/ImportTool.java +++ b/community/import-tool/src/main/java/org/neo4j/tooling/ImportTool.java @@ -53,6 +53,7 @@ import org.neo4j.unsafe.impl.batchimport.input.Input; import org.neo4j.unsafe.impl.batchimport.input.InputNode; import org.neo4j.unsafe.impl.batchimport.input.InputRelationship; +import org.neo4j.unsafe.impl.batchimport.input.MissingRelationshipDataException; import org.neo4j.unsafe.impl.batchimport.input.csv.Configuration; import org.neo4j.unsafe.impl.batchimport.input.csv.CsvInput; import org.neo4j.unsafe.impl.batchimport.input.csv.DataFactory; @@ -60,7 +61,6 @@ import org.neo4j.unsafe.impl.batchimport.staging.ExecutionMonitors; import static java.nio.charset.Charset.defaultCharset; - import static org.neo4j.helpers.Exceptions.launderedException; import static org.neo4j.helpers.Format.bytes; import static org.neo4j.kernel.impl.util.Converters.withDefault; @@ -428,28 +428,38 @@ public int bigFileChannelBufferSizeMultiplier() }; } - private static String manualReference( String page ) + private static String manualReference( ManualPage page, Anchor anchor ) { - return " http://neo4j.com/docs/" + Version.getKernel().getVersion() + "/" + page; + return " http://neo4j.com/docs/" + Version.getKernel().getVersion() + "/" + page.getReference( anchor ); } + + /** * Method name looks strange, but look at how it's used and you'll see why it's named like that. * @param stackTrace whether or not to also print the stack trace of the error. */ private static RuntimeException andPrintError( String typeOfError, Exception e, boolean stackTrace ) { - if ( e.getClass().equals( DuplicateInputIdException.class ) ) + if ( DuplicateInputIdException.class.equals( e.getClass() ) ) { - System.err.println( "Duplicate input ids that would otherwise clash can be put into separate id space," + - " read more about how to use id spaces in the manual:" + - manualReference( "import-tool-header-format.html#_id_spaces" ) ); + System.err.println( "Duplicate input ids that would otherwise clash can be put into separate id space, " + + "read more about how to use id spaces in the manual:" + + manualReference( ManualPage.IMPORT_TOOL_FORMAT, Anchor.ID_SPACES ) ); } - else if ( e.getClass().equals( IllegalMultilineFieldException.class ) ) + else if ( MissingRelationshipDataException.class.equals( e.getClass() ) ) { - System.err.println( "Detected field which spanned multiple lines for an import where " + - Options.MULTILINE_FIELDS.argument() + "=false. If you know that your input data include " + - "fields containing new-line characters then import with this option set to true." ); + System.err.println( String.format( "Relationship missing mandatory field '%s', " + + "read more about relationship format in the manual: %s", + ((MissingRelationshipDataException) e).getFieldType(), + manualReference( ManualPage.IMPORT_TOOL_FORMAT, Anchor.RELATIONSHIP) ) ); + } + else if ( IllegalMultilineFieldException.class.equals( e.getClass() ) ) + { + System.err.println( String.format("Detected field which spanned multiple lines for an import where " + + "%s=false. If you know that your input data include " + + "fields containing new-line characters then import with this option set to true.", + Options.MULTILINE_FIELDS.argument() ) ); } System.err.println( typeOfError + ": " + e.getMessage() ); @@ -645,4 +655,35 @@ static void warn( String warning ) { System.err.println( warning ); } + + private enum ManualPage + { + IMPORT_TOOL_FORMAT("import-tool-header-format.html"); + + private String page; + + ManualPage( String page ) + { + this.page = page; + } + + public String getReference(Anchor anchor) + { + return page + "#" + anchor.anchor; + } + } + + private enum Anchor + { + ID_SPACES("import-tool-id-spaces"), + RELATIONSHIP("import-tool-header-format-rels"); + + private String anchor; + + Anchor( String anchor ) + { + this.anchor = anchor; + } + } + } diff --git a/community/import-tool/src/test/java/org/neo4j/tooling/ImportToolTest.java b/community/import-tool/src/test/java/org/neo4j/tooling/ImportToolTest.java index 9bc848013d823..76279e8646c54 100644 --- a/community/import-tool/src/test/java/org/neo4j/tooling/ImportToolTest.java +++ b/community/import-tool/src/test/java/org/neo4j/tooling/ImportToolTest.java @@ -36,26 +36,31 @@ import org.neo4j.csv.reader.IllegalMultilineFieldException; import org.neo4j.function.IntPredicate; +import org.neo4j.function.Predicate; import org.neo4j.graphdb.DynamicLabel; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Label; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Transaction; -import org.neo4j.helpers.Predicate; import org.neo4j.helpers.collection.FilteringIterator; +import org.neo4j.helpers.collection.IteratorUtil; import org.neo4j.helpers.collection.PrefetchingIterator; import org.neo4j.io.fs.FileUtils; +import org.neo4j.kernel.Version; import org.neo4j.kernel.impl.util.Validator; import org.neo4j.kernel.impl.util.Validators; import org.neo4j.test.EmbeddedDatabaseRule; -import org.neo4j.test.Mute; import org.neo4j.test.RandomRule; +import org.neo4j.test.SuppressOutput; import org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.DuplicateInputIdException; import org.neo4j.unsafe.impl.batchimport.input.InputException; import org.neo4j.unsafe.impl.batchimport.input.csv.Configuration; import org.neo4j.unsafe.impl.batchimport.input.csv.Type; +import static java.lang.String.format; +import static java.lang.System.currentTimeMillis; +import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -63,11 +68,6 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; - -import static java.lang.String.format; -import static java.lang.System.currentTimeMillis; -import static java.util.Arrays.asList; - import static org.neo4j.function.IntPredicates.alwaysTrue; import static org.neo4j.graphdb.DynamicLabel.label; import static org.neo4j.graphdb.DynamicRelationshipType.withName; @@ -91,8 +91,8 @@ public void shouldImportWithAsManyDefaultsAsAvailable() throws Exception // WHEN importTool( - "--into", dbRule.getStoreDir().getAbsolutePath(), - "--nodes", nodeData( true, config, nodeIds, alwaysTrue() ).getAbsolutePath(), + "--into", dbRule.getStoreDir().getAbsolutePath(), + "--nodes", nodeData( true, config, nodeIds, alwaysTrue() ).getAbsolutePath(), "--relationships", relationshipData( true, config, nodeIds, alwaysTrue(), true ).getAbsolutePath() ); // THEN @@ -112,11 +112,11 @@ public void shouldImportWithHeadersBeingInSeparateFiles() throws Exception "--delimiter", "TAB", "--array-delimiter", String.valueOf( config.arrayDelimiter() ), "--nodes", - nodeHeader( config ).getAbsolutePath() + MULTI_FILE_DELIMITER + - nodeData( false, config, nodeIds, alwaysTrue() ).getAbsolutePath(), + nodeHeader( config ).getAbsolutePath() + MULTI_FILE_DELIMITER + + nodeData( false, config, nodeIds, alwaysTrue() ).getAbsolutePath(), "--relationships", - relationshipHeader( config ).getAbsolutePath() + MULTI_FILE_DELIMITER + - relationshipData( false, config, nodeIds, alwaysTrue(), true ).getAbsolutePath() ); + relationshipHeader( config ).getAbsolutePath() + MULTI_FILE_DELIMITER + + relationshipData( false, config, nodeIds, alwaysTrue(), true ).getAbsolutePath() ); // THEN verifyData(); @@ -133,15 +133,15 @@ public void shouldImportSplitInputFiles() throws Exception importTool( "--into", dbRule.getStoreDir().getAbsolutePath(), "--nodes", // One group with one header file and one data file - nodeHeader( config ).getAbsolutePath() + MULTI_FILE_DELIMITER + - nodeData( false, config, nodeIds, lines( 0, NODE_COUNT/2 ) ).getAbsolutePath(), + nodeHeader( config ).getAbsolutePath() + MULTI_FILE_DELIMITER + + nodeData( false, config, nodeIds, lines( 0, NODE_COUNT / 2 ) ).getAbsolutePath(), "--nodes", // One group with two data files, where the header sits in the first file - nodeData( true, config, nodeIds, - lines( NODE_COUNT / 2, NODE_COUNT * 3 / 4 ) ).getAbsolutePath() + MULTI_FILE_DELIMITER + - nodeData( false, config, nodeIds, lines( NODE_COUNT * 3 / 4, NODE_COUNT ) ).getAbsolutePath(), + nodeData( true, config, nodeIds, + lines( NODE_COUNT / 2, NODE_COUNT * 3 / 4 ) ).getAbsolutePath() + MULTI_FILE_DELIMITER + + nodeData( false, config, nodeIds, lines( NODE_COUNT * 3 / 4, NODE_COUNT ) ).getAbsolutePath(), "--relationships", - relationshipHeader( config ).getAbsolutePath() + MULTI_FILE_DELIMITER + - relationshipData( false, config, nodeIds, alwaysTrue(), true ).getAbsolutePath() ); + relationshipHeader( config ).getAbsolutePath() + MULTI_FILE_DELIMITER + + relationshipData( false, config, nodeIds, alwaysTrue(), true ).getAbsolutePath() ); // THEN verifyData(); @@ -153,8 +153,8 @@ public void shouldImportMultipleInputsWithAddedLabelsAndDefaultRelationshipType( // GIVEN List nodeIds = nodeIds(); Configuration config = Configuration.COMMAS; - final String[] firstLabels = { "AddedOne", "AddedTwo" }; - final String[] secondLabels = { "AddedThree" }; + final String[] firstLabels = {"AddedOne", "AddedTwo"}; + final String[] secondLabels = {"AddedThree"}; final String firstType = "TYPE_1"; final String secondType = "TYPE_2"; @@ -162,14 +162,14 @@ public void shouldImportMultipleInputsWithAddedLabelsAndDefaultRelationshipType( importTool( "--into", dbRule.getStoreDir().getAbsolutePath(), "--nodes:" + join( firstLabels, ":" ), - nodeData( true, config, nodeIds, lines( 0, NODE_COUNT/2 ) ).getAbsolutePath(), + nodeData( true, config, nodeIds, lines( 0, NODE_COUNT / 2 ) ).getAbsolutePath(), "--nodes:" + join( secondLabels, ":" ), - nodeData( true, config, nodeIds, lines( NODE_COUNT/2, NODE_COUNT ) ).getAbsolutePath(), + nodeData( true, config, nodeIds, lines( NODE_COUNT / 2, NODE_COUNT ) ).getAbsolutePath(), "--relationships:" + firstType, - relationshipData( true, config, nodeIds, lines( 0, RELATIONSHIP_COUNT/2 ), false ).getAbsolutePath(), + relationshipData( true, config, nodeIds, lines( 0, RELATIONSHIP_COUNT / 2 ), false ).getAbsolutePath(), "--relationships:" + secondType, - relationshipData( true, config, nodeIds, - lines( RELATIONSHIP_COUNT/2, RELATIONSHIP_COUNT ), false ).getAbsolutePath() ); + relationshipData( true, config, nodeIds, + lines( RELATIONSHIP_COUNT / 2, RELATIONSHIP_COUNT ), false ).getAbsolutePath() ); // THEN verifyData( @@ -178,7 +178,7 @@ public void shouldImportMultipleInputsWithAddedLabelsAndDefaultRelationshipType( @Override public void validate( Node node ) { - if ( node.getId() < NODE_COUNT/2 ) + if ( node.getId() < NODE_COUNT / 2 ) { assertNodeHasLabels( node, firstLabels ); } @@ -193,7 +193,7 @@ public void validate( Node node ) @Override public void validate( Relationship relationship ) { - if ( relationship.getId() < RELATIONSHIP_COUNT/2 ) + if ( relationship.getId() < RELATIONSHIP_COUNT / 2 ) { assertEquals( firstType, relationship.getType().name() ); } @@ -214,9 +214,9 @@ public void shouldImportOnlyNodes() throws Exception // WHEN importTool( - "--into", dbRule.getStoreDir().getAbsolutePath(), - "--nodes", nodeData( true, config, nodeIds, alwaysTrue() ).getAbsolutePath() ); - // no relationships + "--into", dbRule.getStoreDir().getAbsolutePath(), + "--nodes", nodeData( true, config, nodeIds, alwaysTrue() ).getAbsolutePath() ); + // no relationships // THEN GraphDatabaseService db = dbRule.getGraphDatabaseService(); @@ -250,7 +250,7 @@ public void shouldImportGroupsOfOverlappingIds() throws Exception // WHEN importTool( - "--into", dbRule.getStoreDir().getAbsolutePath(), + "--into", dbRule.getStoreDir().getAbsolutePath(), "--nodes", nodeHeader( config, groupOne ) + MULTI_FILE_DELIMITER + nodeData( false, config, groupOneNodeIds, alwaysTrue() ), "--nodes", nodeHeader( config, groupTwo ) + MULTI_FILE_DELIMITER + @@ -286,11 +286,11 @@ public void shouldNotBeAbleToMixSpecifiedAndUnspecifiedGroups() throws Exception try { importTool( - "--into", dbRule.getStoreDir().getAbsolutePath(), - "--nodes", nodeHeader( config, "MyGroup" ).getAbsolutePath() + MULTI_FILE_DELIMITER + - nodeData( false, config, groupOneNodeIds, alwaysTrue() ).getAbsolutePath(), - "--nodes", nodeHeader( config ).getAbsolutePath() + MULTI_FILE_DELIMITER + - nodeData( false, config, groupTwoNodeIds, alwaysTrue() ).getAbsolutePath() ); + "--into", dbRule.getStoreDir().getAbsolutePath(), + "--nodes", nodeHeader( config, "MyGroup" ).getAbsolutePath() + MULTI_FILE_DELIMITER + + nodeData( false, config, groupOneNodeIds, alwaysTrue() ).getAbsolutePath(), + "--nodes", nodeHeader( config ).getAbsolutePath() + MULTI_FILE_DELIMITER + + nodeData( false, config, groupTwoNodeIds, alwaysTrue() ).getAbsolutePath() ); fail( "Should have failed" ); } catch ( Exception e ) @@ -309,11 +309,11 @@ public void shouldImportWithoutTypeSpecifiedInRelationshipHeaderbutWithDefaultTy // WHEN importTool( - "--into", dbRule.getStoreDir().getAbsolutePath(), - "--nodes", nodeData( true, config, nodeIds, alwaysTrue() ).getAbsolutePath(), - // there will be no :TYPE specified in the header of the relationships below + "--into", dbRule.getStoreDir().getAbsolutePath(), + "--nodes", nodeData( true, config, nodeIds, alwaysTrue() ).getAbsolutePath(), + // there will be no :TYPE specified in the header of the relationships below "--relationships:" + type, - relationshipData( true, config, nodeIds, alwaysTrue(), false ).getAbsolutePath() ); + relationshipData( true, config, nodeIds, alwaysTrue(), false ).getAbsolutePath() ); // THEN verifyData(); @@ -333,7 +333,7 @@ public void shouldIncludeSourceInformationInNodeIdCollisionError() throws Except try { importTool( - "--into", dbRule.getStoreDir().getAbsolutePath(), + "--into", dbRule.getStoreDir().getAbsolutePath(), "--nodes", nodeHeaderFile.getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData1.getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData2.getAbsolutePath() ); @@ -359,11 +359,11 @@ public void shouldSkipDuplicateNodesIfToldTo() throws Exception // WHEN importTool( - "--into", dbRule.getStoreDir().getAbsolutePath(), + "--into", dbRule.getStoreDir().getAbsolutePath(), "--skip-duplicate-nodes", "--nodes", nodeHeaderFile.getAbsolutePath() + MULTI_FILE_DELIMITER + - nodeData1.getAbsolutePath() + MULTI_FILE_DELIMITER + - nodeData2.getAbsolutePath() ); + nodeData1.getAbsolutePath() + MULTI_FILE_DELIMITER + + nodeData2.getAbsolutePath() ); // THEN GraphDatabaseService db = dbRule.getGraphDatabaseService(); @@ -405,9 +405,9 @@ public void shouldLogRelationshipsReferingToMissingNode() throws Exception // WHEN importing data where some relationships refer to missing nodes importTool( - "--into", dbRule.getStoreDir().getAbsolutePath(), - "--nodes", nodeData.getAbsolutePath(), - "--bad", bad.getAbsolutePath(), + "--into", dbRule.getStoreDir().getAbsolutePath(), + "--nodes", nodeData.getAbsolutePath(), + "--bad", bad.getAbsolutePath(), "--bad-tolerance", "2", "--relationships", relationshipData1.getAbsolutePath() + MULTI_FILE_DELIMITER + relationshipData2.getAbsolutePath() ); @@ -443,12 +443,12 @@ public void shouldFailIfTooManyBadRelationships() throws Exception try { importTool( - "--into", dbRule.getStoreDir().getAbsolutePath(), - "--nodes", nodeData.getAbsolutePath(), - "--bad", bad.getAbsolutePath(), + "--into", dbRule.getStoreDir().getAbsolutePath(), + "--nodes", nodeData.getAbsolutePath(), + "--bad", bad.getAbsolutePath(), "--bad-tolerance", "1", "--relationships", relationshipData1.getAbsolutePath() + MULTI_FILE_DELIMITER + - relationshipData2.getAbsolutePath() ) ; + relationshipData2.getAbsolutePath() ); } catch ( Exception e ) { @@ -478,12 +478,12 @@ public void shouldBeAbleToDisableSkippingOfBadRelationships() throws Exception try { importTool( - "--into", dbRule.getStoreDir().getAbsolutePath(), - "--nodes", nodeData.getAbsolutePath(), - "--bad", bad.getAbsolutePath(), + "--into", dbRule.getStoreDir().getAbsolutePath(), + "--nodes", nodeData.getAbsolutePath(), + "--bad", bad.getAbsolutePath(), "--skip-bad-relationships", "false", "--relationships", relationshipData1.getAbsolutePath() + MULTI_FILE_DELIMITER + - relationshipData2.getAbsolutePath() ) ; + relationshipData2.getAbsolutePath() ); } catch ( Exception e ) { @@ -505,7 +505,7 @@ public void shouldHandleAdditiveLabelsWithSpaces() throws Exception importTool( "--into", dbRule.getStoreDir().getAbsolutePath(), "--nodes:My First Label:My Other Label", - nodeData( true, config, nodeIds, alwaysTrue() ).getAbsolutePath(), + nodeData( true, config, nodeIds, alwaysTrue() ).getAbsolutePath(), "--relationships", relationshipData( true, config, nodeIds, alwaysTrue(), true ).getAbsolutePath() ); // THEN @@ -530,11 +530,11 @@ public void shouldImportFromInputDataEncodedWithSpecificCharset() throws Excepti // WHEN importTool( - "--into", dbRule.getStoreDir().getAbsolutePath(), + "--into", dbRule.getStoreDir().getAbsolutePath(), "--input-encoding", charset.name(), - "--nodes", nodeData( true, config, nodeIds, alwaysTrue(), charset ).getAbsolutePath(), - "--relationships", relationshipData( true, config, nodeIds, alwaysTrue(), true, charset ) - .getAbsolutePath() ); + "--nodes", nodeData( true, config, nodeIds, alwaysTrue(), charset ).getAbsolutePath(), + "--relationships", relationshipData( true, config, nodeIds, alwaysTrue(), true, charset ) + .getAbsolutePath() ); // THEN verifyData(); @@ -552,7 +552,8 @@ public void shouldDisallowImportWithoutNodesInput() throws Exception { importTool( "--into", dbRule.getStoreDir().getAbsolutePath(), - "--relationships", relationshipData( true, config, nodeIds, alwaysTrue(), true ).getAbsolutePath() ); + "--relationships", + relationshipData( true, config, nodeIds, alwaysTrue(), true ).getAbsolutePath() ); fail( "Should have failed" ); } catch ( IllegalArgumentException e ) @@ -572,10 +573,10 @@ public void shouldBeAbleToImportAnonymousNodes() throws Exception // WHEN importTool( - "--into", dbRule.getStoreDir().getAbsolutePath(), - "--nodes", nodeData( true, config, nodeIds, alwaysTrue() ).getAbsolutePath(), + "--into", dbRule.getStoreDir().getAbsolutePath(), + "--nodes", nodeData( true, config, nodeIds, alwaysTrue() ).getAbsolutePath(), "--relationships", relationshipData( true, config, relationshipData.iterator(), - alwaysTrue(), true ).getAbsolutePath() ); + alwaysTrue(), true ).getAbsolutePath() ); // THEN GraphDatabaseService db = dbRule.getGraphDatabaseService(); @@ -609,7 +610,7 @@ public void shouldDisallowMultilineFieldsByDefault() throws Exception try { importTool( - "--into", dbRule.getStoreDir().getAbsolutePath(), + "--into", dbRule.getStoreDir().getAbsolutePath(), "--nodes", data.getAbsolutePath() ); } catch ( Exception e ) @@ -619,6 +620,53 @@ public void shouldDisallowMultilineFieldsByDefault() throws Exception } } + + @Test + public void shouldPrintReferenceLinkOnDataImportErrors() throws Exception + { + shouldPrintReferenceLinkAsPartOfErrorMessage(nodeIds(), + IteratorUtil.iterator( new RelationshipDataLine( "1", "", "type", "name" ) ), + "Relationship missing mandatory field 'END_ID', read more about relationship " + + "format in the manual: http://neo4j.com/docs/" + Version.getKernelVersion() + + "/import-tool-header-format.html#import-tool-header-format-rels" ); + shouldPrintReferenceLinkAsPartOfErrorMessage( nodeIds(), + IteratorUtil.iterator( new RelationshipDataLine( "", "1", "type", "name" ) ), + "Relationship missing mandatory field 'START_ID', read more" + + " about relationship format in the manual: http://neo4j.com/docs/" + Version.getKernelVersion() + + "/import-tool-header-format.html#import-tool-header-format-rels" ); + shouldPrintReferenceLinkAsPartOfErrorMessage( nodeIds(), + IteratorUtil.iterator( new RelationshipDataLine( "1", "2", "", "name" ) ), + "Relationship missing mandatory field 'TYPE', read more about relationship " + + "format in the manual: http://neo4j.com/docs/" + Version.getKernelVersion() + + "/import-tool-header-format.html#import-tool-header-format-rels" ); + shouldPrintReferenceLinkAsPartOfErrorMessage( Arrays.asList( "1", "1" ), + IteratorUtil.iterator( new RelationshipDataLine( "1", "2", "type", "name" ) ), + "Duplicate input ids that would otherwise clash can be put into separate id space, read more " + + "about how to use id spaces in the manual: http://neo4j.com/docs/" + Version.getKernelVersion() + + "/import-tool-header-format.html#import-tool-id-spaces" ); + } + + private void shouldPrintReferenceLinkAsPartOfErrorMessage( List nodeIds, + Iterator relationshipDataLines, String message ) throws Exception + { + Configuration config = Configuration.COMMAS; + try + { + // WHEN + importTool( + "--into", dbRule.getStoreDir().getAbsolutePath(), + "--nodes", nodeData( true, config, nodeIds, alwaysTrue() ).getAbsolutePath(), + "--relationships", relationshipData( true, config, relationshipDataLines, + alwaysTrue(), true ).getAbsolutePath() ); + fail( " Should fail during import." ); + } + catch ( Exception e ) + { + // EXPECT + assertTrue( suppressOutput.getErrorVoice().containsMessage( message ) ); + } + } + private File data( String... lines ) throws Exception { File file = file( fileName( "data.csv" ) ); @@ -637,7 +685,7 @@ private Predicate nodeFilter( final String id ) return new Predicate() { @Override - public boolean accept( Node node ) + public boolean test( Node node ) { return node.getProperty( "id", "" ).equals( id ); } @@ -710,7 +758,7 @@ private Relationship findRelationship( Node startNode, final Node endNode, final return singleOrNull( filter( new Predicate() { @Override - public boolean accept( Relationship item ) + public boolean test( Relationship item ) { return item.getEndNode().equals( endNode ) && item.getProperty( "name" ).equals( relationship.name ); } @@ -757,13 +805,13 @@ private String randomNodeId() } private File nodeData( boolean includeHeader, Configuration config, List nodeIds, - IntPredicate linePredicate ) throws Exception + IntPredicate linePredicate ) throws Exception { return nodeData( includeHeader, config, nodeIds, linePredicate, Charset.defaultCharset() ); } private File nodeData( boolean includeHeader, Configuration config, List nodeIds, - IntPredicate linePredicate, Charset encoding ) throws Exception + IntPredicate linePredicate, Charset encoding ) throws Exception { File file = file( fileName( "nodes.csv" ) ); try ( PrintStream writer = writer( file, encoding ) ) @@ -814,7 +862,7 @@ private String idEntry( String name, Type type, String idGroup ) } private void writeNodeData( PrintStream writer, Configuration config, List nodeIds, - IntPredicate linePredicate ) + IntPredicate linePredicate ) { char delimiter = config.delimiter(); char arrayDelimiter = config.arrayDelimiter(); @@ -1048,7 +1096,9 @@ private void importTool( String... arguments ) throws IOException @Rule public final EmbeddedDatabaseRule dbRule = new EmbeddedDatabaseRule( getClass() ); - public final @Rule RandomRule random = new RandomRule(); - public final @Rule Mute mute = Mute.mute( Mute.System.values() ); + @Rule + public final RandomRule random = new RandomRule(); + @Rule + public final SuppressOutput suppressOutput = SuppressOutput.suppress( SuppressOutput.System.values() ); private int dataIndex; } diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/EntityStoreUpdaterStep.java b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/EntityStoreUpdaterStep.java index bac11a9c549a3..35d454403e10d 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/EntityStoreUpdaterStep.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/EntityStoreUpdaterStep.java @@ -42,8 +42,8 @@ import static java.lang.Math.max; /** - * Writes {@link RecordBatch entity batches} to the underlying stores. Also makes final composition of the - * {@link BatchEntity entities} before writing, such as clumping up {@link PropertyBlock properties} into + * Writes {@link Batch entity batches} to the underlying stores. Also makes final composition of the + * {@link Batch entities} before writing, such as clumping up {@link PropertyBlock properties} into * {@link PropertyRecord property records}. * * @param type of entities. diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/IdMapperPreparationStage.java b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/IdMapperPreparationStage.java index ea0f74eb50601..84a4cc536d16b 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/IdMapperPreparationStage.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/IdMapperPreparationStage.java @@ -29,7 +29,7 @@ import static org.neo4j.unsafe.impl.batchimport.Utils.idsOf; /** - * Performs {@link IdMapper#prepare(InputIterable, org.neo4j.helpers.progress.ProgressListener)} + * Performs {@link IdMapper#prepare(InputIterable, Collector, org.neo4j.helpers.progress.ProgressListener)} * embedded in a {@link Stage} as to take advantage of statistics and monitoring provided by that framework. */ public class IdMapperPreparationStage extends Stage diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/IdMapperPreparationStep.java b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/IdMapperPreparationStep.java index 72103ab88be62..186f2b5f74eb0 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/IdMapperPreparationStep.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/IdMapperPreparationStep.java @@ -28,7 +28,7 @@ import org.neo4j.unsafe.impl.batchimport.stats.StatsProvider; /** - * Preparation of an {@link IdMapper}, {@link IdMapper#prepare(InputIterable, ProgressListener)} + * Preparation of an {@link IdMapper}, {@link IdMapper#prepare(InputIterable, Collector, ProgressListener)} * under running as a normal {@link Step} so that normal execution monitoring can be applied. * Useful since preparing an {@link IdMapper} can take a significant amount of time. */ diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/PropertyEncoderStep.java b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/PropertyEncoderStep.java index a68c4aabacf27..1c919e664df9c 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/PropertyEncoderStep.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/PropertyEncoderStep.java @@ -36,7 +36,7 @@ /** * Encodes property data into {@link PropertyBlock property blocks}, attaching them to each - * {@link BatchEntity}. This step is designed to handle multiple threads doing the property encoding, + * {@link Batch}. This step is designed to handle multiple threads doing the property encoding, * since property encoding is potentially the most costly step in this {@link Stage}. */ public class PropertyEncoderStep diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/cache/idmapping/IdMapper.java b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/cache/idmapping/IdMapper.java index 6e84df3102ee8..7fe4d5bc8b7f1 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/cache/idmapping/IdMapper.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/cache/idmapping/IdMapper.java @@ -19,7 +19,6 @@ */ package org.neo4j.unsafe.impl.batchimport.cache.idmapping; -import org.neo4j.function.IntPredicate; import org.neo4j.helpers.progress.ProgressListener; import org.neo4j.unsafe.impl.batchimport.InputIterable; import org.neo4j.unsafe.impl.batchimport.cache.MemoryStatsVisitor; @@ -40,24 +39,24 @@ public interface IdMapper extends MemoryStatsVisitor.Home * @param actualId the actual node id that the inputId will represent. * @param group {@link Group} this input id will be added to. Used for handling input ids collisions * where multiple equal input ids might be added, as long as all input ids within a single group is unique. - * Group ids are also passed into {@link #get(Object, IntPredicate)}. + * Group ids are also passed into {@link #get(Object, Group)}. * It is required that all input ids belonging to a specific group are put in sequence before putting any * input ids for another group. */ void put( Object inputId, long actualId, Group group ); /** - * @return whether or not a call to {@link #prepare()} needs to commence after all calls to - * {@link #put(Object, long)} and before any call to {@link #get(Object)}. I.e. whether or not all ids - * needs to be put before making any call to {@link #get(Object)}. + * @return whether or not a call to {@link #prepare(InputIterable, Collector, ProgressListener)} needs to commence after all calls to + * {@link #put(Object, long, Group)} and before any call to {@link #get(Object, Group)}. I.e. whether or not all ids + * needs to be put before making any call to {@link #get(Object, Group)}. */ boolean needsPreparation(); /** - * After all mappings have been {@link #put(Object, long)} call this method to prepare for - * {@link #get(Object) querying}. + * After all mappings have been {@link #put(Object, long, Group)} call this method to prepare for + * {@link #get(Object, Group) querying}. * - * @param all ids put earlier, in the event of difficult collisions so that more information have to be read + * @param allIds put earlier, in the event of difficult collisions so that more information have to be read * from the input data again, data that normally isn't necessary and hence discarded. * @param collector {@link Collector} for bad entries, such as duplicate node ids. * @param progress reports preparation progress. @@ -65,14 +64,14 @@ public interface IdMapper extends MemoryStatsVisitor.Home void prepare( InputIterable allIds, Collector collector, ProgressListener progress ); /** - * Returns an actual node id representing {@code inputId}. For this call to work {@link #prepare()} must have - * been called after all calls to {@link #put(Object, long)} have been made, - * iff {@link #needsPreparation()} returns {@code true}. Otherwise ids can be retrieved right after + * Returns an actual node id representing {@code inputId}. For this call to work {@link #prepare(InputIterable, Collector, ProgressListener)} must have + * been called after all calls to {@link #put(Object, long, Group)} have been made, + * if {@link #needsPreparation()} returns {@code true}. Otherwise ids can be retrieved right after * @link #put(Object, long) being put} * * @param inputId the input id to get the actual node id for. * @param group {@link Group} the given {@code inputId} must exist in, i.e. have been put with. - * @return the actual node id previously specified by {@link #put(Object, long)}, or {@code -1} if not found. + * @return the actual node id previously specified by {@link #put(Object, long, Group)}, or {@code -1} if not found. */ long get( Object inputId, Group group ); } diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/cache/idmapping/string/EncodingIdMapper.java b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/cache/idmapping/string/EncodingIdMapper.java index 28353b0cb57fd..04681d5f64930 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/cache/idmapping/string/EncodingIdMapper.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/cache/idmapping/string/EncodingIdMapper.java @@ -50,12 +50,13 @@ import static org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.SourceInformation.encodeSourceInformation; /** - * Maps arbitrary values to long ids. The values can be {@link #put(Object, long) added} in any order, - * but {@link #needsPreparation() needs} {@link #prepare() preparation} in order to {@link #get(Object) get} + * Maps arbitrary values to long ids. The values can be {@link #put(Object, long, Group) added} in any order, + * but {@link #needsPreparation() needs} {@link #prepare(InputIterable, Collector, ProgressListener) preparation} + * in order to {@link #get(Object, Group) get} * ids back later. * - * In the {@link #prepare() preparation phase} the added entries are sorted according to a number representation - * of each input value and {@link #get(Object)} does simple binary search to find the correct one. + * In the {@link #prepare(InputIterable, Collector, ProgressListener) preparation phase} the added entries are sorted according to a number representation + * of each input value and {@link #get(Object, Group)} does simple binary search to find the correct one. * * The implementation is space-efficient, much more so than using, say, a {@link HashMap}. * diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/Groups.java b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/Groups.java index 8bfb7f607f3fb..7473fa3d823dd 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/Groups.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/Groups.java @@ -33,7 +33,6 @@ public class Groups /** * @param name group name or {@code null} for a {@link Group#GLOBAL global group}. - * @param part name of the group, see {@link Group#partId()} * @return {@link Group} for the given name. If the group doesn't already exist it will be created * with a new id. If {@code name} is {@code null} then the {@link Group#GLOBAL global group} is returned. * This method also prevents mixing global and non-global groups, i.e. if first call is {@code null}, diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/MissingRelationshipDataException.java b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/MissingRelationshipDataException.java new file mode 100644 index 0000000000000..45b158ccaed88 --- /dev/null +++ b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/MissingRelationshipDataException.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2002-2015 "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 . + */ +package org.neo4j.unsafe.impl.batchimport.input; + +import org.neo4j.unsafe.impl.batchimport.input.csv.Type; + +public class MissingRelationshipDataException extends DataException +{ + private Type fieldType; + + public MissingRelationshipDataException(Type missedField, String message ) + { + super( message ); + this.fieldType = missedField; + } + + public Type getFieldType() + { + return fieldType; + } +} diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/csv/CsvInput.java b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/csv/CsvInput.java index cc4bb7dcc259a..ebfb3aeefb49c 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/csv/CsvInput.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/csv/CsvInput.java @@ -32,11 +32,11 @@ import org.neo4j.unsafe.impl.batchimport.cache.idmapping.IdGenerator; import org.neo4j.unsafe.impl.batchimport.cache.idmapping.IdMapper; import org.neo4j.unsafe.impl.batchimport.input.Collector; -import org.neo4j.unsafe.impl.batchimport.input.DataException; import org.neo4j.unsafe.impl.batchimport.input.Groups; import org.neo4j.unsafe.impl.batchimport.input.Input; import org.neo4j.unsafe.impl.batchimport.input.InputNode; import org.neo4j.unsafe.impl.batchimport.input.InputRelationship; +import org.neo4j.unsafe.impl.batchimport.input.MissingRelationshipDataException; /** * Provides {@link Input} from data contained in tabular/csv form. Expects factories for instantiating @@ -154,15 +154,18 @@ public void validate( InputRelationship entity ) { if ( entity.startNode() == null ) { - throw new DataException( entity + " is missing " + Type.START_ID + " field" ); + throw new MissingRelationshipDataException(Type.START_ID, + entity + " is missing " + Type.START_ID + " field" ); } if ( entity.endNode() == null ) { - throw new DataException( entity + " is missing " + Type.END_ID + " field" ); + throw new MissingRelationshipDataException(Type.END_ID, + entity + " is missing " + Type.END_ID + " field" ); } if ( !entity.hasTypeId() && entity.type() == null ) { - throw new DataException( entity + " is missing " + Type.TYPE + " field" ); + throw new MissingRelationshipDataException(Type.TYPE, + entity + " is missing " + Type.TYPE + " field" ); } } } ); diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/csv/DataFactories.java b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/csv/DataFactories.java index ad664f284eeaa..da09d38eb1f95 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/csv/DataFactories.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/csv/DataFactories.java @@ -186,8 +186,8 @@ private interface HeaderCharSeekerFactory CharSeeker open( CharSeeker seeker, Configuration config ) throws IOException; /** - * Closes the header {@link CharSeeker}. Only close if {@link #openCharSeeker(CharSeeker)} opens its own. - * @param seeker {@link CharSeeker} returned from {@link #openCharSeeker(CharSeeker)}. + * Closes the header {@link CharSeeker}. Only close if {@link #open(CharSeeker, Configuration)} opens its own. + * @param seeker {@link CharSeeker} returned from {@link #open(CharSeeker, Configuration)}. */ void close( CharSeeker seeker ); } diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/csv/InputNodeDeserialization.java b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/csv/InputNodeDeserialization.java index 8789cee6cb568..eefd5e1082453 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/csv/InputNodeDeserialization.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/input/csv/InputNodeDeserialization.java @@ -73,7 +73,7 @@ public void handle( Entry entry, Object value ) id = value; break; case LABEL: - addLabels( entry, value ); + addLabels( value ); break; default: super.handle( entry, value ); @@ -105,17 +105,17 @@ private void ensureLabelsCapacity( int length ) } } - private void addLabels( Entry entry, Object value ) + private void addLabels( Object value ) { if ( value instanceof String ) { - ensureLabelsCapacity( labelsCursor+1 ); + ensureLabelsCapacity( labelsCursor + 1 ); labels[labelsCursor++] = (String) value; } else if ( value instanceof String[] ) { String[] labelsToAdd = (String[]) value; - ensureLabelsCapacity( labelsCursor+labelsToAdd.length ); + ensureLabelsCapacity( labelsCursor + labelsToAdd.length ); for ( String label : (String[]) value ) { labels[labelsCursor++] = label; diff --git a/community/kernel/src/test/java/org/neo4j/helpers/progress/ProgressMonitorTest.java b/community/kernel/src/test/java/org/neo4j/helpers/progress/ProgressMonitorTest.java index ed217e32936b1..9c30107752e83 100644 --- a/community/kernel/src/test/java/org/neo4j/helpers/progress/ProgressMonitorTest.java +++ b/community/kernel/src/test/java/org/neo4j/helpers/progress/ProgressMonitorTest.java @@ -40,7 +40,7 @@ import java.util.concurrent.TimeoutException; import org.neo4j.helpers.ProcessFailureException; -import org.neo4j.test.Mute; +import org.neo4j.test.SuppressOutput; import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertEquals; @@ -604,7 +604,7 @@ public void shouldReportOpenEndedProgressInANiceWay() throws Exception @Rule public final TestName testName = new TestName(); @Rule - public Mute mute = Mute.muteAll(); + public SuppressOutput suppressOutput = SuppressOutput.suppressAll(); @Rule public final SingleIndicator factory = new SingleIndicator(); diff --git a/community/kernel/src/test/java/org/neo4j/test/Mute.java b/community/kernel/src/test/java/org/neo4j/test/SuppressOutput.java similarity index 72% rename from community/kernel/src/test/java/org/neo4j/test/Mute.java rename to community/kernel/src/test/java/org/neo4j/test/SuppressOutput.java index c0ca9faa81e0a..fc40bf02319df 100644 --- a/community/kernel/src/test/java/org/neo4j/test/Mute.java +++ b/community/kernel/src/test/java/org/neo4j/test/SuppressOutput.java @@ -38,25 +38,25 @@ import java.util.logging.StreamHandler; /** - * Mutes outputs such as System.out, System.err and java.util.logging for example when running a test. + * Suppresses outputs such as System.out, System.err and java.util.logging for example when running a test. * It's also a {@link TestRule} which makes it fit in nicely in JUnit. * - * The muting occurs visitor-style and if there's an exception in the code executed when being muted + * The suppressing occurs visitor-style and if there's an exception in the code executed when being muted * all the logging that was temporarily muted will be resent to the peers as if they weren't muted to begin with. */ -public final class Mute implements TestRule +public final class SuppressOutput implements TestRule { - public static Mute mute( Mutable... mutables ) + public static SuppressOutput suppress( Suppressible... suppressibles ) { - return new Mute( mutables ); + return new SuppressOutput( suppressibles ); } - public static Mute muteAll() + public static SuppressOutput suppressAll() { - return mute( System.out, System.err, java_util_logging ); + return suppress( System.out, System.err, java_util_logging ); } - public enum System implements Mutable + public enum System implements Suppressible { out { @@ -80,11 +80,11 @@ PrintStream replace( PrintStream replacement ) }; @Override - public Voice mute() + public Voice suppress() { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); final PrintStream old = replace( new PrintStream( buffer ) ); - return new Voice() + return new Voice(this, buffer) { @Override void restore( boolean failure ) throws IOException @@ -101,19 +101,19 @@ void restore( boolean failure ) throws IOException abstract PrintStream replace( PrintStream replacement ); } - public static final Mutable java_util_logging = java_util_logging( null, null ); + public static final Suppressible java_util_logging = java_util_logging( new ByteArrayOutputStream(), null ); - public static Mutable java_util_logging( OutputStream redirectTo, Level level ) + public static Suppressible java_util_logging( final OutputStream redirectTo, Level level ) { final Handler replacement = redirectTo == null ? null : new StreamHandler( redirectTo, new SimpleFormatter() ); if ( replacement != null && level != null ) { replacement.setLevel( level ); } - return new Mutable() + return new Suppressible() { @Override - public Voice mute() + public Voice suppress() { final Logger logger = LogManager.getLogManager().getLogger( "" ); final Level level = logger.getLevel(); @@ -127,7 +127,7 @@ public Voice mute() logger.addHandler( replacement ); logger.setLevel( Level.ALL ); } - return new Voice() + return new Voice(this, redirectTo) { @Override void restore( boolean failure ) throws IOException @@ -163,13 +163,43 @@ public T call( Callable callable ) throws Exception } } - private final Mutable[] mutables; + private final Suppressible[] suppressibles; + private Voice[] voices; - private Mute( Mutable[] mutables ) + private SuppressOutput( Suppressible[] suppressibles ) { - this.mutables = mutables; + this.suppressibles = suppressibles; } + public Voice[] getAllVoices() + { + return voices; + } + + public Voice getOutputVoice() + { + return getVoice( System.out ); + } + + public Voice getErrorVoice() + { + return getVoice( System.err ); + } + + public Voice getVoice( Suppressible suppressible ) + { + for ( Voice voice : voices ) + { + if ( suppressible.equals( voice.getSuppressible() ) ) + { + return voice; + } + } + return null; + } + + + @Override public Statement apply( final Statement base, Description description ) { @@ -178,7 +208,7 @@ public Statement apply( final Statement base, Description description ) @Override public void evaluate() throws Throwable { - Voice[] voices = captureVoices(); + voices = captureVoices(); boolean failure = true; try { @@ -193,25 +223,44 @@ public void evaluate() throws Throwable }; } - public interface Mutable + public interface Suppressible { - Voice mute(); + Voice suppress(); } - private static abstract class Voice + public static abstract class Voice { + private Suppressible suppressible; + private OutputStream voiceStream; + + public Voice(Suppressible suppressible, OutputStream originalStream) + { + this.suppressible = suppressible; + this.voiceStream = originalStream; + } + + public Suppressible getSuppressible() + { + return suppressible; + } + + public boolean containsMessage( String message ) + { + return voiceStream.toString().contains( message ); + } + abstract void restore( boolean failure ) throws IOException; } Voice[] captureVoices() { - Voice[] voices = new Voice[mutables.length]; + Voice[] voices = new Voice[suppressibles.length]; boolean ok = false; try { for ( int i = 0; i < voices.length; i++ ) { - voices[i] = mutables[i].mute(); + voices[i] = suppressibles[i].suppress(); } ok = true; } diff --git a/community/neo4j-harness/src/test/java/org/neo4j/harness/FixturesTest.java b/community/neo4j-harness/src/test/java/org/neo4j/harness/FixturesTest.java index e959a60b2e631..9fec789d6d6ec 100644 --- a/community/neo4j-harness/src/test/java/org/neo4j/harness/FixturesTest.java +++ b/community/neo4j-harness/src/test/java/org/neo4j/harness/FixturesTest.java @@ -29,7 +29,7 @@ import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Transaction; import org.neo4j.io.fs.FileUtils; -import org.neo4j.test.Mute; +import org.neo4j.test.SuppressOutput; import org.neo4j.test.TargetDirectory; import org.neo4j.test.server.HTTP; @@ -44,7 +44,7 @@ public class FixturesTest @Rule public TargetDirectory.TestDirectory testDir = TargetDirectory.testDirForTest( FixturesTest.class ); - @Rule public Mute mute = Mute.muteAll(); + @Rule public SuppressOutput suppressOutput = SuppressOutput.suppressAll(); @Test public void shouldAccepSingleCypherFileAsFixture() throws Exception diff --git a/community/neo4j-harness/src/test/java/org/neo4j/harness/InProcessBuilderTest.java b/community/neo4j-harness/src/test/java/org/neo4j/harness/InProcessBuilderTest.java index 0fdb2c72140ec..8086ee14b2c26 100644 --- a/community/neo4j-harness/src/test/java/org/neo4j/harness/InProcessBuilderTest.java +++ b/community/neo4j-harness/src/test/java/org/neo4j/harness/InProcessBuilderTest.java @@ -50,7 +50,7 @@ import org.neo4j.server.configuration.Configurator; import org.neo4j.server.configuration.ServerSettings; import org.neo4j.server.rest.domain.JsonParseException; -import org.neo4j.test.Mute; +import org.neo4j.test.SuppressOutput; import org.neo4j.test.TargetDirectory; import org.neo4j.test.TestGraphDatabaseFactory; import org.neo4j.test.server.HTTP; @@ -70,7 +70,7 @@ public class InProcessBuilderTest @Rule public TargetDirectory.TestDirectory testDir = TargetDirectory.testDirForTest( InProcessBuilderTest.class ); - @Rule public Mute mute = Mute.muteAll(); + @Rule public SuppressOutput suppressOutput = SuppressOutput.suppressAll(); @Test public void shouldLaunchAServerInSpecifiedDirectory() throws Exception diff --git a/community/neo4j-harness/src/test/java/org/neo4j/harness/JUnitRuleTest.java b/community/neo4j-harness/src/test/java/org/neo4j/harness/JUnitRuleTest.java index fc4cc5a37a25d..e0bae2984fbaf 100644 --- a/community/neo4j-harness/src/test/java/org/neo4j/harness/JUnitRuleTest.java +++ b/community/neo4j-harness/src/test/java/org/neo4j/harness/JUnitRuleTest.java @@ -34,7 +34,7 @@ import org.neo4j.harness.extensionpackage.MyUnmanagedExtension; import org.neo4j.harness.junit.Neo4jRule; import org.neo4j.helpers.collection.IteratorUtil; -import org.neo4j.test.Mute; +import org.neo4j.test.SuppressOutput; import org.neo4j.test.TargetDirectory; import org.neo4j.test.server.HTTP; @@ -68,7 +68,7 @@ public Void apply( GraphDatabaseService graphDatabaseService ) throws RuntimeExc @Rule public TargetDirectory.TestDirectory testDirectory = testDirForTest( getClass() ); - @Rule public Mute mute = Mute.muteAll(); + @Rule public SuppressOutput suppressOutput = SuppressOutput.suppressAll(); @Test public void shouldExtensionWork() throws Exception diff --git a/community/neo4j-harness/src/test/java/org/neo4j/harness/doc/ExtensionTestingDocTest.java b/community/neo4j-harness/src/test/java/org/neo4j/harness/doc/ExtensionTestingDocTest.java index 984062190c77c..aa7a30696c00c 100644 --- a/community/neo4j-harness/src/test/java/org/neo4j/harness/doc/ExtensionTestingDocTest.java +++ b/community/neo4j-harness/src/test/java/org/neo4j/harness/doc/ExtensionTestingDocTest.java @@ -34,7 +34,7 @@ import org.neo4j.harness.ServerControls; import org.neo4j.harness.TestServerBuilders; import org.neo4j.helpers.collection.IteratorUtil; -import org.neo4j.test.Mute; +import org.neo4j.test.SuppressOutput; import org.neo4j.test.server.HTTP; import static org.junit.Assert.*; @@ -42,7 +42,7 @@ public class ExtensionTestingDocTest { @Rule - public Mute mute = Mute.muteAll(); + public SuppressOutput suppressOutput = SuppressOutput.suppressAll(); // START SNIPPET: testExtension @Path("") diff --git a/community/neo4j-harness/src/test/java/org/neo4j/harness/doc/JUnitDocTest.java b/community/neo4j-harness/src/test/java/org/neo4j/harness/doc/JUnitDocTest.java index 4cb7c1d5ebc87..d52fd1bf88f14 100644 --- a/community/neo4j-harness/src/test/java/org/neo4j/harness/doc/JUnitDocTest.java +++ b/community/neo4j-harness/src/test/java/org/neo4j/harness/doc/JUnitDocTest.java @@ -30,14 +30,14 @@ import org.neo4j.graphdb.Transaction; import org.neo4j.harness.junit.Neo4jRule; import org.neo4j.helpers.collection.IteratorUtil; -import org.neo4j.test.Mute; +import org.neo4j.test.SuppressOutput; import org.neo4j.test.server.HTTP; import static org.junit.Assert.*; public class JUnitDocTest { - @Rule public Mute mute = Mute.muteAll(); + @Rule public SuppressOutput suppressOutput = SuppressOutput.suppressAll(); // START SNIPPET: useJUnitRule @Rule diff --git a/community/server/src/test/java/org/neo4j/server/BaseBootstrapperTest.java b/community/server/src/test/java/org/neo4j/server/BaseBootstrapperTest.java index 18a91404cee9e..71f109e87a077 100644 --- a/community/server/src/test/java/org/neo4j/server/BaseBootstrapperTest.java +++ b/community/server/src/test/java/org/neo4j/server/BaseBootstrapperTest.java @@ -27,7 +27,7 @@ import java.io.File; import org.neo4j.io.fs.FileUtils; -import org.neo4j.test.Mute; +import org.neo4j.test.SuppressOutput; import org.neo4j.test.server.ExclusiveServerTestBase; import static org.junit.Assert.assertEquals; @@ -36,7 +36,7 @@ public abstract class BaseBootstrapperTest extends ExclusiveServerTestBase { @Rule - public final Mute mute = Mute.muteAll(); + public final SuppressOutput suppressOutput = SuppressOutput.suppressAll(); private Bootstrapper bootstrapper; diff --git a/community/server/src/test/java/org/neo4j/server/configuration/PropertyFileConfiguratorTest.java b/community/server/src/test/java/org/neo4j/server/configuration/PropertyFileConfiguratorTest.java index 9d3c50f1c0bfd..d21c79fa0c1ca 100644 --- a/community/server/src/test/java/org/neo4j/server/configuration/PropertyFileConfiguratorTest.java +++ b/community/server/src/test/java/org/neo4j/server/configuration/PropertyFileConfiguratorTest.java @@ -31,17 +31,17 @@ import org.neo4j.logging.AssertableLogProvider; import org.neo4j.logging.FormattedLog; import org.neo4j.logging.Log; -import org.neo4j.test.Mute; +import org.neo4j.test.SuppressOutput; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.neo4j.logging.AssertableLogProvider.inLog; -import static org.neo4j.test.Mute.muteAll; +import static org.neo4j.test.SuppressOutput.suppressAll; public class PropertyFileConfiguratorTest { @Rule - public final Mute mute = muteAll(); + public final SuppressOutput suppressOutput = suppressAll(); @Rule public final TemporaryFolder folder = new TemporaryFolder(); diff --git a/community/server/src/test/java/org/neo4j/server/database/TestLifecycleManagedDatabase.java b/community/server/src/test/java/org/neo4j/server/database/TestLifecycleManagedDatabase.java index 9cd59b241b47f..b245cfb405a20 100644 --- a/community/server/src/test/java/org/neo4j/server/database/TestLifecycleManagedDatabase.java +++ b/community/server/src/test/java/org/neo4j/server/database/TestLifecycleManagedDatabase.java @@ -35,7 +35,7 @@ import org.neo4j.logging.AssertableLogProvider; import org.neo4j.server.web.ServerInternalSettings; import org.neo4j.test.ImpermanentDatabaseRule; -import org.neo4j.test.Mute; +import org.neo4j.test.SuppressOutput; import static org.hamcrest.Matchers.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; @@ -47,12 +47,12 @@ import static org.neo4j.helpers.collection.MapUtil.stringMap; import static org.neo4j.logging.AssertableLogProvider.inLog; import static org.neo4j.server.ServerTestUtils.createTempDir; -import static org.neo4j.test.Mute.muteAll; +import static org.neo4j.test.SuppressOutput.suppressAll; public class TestLifecycleManagedDatabase { @Rule - public Mute mute = muteAll(); + public SuppressOutput suppressOutput = suppressAll(); private final AssertableLogProvider logProvider = new AssertableLogProvider(); diff --git a/community/server/src/test/java/org/neo4j/server/modules/DBMSModuleTest.java b/community/server/src/test/java/org/neo4j/server/modules/DBMSModuleTest.java index 3071b916c6567..d7b655936507f 100644 --- a/community/server/src/test/java/org/neo4j/server/modules/DBMSModuleTest.java +++ b/community/server/src/test/java/org/neo4j/server/modules/DBMSModuleTest.java @@ -26,7 +26,7 @@ import org.junit.Test; import org.neo4j.server.CommunityNeoServer; import org.neo4j.server.web.WebServer; -import org.neo4j.test.Mute; +import org.neo4j.test.SuppressOutput; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyCollection; @@ -36,7 +36,8 @@ public class DBMSModuleTest { @Rule - public Mute mute = Mute.mute( Mute.System.err, Mute.System.out ); + public SuppressOutput suppressOutput = SuppressOutput.suppress( SuppressOutput.System.err, + SuppressOutput.System.out ); @SuppressWarnings( "unchecked" ) @Test diff --git a/community/server/src/test/java/org/neo4j/server/preflight/TestPreflightTasks.java b/community/server/src/test/java/org/neo4j/server/preflight/TestPreflightTasks.java index f2751eed6a96f..34cd10269ef42 100644 --- a/community/server/src/test/java/org/neo4j/server/preflight/TestPreflightTasks.java +++ b/community/server/src/test/java/org/neo4j/server/preflight/TestPreflightTasks.java @@ -23,13 +23,13 @@ import org.junit.Test; import org.neo4j.logging.AssertableLogProvider; import org.neo4j.logging.NullLogProvider; -import org.neo4j.test.Mute; +import org.neo4j.test.SuppressOutput; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.neo4j.logging.AssertableLogProvider.inLog; -import static org.neo4j.test.Mute.muteAll; +import static org.neo4j.test.SuppressOutput.suppressAll; public class TestPreflightTasks { @@ -140,5 +140,5 @@ public String getFailureMessage() } @Rule - public Mute mute = muteAll(); + public SuppressOutput suppressOutput = suppressAll(); } diff --git a/community/server/src/test/java/org/neo4j/server/rest/paging/PagedTraverserDocIT.java b/community/server/src/test/java/org/neo4j/server/rest/paging/PagedTraverserDocIT.java index a7cf8147ae5dc..5b41efc4ac325 100644 --- a/community/server/src/test/java/org/neo4j/server/rest/paging/PagedTraverserDocIT.java +++ b/community/server/src/test/java/org/neo4j/server/rest/paging/PagedTraverserDocIT.java @@ -56,7 +56,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; -import static org.neo4j.test.Mute.muteAll; +import static org.neo4j.test.SuppressOutput.suppressAll; public class PagedTraverserDocIT extends ExclusiveServerTestBase { @@ -92,7 +92,7 @@ public static void setupServer() throws Exception .withClock( clock ) .build(); - muteAll().call( new Callable() + suppressAll().call( new Callable() { @Override public Void call() throws Exception @@ -113,7 +113,7 @@ public void setupTheDatabase() throws Exception @AfterClass public static void stopServer() throws Exception { - muteAll().call( new Callable() + suppressAll().call( new Callable() { @Override public Void call() throws Exception diff --git a/community/server/src/test/java/org/neo4j/server/rest/web/CollectUserAgentFilterTest.java b/community/server/src/test/java/org/neo4j/server/rest/web/CollectUserAgentFilterTest.java index b54d59bc09890..1b00e714a60ee 100644 --- a/community/server/src/test/java/org/neo4j/server/rest/web/CollectUserAgentFilterTest.java +++ b/community/server/src/test/java/org/neo4j/server/rest/web/CollectUserAgentFilterTest.java @@ -29,7 +29,7 @@ import javax.servlet.http.HttpServletRequest; import org.neo4j.concurrent.RecentK; -import org.neo4j.test.Mute; +import org.neo4j.test.SuppressOutput; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasItems; @@ -40,7 +40,7 @@ import static org.mockito.Mockito.stub; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.neo4j.test.Mute.muteAll; +import static org.neo4j.test.SuppressOutput.suppressAll; public class CollectUserAgentFilterTest { @@ -49,7 +49,7 @@ public class CollectUserAgentFilterTest private final CollectUserAgentFilter filter = new CollectUserAgentFilter( agents ); @Rule - public Mute mute = muteAll(); + public SuppressOutput suppressOutput = suppressAll(); @Test public void shouldRecordASingleUserAgent() throws IOException, ServletException diff --git a/community/server/src/test/java/org/neo4j/server/rrd/RrdFactoryTest.java b/community/server/src/test/java/org/neo4j/server/rrd/RrdFactoryTest.java index 6aed3851f584f..11fbfe9cea0c7 100644 --- a/community/server/src/test/java/org/neo4j/server/rrd/RrdFactoryTest.java +++ b/community/server/src/test/java/org/neo4j/server/rrd/RrdFactoryTest.java @@ -40,7 +40,7 @@ import org.neo4j.server.database.RrdDbWrapper; import org.neo4j.server.database.WrappedDatabase; import org.neo4j.test.ImpermanentGraphDatabase; -import org.neo4j.test.Mute; +import org.neo4j.test.SuppressOutput; import org.neo4j.test.TargetDirectory; import org.neo4j.test.TestGraphDatabaseFactory; @@ -50,7 +50,7 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import static org.neo4j.test.Mute.muteAll; +import static org.neo4j.test.SuppressOutput.suppressAll; public class RrdFactoryTest { @@ -62,7 +62,7 @@ public class RrdFactoryTest @Rule public TargetDirectory.TestDirectory testDirectory = target.testDirectory(); @Rule - public Mute mute = muteAll(); + public SuppressOutput suppressOutput = suppressAll(); @Before public void setUp() throws IOException diff --git a/community/server/src/test/java/org/neo4j/server/web/JettyThreadLimitTest.java b/community/server/src/test/java/org/neo4j/server/web/JettyThreadLimitTest.java index 782f0cde7e6cc..e370861138ea2 100644 --- a/community/server/src/test/java/org/neo4j/server/web/JettyThreadLimitTest.java +++ b/community/server/src/test/java/org/neo4j/server/web/JettyThreadLimitTest.java @@ -26,18 +26,18 @@ import org.junit.Test; import org.neo4j.logging.NullLogProvider; -import org.neo4j.test.Mute; +import org.neo4j.test.SuppressOutput; import static org.junit.Assert.assertEquals; -import static org.neo4j.test.Mute.muteAll; +import static org.neo4j.test.SuppressOutput.suppressAll; import org.neo4j.kernel.configuration.Config; public class JettyThreadLimitTest { @Rule - public Mute mute = muteAll(); + public SuppressOutput suppressOutput = suppressAll(); @Test public void shouldHaveConfigurableJettyThreadPoolSize() throws Exception diff --git a/community/server/src/test/java/org/neo4j/server/web/TestJetty9WebServer.java b/community/server/src/test/java/org/neo4j/server/web/TestJetty9WebServer.java index 6af3b647c9296..4c343782370bc 100644 --- a/community/server/src/test/java/org/neo4j/server/web/TestJetty9WebServer.java +++ b/community/server/src/test/java/org/neo4j/server/web/TestJetty9WebServer.java @@ -36,13 +36,14 @@ import org.neo4j.server.helpers.CommunityServerBuilder; import org.neo4j.test.ImpermanentDatabaseRule; import org.neo4j.test.ImpermanentGraphDatabase; -import org.neo4j.test.Mute; import org.neo4j.test.server.ExclusiveServerTestBase; import org.neo4j.test.server.HTTP; +import org.neo4j.test.SuppressOutput; + import static org.junit.Assert.assertEquals; import static org.neo4j.helpers.collection.MapUtil.stringMap; -import static org.neo4j.test.Mute.muteAll; +import static org.neo4j.test.SuppressOutput.suppressAll; public class TestJetty9WebServer extends ExclusiveServerTestBase { @@ -128,7 +129,7 @@ public void shouldDisallowDirectoryListings() throws Exception } @Rule - public Mute mute = muteAll(); + public SuppressOutput suppressOutput = suppressAll(); @Rule public ImpermanentDatabaseRule dbRule = new ImpermanentDatabaseRule(); diff --git a/community/server/src/test/java/org/neo4j/server/webadmin/rest/CommunityVersionAndEditionServiceDocIT.java b/community/server/src/test/java/org/neo4j/server/webadmin/rest/CommunityVersionAndEditionServiceDocIT.java index e90fcb3951618..dfa5c145b7ba2 100644 --- a/community/server/src/test/java/org/neo4j/server/webadmin/rest/CommunityVersionAndEditionServiceDocIT.java +++ b/community/server/src/test/java/org/neo4j/server/webadmin/rest/CommunityVersionAndEditionServiceDocIT.java @@ -43,7 +43,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; -import static org.neo4j.test.Mute.muteAll; +import static org.neo4j.test.SuppressOutput.suppressAll; /* Note that when running this test from within an IDE, the version field will be an empty string. This is because the @@ -78,7 +78,7 @@ public static void setupServer() throws Exception .withClock( clock ) .build(); - muteAll().call( new Callable() + suppressAll().call( new Callable() { @Override public Void call() throws Exception @@ -99,7 +99,7 @@ public void setupTheDatabase() throws Exception @AfterClass public static void stopServer() throws Exception { - muteAll().call( new Callable() + suppressAll().call( new Callable() { @Override public Void call() throws Exception diff --git a/community/server/src/test/java/org/neo4j/test/server/ExclusiveServerTestBase.java b/community/server/src/test/java/org/neo4j/test/server/ExclusiveServerTestBase.java index baa26261e116f..b2e86c45a9c71 100644 --- a/community/server/src/test/java/org/neo4j/test/server/ExclusiveServerTestBase.java +++ b/community/server/src/test/java/org/neo4j/test/server/ExclusiveServerTestBase.java @@ -25,25 +25,26 @@ import java.util.concurrent.Callable; -import org.neo4j.test.Mute; +import org.neo4j.test.SuppressOutput; import org.neo4j.test.TargetDirectory; -import static org.neo4j.test.Mute.muteAll; +import static org.neo4j.test.SuppressOutput.suppressAll; public class ExclusiveServerTestBase { public TargetDirectory folder = TargetDirectory.forTest( getClass() ); @Rule - public Mute mute = muteAll(); + public SuppressOutput suppressOutput = suppressAll(); @Rule public TestName name = new TestName(); @BeforeClass public static void ensureServerNotRunning() throws Exception { + System.setProperty( "org.neo4j.useInsecureCertificateGeneration", "true" ); - muteAll().call( new Callable() + suppressAll().call( new Callable() { @Override public Void call() throws Exception diff --git a/community/server/src/test/java/org/neo4j/test/server/SharedServerTestBase.java b/community/server/src/test/java/org/neo4j/test/server/SharedServerTestBase.java index 7406332593509..e1ccf925eb3f6 100644 --- a/community/server/src/test/java/org/neo4j/test/server/SharedServerTestBase.java +++ b/community/server/src/test/java/org/neo4j/test/server/SharedServerTestBase.java @@ -27,9 +27,9 @@ import org.neo4j.server.NeoServer; import org.neo4j.server.helpers.ServerHelper; -import org.neo4j.test.Mute; +import org.neo4j.test.SuppressOutput; -import static org.neo4j.test.Mute.muteAll; +import static org.neo4j.test.SuppressOutput.suppressAll; public class SharedServerTestBase { @@ -43,7 +43,7 @@ protected static NeoServer server() private static NeoServer server; @Rule - public Mute mute = muteAll(); + public SuppressOutput suppressOutput = suppressAll(); @BeforeClass public static void allocateServer() throws Throwable @@ -51,7 +51,7 @@ public static void allocateServer() throws Throwable System.setProperty( "org.neo4j.useInsecureCertificateGeneration", "true" ); if ( !useExternal ) { - muteAll().call( new Callable() + suppressAll().call( new Callable() { @Override public Void call() throws Exception @@ -71,7 +71,7 @@ public static void releaseServer() throws Exception { try { - muteAll().call( new Callable() + suppressAll().call( new Callable() { @Override public Void call() throws Exception diff --git a/enterprise/backup/src/test/java/org/neo4j/backup/BackupServiceIT.java b/enterprise/backup/src/test/java/org/neo4j/backup/BackupServiceIT.java index 4c0336af6c5d9..1674a41887852 100644 --- a/enterprise/backup/src/test/java/org/neo4j/backup/BackupServiceIT.java +++ b/enterprise/backup/src/test/java/org/neo4j/backup/BackupServiceIT.java @@ -56,14 +56,14 @@ import org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation; import org.neo4j.kernel.impl.transaction.log.IOCursor; import org.neo4j.kernel.impl.transaction.log.LogFile; -import org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer; -import org.neo4j.kernel.impl.transaction.log.rotation.LogRotation; import org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore; import org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles; import org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionStore; import org.neo4j.kernel.impl.transaction.log.TransactionIdStore; +import org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer; import org.neo4j.kernel.impl.transaction.log.entry.LogHeader; import org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader; +import org.neo4j.kernel.impl.transaction.log.rotation.LogRotation; import org.neo4j.kernel.impl.transaction.state.DataSourceManager; import org.neo4j.kernel.impl.transaction.state.NeoStoreSupplier; import org.neo4j.kernel.impl.util.Dependencies; @@ -76,8 +76,8 @@ import org.neo4j.test.DatabaseRule; import org.neo4j.test.DbRepresentation; import org.neo4j.test.EmbeddedDatabaseRule; -import org.neo4j.test.Mute; import org.neo4j.test.PageCacheRule; +import org.neo4j.test.SuppressOutput; import org.neo4j.test.TargetDirectory; import static java.util.concurrent.TimeUnit.SECONDS; @@ -128,7 +128,7 @@ public void finishStreamingStoreFile( File storefile ) @Rule public EmbeddedDatabaseRule dbRule = new EmbeddedDatabaseRule( storeDir ); @Rule - public Mute mute = Mute.muteAll(); + public SuppressOutput suppressOutput = SuppressOutput.suppressAll(); @Rule public final PageCacheRule pageCacheRule = new PageCacheRule(); diff --git a/enterprise/server-enterprise/src/test/java/org/neo4j/server/webadmin/rest/EnterpriseVersionAndEditionServiceIT.java b/enterprise/server-enterprise/src/test/java/org/neo4j/server/webadmin/rest/EnterpriseVersionAndEditionServiceIT.java index 9189026ae9b62..61e3cc834f34a 100644 --- a/enterprise/server-enterprise/src/test/java/org/neo4j/server/webadmin/rest/EnterpriseVersionAndEditionServiceIT.java +++ b/enterprise/server-enterprise/src/test/java/org/neo4j/server/webadmin/rest/EnterpriseVersionAndEditionServiceIT.java @@ -40,7 +40,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; -import static org.neo4j.test.Mute.muteAll; +import static org.neo4j.test.SuppressOutput.suppressAll; /* Note that when running this test from within an IDE, the version field will be an empty string. This is because the @@ -66,7 +66,7 @@ public static void setupServer() throws Exception .withClock( clock ) .build(); - muteAll().call( new Callable() + suppressAll().call( new Callable() { @Override public Void call() throws Exception @@ -87,7 +87,7 @@ public void setupTheDatabase() throws Exception @AfterClass public static void stopServer() throws Exception { - muteAll().call( new Callable() + suppressAll().call( new Callable() { @Override public Void call() throws Exception