1919import com .rabbitmq .client .Connection ;
2020import com .rabbitmq .client .ConnectionFactory ;
2121import com .rabbitmq .client .impl .AMQImpl ;
22- import org .hamcrest .Matchers ;
23- import org .hamcrest .junit .MatcherAssert ;
2422import org .junit .jupiter .api .AfterEach ;
2523import org .junit .jupiter .api .BeforeEach ;
26- import org .junit .jupiter .api .Test ;
2724import org .junit .jupiter .params .ParameterizedTest ;
2825import org .junit .jupiter .params .provider .Arguments ;
2926import org .junit .jupiter .params .provider .MethodSource ;
@@ -53,34 +50,37 @@ public class PublisherOnlyStopsCorrectlyTest {
5350 MulticastParams params ;
5451
5552 Stats stats = new Stats (0 ) {
53+
5654 @ Override
5755 protected void report (long now ) {
5856 }
5957 };
6058
6159 ExecutorService executorService ;
6260
63- @ BeforeEach public void init () {
61+ static Stream <Arguments > publisherOnlyStopsWhenBrokerCrashesArguments () {
62+ return Stream .of (
63+ // number of messages before throwing exception, configurator, assertion message
64+ Arguments .of (10 , (Consumer <MulticastParams >) (params ) -> { }, "Sender should have failed and program should stop" ),
65+ Arguments .of (2 , (Consumer <MulticastParams >) (params ) -> params .setPublishingInterval (1 ), "Sender should have failed and program should stop" )
66+ );
67+ }
68+
69+ @ BeforeEach
70+ public void init () {
6471 params = new MulticastParams ();
6572 executorService = Executors .newSingleThreadExecutor ();
6673 }
6774
68- @ AfterEach public void tearDown () {
75+ @ AfterEach
76+ public void tearDown () {
6977 executorService .shutdownNow ();
7078 }
7179
72- static Stream <Arguments > publisherOnlyStopsWhenBrokerCrashesArguments () {
73- return Stream .of (
74- // number of messages before throwing exception, configurator, assertion message
75- Arguments .of (10 , (Consumer <MulticastParams >)(params ) -> {}, "Sender should have failed and program should stop" ),
76- Arguments .of (2 , (Consumer <MulticastParams >)(params ) -> params .setPublishingInterval (1 ), "Sender should have failed and program should stop" )
77- );
78- }
79-
8080 @ ParameterizedTest
8181 @ MethodSource ("publisherOnlyStopsWhenBrokerCrashesArguments" )
8282 public void publisherOnlyStopsWhenBrokerCrashes (
83- int messageTotal , Consumer <MulticastParams > configurator , String message ) throws Exception {
83+ int messageTotal , Consumer <MulticastParams > configurator , String message ) throws Exception {
8484 params .setConsumerCount (0 );
8585 params .setProducerCount (1 );
8686 configurator .accept (params );
@@ -112,7 +112,6 @@ public void publisherOnlyStopsWhenBrokerCrashes(
112112 return null ;
113113 });
114114 assertThat (message , latch .await (10 , TimeUnit .SECONDS ), is (true ));
115-
116115 }
117116
118117 private MulticastSet getMulticastSet (ConnectionFactory connectionFactory ) {
@@ -123,5 +122,4 @@ stats, connectionFactory, params, singletonList("amqp://localhost"),
123122 set .setThreadingHandler (new MulticastSet .DefaultThreadingHandler ());
124123 return set ;
125124 }
126-
127125}
0 commit comments