@SmackIntegrationTest public void testStreamManagement(XMPPTCPConnection conOne, XMPPTCPConnection conTwo) throws InterruptedException, SmackException, IOException, XMPPException { final String body1 = "Hi, what's up? " + testRunId; final String body2 = "Hi, what's up? I've been just instantly shutdown" + testRunId; final String body3 = "Hi, what's up? I've been just resumed" + testRunId; final StanzaCollector collector = conTwo.createStanzaCollector(new AndFilter( MessageWithBodiesFilter.INSTANCE, FromMatchesFilter.createFull(conOne.getUser()))); try { send(body1, conOne, conTwo); assertMessageWithBodyReceived(body1, collector); conOne.instantShutdown(); send(body2, conOne, conTwo); // Reconnect with xep198 conOne.connect().login(); assertMessageWithBodyReceived(body2, collector); send(body3, conOne, conTwo); assertMessageWithBodyReceived(body3, collector); } finally { collector.cancel(); } }
private <R extends OAStanza> R sendOAStanza(XMPPTCPConnection authConnection, OAStanza stanza, Class<R> replyClass, long replyTimeout) { StanzaCollector collector = authConnection.createStanzaCollector(new OAReplyFilter(stanza, authConnection)); messageLock.lock(); try { authConnection.sendStanza(stanza); return replyClass.cast(getNextStanzaSkipContinues(collector, replyTimeout, authConnection)); } catch (InterruptedException | SmackException | XMPPErrorException e) { throw new RuntimeException("Failed communicating with Harmony Hub", e); } finally { messageLock.unlock(); collector.cancel(); } }
private Stanza sendOAStanza(XMPPTCPConnection authConnection, OAStanza stanza, long replyTimeout) { StanzaCollector collector = authConnection .createStanzaCollector(new EmptyIncrementedIdReplyFilter(stanza, authConnection)); messageLock.lock(); try { authConnection.sendStanza(stanza); return getNextStanzaSkipContinues(collector, replyTimeout, authConnection); } catch (InterruptedException | SmackException | XMPPErrorException e) { throw new RuntimeException("Failed communicating with Harmony Hub", e); } finally { messageLock.unlock(); collector.cancel(); } }