Permalink
Browse files

unit tests verifying VYSPER-337

git-svn-id: https://svn.apache.org/repos/asf/mina/vysper/trunk@1423331 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent cfbfad6 commit d0a71703902a9aa820ab5a9c9a0b08c9911b6d84 Bernd Fondermann committed Dec 18, 2012
@@ -40,8 +40,10 @@
import org.apache.vysper.xmpp.state.resourcebinding.DefaultResourceRegistry;
import org.apache.vysper.xmpp.state.resourcebinding.ResourceRegistry;
+import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadPoolExecutor;
/**
*/
@@ -205,5 +207,58 @@ public void testShutdown() throws DeliveryException {
// test succeeds
}
}
+
+ public void testSequentialDeliveryOneThread() throws DeliveryException, XMLSemanticError, EntityFormatException {
+
+ DefaultServerRuntimeContext serverRuntimeContext = new DefaultServerRuntimeContext(null, null);
+
+ stanzaRelay.setServerRuntimeContext(serverRuntimeContext);
+ stanzaRelay.setMaxThreadCount(1);
+
+ TestSessionContext sessionContext = createSessionForTo(TO_ENTITY, 1);
+
+ final int STANZA_COUNT = 1000;
+
+ for (int i = 0; i < STANZA_COUNT; i++) {
+ Stanza stanza = StanzaBuilder.createMessageStanza(FROM_ENTITY, TO_ENTITY, "en", "" + i).build();
+ stanzaRelay.relay(TO_ENTITY, stanza, null);
+ }
+ for (int i = 0; i < STANZA_COUNT; i++) {
+ final Stanza nextResponse = sessionContext.getNextRecordedResponse(100);
+ assertEquals("" + i, nextResponse.getSingleInnerElementsNamed("body").getSingleInnerText().getText());
+ }
+
+ }
+
+ public void testSequentialDeliveryManyThreads() throws DeliveryException, XMLSemanticError, EntityFormatException {
+
+ DefaultServerRuntimeContext serverRuntimeContext = new DefaultServerRuntimeContext(null, null);
+
+ stanzaRelay.setServerRuntimeContext(serverRuntimeContext);
+ stanzaRelay.setMaxThreadCount(10);
+
+ TestSessionContext sessionContext = createSessionForTo(TO_ENTITY, 1);
+
+ final int STANZA_COUNT = 1000;
+
+ for (int i = 0; i < STANZA_COUNT; i++) {
+ Stanza stanza = StanzaBuilder.createMessageStanza(FROM_ENTITY, TO_ENTITY, "en", "" + i).build();
+ stanzaRelay.relay(TO_ENTITY, stanza, null);
+ }
+
+ /*
+ our handling currently does not enforce strict ordered delivery (for example by session).
+ If stanzas A and B enter the Relay's queue in that order, we only ensure that processing is started in
+ that order. However, it might as well happen that B is processed in parallel to A, and even exits
+ before A.
+ */
+
+ for (int i = 0; i < STANZA_COUNT; i++) {
+ final Stanza nextResponse = sessionContext.getNextRecordedResponse(100);
+ boolean matches = ("" + i).equals(nextResponse.getSingleInnerElementsNamed("body").getSingleInnerText().getText());
+ if (!matches) return; // succeed
+ }
+ Assert.fail("delivered in sequence is unexpected, see VYSPER-337");
+ }
}

0 comments on commit d0a7170

Please sign in to comment.