cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dsosno...@apache.org
Subject [1/5] git commit: Improve reliability of test by ignoring the exact order of callbacks, as long as they're consistent (messages accepted in order, one and only one ack per message, messages always accepted before acked).
Date Mon, 23 Jun 2014 01:33:08 GMT
Repository: cxf
Updated Branches:
  refs/heads/master eb3d8f425 -> 45867c50a


Improve reliability of test by ignoring the exact order of callbacks, as
long as they're consistent (messages accepted in order, one and only one
ack per message, messages always accepted before acked).

Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/e8abc3be
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e8abc3be
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e8abc3be

Branch: refs/heads/master
Commit: e8abc3beb291e979fe9a6b932ad3fcbe0b08b64f
Parents: fcf3c8a
Author: dsosnoski <dsosnoski@apache.org>
Authored: Mon May 26 19:38:39 2014 +1200
Committer: dsosnoski <dsosnoski@apache.org>
Committed: Sun Jun 22 20:35:58 2014 +1200

----------------------------------------------------------------------
 .../ws/rm/MessageCallbackOnewayTest.java        | 74 +++++++++-----------
 1 file changed, 35 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/e8abc3be/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/MessageCallbackOnewayTest.java
----------------------------------------------------------------------
diff --git a/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/MessageCallbackOnewayTest.java
b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/MessageCallbackOnewayTest.java
index 4643026..0e7111a 100644
--- a/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/MessageCallbackOnewayTest.java
+++ b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/MessageCallbackOnewayTest.java
@@ -22,8 +22,10 @@ package org.apache.cxf.systest.ws.rm;
 import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
 import java.util.logging.Logger;
