diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/EventConsumerThread.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/EventConsumerThread.java index 79d5c85ab1..2e5b5d3f20 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/EventConsumerThread.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/EventConsumerThread.java @@ -21,7 +21,6 @@ import org.apache.maven.surefire.api.event.Event; import org.apache.maven.surefire.api.fork.ForkNodeArguments; -import org.apache.maven.surefire.api.stream.AbstractStreamDecoder.Memento; import org.apache.maven.surefire.extensions.CloseableDaemonThread; import org.apache.maven.surefire.extensions.EventHandler; import org.apache.maven.surefire.extensions.util.CountdownCloseable; @@ -67,10 +66,9 @@ public void run() CountdownCloseable c = countdownCloseable; EventDecoder eventDecoder = decoder ) { - Memento memento = eventDecoder.new Memento(); do { - Event event = eventDecoder.decode( memento ); + Event event = eventDecoder.decode(); if ( event != null && !disabled ) { eventHandler.handleEvent( event ); diff --git a/maven-surefire-common/src/main/java/org/apache/maven/surefire/stream/EventDecoder.java b/maven-surefire-common/src/main/java/org/apache/maven/surefire/stream/EventDecoder.java index ea11889846..fa61d491ef 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/surefire/stream/EventDecoder.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/surefire/stream/EventDecoder.java @@ -140,6 +140,8 @@ public class EventDecoder extends AbstractStreamDecoder strings = new ArrayList<>(); int countDecodedBytes = 0; for ( boolean endOfInput = false; !endOfInput; ) { - final int bytesToRead = totalBytes - countDecodedBytes; + final int bytesToRead = totalBytes - countDecodedBytes; // our wish to read bytes as much as possible read( memento, bytesToRead ); - int bytesToDecode = min( input.remaining(), bytesToRead ); + final ByteBuffer input = memento.getByteBuffer(); + int bytesToDecode = min( input.remaining(), bytesToRead ); // our guarantee of available bytes in buffer final boolean isLastChunk = bytesToDecode == bytesToRead; endOfInput = countDecodedBytes + bytesToDecode >= totalBytes; - do - { - boolean endOfChunk = output.remaining() >= bytesToRead; - boolean endOfOutput = isLastChunk && endOfChunk; - int readInputBytes = decodeString( memento.getDecoder(), input, output, bytesToDecode, endOfOutput, - memento.getLine().getPositionByteBuffer() ); - bytesToDecode -= readInputBytes; - countDecodedBytes += readInputBytes; - } - while ( isLastChunk && bytesToDecode > 0 && output.hasRemaining() ); - - if ( isLastChunk || !output.hasRemaining() ) - { - strings.add( ( (Buffer) output ).flip().toString() ); - ( (Buffer) output ).clear(); - } + boolean endOfChunk = output.remaining() >= bytesToRead; + boolean endOfOutput = isLastChunk && endOfChunk; + int readInputBytes = decodeString( memento.getDecoder(), input, output, bytesToDecode, endOfOutput, + memento.getLine().getPositionByteBuffer() ); + countDecodedBytes += readInputBytes; + strings.add( ( (Buffer) output ).flip().toString() ); + ( (Buffer) output ).clear(); + memento.getLine().setPositionByteBuffer( 0 ); } - memento.getDecoder().reset(); - ( (Buffer) output ).clear(); - return toString( strings ); } diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/api/stream/MalformedChannelException.java b/surefire-api/src/main/java/org/apache/maven/surefire/api/stream/MalformedChannelException.java index cf4468ffce..89447356c9 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/api/stream/MalformedChannelException.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/api/stream/MalformedChannelException.java @@ -20,7 +20,7 @@ */ /** - * + * No supported message type. */ public class MalformedChannelException extends Exception { diff --git a/surefire-api/src/test/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoderTest.java b/surefire-api/src/test/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoderTest.java index 2ff06eab62..2cec298222 100644 --- a/surefire-api/src/test/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoderTest.java +++ b/surefire-api/src/test/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoderTest.java @@ -664,7 +664,7 @@ protected Mock( @Nonnull ReadableByteChannel channel, @Nonnull ForkNodeArguments } @Override - public Event decode( @Nonnull Memento memento ) throws MalformedChannelException + public Event decode() throws MalformedChannelException { throw new MalformedChannelException(); } diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/CommandChannelDecoder.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/CommandChannelDecoder.java index 85bda73a83..8b7a5d7b7c 100644 --- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/CommandChannelDecoder.java +++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/CommandChannelDecoder.java @@ -22,7 +22,6 @@ import org.apache.maven.surefire.api.booter.Command; import org.apache.maven.surefire.api.booter.MasterProcessChannelDecoder; import org.apache.maven.surefire.api.fork.ForkNodeArguments; -import org.apache.maven.surefire.api.stream.AbstractStreamDecoder.Memento; import org.apache.maven.surefire.api.stream.MalformedChannelException; import org.apache.maven.surefire.booter.stream.CommandDecoder; @@ -40,7 +39,6 @@ public class CommandChannelDecoder implements MasterProcessChannelDecoder { private final CommandDecoder decoder; - private Memento memento; public CommandChannelDecoder( @Nonnull ReadableByteChannel channel, @Nonnull ForkNodeArguments arguments ) @@ -53,18 +51,11 @@ public CommandChannelDecoder( @Nonnull ReadableByteChannel channel, @SuppressWarnings( "checkstyle:innerassignment" ) public Command decode() throws IOException { - if ( memento == null ) - { - // do not create memento in constructor because the constructor is called in another thread - // memento is the thread confinement object - memento = decoder.new Memento(); - } - do { try { - Command command = decoder.decode( memento ); + Command command = decoder.decode(); if ( command != null ) { return command; diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/stream/CommandDecoder.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/stream/CommandDecoder.java index 4a7e257f71..9387f85d58 100644 --- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/stream/CommandDecoder.java +++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/stream/CommandDecoder.java @@ -70,6 +70,7 @@ public class CommandDecoder extends AbstractStreamDecoder