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 2019/10/25 20:11:26 UTC
[maven-surefire] branch maven2surefire-jvm-communication updated:
fixed compilation errors (two tests hang, and see: todo stdOut)
This is an automated email from the ASF dual-hosted git repository.
tibordigana pushed a commit to branch maven2surefire-jvm-communication
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/maven2surefire-jvm-communication by this push:
new fae7bd7 fixed compilation errors (two tests hang, and see: todo stdOut)
fae7bd7 is described below
commit fae7bd7045970ff4900302eacc3d299a0b72b5ff
Author: tibordigana <ti...@apache.org>
AuthorDate: Fri Oct 25 22:11:15 2019 +0200
fixed compilation errors (two tests hang, and see: todo stdOut)
---
.../plugin/surefire/booterclient/ForkStarter.java | 10 ++--
.../lazytestprovider/AbstractCommandReader.java | 3 +-
.../lazytestprovider/DefaultCommandReader.java | 55 ++++++----------------
.../ExecutableCommandlineFactory.java | 2 +-
.../lazytestprovider/TestLessInputStream.java | 3 --
.../lazytestprovider/TestProvidingInputStream.java | 3 --
...AbstractEventHandler.java => EventHandler.java} | 5 +-
.../booterclient/output/ExecutableCommandline.java | 5 +-
.../output/NetworkingProcessExecutor.java | 2 +-
.../booterclient/output/PipeProcessExecutor.java | 10 ++--
.../output/ThreadedStreamConsumer.java | 8 +++-
.../booterclient/ForkConfigurationTest.java | 6 ++-
.../TestLessInputStreamBuilderTest.java | 32 ++++++++++++-
.../TestProvidingInputStreamTest.java | 46 ++++++++++++++----
14 files changed, 113 insertions(+), 77 deletions(-)
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 fd06a6c..5c28299 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
@@ -280,7 +280,7 @@ public class ForkStarter
defaultReporterFactories.add( forkedReporterFactory );
ForkClient forkClient =
new ForkClient( forkedReporterFactory, stream, log, new AtomicBoolean(), forkNumber );
- ExecutableCommandline<?> executableCommandline =
+ ExecutableCommandline<String> executableCommandline =
forkConfiguration.getExecutableCommandlineFactory().createExecutableCommandline( stream );
return fork( null, props, forkClient, effectiveSystemProperties, forkNumber, stream,
executableCommandline, false );
@@ -372,7 +372,7 @@ public class ForkStarter
Map<String, String> providerProperties = providerConfiguration.getProviderProperties();
try
{
- ExecutableCommandline<?> executableCommandline =
+ ExecutableCommandline<String> executableCommandline =
forkConfiguration.getExecutableCommandlineFactory()
.createExecutableCommandline( testProvidingInputStream );
return fork( null, new PropertiesWrapper( providerProperties ), forkClient,
@@ -449,7 +449,7 @@ public class ForkStarter
TestLessInputStream stream = builder.build();
try
{
- ExecutableCommandline<?> executableCommandline =
+ ExecutableCommandline<String> executableCommandline =
forkConfiguration.getExecutableCommandlineFactory()
.createExecutableCommandline( stream );
return fork( testSet,
@@ -551,7 +551,7 @@ public class ForkStarter
private RunResult fork( Object testSet, KeyValueSource providerProperties, ForkClient forkClient,
SurefireProperties effectiveSystemProperties, int forkNumber,
- AbstractCommandReader commandSender, ExecutableCommandline<?> executableCommandline,
+ AbstractCommandReader commandSender, ExecutableCommandline<String> executableCommandline,
boolean readTestsFromInStream )
throws SurefireBooterForkException
{
@@ -617,7 +617,7 @@ public class ForkStarter
new NativeStdErrStreamConsumer( forkClient.getDefaultReporterFactory() );
CommandLineCallable future = executableCommandline.executeCommandLineAsCallable( cli, commandSender,
- threadedStreamConsumer, /*todo*/stdOut, stdErrConsumer, closer );
+ threadedStreamConsumer, /*todo stdOut*/ null, stdErrConsumer, closer );
currentForkClients.add( forkClient );
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/AbstractCommandReader.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/AbstractCommandReader.java
index 797753d..9d2c738 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/AbstractCommandReader.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/AbstractCommandReader.java
@@ -20,7 +20,6 @@ package org.apache.maven.plugin.surefire.booterclient.lazytestprovider;
*/
import java.io.IOException;
-import java.io.InputStream;
import static java.util.Objects.requireNonNull;
@@ -41,7 +40,7 @@ public abstract class AbstractCommandReader
*
* @return encoded command, or null if closed
*/
- public abstract byte[] readNextCommand();
+ public abstract byte[] readNextCommand() throws IOException;
public abstract void close();
public abstract boolean isClosed();
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/DefaultCommandReader.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/DefaultCommandReader.java
index b54b16e..1479c48 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/DefaultCommandReader.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/DefaultCommandReader.java
@@ -34,9 +34,6 @@ import java.io.IOException;
public abstract class DefaultCommandReader
extends AbstractCommandReader
{
- private byte[] currentBuffer;
- private int currentPos;
-
/**
* Opposite to {@link #isClosed()}.
* @return {@code true} if not closed
@@ -60,59 +57,37 @@ public abstract class DefaultCommandReader
protected abstract Command nextCommand();
/**
- * Returns quietly and immediately.
- */
- protected final void invalidateInternalBuffer()
- {
- currentBuffer = null;
- currentPos = 0;
- }
-
- /**
* Used by single thread in StreamFeeder class.
*
* @return {@inheritDoc}
* @throws IOException {@inheritDoc}
*/
- @SuppressWarnings( "checkstyle:magicnumber" )
@Override
- public int read()
+ public byte[] readNextCommand()
throws IOException
{
+ tryFlush();
+
if ( isClosed() )
{
- tryFlush();
- return -1;
+ return null;
}
- if ( currentBuffer == null )
+ if ( !canContinue() )
{
- tryFlush();
-
- if ( !canContinue() )
- {
- close();
- return -1;
- }
-
- beforeNextCommand();
-
- if ( isClosed() )
- {
- return -1;
- }
-
- Command cmd = nextCommand();
- MasterProcessCommand cmdType = cmd.getCommandType();
- currentBuffer = cmdType.hasDataType() ? cmdType.encode( cmd.getData() ) : cmdType.encode();
+ close();
+ return null;
}
- int b = currentBuffer[currentPos++] & 0xff;
- if ( currentPos == currentBuffer.length )
+ beforeNextCommand();
+
+ if ( isClosed() )
{
- currentBuffer = null;
- currentPos = 0;
+ return null;
}
- return b;
+
+ Command cmd = nextCommand();
+ MasterProcessCommand cmdType = cmd.getCommandType();
+ return cmdType.hasDataType() ? cmdType.encode( cmd.getData() ) : cmdType.encode();
}
}
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/ExecutableCommandlineFactory.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/ExecutableCommandlineFactory.java
index 824ea1a..e36f3a8 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/ExecutableCommandlineFactory.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/ExecutableCommandlineFactory.java
@@ -31,5 +31,5 @@ public interface ExecutableCommandlineFactory
{
//todo Enrico, the parameter is not needed in Pipes. It is needed in TCP/IP
@Nonnull
- ExecutableCommandline createExecutableCommandline( AbstractCommandReader forkInputStream );
+ ExecutableCommandline<String> createExecutableCommandline( AbstractCommandReader forkInputStream );
}
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestLessInputStream.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestLessInputStream.java
index d8e72b7..d04537d 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestLessInputStream.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestLessInputStream.java
@@ -141,7 +141,6 @@ public final class TestLessInputStream
{
if ( closed.compareAndSet( false, true ) )
{
- invalidateInternalBuffer();
barrier.drainPermits();
barrier.release();
}
@@ -166,8 +165,6 @@ public final class TestLessInputStream
}
catch ( InterruptedException e )
{
- // help GC to free this object because StreamFeeder Thread cannot read it anyway after IOE
- invalidateInternalBuffer();
throw new IOException( e.getLocalizedMessage() );
}
}
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java
index a8392c9..6f3a4de 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java
@@ -168,7 +168,6 @@ public final class TestProvidingInputStream
{
if ( closed.compareAndSet( false, true ) )
{
- invalidateInternalBuffer();
barrier.drainPermits();
barrier.release();
}
@@ -183,8 +182,6 @@ public final class TestProvidingInputStream
}
catch ( InterruptedException e )
{
- // help GC to free this object because StreamFeeder Thread cannot read it anyway after IOE
- invalidateInternalBuffer();
throw new IOException( e.getLocalizedMessage(), e );
}
}
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/AbstractEventHandler.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/EventHandler.java
similarity index 91%
rename from maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/AbstractEventHandler.java
rename to maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/EventHandler.java
index 2f56055..b503ae9 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/AbstractEventHandler.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/EventHandler.java
@@ -21,8 +21,9 @@ package org.apache.maven.plugin.surefire.booterclient.output;
/**
*
+ * @param <T> type of event
*/
-abstract class AbstractEventHandler<T>
+interface EventHandler<T>
{
- abstract void handleEvent( T event );
+ void handleEvent( T event );
}
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ExecutableCommandline.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ExecutableCommandline.java
index f53a9a1..7694cda 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ExecutableCommandline.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ExecutableCommandline.java
@@ -28,13 +28,14 @@ import org.apache.maven.shared.utils.cli.StreamConsumer;
import javax.annotation.Nonnull;
/**
- *
+ * todo add javadoc
+ * @param <T> type of event
*/
public interface ExecutableCommandline<T>
{
@Nonnull CommandLineCallable executeCommandLineAsCallable( @Nonnull Commandline cli,
@Nonnull AbstractCommandReader commands,
- @Nonnull AbstractEventHandler<T> events,
+ @Nonnull EventHandler<T> events,
StreamConsumer stdOut,
StreamConsumer stdErr,
@Nonnull Runnable runAfterProcessTermination )
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/NetworkingProcessExecutor.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/NetworkingProcessExecutor.java
index 56a1b22..f424980 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/NetworkingProcessExecutor.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/NetworkingProcessExecutor.java
@@ -41,7 +41,7 @@ final class NetworkingProcessExecutor
@Override
public CommandLineCallable executeCommandLineAsCallable( @Nonnull Commandline cli,
@Nonnull AbstractCommandReader commands,
- @Nonnull AbstractEventHandler events,
+ @Nonnull EventHandler events,
StreamConsumer stdOut,
StreamConsumer stdErr,
@Nonnull Runnable runAfterProcessTermination )
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/PipeProcessExecutor.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/PipeProcessExecutor.java
index c8704c8..fb0b9e8 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/PipeProcessExecutor.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/PipeProcessExecutor.java
@@ -28,6 +28,7 @@ import org.apache.maven.shared.utils.cli.StreamConsumer;
import javax.annotation.Nonnull;
+import java.io.IOException;
import java.io.InputStream;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
@@ -43,7 +44,7 @@ final class PipeProcessExecutor
@Nonnull
public CommandLineCallable executeCommandLineAsCallable( @Nonnull Commandline cli,
@Nonnull AbstractCommandReader commands,
- @Nonnull AbstractEventHandler<String> events,
+ @Nonnull EventHandler<String> events,
StreamConsumer stdOut,
StreamConsumer stdErr,
@Nonnull Runnable runAfterProcessTermination )
@@ -55,9 +56,9 @@ final class PipeProcessExecutor
private static class EventHandlerAdapter implements StreamConsumer
{
- private final AbstractEventHandler<String> events;
+ private final EventHandler<String> events;
- private EventHandlerAdapter( AbstractEventHandler<String> events )
+ private EventHandlerAdapter( EventHandler<String> events )
{
this.events = events;
}
@@ -83,7 +84,7 @@ final class PipeProcessExecutor
}
@Override
- public int read()
+ public int read() throws IOException
{
if ( commands.isClosed() )
{
@@ -104,6 +105,7 @@ final class PipeProcessExecutor
}
}
+ @SuppressWarnings( "checkstyle:magicnumber" )
int b = currentBuffer[currentPos++] & 0xff;
if ( currentPos == currentBuffer.length )
{
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 388f16d..96723d1 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
@@ -36,7 +36,7 @@ import static java.lang.Thread.currentThread;
* @author Kristian Rosenvold
*/
public final class ThreadedStreamConsumer
- implements StreamConsumer, Closeable
+ implements StreamConsumer, EventHandler<String>, Closeable
{
private static final String END_ITEM = "";
@@ -113,6 +113,12 @@ public final class ThreadedStreamConsumer
}
@Override
+ public void handleEvent( String event )
+ {
+ consumeLine( event );
+ }
+
+ @Override
public void consumeLine( String s )
{
if ( stop.get() && !thread.isAlive() )
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
index 3fe0ecd..f21f619 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
@@ -22,6 +22,7 @@ package org.apache.maven.plugin.surefire.booterclient;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.maven.plugin.surefire.JdkAttributes;
+import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.ExecutableCommandlineFactory;
import org.apache.maven.plugin.surefire.log.api.NullConsoleLogger;
import org.apache.maven.shared.utils.StringUtils;
import org.apache.maven.shared.utils.cli.Commandline;
@@ -46,6 +47,7 @@ import static org.fest.util.Files.temporaryFolder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
public class ForkConfigurationTest
{
@@ -218,13 +220,13 @@ public class ForkConfigurationTest
assertTrue( tmpDir.mkdirs() );
return new JarManifestForkConfiguration( emptyClasspath(), tmpDir, null,
cwd, new Properties(), argLine, Collections.<String, String>emptyMap(), false, 1, false,
- platform, new NullConsoleLogger() );
+ platform, new NullConsoleLogger(), mock(ExecutableCommandlineFactory.class) );
}
// based on http://stackoverflow.com/questions/2591083/getting-version-of-java-in-runtime
private static boolean isJavaVersionAtLeast7u60()
{
String[] javaVersionElements = System.getProperty( "java.runtime.version" ).split( "\\.|_|-b" );
- return Integer.valueOf( javaVersionElements[1] ) >= 7 && Integer.valueOf( javaVersionElements[3] ) >= 60;
+ return Integer.parseInt( javaVersionElements[1] ) >= 7 && Integer.parseInt( javaVersionElements[3] ) >= 60;
}
}
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestLessInputStreamBuilderTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestLessInputStreamBuilderTest.java
index 4d95588..e9b1b3a 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestLessInputStreamBuilderTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestLessInputStreamBuilderTest.java
@@ -28,6 +28,7 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.io.IOException;
+import java.io.InputStream;
import java.util.Iterator;
import java.util.NoSuchElementException;
@@ -137,8 +138,35 @@ public class TestLessInputStreamBuilderTest
throws IOException
{
TestLessInputStreamBuilder builder = new TestLessInputStreamBuilder();
- TestLessInputStream pluginIs = builder.build();
- MasterProcessChannelDecoder decoder = new DefaultMasterProcessChannelDecoder( pluginIs, null );
+ final TestLessInputStream pluginIs = builder.build();
+ InputStream is = new InputStream()
+ {
+ private byte[] buffer;
+ private int idx;
+
+ @Override
+ public int read() throws IOException
+ {
+ if ( buffer == null )
+ {
+ idx = 0;
+ buffer = pluginIs.readNextCommand();
+ }
+
+ if ( buffer != null )
+ {
+ byte b = buffer[idx++];
+ if ( idx == buffer.length )
+ {
+ buffer = null;
+ idx = 0;
+ }
+ return b;
+ }
+ throw new IOException();
+ }
+ };
+ MasterProcessChannelDecoder decoder = new DefaultMasterProcessChannelDecoder( is, null );
builder.getImmediateCommands().acknowledgeByeEventReceived();
builder.getImmediateCommands().noop();
Command bye = decoder.decode();
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStreamTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStreamTest.java
index ebd23bf..78c637f 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStreamTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStreamTest.java
@@ -27,6 +27,7 @@ import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.lang.Thread.State;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.concurrent.Callable;
@@ -49,13 +50,13 @@ import static org.junit.Assert.assertTrue;
public class TestProvidingInputStreamTest
{
@Test
- public void closedStreamShouldReturnEndOfStream()
+ public void closedStreamShouldReturnNullAsEndOfStream()
throws IOException
{
Queue<String> commands = new ArrayDeque<>();
TestProvidingInputStream is = new TestProvidingInputStream( commands );
is.close();
- assertThat( is.read(), is( -1 ) );
+ assertThat( is.readNextCommand(), is( nullValue() ) );
}
@Test
@@ -78,7 +79,7 @@ public class TestProvidingInputStreamTest
} );
Thread assertionThread = new Thread( futureTask );
assertionThread.start();
- assertThat( is.read(), is( -1 ) );
+ assertThat( is.readNextCommand(), is( nullValue() ) );
State state = futureTask.get();
assertThat( state, is( State.WAITING ) );
}
@@ -102,7 +103,7 @@ public class TestProvidingInputStreamTest
StringBuilder stream = new StringBuilder();
for ( int i = 0; i < 82; i++ )
{
- stream.append( (char) is.read() );
+ stream.append( new String( is.readNextCommand(), StandardCharsets.US_ASCII ) );
}
assertThat( stream.toString(),
is( ":maven-surefire-std-out:testset-finished::maven-surefire-std-out:testset-finished:" ) );
@@ -111,7 +112,7 @@ public class TestProvidingInputStreamTest
is.close();
assertTrue( emptyStream );
- assertThat( is.read(), is( -1 ) );
+ assertThat( is.readNextCommand(), is( nullValue() ) );
}
@Test
@@ -133,7 +134,7 @@ public class TestProvidingInputStreamTest
StringBuilder stream = new StringBuilder();
for ( int i = 0; i < 43; i++ )
{
- stream.append( (char) is.read() );
+ stream.append( new String( is.readNextCommand(), StandardCharsets.US_ASCII ) );
}
assertThat( stream.toString(),
is( ":maven-surefire-std-out:run-testclass:Test:" ) );
@@ -145,8 +146,35 @@ public class TestProvidingInputStreamTest
public void shouldDecodeTwoCommands()
throws IOException
{
- TestProvidingInputStream pluginIs = new TestProvidingInputStream( new ConcurrentLinkedQueue<String>() );
- MasterProcessChannelDecoder decoder = new DefaultMasterProcessChannelDecoder( pluginIs, null );
+ final TestProvidingInputStream pluginIs = new TestProvidingInputStream( new ConcurrentLinkedQueue<String>() );
+ InputStream is = new InputStream()
+ {
+ private byte[] buffer;
+ private int idx;
+
+ @Override
+ public int read() throws IOException
+ {
+ if ( buffer == null )
+ {
+ idx = 0;
+ buffer = pluginIs.readNextCommand();
+ }
+
+ if ( buffer != null )
+ {
+ byte b = buffer[idx++];
+ if ( idx == buffer.length )
+ {
+ buffer = null;
+ idx = 0;
+ }
+ return b;
+ }
+ throw new IOException();
+ }
+ };
+ MasterProcessChannelDecoder decoder = new DefaultMasterProcessChannelDecoder( is, null );
pluginIs.acknowledgeByeEventReceived();
pluginIs.noop();
Command bye = decoder.decode();
@@ -184,7 +212,7 @@ public class TestProvidingInputStreamTest
try
{
//noinspection ResultOfMethodCallIgnored
- is.read();
+ is.readNextCommand();
}
catch ( IOException e )
{