KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > perf > LoadTest


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21
22 package org.jacorb.test.notification.perf;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26
27 import junit.framework.Test;
28 import junit.textui.TestRunner;
29
30 import org.jacorb.test.notification.NotificationTestCase;
31 import org.jacorb.test.notification.NotificationTestCaseSetup;
32 import org.jacorb.test.notification.StructuredPushReceiver;
33 import org.jacorb.test.notification.StructuredPushSender;
34 import org.omg.CORBA.Any JavaDoc;
35 import org.omg.CORBA.IntHolder JavaDoc;
36 import org.omg.CORBA.ORB JavaDoc;
37 import org.omg.CosNotification.EventHeader;
38 import org.omg.CosNotification.EventType;
39 import org.omg.CosNotification.FixedEventHeader;
40 import org.omg.CosNotification.Property;
41 import org.omg.CosNotification.StructuredEvent;
42 import org.omg.CosNotifyChannelAdmin.EventChannel;
43 import org.omg.CosNotifyChannelAdmin.EventChannelFactory;
44 import org.omg.CosNotifyChannelAdmin.EventChannelFactoryHelper;
45
46 /**
47  * @author Alphonse Bendt
48  * @version $Id: LoadTest.java,v 1.1 2005/05/01 21:16:32 alphonse.bendt Exp $
49  */

50 public class LoadTest extends NotificationTestCase
51 {
52     int count = 0;
53
54     EventChannelFactory factory;
55
56     EventChannel channel;
57
58     IntHolder JavaDoc intHolder;
59
60     boolean active = true;
61
62     public LoadTest(String JavaDoc name, NotificationTestCaseSetup setup)
63     {
64         super(name, setup);
65     }
66
67     public void setUpTest() throws Exception JavaDoc
68     {
69         ORB JavaDoc orb = getORB();
70
71         factory = EventChannelFactoryHelper.narrow(orb
72                 .resolve_initial_references("NotificationService"));
73
74         intHolder = new IntHolder JavaDoc();
75
76         channel = factory.create_channel(new Property[0], new Property[0], intHolder);
77     }
78
79     public void tearDownTest()
80     {
81         channel.destroy();
82     }
83
84     public static Test suite() throws Exception JavaDoc
85     {
86         return NotificationTestCase.suite(LoadTest.class);
87     }
88
89     public void testLoad() throws Exception JavaDoc
90     {
91         final List JavaDoc received = new ArrayList JavaDoc();
92
93         StructuredPushSender sender = new StructuredPushSender(getClientORB());
94         
95         StructuredPushReceiver receiver = new StructuredPushReceiver(getClientORB());
96
97         System.out.println("connect sender");
98         sender.connect(channel, true);
99         System.out.println("connect receiver");
100         receiver.connect(channel, true);
101
102         boolean _active = active;
103
104         int batchSize = 1000;
105         
106         while (_active)
107         {
108             for (int x = 0; x < batchSize; ++x)
109             {
110                 Any JavaDoc any = getORB().create_any();
111                 any.insert_long(x);
112
113                 StructuredEvent event = new StructuredEvent();
114                 event.filterable_data = new Property[] { new Property("number", any) };
115                 event.header = new EventHeader();
116                 event.header.fixed_header = new FixedEventHeader();
117                 event.header.variable_header = new Property[0];
118                 event.header.fixed_header.event_name = "event_name";
119                 event.header.fixed_header.event_type = new EventType("domain_name", "type_name");
120                 event.remainder_of_body = getClientORB().create_any();
121
122                 event.remainder_of_body.insert_longlong(System.currentTimeMillis());
123                 sender.pushConsumer_.push_structured_event(event);
124
125                 // Thread.sleep(10);
126
}
127
128             synchronized (this)
129             {
130                 _active = active;
131             }
132             Thread.sleep(4000);
133             
134             assertEquals(batchSize, received.size());
135             
136             _active = false;
137         }
138
139         Thread.sleep(60000);
140     }
141
142     public static void main(String JavaDoc[] args) throws Exception JavaDoc
143     {
144         TestRunner.run(suite());
145     }
146 }
Popular Tags