logs and sleep( 1000 ) before exit()
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/85eecedc Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/85eecedc Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/85eecedc Branch: refs/heads/2.19.2-experimental Commit: 85eecedcb771276f26f850ef640711d13ccc335c Parents: bff89ca Author: Tibor17 <tibo...@lycos.com> Authored: Sun Feb 19 11:26:48 2017 +0100 Committer: Tibor17 <tibo...@lycos.com> Committed: Sun Feb 19 11:26:48 2017 +0100 ---------------------------------------------------------------------- .../surefire/booterclient/ForkStarter.java | 3 ++ .../lazytestprovider/AbstractCommandStream.java | 41 ++++++++++++++--- .../OutputStreamFlushableCommandline.java | 3 +- .../output/ThreadedStreamConsumer.java | 12 +++++ pom.xml | 2 +- .../maven/surefire/booter/CommandReader.java | 1 + .../surefire/booter/MasterProcessCommand.java | 7 +++ .../maven/surefire/booter/ForkedBooter.java | 17 ++++++- .../surefire/booter/SystemPropertyManager.java | 2 +- surefire-integration-tests/pom.xml | 2 +- .../surefire/its/fixture/MavenLauncher.java | 45 ++++++++++++++++--- .../surefire/its/fixture/MavenLauncherTest.java | 47 ++++++++++++++++++++ .../surefire/its/fixture/SurefireLauncher.java | 6 +-- 13 files changed, 168 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/85eecedc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java index 54d304a..1744f40 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java @@ -769,6 +769,7 @@ public class ForkStarter { public void run() { + System.out.println( System.currentTimeMillis() + " ForkStarter NOOP sent" ); builder.getImmediateCommands().noop(); } }, 0, PING_IN_SECONDS, SECONDS ); @@ -780,8 +781,10 @@ public class ForkStarter { public void run() { + System.out.println( System.currentTimeMillis() + " ForkStarter NOOP before a loop" ); for ( TestProvidingInputStream stream : streams ) { + System.out.println( System.currentTimeMillis() + " ForkStarter NOOP sent in a loop" ); stream.noop(); } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/85eecedc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/AbstractCommandStream.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/AbstractCommandStream.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/AbstractCommandStream.java index 4d6331c..3a9c31b 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/AbstractCommandStream.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/AbstractCommandStream.java @@ -28,11 +28,11 @@ import java.io.IOException; * Reader stream sends commands to forked jvm std-{@link java.io.InputStream input-stream}. * * @author <a href="mailto:tibordig...@apache.org">Tibor Digana (tibor17)</a> - * @since 2.19 * @see org.apache.maven.surefire.booter.Command + * @since 2.19 */ public abstract class AbstractCommandStream - extends AbstractForkInputStream + extends AbstractForkInputStream { private byte[] currentBuffer; private int currentPos; @@ -51,7 +51,7 @@ public abstract class AbstractCommandStream * closed (see {@link #isClosed()} returns {@code true}) before this method has returned. */ protected void beforeNextCommand() - throws IOException + throws IOException { } @@ -80,7 +80,7 @@ public abstract class AbstractCommandStream @SuppressWarnings( "checkstyle:magicnumber" ) @Override public int read() - throws IOException + throws IOException { if ( isClosed() ) { @@ -106,17 +106,48 @@ public abstract class AbstractCommandStream } Command cmd = nextCommand(); + System.out.println( getClass().getSimpleName() + " will send " + cmd.getCommandType() ); lastCommand = cmd.getCommandType(); buffer = lastCommand.hasDataType() ? lastCommand.encode( cmd.getData() ) : lastCommand.encode(); } - int b = buffer[currentPos++] & 0xff; + int b = buffer[currentPos++] & 0xff; if ( currentPos == buffer.length ) { + Integer cmd = null; + Integer len = null; + int offset = 0; + if ( currentBuffer.length >= 4 ) + { + offset = 4; + cmd = toInt( currentBuffer, 0 ); + } + if ( currentBuffer.length >= 8 ) + { + offset = 8; + len = toInt( currentBuffer, 4 ); + } + System.out.println( getClass().getSimpleName() + + " last byte sent of cmd " + + lastCommand + + cmd + + " " + + len + + " " + + new String( buffer, offset, currentBuffer.length - offset ) ); buffer = null; currentPos = 0; } currentBuffer = buffer; return b; } + + @SuppressWarnings( "checkstyle:magicnumber" ) + private static int toInt( byte[] array, int offset ) + { + return ( array[ offset ] << 24 ) & 0xff000000 + | ( array[ offset + 1 ] << 16 ) & 0x00ff0000 + | ( array[ offset + 2 ] << 8 ) & 0x0000ff00 + | array[ offset + 3 ] & 0x000000ff; + } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/85eecedc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/OutputStreamFlushableCommandline.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/OutputStreamFlushableCommandline.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/OutputStreamFlushableCommandline.java index 0abf42f..5cd19f2 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/OutputStreamFlushableCommandline.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/OutputStreamFlushableCommandline.java @@ -38,7 +38,7 @@ public class OutputStreamFlushableCommandline /** * Wraps an output stream in order to delegate a flush. */ - private final class OutputStreamFlushReceiver + private static final class OutputStreamFlushReceiver implements FlushReceiver { private final OutputStream outputStream; @@ -51,6 +51,7 @@ public class OutputStreamFlushableCommandline public void flush() throws IOException { + System.out.println( getClass().getSimpleName() + " flush OutputStream " ); outputStream.flush(); } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/85eecedc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java index c7d39ae..18a3083 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java @@ -81,6 +81,10 @@ public final class ThreadedStreamConsumer try { String item = ThreadedStreamConsumer.this.items.take(); + System.out.println( ThreadedStreamConsumer.class.getSimpleName() + + "#" + ThreadedStreamConsumer.this.hashCode() + + " run() :: items :: " + + item ); if ( shouldStopQueueing( item ) ) { break; @@ -116,12 +120,16 @@ public final class ThreadedStreamConsumer { if ( stop && !thread.isAlive() ) { + System.out.println( getClass().getSimpleName() + "#" + hashCode() + + " consumeLine() :: items.clear()." ); items.clear(); return; } try { + System.out.println( getClass().getSimpleName() + "#" + hashCode() + + " consumeLine() :: items.put( s ) :: " + s ); items.put( s ); } catch ( InterruptedException e ) @@ -134,6 +142,8 @@ public final class ThreadedStreamConsumer public void close() throws IOException { + System.out.println( getClass().getSimpleName() + "#" + hashCode() + + " close()" ); if ( stop ) { return; @@ -141,6 +151,8 @@ public final class ThreadedStreamConsumer try { + System.out.println( getClass().getSimpleName() + "#" + hashCode() + + " close() :: END_ITEM" ); items.put( END_ITEM ); thread.join( CLOSE_TIMEOUT_MILLIS ); } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/85eecedc/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 3b8ab65..1eb5572 100644 --- a/pom.xml +++ b/pom.xml @@ -215,7 +215,7 @@ <dependency> <groupId>org.apache.maven.shared</groupId> <artifactId>maven-shared-utils</artifactId> - <version>0.9</version> + <version>0.9.1-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.maven.shared</groupId> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/85eecedc/surefire-api/src/main/java/org/apache/maven/surefire/booter/CommandReader.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/CommandReader.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/CommandReader.java index 65f49a2..d7fd900 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/CommandReader.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/CommandReader.java @@ -387,6 +387,7 @@ public final class CommandReader } else { + System.out.println( System.currentTimeMillis() + " CommandReader " + command.getCommandType() ); switch ( command.getCommandType() ) { case RUN_CLASS: http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/85eecedc/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java index d5e314a..ece0716 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java @@ -116,6 +116,8 @@ public enum MasterProcessCommand MasterProcessCommand command = resolve( is.readInt() ); if ( command == null ) { + System.out.println( MasterProcessCommand.class.getSimpleName() + + " Stream is corrupted. command == null" ); return null; } else @@ -128,6 +130,8 @@ public enum MasterProcessCommand if ( command.getDataType() == Void.class ) { + System.out.println( format( "Command %s unexpectedly read Void data with length %d.", + command, dataLength ) ); throw new IOException( format( "Command %s unexpectedly read Void data with length %d.", command, dataLength ) ); } @@ -184,6 +188,9 @@ public enum MasterProcessCommand return command; } } + + System.out.println( MasterProcessCommand.class.getSimpleName() + + " Stream is corrupted. id=" + id ); return null; } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/85eecedc/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java ---------------------------------------------------------------------- diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java index 5cc2134..e18b08e 100644 --- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java +++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java @@ -204,6 +204,7 @@ public final class ForkedBooter { public void update( Command command ) { + System.out.println( System.currentTimeMillis() + " ForkedBooter exit handler" ); exit( 1, command.toShutdownData(), reader, true ); } }; @@ -215,9 +216,12 @@ public final class ForkedBooter { public void run() { + System.out.println( System.currentTimeMillis() + " ForkedBooter NOOP timer" ); boolean hasPing = pingDone.getAndSet( false ); if ( !hasPing ) { + System.out.println( System.currentTimeMillis() + + " ForkedBooter PING timer: plugin did not send me NOOP signal > exit" ); exit( 1, KILL, reader, true ); } } @@ -246,6 +250,17 @@ public final class ForkedBooter reader.stop(); } launchLastDitchDaemonShutdownThread( returnCode ); + try + { + // on FreeBSD the std/out is FileOutputStream. + // it looks like the ThreadedStreamConsumer has not time to read out all data because process + // was closed faster. No shared memory between processes. + Thread.sleep( 1000 ); + } + catch ( InterruptedException e ) + { + e.printStackTrace(); + } System.exit( returnCode ); case DEFAULT: // refers to shutdown=testset, but not used now, keeping reader open @@ -278,7 +293,7 @@ public final class ForkedBooter + systemExitTimeoutInSeconds + "s" ); ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor( 1, threadFactory ); - executor.setMaximumPoolSize( 1 ); + executor.setMaximumPoolSize( 2 ); executor.prestartCoreThread(); return executor; } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/85eecedc/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java ---------------------------------------------------------------------- diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java index 713d4fe..8a4415b 100644 --- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java +++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java @@ -105,7 +105,7 @@ public class SystemPropertyManager } } - public static void close( InputStream inputStream ) + private static void close( InputStream inputStream ) { if ( inputStream == null ) { http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/85eecedc/surefire-integration-tests/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/pom.xml b/surefire-integration-tests/pom.xml index beab2be..6d5b03f 100644 --- a/surefire-integration-tests/pom.xml +++ b/surefire-integration-tests/pom.xml @@ -99,7 +99,7 @@ <forkMode>never</forkMode> <argLine>${argLine}</argLine> <includes> - <include>org/apache/**/*IT*.java</include> + <include>org/apache/**/ForkModeIT.java</include> </includes> <!-- Pass current surefire version to the main suite so that it --> <!-- can forward to all integration test projects. SUREFIRE-513 --> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/85eecedc/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncher.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncher.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncher.java index 1198fcb..0945068 100755 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncher.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncher.java @@ -19,18 +19,22 @@ package org.apache.maven.surefire.its.fixture; * under the License. */ +import org.apache.commons.lang.text.StrSubstitutor; +import org.apache.maven.it.VerificationException; +import org.apache.maven.it.Verifier; +import org.apache.maven.it.util.ResourceExtractor; +import org.apache.maven.shared.utils.io.FileUtils; + import java.io.File; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.ListIterator; import java.util.Map; -import org.apache.commons.lang.text.StrSubstitutor; -import org.apache.maven.it.VerificationException; -import org.apache.maven.it.Verifier; -import org.apache.maven.it.util.ResourceExtractor; -import org.apache.maven.shared.utils.io.FileUtils; + +import static java.util.Collections.unmodifiableList; /** * Encapsulate all needed features to start a maven run @@ -203,13 +207,13 @@ public class MavenLauncher public MavenLauncher skipClean() { - goals.add( "-Dclean.skip=true" ); + writeGoal( "-Dclean.skip=true" ); return this; } public MavenLauncher addGoal( String goal ) { - goals.add( goal ); + writeGoal( goal ); return this; } @@ -223,6 +227,33 @@ public class MavenLauncher return conditionalExec( "test" ); } + List<String> getGoals() + { + return unmodifiableList( goals ); + } + + private void writeGoal( String newGoal ) + { + if ( newGoal != null && newGoal.startsWith( "-D" ) ) + { + final String sysPropKey = + newGoal.contains( "=" ) ? newGoal.substring( 0, newGoal.indexOf( '=' ) ) : newGoal; + + final String sysPropStarter = sysPropKey + "="; + + for ( ListIterator<String> it = goals.listIterator(); it.hasNext(); ) + { + String goal = it.next(); + if ( goal.equals( sysPropKey ) || goal.startsWith( sysPropStarter ) ) + { + it.set( newGoal ); + return; + } + } + } + goals.add( newGoal ); + } + private OutputValidator conditionalExec(String goal) { OutputValidator verify; http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/85eecedc/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncherTest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncherTest.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncherTest.java new file mode 100644 index 0000000..4a638b6 --- /dev/null +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncherTest.java @@ -0,0 +1,47 @@ +package org.apache.maven.surefire.its.fixture; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.hamcrest.CoreMatchers.hasItems; + +/** + * @author <a href="mailto:tibordig...@apache.org">Tibor Digana (tibor17)</a> + * @since 2.19.2 + */ +public class MavenLauncherTest +{ + @Test + public void shouldNotDuplicateSystemProperties() + { + MavenLauncher launcher = new MavenLauncher( getClass(), "", "" ) + .addGoal( "-DskipTests" ) + .addGoal( "-Dx=a" ) + .addGoal( "-DskipTests" ) + .addGoal( "-Dx=b" ); + + assertThat( launcher.getGoals(), hasItems( "-Dx=b", "-DskipTests" ) ); + + assertThat( launcher.getGoals().size(), is( 2 ) ); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/85eecedc/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java index 23a09b0..1c78680 100755 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java @@ -42,7 +42,7 @@ public class SurefireLauncher private final MavenLauncher mavenLauncher; - private final String testNgVersion = System.getProperty( "testng.version" ); + private final String testNgVersion = System.getProperty( "testng.version" );//todo private final String surefireVersion = System.getProperty( "surefire.version" ); @@ -129,14 +129,14 @@ public class SurefireLauncher if ( this.testNgVersion != null ) { - goals1.add( "-DtestNgVersion=" + testNgVersion ); + goals1.add( "-DtestNgVersion=" + testNgVersion );//todo ArtifactVersion v = new DefaultArtifactVersion( testNgVersion ); try { if ( VersionRange.createFromVersionSpec( "(,5.12.1)" ).containsVersion( v ) ) { - goals1.add( "-DtestNgClassifier=jdk15" ); + goals1.add( "-DtestNgClassifier=jdk15" );//todo } } catch ( InvalidVersionSpecificationException e )