What''s wrong with my test?

Hi all,

In order to test the reliability of the basic functionalities (connection, and packet listener) of my future IM client,

I’'ve done the following test a lot of times (25 times), and bad surprise on packet listener:

On 10 runs of XmppTest class test, I have, on average just 65% of CASE 1!

CASE 1:

//…log OK: presence packet seen…

: initialisation…

: connection created…

: packets listener initialized…

: user logged in…

instance created!

packet read:

//…

CASE 2:

//…log ko: presence packet not seen!..

: initialisation…

: connection created…

: packets listener initialized…

: user logged in…

instance created!

//…

=> sometimes packet is not read (or catched)! I cannot explain!!!

Any ideas? if some one could make the same test it would be great for my understanding…

Here, the code snippet of the basic XmppTest class test (which I could update with corrections when needed, to use it as example on this thread…)

package fr.elh.im.core;

import org.jivesoftware.smack.PacketListener;

import org.jivesoftware.smack.XMPPConnection;

import org.jivesoftware.smack.XMPPException;

import org.jivesoftware.smack.filter.AndFilter;

import org.jivesoftware.smack.filter.PacketFilter;

import org.jivesoftware.smack.filter.PacketTypeFilter;

import org.jivesoftware.smack.packet.Packet;

import org.jivesoftware.smack.packet.Presence;

import fr.elh.im.utils.Constantes;

import fr.elh.im.xmpp.BasicPacketFilter;

/**

  • @author me

*/

public class XmppTest {

private static final String LOGIN = “user1”;

private static final String PWD = “test”;

/**

  • the xmpp connection

*/

public XMPPConnection connection;

/**

  • the packet filter

*/

public PacketFilter packetFilter;

/**

  • the packet listener

*/

public PacketListener packetListener = new PacketListener() {

public void processPacket(Packet packet) {

if(null != packet){

String xmlPacket = packet.toXML();

System.out.println(">packet read: " + xmlPacket);//dbg

}

}

};

/**

  • default constructor

*/

public XmppTest() {

System.out.println(“[DBG]: initialisation…”);//dbg

createConnection();

System.out.println(“[DBG]: connection created…”);//dbg

initPacketsListener();

System.out.println(“[DBG]: packets listener initialized…”);//dbg

loginUserConnection(LOGIN,PWD);

System.out.println(“[DBG]: user logged in…”);//dbg

}

/**

  • Initialize the packet listener and filter packets on Presence criteria

  • (BasicPacketFilter() just accepts…)

*/

private void initPacketsListener(){

packetFilter = new AndFilter(new PacketTypeFilter(Presence.class), new BasicPacketFilter());

connection.addPacketListener(packetListener, packetFilter);

}

/**

  • Create the Xmpp connection

*/

private void createConnection() {

try {

connection = new XMPPConnection(Constantes.jabberDomain.toString(),

5222);

} catch (XMPPException e) {

System.out

.println(“Error: could not create XMPP connection!”);// dbg

e.printStackTrace();

}

}

/**

  • @param l : login

  • @param p : pwd

*/

private void loginUserConnection(String l, String p) {

try {

connection.login(l, p);

} catch (XMPPException e) {

System.out.println("Error: authentification failed for: "

  • l);

e.printStackTrace();

}

}

// main method for testings…

public static void main(String args) {

XmppTest test = new XmppTest();

if (null != test) {

System.out.println(“instance created!”);

} else {

System.out.println(“instance NOT created!”);

}

}

}

NB:

  • I never run 2 instances of XmppTest class at the same time during testings.

  • user 2 is always online during testings.

  • I’'m using smack 2.2.1 (seems to be the same with 2.2.0) and wilfire server 2.6.2 on win xp.

  • testings are done with Eclipse 3.2.0 and jdk1.5.

thx a lot…

Alex

Hi all,

I’'ve done again the same tests with the same code but using the Smack Enhanced Debugger to see the packets traffic, and I obtain very good results: 100% of case 1! (=> every presence packet are read at every run)

I’'ve tried to put some Thread.sleep(xxx) in XmppTest to check an eventual delay trouble, but no result…

Does that mean EnhancedDebbuger class does some basic and/or complex stuff that XmppTest class have missed?

help me please, i’'m in a blackhole and unable to bet on smack!

thanks a lot…

Alex

Hey Alex,

I recreated your test but without the BasicPacketFilter since I don’'t have access to it. I just set new PacketTypeFilter(Presence.class)[/code] to packetFilter. I first run the test and no presence was received. I then added a Thread.sleep(500) after creating an instance of XmppTest and it always worked.

XmppTest test = new XmppTest();

Thread.sleep(500);

/code

BTW, in your case, make sure thta user2@myDomain is always online so you can get his presence.

Regards,

– Gato

Hi Gato,

Thanks a lot for having testing…

I’‘ve only tried with Thread.sleep(100)…it was too short, and that’'s certainly why it did not work…

Thanks again, problem solved…

Alex