1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 18:59:41 +02:00

SMACK-412 Added the pingMyServer back in, cleaned up unneeded synchronization and removed minimum ping interval.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_3_0@13588 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
rcollier 2013-03-23 11:59:08 +00:00
parent 999c86ef4c
commit a14178990b
8 changed files with 174 additions and 42 deletions

View file

@ -21,9 +21,12 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.ping.packet.Ping;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class ServerPingTest {
public class KeepaliveTest {
private static final long PING_MINIMUM = 1000;
private static String TO = "juliet@capulet.lit/balcony";
private static String ID = "s2c1";
@ -31,7 +34,21 @@ public class ServerPingTest {
{
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
}
private int originalTimeout;
@Before
public void resetProperties()
{
originalTimeout = SmackConfiguration.getPacketReplyTimeout();
SmackConfiguration.setPacketReplyTimeout(1000);
}
@After
public void restoreProperties()
{
SmackConfiguration.setPacketReplyTimeout(originalTimeout);
}
/*
* Stanza copied from spec
*/
@ -133,7 +150,7 @@ public class ServerPingTest {
private DummyConnection getConnection() {
DummyConnection con = new DummyConnection();
ServerPingManager mgr = ServerPingManager.getInstanceFor(con);
mgr.setPingInterval(ServerPingManager.PING_MINIMUM);
mgr.setPingInterval(PING_MINIMUM);
return con;
}
@ -141,7 +158,7 @@ public class ServerPingTest {
private ThreadedDummyConnection getThreadedConnection() {
ThreadedDummyConnection con = new ThreadedDummyConnection();
ServerPingManager mgr = ServerPingManager.getInstanceFor(con);
mgr.setPingInterval(ServerPingManager.PING_MINIMUM);
mgr.setPingInterval(PING_MINIMUM);
return con;
}
@ -157,6 +174,6 @@ public class ServerPingTest {
}
private long getWaitTime() {
return ServerPingManager.PING_MINIMUM + SmackConfiguration.getPacketReplyTimeout() + 3000;
return PING_MINIMUM + SmackConfiguration.getPacketReplyTimeout() + 3000;
}
}

View file

@ -23,19 +23,28 @@ import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.ping.packet.Ping;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class PingPongTest {
public class PingTest {
private DummyConnection dummyCon;
private ThreadedDummyConnection threadedCon;
@Before
public void setup() {
dummyCon = new DummyConnection();
threadedCon = new ThreadedDummyConnection();
}
@Test
public void checkSendingPing() throws Exception {
DummyConnection con = new DummyConnection();
PingManager pinger = new PingManager(con);
dummyCon = new DummyConnection();
PingManager pinger = new PingManager(dummyCon);
pinger.ping("test@myserver.com");
Packet sentPacket = con.getSentPacket();
Packet sentPacket = dummyCon.getSentPacket();
assertTrue(sentPacket instanceof Ping);
@ -43,9 +52,9 @@ public class PingPongTest {
@Test
public void checkSuccessfulPing() throws Exception {
ThreadedDummyConnection con = new ThreadedDummyConnection();
threadedCon = new ThreadedDummyConnection();
PingManager pinger = new PingManager(con);
PingManager pinger = new PingManager(threadedCon);
boolean pingSuccess = pinger.ping("test@myserver.com");
@ -59,8 +68,8 @@ public class PingPongTest {
*/
@Test
public void checkFailedPingOnTimeout() throws Exception {
DummyConnection con = new DummyConnection();
PingManager pinger = new PingManager(con);
dummyCon = new DummyConnection();
PingManager pinger = new PingManager(dummyCon);
boolean pingSuccess = pinger.ping("test@myserver.com");
@ -69,12 +78,12 @@ public class PingPongTest {
}
/**
* DummyConnection will not reply so it will timeout.
* Server returns an exception for entity.
* @throws Exception
*/
@Test
public void checkFailedPingError() throws Exception {
ThreadedDummyConnection con = new ThreadedDummyConnection();
public void checkFailedPingToEntityError() throws Exception {
threadedCon = new ThreadedDummyConnection();
//@formatter:off
String reply =
"<iq type='error' id='qrzSp-16' to='test@myserver.com'>" +
@ -84,17 +93,62 @@ public class PingPongTest {
"</error>" +
"</iq>";
//@formatter:on
IQ serviceUnavailable = PacketParserUtils.parseIQ(TestUtils.getIQParser(reply), threadedCon);
threadedCon.addIQReply(serviceUnavailable);
PingManager pinger = new PingManager(threadedCon);
boolean pingSuccess = pinger.ping("test@myserver.com");
assertFalse(pingSuccess);
}
@Test
public void checkPingToServerSuccess() throws Exception {
ThreadedDummyConnection con = new ThreadedDummyConnection();
PingManager pinger = new PingManager(con);
boolean pingSuccess = pinger.pingMyServer();
assertTrue(pingSuccess);
}
/**
* Server returns an exception.
* @throws Exception
*/
@Test
public void checkPingToServerError() throws Exception {
ThreadedDummyConnection con = new ThreadedDummyConnection();
//@formatter:off
String reply =
"<iq type='error' id='qrzSp-16' to='test@myserver.com' from='" + con.getServiceName() + "'>" +
"<ping xmlns='urn:xmpp:ping'/>" +
"<error type='cancel'>" +
"<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
"</error>" +
"</iq>";
//@formatter:on
IQ serviceUnavailable = PacketParserUtils.parseIQ(TestUtils.getIQParser(reply), con);
con.addIQReply(serviceUnavailable);
PingManager pinger = new PingManager(con);
boolean pingSuccess = pinger.ping("test@myserver.com");
assertFalse(pingSuccess);
boolean pingSuccess = pinger.pingMyServer();
assertTrue(pingSuccess);
}
@Test
public void checkPingToServerTimeout() throws Exception {
DummyConnection con = new DummyConnection();
PingManager pinger = new PingManager(con);
boolean pingSuccess = pinger.pingMyServer();
assertFalse(pingSuccess);
}
@Test
public void checkSuccessfulDiscoRequest() throws Exception {
ThreadedDummyConnection con = new ThreadedDummyConnection();