You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2022/04/13 00:28:42 UTC

[maven-surefire] branch AFTER-SUREFIRE-2058 created (now 345cfe2d6)

This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a change to branch AFTER-SUREFIRE-2058
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git


      at 345cfe2d6 Refactored decode(Memento) and embedded Memento in the decoder instance

This branch includes the following new commits:

     new 178cb6509 Commits after SUREFIRE-2058 regarding AbstractStreamDecoder
     new 345cfe2d6 Refactored decode(Memento) and embedded Memento in the decoder instance

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-surefire] 01/02: Commits after SUREFIRE-2058 regarding AbstractStreamDecoder

Posted by ti...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch AFTER-SUREFIRE-2058
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git

commit 178cb6509bb9a5b6f34d749b12cb325c6d3f2d17
Author: tibor.digana <ti...@apache.org>
AuthorDate: Wed Apr 13 01:08:56 2022 +0200

    Commits after SUREFIRE-2058 regarding AbstractStreamDecoder
---
 .../surefire/api/stream/AbstractStreamDecoder.java | 30 ++++++++--------------
 1 file changed, 11 insertions(+), 19 deletions(-)

diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoder.java b/surefire-api/src/main/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoder.java
index facf30bcb..740541480 100644
--- a/surefire-api/src/main/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoder.java
+++ b/surefire-api/src/main/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoder.java
@@ -305,32 +305,24 @@ public abstract class AbstractStreamDecoder<M, MT extends Enum<MT>, ST extends E
         memento.getDecoder().reset();
         final CharBuffer output = memento.getCharBuffer();
         ( (Buffer) output ).clear();
-        final ByteBuffer input = memento.getByteBuffer();
         final List<String> 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();


[maven-surefire] 02/02: Refactored decode(Memento) and embedded Memento in the decoder instance

Posted by ti...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch AFTER-SUREFIRE-2058
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git

commit 345cfe2d633a5c0f2b25e94d1c4f749c9561508c
Author: tibor.digana <ti...@apache.org>
AuthorDate: Wed Apr 13 02:28:26 2022 +0200

    Refactored decode(Memento) and embedded Memento in the decoder instance
---
 .../maven/plugin/surefire/extensions/EventConsumerThread.java |  4 +---
 .../java/org/apache/maven/surefire/stream/EventDecoder.java   | 11 ++++++++++-
 .../maven/surefire/api/stream/AbstractStreamDecoder.java      | 10 +++++++++-
 .../maven/surefire/api/stream/MalformedChannelException.java  |  2 +-
 .../maven/surefire/booter/spi/CommandChannelDecoder.java      | 11 +----------
 .../apache/maven/surefire/booter/stream/CommandDecoder.java   | 10 +++++++++-
 6 files changed, 31 insertions(+), 17 deletions(-)

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 79d5c85ab..2e5b5d3f2 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 @@ package org.apache.maven.plugin.surefire.extensions;
 
 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 class EventConsumerThread extends CloseableDaemonThread
               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 ea1188984..fa61d491e 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<Event, ForkedProcessEven
 
     private final OutputStream debugSink;
 
+    private Memento memento;
+
     public EventDecoder( @Nonnull ReadableByteChannel channel,
                          @Nonnull ForkNodeArguments arguments )
     {
@@ -148,8 +150,15 @@ public class EventDecoder extends AbstractStreamDecoder<Event, ForkedProcessEven
     }
 
     @Override
-    public Event decode( @Nonnull Memento memento ) throws IOException
+    public Event 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 = new Memento();
+        }
+
         try
         {
             ForkedProcessEventType eventType = readMessageType( memento );
diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoder.java b/surefire-api/src/main/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoder.java
index 740541480..0ed7e18cc 100644
--- a/surefire-api/src/main/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoder.java
+++ b/surefire-api/src/main/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoder.java
@@ -89,7 +89,15 @@ public abstract class AbstractStreamDecoder<M, MT extends Enum<MT>, ST extends E
         logger = arguments.getConsoleLogger();
     }
 
-    public abstract M decode( @Nonnull Memento memento ) throws MalformedChannelException, IOException;
+    /**
+     * Decoding and returns a message {@code M} and waiting, if necessary, for the next
+     * message received from the channel.
+     *
+     * @return message {@code M}, or null if could not decode a message due to a frame error
+     * @throws MalformedChannelException the channel error
+     * @throws IOException stream I/O exception
+     */
+    public abstract M decode() throws MalformedChannelException, IOException;
 
     @Nonnull
     protected abstract byte[] getEncodedMagicNumber();
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 cf4468ffc..89447356c 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 @@ package org.apache.maven.surefire.api.stream;
  */
 
 /**
- *
+ * No supported message type.
  */
 public class MalformedChannelException extends Exception
 {
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 85bda73a8..8b7a5d7b7 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 @@ package org.apache.maven.surefire.booter.spi;
 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 @@ import java.nio.channels.ReadableByteChannel;
 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 class CommandChannelDecoder implements MasterProcessChannelDecoder
     @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 4a7e257f7..9387f85d5 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<Command, MasterProcess
 
     private final ForkNodeArguments arguments;
     private final OutputStream debugSink;
+    private Memento memento;
 
     public CommandDecoder( @Nonnull ReadableByteChannel channel,
                            @Nonnull ForkNodeArguments arguments )
@@ -80,8 +81,15 @@ public class CommandDecoder extends AbstractStreamDecoder<Command, MasterProcess
     }
 
     @Override
-    public Command decode( @Nonnull Memento memento ) throws IOException, MalformedChannelException
+    public Command decode() throws IOException, MalformedChannelException
     {
+        if ( memento == null )
+        {
+            // do not create memento in constructor because the constructor is called in another thread
+            // memento is the thread confinement object
+            memento = new Memento();
+        }
+
         try
         {
             MasterProcessCommand commandType = readMessageType( memento );