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 2017/05/27 12:28:19 UTC
maven-surefire git commit: more unit tests to see streams are
properly decoded
Repository: maven-surefire
Updated Branches:
refs/heads/master a7e867007 -> 1ca8374d2
more unit tests to see streams are properly decoded
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/1ca8374d
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/1ca8374d
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/1ca8374d
Branch: refs/heads/master
Commit: 1ca8374d2618fa2667bd4a82c9684a30fba619d9
Parents: a7e8670
Author: Tibor17 <ti...@apache.org>
Authored: Sat May 27 14:28:05 2017 +0200
Committer: Tibor17 <ti...@apache.org>
Committed: Sat May 27 14:28:05 2017 +0200
----------------------------------------------------------------------
.../TestLessInputStreamBuilderTest.java | 26 ++++++++++++++++++--
.../TestProvidingInputStreamTest.java | 22 +++++++++++++++++
.../booter/MasterProcessCommandTest.java | 16 ++++++++++++
3 files changed, 62 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/1ca8374d/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestLessInputStreamBuilderTest.java
----------------------------------------------------------------------
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 6dee0a4..5d9b5af 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
@@ -20,10 +20,12 @@ package org.apache.maven.plugin.surefire.booterclient.lazytestprovider;
*/
import org.apache.maven.surefire.booter.Command;
+import org.apache.maven.surefire.booter.MasterProcessCommand;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import java.io.DataInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.NoSuchElementException;
@@ -31,12 +33,15 @@ import java.util.NoSuchElementException;
import static org.apache.maven.plugin.surefire.booterclient.lazytestprovider.TestLessInputStream.TestLessInputStreamBuilder;
import static org.apache.maven.surefire.booter.Command.NOOP;
import static org.apache.maven.surefire.booter.Command.SKIP_SINCE_NEXT_TEST;
+import static org.apache.maven.surefire.booter.MasterProcessCommand.BYE_ACK;
import static org.apache.maven.surefire.booter.MasterProcessCommand.SHUTDOWN;
+import static org.apache.maven.surefire.booter.MasterProcessCommand.decode;
import static org.apache.maven.surefire.booter.Shutdown.EXIT;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
/**
* Testing cached and immediate commands in {@link TestLessInputStream}.
@@ -126,4 +131,21 @@ public class TestLessInputStreamBuilderTest
e.expect( NoSuchElementException.class );
is.nextCommand();
}
+
+ @Test
+ public void shouldDecodeTwoCommands()
+ throws IOException
+ {
+ TestLessInputStreamBuilder builder = new TestLessInputStreamBuilder();
+ TestLessInputStream pluginIs = builder.build();
+ builder.getImmediateCommands().acknowledgeByeEventReceived();
+ builder.getImmediateCommands().noop();
+ DataInputStream is = new DataInputStream( pluginIs );
+ Command bye = decode( is );
+ assertThat( bye, is( notNullValue() ) );
+ assertThat( bye.getCommandType(), is( BYE_ACK ) );
+ Command noop = decode( is );
+ assertThat( noop, is( notNullValue() ) );
+ assertThat( noop.getCommandType(), is( MasterProcessCommand.NOOP ) );
+ }
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/1ca8374d/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStreamTest.java
----------------------------------------------------------------------
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 6f25ec3..3f94039 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
@@ -19,15 +19,21 @@ package org.apache.maven.plugin.surefire.booterclient.lazytestprovider;
* under the License.
*/
+import org.apache.maven.surefire.booter.Command;
+import org.apache.maven.surefire.booter.MasterProcessCommand;
import org.junit.Test;
+import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
+import static org.apache.maven.surefire.booter.MasterProcessCommand.BYE_ACK;
+import static org.apache.maven.surefire.booter.MasterProcessCommand.decode;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
@@ -130,6 +136,22 @@ public class TestProvidingInputStreamTest
assertThat( is.read(), is( (int) 't' ) );
}
+ @Test
+ public void shouldDecodeTwoCommands()
+ throws IOException
+ {
+ TestProvidingInputStream pluginIs = new TestProvidingInputStream( new ConcurrentLinkedDeque<String>() );
+ pluginIs.acknowledgeByeEventReceived();
+ pluginIs.noop();
+ DataInputStream is = new DataInputStream( pluginIs );
+ Command bye = decode( is );
+ assertThat( bye, is( notNullValue() ) );
+ assertThat( bye.getCommandType(), is( BYE_ACK ) );
+ Command noop = decode( is );
+ assertThat( noop, is( notNullValue() ) );
+ assertThat( noop.getCommandType(), is( MasterProcessCommand.NOOP ) );
+ }
+
private static void sleep( long millis )
{
try
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/1ca8374d/surefire-api/src/test/java/org/apache/maven/surefire/booter/MasterProcessCommandTest.java
----------------------------------------------------------------------
diff --git a/surefire-api/src/test/java/org/apache/maven/surefire/booter/MasterProcessCommandTest.java b/surefire-api/src/test/java/org/apache/maven/surefire/booter/MasterProcessCommandTest.java
index 6e66a18..19740fd 100644
--- a/surefire-api/src/test/java/org/apache/maven/surefire/booter/MasterProcessCommandTest.java
+++ b/surefire-api/src/test/java/org/apache/maven/surefire/booter/MasterProcessCommandTest.java
@@ -157,4 +157,20 @@ public class MasterProcessCommandTest
assertThat( command.getCommandType(), is( RUN_CLASS ) );
assertThat( command.getData(), is( "pkg.Test" ) );
}
+
+ public void testShouldDecodeTwoCommands() throws IOException
+ {
+ byte[] cmd1 = BYE_ACK.encode();
+ byte[] cmd2 = NOOP.encode();
+ byte[] stream = new byte[cmd1.length + cmd2.length];
+ System.arraycopy( cmd1, 0, stream, 0, cmd1.length );
+ System.arraycopy( cmd2, 0, stream, cmd1.length, cmd2.length );
+ DataInputStream is = new DataInputStream( new ByteArrayInputStream( stream ) );
+ Command bye = decode( is );
+ assertNotNull( bye );
+ assertThat( bye.getCommandType(), is( BYE_ACK ) );
+ Command noop = decode( is );
+ assertNotNull( noop );
+ assertThat( noop.getCommandType(), is( NOOP ) );
+ }
}