2929import java .util .concurrent .atomic .AtomicInteger ;
3030
3131import org .junit .jupiter .api .Test ;
32- import org .junit .jupiter .api .condition .DisabledOnOs ;
33- import org .junit .jupiter .api .condition .OS ;
3432
3533import org .springframework .core .task .SimpleAsyncTaskExecutor ;
3634import org .springframework .integration .ip .IpHeaders ;
5048 * @since 2.0
5149 */
5250@ Multicast
53- @ DisabledOnOs (value = OS .MAC , disabledReason = "Multicast tests don't work on MacOS" )
5451public class DatagramPacketMulticastSendingHandlerTests implements TestApplicationContextAware {
5552
5653 @ Test
@@ -64,7 +61,7 @@ public void verifySendMulticast(MulticastCondition multicastCondition) throws Ex
6461 }
6562 final int testPort = socket .getLocalPort ();
6663 final String multicastAddress = multicastCondition .getGroup ();
67- final String payload = "foo " ;
64+ final String payload = "test " ;
6865 final CountDownLatch listening = new CountDownLatch (2 );
6966 final CountDownLatch received = new CountDownLatch (2 );
7067 Runnable catcher = () -> {
@@ -94,7 +91,7 @@ public void verifySendMulticast(MulticastCondition multicastCondition) throws Ex
9491 Executor executor = new SimpleAsyncTaskExecutor ("verifySendMulticast-" );
9592 executor .execute (catcher );
9693 executor .execute (catcher );
97- assertThat (listening .await (10000 , TimeUnit .MILLISECONDS )).isTrue ();
94+ assertThat (listening .await (20 , TimeUnit .SECONDS )).isTrue ();
9895 MulticastSendingMessageHandler handler = new MulticastSendingMessageHandler (multicastAddress , testPort );
9996 handler .setBeanFactory (TEST_INTEGRATION_CONTEXT );
10097 NetworkInterface nic = multicastCondition .getNic ();
@@ -117,26 +114,19 @@ public void verifySendMulticast(MulticastCondition multicastCondition) throws Ex
117114 }
118115 handler .afterPropertiesSet ();
119116 handler .handleMessage (MessageBuilder .withPayload (payload ).build ());
120- assertThat (received .await (10000 , TimeUnit .MILLISECONDS )).isTrue ();
117+ assertThat (received .await (20000 , TimeUnit .MILLISECONDS )).isTrue ();
121118 handler .stop ();
122119 socket .close ();
123120 }
124121
125122 @ Test
126123 public void verifySendMulticastWithAcks (MulticastCondition multicastCondition ) throws Exception {
127-
128- MulticastSocket socket ;
129- try {
130- socket = new MulticastSocket ();
131- }
132- catch (Exception e ) {
133- return ;
134- }
124+ MulticastSocket socket = new MulticastSocket ();
135125 final int testPort = socket .getLocalPort ();
136126 final AtomicInteger ackPort = new AtomicInteger ();
137127
138128 final String multicastAddress = multicastCondition .getGroup ();
139- final String payload = "foobar " ;
129+ final String payload = "test_test " ;
140130 final CountDownLatch listening = new CountDownLatch (2 );
141131 final CountDownLatch ackListening = new CountDownLatch (1 );
142132 final CountDownLatch ackSent = new CountDownLatch (2 );
@@ -151,14 +141,14 @@ public void verifySendMulticastWithAcks(MulticastCondition multicastCondition) t
151141 InetAddress group = InetAddress .getByName (multicastAddress );
152142 socket1 .joinGroup (new InetSocketAddress (group , 0 ), null );
153143 listening .countDown ();
154- assertThat (ackListening .await (10 , TimeUnit .SECONDS )).isTrue ();
144+ assertThat (ackListening .await (20 , TimeUnit .SECONDS )).isTrue ();
155145 socket1 .receive (receivedPacket );
156146 socket1 .close ();
157147 byte [] src = receivedPacket .getData ();
158148 int length = receivedPacket .getLength ();
159149 int offset = receivedPacket .getOffset ();
160- byte [] dest = new byte [6 ];
161- System .arraycopy (src , offset + length - 6 , dest , 0 , 6 );
150+ byte [] dest = new byte [9 ];
151+ System .arraycopy (src , offset + length - 9 , dest , 0 , 9 );
162152 assertThat (new String (dest )).isEqualTo (payload );
163153 DatagramPacketMessageMapper mapper = new DatagramPacketMessageMapper ();
164154 mapper .setAcknowledge (true );
@@ -196,9 +186,9 @@ public void verifySendMulticastWithAcks(MulticastCondition multicastCondition) t
196186 Executor executor = new SimpleAsyncTaskExecutor ("verifySendMulticastWithAcks-" );
197187 executor .execute (catcher );
198188 executor .execute (catcher );
199- assertThat (listening .await (10000 , TimeUnit .MILLISECONDS )).isTrue ();
189+ assertThat (listening .await (20000 , TimeUnit .MILLISECONDS )).isTrue ();
200190 MulticastSendingMessageHandler handler =
201- new MulticastSendingMessageHandler (multicastAddress , testPort , true , true , "localhost" , 0 , 10000 );
191+ new MulticastSendingMessageHandler (multicastAddress , testPort , true , true , "localhost" , 0 , 20000 );
202192
203193 if (nic != null ) {
204194 String hostName = null ;
@@ -225,7 +215,7 @@ public void verifySendMulticastWithAcks(MulticastCondition multicastCondition) t
225215 ackPort .set (handler .getAckPort ());
226216 ackListening .countDown ();
227217 handler .handleMessage (MessageBuilder .withPayload (payload ).build ());
228- assertThat (ackSent .await (10000 , TimeUnit .MILLISECONDS )).isTrue ();
218+ assertThat (ackSent .await (20000 , TimeUnit .MILLISECONDS )).isTrue ();
229219 handler .stop ();
230220 socket .close ();
231221 }
0 commit comments