XmppConnectionIntegrationTest.java

  1. /**
  2.  *
  3.  * Copyright 2018-2020 Florian Schmaus
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smack;

  18. import java.util.List;
  19. import java.util.logging.Level;

  20. import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection;

  21. import org.igniterealtime.smack.XmppConnectionStressTest;
  22. import org.igniterealtime.smack.XmppConnectionStressTest.StressTestFailedException.ErrorsWhileSendingOrReceivingException;
  23. import org.igniterealtime.smack.XmppConnectionStressTest.StressTestFailedException.NotAllMessagesReceivedException;
  24. import org.igniterealtime.smack.inttest.AbstractSmackLowLevelIntegrationTest;
  25. import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
  26. import org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest;

  27. public class XmppConnectionIntegrationTest extends AbstractSmackLowLevelIntegrationTest {

  28.     public XmppConnectionIntegrationTest(SmackIntegrationTestEnvironment environment) {
  29.         super(environment);
  30.     }

  31.     @SmackIntegrationTest(connectionCount = 4)
  32.     public void allToAllMessageSendTest(List<AbstractXMPPConnection> connections)
  33.             throws InterruptedException, NotAllMessagesReceivedException, ErrorsWhileSendingOrReceivingException {
  34.         final long seed = 42;
  35.         final int messagesPerConnection = 3; // 100
  36.         final int maxPayloadChunkSize = 16; // 512
  37.         final int maxPayloadChunks = 4; // 32
  38.         final boolean intermixMessages = false; // true

  39.         XmppConnectionStressTest.Configuration stressTestConfiguration = new XmppConnectionStressTest.Configuration(
  40.                 seed, messagesPerConnection, maxPayloadChunkSize, maxPayloadChunks, intermixMessages);

  41.         XmppConnectionStressTest stressTest = new XmppConnectionStressTest(stressTestConfiguration);

  42.         stressTest.run(connections, timeout);

  43.         final Level connectionStatsLogLevel = Level.FINE;
  44.         if (LOGGER.isLoggable(connectionStatsLogLevel)) {
  45.             if (connections.get(0) instanceof ModularXmppClientToServerConnection) {
  46.                 for (XMPPConnection connection : connections) {
  47.                     ModularXmppClientToServerConnection xmppC2sConnection = (ModularXmppClientToServerConnection) connection;
  48.                     ModularXmppClientToServerConnection.Stats stats = xmppC2sConnection.getStats();
  49.                     LOGGER.log(connectionStatsLogLevel,
  50.                             "Connections stats for " + xmppC2sConnection + ":\n{}",
  51.                             stats);
  52.                 }
  53.             }
  54.         }
  55.     }

  56. }