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 2020/06/08 18:42:15 UTC
[maven-surefire] branch SUREFIRE-1796 updated: FutureTask.get()
checking exception instead of try-catch within the Thread
This is an automated email from the ASF dual-hosted git repository.
tibordigana pushed a commit to branch SUREFIRE-1796
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/SUREFIRE-1796 by this push:
new c6f52fb FutureTask.get() checking exception instead of try-catch within the Thread
c6f52fb is described below
commit c6f52fbb756482b0dfc3e5fae73c434b192db1fd
Author: tibordigana <ti...@apache.org>
AuthorDate: Mon Jun 8 20:42:04 2020 +0200
FutureTask.get() checking exception instead of try-catch within the Thread
---
.../maven/plugin/surefire/extensions/E2ETest.java | 61 ++++++++++------------
1 file changed, 29 insertions(+), 32 deletions(-)
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
index a6c744d..fda9d7f 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
@@ -38,12 +38,15 @@ import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.util.UUID;
+import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import static org.fest.assertions.Assertions.assertThat;
+import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -199,29 +202,27 @@ public class E2ETest
ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
- try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments );
+ SurefireMasterProcessChannelProcessorFactory client = new SurefireMasterProcessChannelProcessorFactory() )
{
- Thread t = new Thread()
+ FutureTask<String> task = new FutureTask<>( new Callable<String>()
{
@Override
- public void run()
+ public String call() throws Exception
{
- SurefireMasterProcessChannelProcessorFactory client
- = new SurefireMasterProcessChannelProcessorFactory();
- try
- {
- client.connect( server.getForkNodeConnectionString() );
- }
- catch ( IOException e )
- {
- e.printStackTrace();
- throw new RuntimeException( e );
- }
+ client.connect( server.getForkNodeConnectionString() );
+ return "client connected";
}
- };
+ } );
+
+ Thread t = new Thread( task );
t.setDaemon( true );
t.start();
+
server.connectToClient();
+
+ assertThat( task.get() )
+ .isEqualTo( "client connected" );
}
}
@@ -231,28 +232,22 @@ public class E2ETest
ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
- try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments );
+ SurefireMasterProcessChannelProcessorFactory client = new SurefireMasterProcessChannelProcessorFactory() )
{
- Thread t = new Thread()
+ FutureTask<String> task = new FutureTask<>( new Callable<String>()
{
@Override
- public void run()
+ public String call() throws Exception
{
- SurefireMasterProcessChannelProcessorFactory client
- = new SurefireMasterProcessChannelProcessorFactory();
- try
- {
- URI connectionString = new URI( server.getForkNodeConnectionString() );
- client.connect( "tcp://" + connectionString.getHost() + ":" + connectionString.getPort()
- + "?sessionId=6ba7b812-9dad-11d1-80b4-00c04fd430c8" );
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- throw new RuntimeException( e );
- }
+ URI connectionString = new URI( server.getForkNodeConnectionString() );
+ client.connect( "tcp://" + connectionString.getHost() + ":" + connectionString.getPort()
+ + "?sessionId=6ba7b812-9dad-11d1-80b4-00c04fd430c8" );
+ return "client connected";
}
- };
+ } );
+
+ Thread t = new Thread( task );
t.setDaemon( true );
t.start();
@@ -260,6 +255,8 @@ public class E2ETest
e.expectMessage( "authentication failed" );
server.connectToClient();
+
+ fail( task.get() );
}
}
}