01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tctest.spring.integrationtests.tests;
06:
07: import com.tc.test.server.appserver.deployment.AbstractTwoServerDeploymentTest;
08: import com.tc.test.server.appserver.deployment.DeploymentBuilder;
09: import com.tc.test.server.appserver.deployment.TestCallback;
10: import com.tctest.spring.bean.EventManager;
11: import com.tctest.spring.integrationtests.SpringTwoServerTestSetup;
12:
13: import junit.framework.Test;
14:
15: public class DistributedEventsTest extends
16: AbstractTwoServerDeploymentTest {
17:
18: private static final String REMOTE_SERVICE_NAME = "EventManager";
19:
20: private EventManager eventManager1;
21: private EventManager eventManager2;
22:
23: // public DistributedEventsTest() {
24: // disableAllUntil("2007-02-27");
25: // }
26:
27: protected void setUp() throws Exception {
28: super .setUp();
29:
30: eventManager1 = (EventManager) server0.getProxy(
31: EventManager.class, REMOTE_SERVICE_NAME);
32: eventManager2 = (EventManager) server1.getProxy(
33: EventManager.class, REMOTE_SERVICE_NAME);
34:
35: eventManager1.clear();
36: eventManager2.clear();
37:
38: assertEquals(0, eventManager1.size());
39: assertEquals(0, eventManager2.size());
40: }
41:
42: public void testDistributedEvent() throws Throwable {
43: eventManager1.publishEvents("foo1", "bar1", 3);
44: eventManager1.publishEvents("foo1", "bar2", 4);
45:
46: waitForSuccess(60 * 3, new TestCallback() {
47: public void check() {
48: assertEquals("Got local", 7, eventManager1.size());
49: assertEquals("Should be distributed", 7, eventManager2
50: .size());
51: }
52: });
53: }
54:
55: public void testNonDistributedEvent() throws Throwable {
56: eventManager1.publishLocalEvent("foo2", "bar1");
57: Thread.sleep(1000L * 5);
58: assertEquals("Got local", 1, eventManager1.size());
59: assertEquals("Should not be distributed", 0, eventManager2
60: .size());
61: }
62:
63: private static class SingletonTestSetup extends
64: SpringTwoServerTestSetup {
65:
66: private SingletonTestSetup() {
67: super (DistributedEventsTest.class,
68: "/tc-config-files/event-tc-config.xml",
69: "distributed-events");
70: }
71:
72: protected void configureWar(DeploymentBuilder builder) {
73: builder
74: .addBeanDefinitionFile("classpath:/com/tctest/spring/distributedevents.xml");
75: builder.addRemoteService(REMOTE_SERVICE_NAME,
76: "eventManager", EventManager.class);
77: }
78:
79: }
80:
81: public static Test suite() {
82: return new SingletonTestSetup();
83: }
84: }
|