use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.
the class IoTControlIntegrationTest method controlTest.
/**
* Connection one provides a thing, which is controlled by connection two.
*
* @throws Exception if an exception occurs.
* @throws TimeoutException if there was a timeout.
*/
@SmackIntegrationTest
public // @SmackSerialIntegrationTest
void controlTest() throws Exception {
final String key = StringUtils.randomString(12);
final String sn = StringUtils.randomString(12);
final SimpleResultSyncPoint syncPoint = new SimpleResultSyncPoint();
Thing controlThing = Thing.builder().setKey(key).setSerialNumber(sn).setControlRequestHandler(new ThingControlRequest() {
@Override
public void processRequest(Jid from, Collection<SetData> setData) throws XMPPErrorException {
if (!from.equals(conTwo.getUser())) {
return;
}
for (final SetData data : setData) {
if (!data.getName().equals(testRunId))
continue;
if (!(data instanceof SetBoolData))
continue;
SetBoolData boolData = (SetBoolData) data;
if (boolData.getBooleanValue()) {
syncPoint.signal();
break;
}
}
}
}).build();
IoTControlManagerOne.installThing(controlThing);
try {
IntegrationTestRosterUtil.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
SetData data = new SetBoolData(testRunId, true);
IoTSetResponse response = IoTControlManagerTwo.setUsingIq(conOne.getUser(), data);
assertNotNull(response);
} finally {
IoTControlManagerOne.uninstallThing(controlThing);
IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
}
syncPoint.waitForResult(timeout);
}
use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.
the class XmppConnectionIntegrationTest method allToAllMessageSendTest.
@SmackIntegrationTest(connectionCount = 4)
public void allToAllMessageSendTest(List<AbstractXMPPConnection> connections) throws InterruptedException, NotAllMessagesReceivedException, ErrorsWhileSendingOrReceivingException {
final long seed = 42;
// 100
final int messagesPerConnection = 3;
// 512
final int maxPayloadChunkSize = 16;
// 32
final int maxPayloadChunks = 4;
// true
final boolean intermixMessages = false;
XmppConnectionStressTest.Configuration stressTestConfiguration = new XmppConnectionStressTest.Configuration(seed, messagesPerConnection, maxPayloadChunkSize, maxPayloadChunks, intermixMessages);
XmppConnectionStressTest stressTest = new XmppConnectionStressTest(stressTestConfiguration);
stressTest.run(connections, timeout);
final Level connectionStatsLogLevel = Level.FINE;
if (LOGGER.isLoggable(connectionStatsLogLevel)) {
if (connections.get(0) instanceof ModularXmppClientToServerConnection) {
for (XMPPConnection connection : connections) {
ModularXmppClientToServerConnection xmppC2sConnection = (ModularXmppClientToServerConnection) connection;
ModularXmppClientToServerConnection.Stats stats = xmppC2sConnection.getStats();
LOGGER.log(connectionStatsLogLevel, "Connections stats for " + xmppC2sConnection + ":\n{}", stats);
}
}
}
}
use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.
the class SimpleXmppConnectionIntegrationTest method createConnectionTest.
@SmackIntegrationTest(connectionCount = 2)
public void createConnectionTest(List<AbstractXMPPConnection> connections) throws TimeoutException, Exception {
final AbstractXMPPConnection conOne = connections.get(0), conTwo = connections.get(1);
EntityFullJid userTwo = conTwo.getUser();
final String messageBody = testRunId + ": Hello from the other side!";
Message message = conTwo.getStanzaFactory().buildMessageStanza().to(userTwo).setBody(messageBody).build();
final SimpleResultSyncPoint messageReceived = new SimpleResultSyncPoint();
final StanzaListener stanzaListener = (Stanza stanza) -> {
if (((Message) stanza).getBody().equals(messageBody)) {
messageReceived.signal();
}
};
conTwo.addAsyncStanzaListener(stanzaListener, MessageWithBodiesFilter.INSTANCE);
try {
conOne.sendStanza(message);
messageReceived.waitForResult(timeout);
} finally {
conTwo.removeAsyncStanzaListener(stanzaListener);
}
}
use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.
the class OutgoingMessageListenerIntegrationTest method outgoingMessageListenerTest.
@SmackIntegrationTest
public void outgoingMessageListenerTest() throws Exception {
final String body = StringUtils.randomString(16);
final SimpleResultSyncPoint syncPoint = new SimpleResultSyncPoint();
final OutgoingChatMessageListener listener = new OutgoingChatMessageListener() {
@Override
public void newOutgoingMessage(EntityBareJid to, MessageBuilder messageBuilder, Chat chat) {
Message message = messageBuilder.build();
if (message.getBody().equals(body)) {
syncPoint.signal();
}
}
};
EntityBareJid peer = conTwo.getUser().asEntityBareJid();
try {
chatManagerOne.addOutgoingListener(listener);
Chat chat = chatManagerOne.chatWith(peer);
chat.send(body);
syncPoint.waitForResult(timeout);
} finally {
chatManagerOne.removeOutgoingListener(listener);
}
}
use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.
the class RosterIntegrationTest method subscribeRequestListenerTest.
@SmackIntegrationTest
public void subscribeRequestListenerTest() throws TimeoutException, Exception {
IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
final SubscribeListener subscribeListener = new SubscribeListener() {
@Override
public SubscribeAnswer processSubscribe(Jid from, Presence subscribeRequest) {
if (from.equals(conOne.getUser().asBareJid())) {
return SubscribeAnswer.Approve;
}
return SubscribeAnswer.Deny;
}
};
rosterTwo.addSubscribeListener(subscribeListener);
final String conTwosRosterName = "ConTwo " + testRunId;
final SimpleResultSyncPoint addedAndSubscribed = new SimpleResultSyncPoint();
rosterOne.addRosterListener(new AbstractRosterListener() {
@Override
public void entriesAdded(Collection<Jid> addresses) {
checkIfAddedAndSubscribed(addresses);
}
@Override
public void entriesUpdated(Collection<Jid> addresses) {
checkIfAddedAndSubscribed(addresses);
}
private void checkIfAddedAndSubscribed(Collection<Jid> addresses) {
for (Jid jid : addresses) {
if (!jid.equals(conTwo.getUser().asBareJid())) {
continue;
}
BareJid bareJid = conTwo.getUser().asBareJid();
RosterEntry rosterEntry = rosterOne.getEntry(bareJid);
if (rosterEntry == null) {
addedAndSubscribed.signalFailure("No roster entry for " + bareJid);
return;
}
String name = rosterEntry.getName();
if (StringUtils.isNullOrEmpty(name)) {
addedAndSubscribed.signalFailure("Roster entry without name");
return;
}
if (!rosterEntry.getName().equals(conTwosRosterName)) {
addedAndSubscribed.signalFailure("Roster name does not match");
return;
}
if (!rosterEntry.getType().equals(ItemType.to)) {
return;
}
addedAndSubscribed.signal();
}
}
});
try {
rosterOne.createItemAndRequestSubscription(conTwo.getUser().asBareJid(), conTwosRosterName, null);
assertTrue(addedAndSubscribed.waitForResult(2 * connection.getReplyTimeout()));
} finally {
rosterTwo.removeSubscribeListener(subscribeListener);
}
}
Aggregations