KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > smack > FloodTest


1 /**
2  * $RCSfile$
3  * $Revision: 2486 $
4  * $Date: 2005-04-15 18:46:53 -0300 (Fri, 15 Apr 2005) $
5  *
6  * Copyright 2003-2004 Jive Software.
7  *
8  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */

20
21 package org.jivesoftware.smack;
22
23 import org.jivesoftware.smack.test.SmackTestCase;
24
25 /**
26  * Simple test to measure server performance.
27  *
28  * @author Gaston Dombiak
29  */

30 public class FloodTest extends SmackTestCase {
31
32     public FloodTest(String JavaDoc arg0) {
33         super(arg0);
34     }
35
36     public void testMessageFlood() {
37         try {
38             Chat chat11 = getConnection(0).createChat(getBareJID(1));
39             Chat chat12 = new Chat(getConnection(1), getBareJID(0), chat11.getThreadID());
40
41             Chat chat21 = getConnection(0).createChat(getBareJID(2));
42             Chat chat22 = new Chat(getConnection(2), getBareJID(0), chat21.getThreadID());
43
44             Chat chat31 = getConnection(0).createChat(getBareJID(3));
45             Chat chat32 = new Chat(getConnection(3), getBareJID(0), chat31.getThreadID());
46
47             for (int i=0; i<500; i++) {
48                 chat11.sendMessage("Hello_1" + i);
49                 chat21.sendMessage("Hello_2" + i);
50                 chat31.sendMessage("Hello_3" + i);
51             }
52             for (int i=0; i<500; i++) {
53                 assertNotNull("Some message was lost (" + i + ")", chat12.nextMessage(1000));
54                 assertNotNull("Some message was lost (" + i + ")", chat22.nextMessage(1000));
55                 assertNotNull("Some message was lost (" + i + ")", chat32.nextMessage(1000));
56             }
57         }
58         catch (Exception JavaDoc e) {
59             e.printStackTrace();
60             fail(e.getMessage());
61         }
62     }
63
64     /*public void testMUCFlood() {
65         try {
66             int floodNumber = 50000;
67             MultiUserChat chat = new MultiUserChat(getConnection(0), "myroom@" + getMUCDomain());
68             chat.create("phatom");
69             chat.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
70
71             MultiUserChat chat2 = new MultiUserChat(getConnection(1), "myroom@" + getMUCDomain());
72             chat2.join("christine");
73
74             for (int i=0; i<floodNumber; i++)
75             {
76                 chat.sendMessage("hi");
77             }
78
79             Thread.sleep(200);
80
81             for (int i=0; i<floodNumber; i++)
82             {
83                 if (i % 100 == 0) {
84                     System.out.println(i);
85                 }
86                 assertNotNull("Received " + i + " of " + floodNumber + " messages",
87                         chat2.nextMessage(SmackConfiguration.getPacketReplyTimeout()));
88             }
89
90             chat.leave();
91             //chat2.leave();
92
93         } catch (Exception e) {
94             e.printStackTrace();
95             fail(e.getMessage());
96         }
97     }*/

98
99     protected int getMaxConnections() {
100         return 4;
101     }
102 }
103
Popular Tags