if(USE_DEBUGGER) { System.out.println("Press any key to continue..."); try { System.in.read(); } catch(java.io.IOException ioex) { } }
    public void testLoad() {        try {            final String startMessage="start";            final String stopMessage="stop";            final Object mutex=new Object();            final Vector receivedTimes=new Vector(MESSAGE_NUMBER);            final Vector normalMessages=new Vector(MESSAGE_NUMBER);            final Vector tooQuickMessages=new Vector();            final Vector tooSlowMessages=new Vector();            if(USE_DEBUGGER) {                System.out.println("Press any key to continue...");                try {                    System.in.read();                }                catch(java.io.IOException ioex) {                }            }            adapter1.setListener(new MessageListener() {                private boolean started=false;                private boolean stopped=false;                private long counter = 0L;                                public byte[] getState() {                    return null;                }                public void setState(byte[] state) {                }                public void receive(Message jgMessage) {                    Object message=jgMessage.getObject();                    if(startMessage.equals(message)) {                        started=true;                        finishedReceiving=false;                    }                    else if(stopMessage.equals(message)) {                        stopped=true;                        finishedReceiving=true;                        synchronized(mutex) {                            mutex.notifyAll();                        }                    }                    else if(message instanceof Long) {                        Long travelTime=new Long(System.currentTimeMillis() - ((Long)message).longValue());                        try {                        	assertEquals(counter, ((EncryptOrderTestHeader)((Message)jgMessage).getHeader("EncryptOrderTest")).seqno);                        	counter++;                        } catch (Exception e){                        	log.warn(e);                        	orderCounterFailure =true;                        }                        if(!started)                            tooQuickMessages.add(message);                        else if(started && !stopped) {                            receivedTimes.add(travelTime);                            normalMessages.add(message);                        }                        else                            tooSlowMessages.add(message);                    }                }            });            System.out.println("Free memory: " + Runtime.getRuntime().freeMemory());            System.out.println("Total memory: " + Runtime.getRuntime().totalMemory());            System.out.println("Starting sending messages.");            long time=System.currentTimeMillis();            Message startJgMessage=new Message();            startJgMessage.setObject(startMessage);            JChannel sender= channel2;            sender.send(startJgMessage);            for(int i=0; i < MESSAGE_NUMBER; i++) {                Long message=new Long(System.currentTimeMillis());                                Message jgMessage=new Message();                jgMessage.putHeader("EncryptOrderTest", new EncryptOrderTestHeader(i));                jgMessage.setObject(message);                sender.send(jgMessage);                if(i % 1000 == 0)                    System.out.println("sent " + i + " messages.");                if(SLEEP_BETWEEN_SENDING)                    org.jgroups.util.Util.sleep(1, true);            }            Message stopJgMessage=new Message();            stopJgMessage.setObject(stopMessage);            sender.send(stopJgMessage);            time=System.currentTimeMillis() - time;            System.out.println("Finished sending messages. Operation took " + time);            synchronized(mutex) {                int received=0;                while(!finishedReceiving) {                    mutex.wait(1000);                    if(receivedTimes.size() != received) {                        received=receivedTimes.size();                        System.out.println();                        System.out.print("Received " + receivedTimes.size() + " messages.");                    }                    else {                        System.out.print(".");                    }                }            }            try {                Thread.sleep(1000);            }            catch(Exception ex) {            }            double avgDeliveryTime=-1.0;            long maxDeliveryTime=Long.MIN_VALUE;            long minDeliveryTime=Long.MAX_VALUE;            Iterator iterator=receivedTimes.iterator();            while(iterator.hasNext()) {                Long message=(Long)iterator.next();                if(avgDeliveryTime == -1.0)                    avgDeliveryTime=message.longValue();                else                    avgDeliveryTime=(avgDeliveryTime + message.doubleValue()) / 2.0;                if(message.longValue() > maxDeliveryTime)                    maxDeliveryTime=message.longValue();                if(message.longValue() < minDeliveryTime)                    minDeliveryTime=message.longValue();            }            System.out.println("Sent " + MESSAGE_NUMBER + " messages.");            System.out.println("Received " + receivedTimes.size() + " messages.");            System.out.println("Average delivery time " + avgDeliveryTime + " ms");            System.out.println("Minimum delivery time " + minDeliveryTime + " ms");            System.out.println("Maximum delivery time " + maxDeliveryTime + " ms");            System.out.println("Received " + tooQuickMessages.size() + " too quick messages");            System.out.println("Received " + tooSlowMessages.size() + " too slow messages");        }        catch(Exception ex) {            ex.printStackTrace();        }        System.out.println("Free memory: " + Runtime.getRuntime().freeMemory());        System.out.println("Total memory: " + Runtime.getRuntime().totalMemory());        System.out.println("Performing GC");        Runtime.getRuntime().gc();        try {            Thread.sleep(2000);        }        catch(InterruptedException ex) {        }        System.out.println("Free memory: " + Runtime.getRuntime().freeMemory());        System.out.println("Total memory: " + Runtime.getRuntime().totalMemory());        if(USE_DEBUGGER) {            System.out.println("Press any key to finish...");            try {                System.in.read();            }            catch(java.io.IOException ioex) {            }        }        assertTrue("Message ordering is incorrect - check log output",(!orderCounterFailure));    }