@@ -64,8 +66,8 @@ import org.junit.Test;
  */
 public class MessageCallbackOnewayTest extends AbstractBusClientServerTestBase {
     public static final String PORT = allocatePort(MessageCallbackOnewayTest.class);
-    private static final String GREETER_ADDRESS 
-        = "http://localhost:" + PORT + "/SoapContext/GreeterPort";
+    private static final String GREETER_ADDRESS  = "http://localhost:" + PORT + "/SoapContext/GreeterPort";
+    private static final Long RETRANSMISSION_INTERVAL = new Long(2000);
 
     private static final Logger LOG = LogUtils.getLogger(MessageCallbackOnewayTest.class);
 
@@ -90,10 +92,24 @@ public class MessageCallbackOnewayTest extends AbstractBusClientServerTestBase
{
         Thread.sleep(100);
     }
     
-    private void verifyCallback(int index, boolean accept, long mnum) {
-        Callback cb = callback.getCallbacks().get(index);
-        assertEquals(accept, cb.isAccept());
-        assertEquals(mnum, cb.getMsgNumber());
+    /**
+     * Checks that all callbacks are received, that messages are accepted in order, and that
each message is accepted
+     * before it is acknowledged (order of acknowledgements doesn't really matter).
+     */
+    private void verifyCallbacks() {
+        List<Callback> cbs = callback.getCallbacks();
+        Set<Long> acks = new HashSet<Long>();
+        long nextNum = 1;
+        for (Callback cb: cbs) {
+            if (cb.isAccept()) {
+                assertEquals(nextNum++, cb.getMsgNumber());
+            } else {
+                assertTrue(cb.getMsgNumber() < nextNum);
+                Long num = Long.valueOf(cb.getMsgNumber());
+                assertFalse(acks.contains(num));
+                acks.add(num);
+            }
+        }
     }
 
     @Test    
@@ -111,18 +127,13 @@ public class MessageCallbackOnewayTest extends AbstractBusClientServerTestBase
{
         
         greeterBus.getOutInterceptors().add(new MessageLossSimulator());
         RMManager manager = greeterBus.getExtension(RMManager.class);
-        manager.getConfiguration().setBaseRetransmissionInterval(new Long(2000));
+        manager.getConfiguration().setBaseRetransmissionInterval(RETRANSMISSION_INTERVAL);
         String[] callArgs = new String[] {"one", "two", "three", "four"};
         for (int i = 0; i < callArgs.length; i++) {
             greeter.greetMeOneWay(callArgs[i]);
         }
-        callback.waitDone(6, 3000, 60000);
-        verifyCallback(0, true, 1);
-        verifyCallback(1, true, 2);
-        verifyCallback(2, true, 3);
-        verifyCallback(3, false, 3);
-        verifyCallback(4, false, 1);
-        verifyCallback(5, true, 4);
+        callback.waitDone(8, 3000, 60000);
+        verifyCallbacks();
     }
 
     @Test    
@@ -140,19 +151,14 @@ public class MessageCallbackOnewayTest extends AbstractBusClientServerTestBase
{
         
         greeterBus.getOutInterceptors().add(new MessageLossSimulator());
         RMManager manager = greeterBus.getExtension(RMManager.class);
-        manager.getConfiguration().setBaseRetransmissionInterval(new Long(2000));
+        manager.getConfiguration().setBaseRetransmissionInterval(RETRANSMISSION_INTERVAL);
         String[] callArgs = new String[] {"one", "two", "three", "four"};
         for (int i = 0; i < callArgs.length; i++) {
             greeter.greetMeOneWay(callArgs[i]);
         }
         
-        callback.waitDone(6, 3000, 60000);
-        verifyCallback(0, true, 1);
-        verifyCallback(1, true, 2);
-        verifyCallback(2, true, 3);
-        verifyCallback(3, false, 3);
-        verifyCallback(4, false, 1);
-        verifyCallback(5, true, 4);
+        callback.waitDone(8, 3000, 60000);
+        verifyCallbacks();
     }
 
     @Test    
@@ -170,19 +176,14 @@ public class MessageCallbackOnewayTest extends AbstractBusClientServerTestBase
{
         
         greeterBus.getOutInterceptors().add(new MessageLossSimulator());
         RMManager manager = greeterBus.getExtension(RMManager.class);
-        manager.getConfiguration().setBaseRetransmissionInterval(new Long(2000));
+        manager.getConfiguration().setBaseRetransmissionInterval(RETRANSMISSION_INTERVAL);
         String[] callArgs = new String[] {"one", "two", "three", "four"};
         for (int i = 0; i < callArgs.length; i++) {
             greeter.greetMeOneWay(callArgs[i]);
         }
         
-        callback.waitDone(6, 3000, 60000);
-        verifyCallback(0, true, 1);
-        verifyCallback(1, true, 2);
-        verifyCallback(2, true, 3);
-        verifyCallback(3, false, 3);
-        verifyCallback(4, false, 1);
-        verifyCallback(5, true, 4);
+        callback.waitDone(8, 3000, 60000);
+        verifyCallbacks();
     }
 
     @Test    
@@ -200,21 +201,14 @@ public class MessageCallbackOnewayTest extends AbstractBusClientServerTestBase
{
         
         greeterBus.getOutInterceptors().add(new MessageLossSimulator());
         RMManager manager = greeterBus.getExtension(RMManager.class);
-        manager.getConfiguration().setBaseRetransmissionInterval(new Long(2000));
+        manager.getConfiguration().setBaseRetransmissionInterval(RETRANSMISSION_INTERVAL);
         String[] callArgs = new String[] {"one", "two", "three", "four"};
         for (int i = 0; i < callArgs.length; i++) {
             greeter.greetMeOneWay(callArgs[i]);
         }
         
         callback.waitDone(8, 3000, 60000);
-        verifyCallback(0, true, 1);
-        verifyCallback(1, true, 2);
-        verifyCallback(2, true, 3);
-        verifyCallback(3, false, 2);
-        verifyCallback(4, false, 1);
-        verifyCallback(5, true, 4);
-        verifyCallback(6, false, 4);
-        verifyCallback(7, false, 3);
+        verifyCallbacks();
     }
 
     // --- test utilities ---
@@ -362,6 +356,7 @@ public class MessageCallbackOnewayTest extends AbstractBusClientServerTestBase
{
             synchronized (callbacks) {
                 callbacks.add(new Callback(true, msgNum));
                 callbacks.notifyAll();
+                System.out.println("Message accepted " + msgNum);
             }
         }
 
@@ -370,6 +365,7 @@ public class MessageCallbackOnewayTest extends AbstractBusClientServerTestBase
{
             synchronized (callbacks) {
                 callbacks.add(new Callback(false, msgNum));
                 callbacks.notifyAll();
+                System.out.println("Message acknowledged " + msgNum);
             }
         }
         


Mime
View raw message