001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tctest.spring.integrationtests.load;
006:
007: import com.tc.test.server.appserver.deployment.Deployment;
008: import com.tc.test.server.appserver.deployment.ServerTestSetup;
009: import com.tc.test.server.appserver.deployment.TestCallback;
010: import com.tc.test.server.appserver.deployment.WebApplicationServer;
011: import com.tctest.spring.bean.EventManager;
012: import com.tctest.spring.integrationtests.SpringDeploymentTest;
013:
014: import java.util.ArrayList;
015: import java.util.Date;
016: import java.util.Iterator;
017: import java.util.List;
018:
019: import junit.framework.Test;
020:
021: public class DistributedEventsLoadTest extends SpringDeploymentTest {
022: private static final boolean DEBUG = false;
023: private static final int NUM_ITERATION = 500;
024:
025: private static final String REMOTE_SERVICE_NAME = "EventManager";
026: private static final String BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/distributedevents.xml";
027: private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/event-tc-config.xml";
028: private static final String CONTEXT = "distributed-events";
029: private static final String BEAN_NAME = "eventManager";
030:
031: private Deployment deployment;
032:
033: public static Test suite() {
034: return new ServerTestSetup(DistributedEventsLoadTest.class);
035: }
036:
037: public DistributedEventsLoadTest() {
038: // this.disableAllUntil("2010-01-01", new String[]{"solaris"});
039: }
040:
041: protected void setUp() throws Exception {
042: super .setUp();
043: if (deployment == null) {
044: deployment = makeWAR();
045: }
046: }
047:
048: public void testFourNodeDistributedEventsLoad() throws Throwable {
049: publishDistributedEvents(4);
050: }
051:
052: private void publishDistributedEvents(final int nodeCount)
053: throws Throwable {
054: List servers = new ArrayList();
055: final List eventManagers = new ArrayList();
056:
057: try {
058: for (int i = 0; i < nodeCount; i++) {
059: WebApplicationServer server = makeWebApplicationServer(CONFIG_FILE_FOR_TEST);
060: server.addWarDeployment(deployment, CONTEXT);
061: server.start();
062: servers.add(server);
063: EventManager em = (EventManager) server.getProxy(
064: EventManager.class, REMOTE_SERVICE_NAME);
065: em.size();
066: eventManagers.add(em);
067: }
068:
069: debugPrintln("publishDistributedEvents(): num_iteration per node = "
070: + NUM_ITERATION);
071:
072: long startTime = System.currentTimeMillis();
073:
074: debugPrintln("publishDistributedEvents(): startTime = "
075: + startTime);
076:
077: for (int i = 0; i < NUM_ITERATION; i++) {
078: for (int node = 0; node < nodeCount; node++) {
079: debugPrintln("publishDistributedEvents(): node:"
080: + node + " iteration:" + i);
081: ((EventManager) eventManagers.get(node))
082: .publishEvents("foo" + node, "bar" + i, 2);
083: }
084: }
085:
086: waitForSuccess(8 * 60, new TestCallback() {
087: public void check() {
088: for (Iterator iter = eventManagers.iterator(); iter
089: .hasNext();) {
090: EventManager em = (EventManager) iter.next();
091: assertEquals(NUM_ITERATION * nodeCount * 2, em
092: .size());
093: }
094: }
095: });
096:
097: long endTime = 0;
098: for (Iterator iter = eventManagers.iterator(); iter
099: .hasNext();) {
100: EventManager em = (EventManager) iter.next();
101: Date date = em.getLastEventTime();
102:
103: debugPrintln("eventManager = " + em.toString()
104: + " lastEventTime = " + date.getTime());
105:
106: if (date.getTime() > endTime) {
107: endTime = date.getTime();
108: }
109: }
110:
111: long totalTime = endTime - startTime;
112:
113: printData(nodeCount, totalTime);
114:
115: } finally {
116: for (Iterator it = servers.iterator(); it.hasNext();) {
117: ((WebApplicationServer) it.next())
118: .stopIgnoringExceptions();
119: }
120: }
121: }
122:
123: private Deployment makeWAR() throws Exception {
124: return makeDeploymentBuilder(CONTEXT + ".war")
125: .addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST)
126: .addRemoteService(REMOTE_SERVICE_NAME, BEAN_NAME,
127: EventManager.class)
128: .addDirectoryOrJARContainingClass(EventManager.class)
129: .addDirectoryContainingResource(CONFIG_FILE_FOR_TEST)
130: .makeDeployment();
131: }
132:
133: private void printData(int nodeCount, long totalTime) {
134: System.out
135: .println("**%% TERRACOTTA TEST STATISTICS %%**: nodes="
136: + nodeCount + " iteration="
137: + (NUM_ITERATION * nodeCount) + " time="
138: + totalTime + " nanoseconds avg="
139: + (totalTime / (NUM_ITERATION * nodeCount))
140: + " nanoseconds/iteration");
141: }
142:
143: private void debugPrintln(String s) {
144: if (DEBUG) {
145: System.out.println("XXXXX " + s);
146: }
147: }
148:
149: }
|