01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tctest.spring.integrationtests.tests;
05:
06: import com.tc.test.server.appserver.deployment.AbstractTwoServerDeploymentTest;
07: import com.tc.test.server.appserver.deployment.DeploymentBuilder;
08: import com.tctest.spring.bean.ISingleton;
09: import com.tctest.spring.integrationtests.SpringTwoServerTestSetup;
10:
11: import junit.framework.Test;
12:
13: /**
14: * Runs a couple of tests within the same JVM
15: *
16: * @author cer
17: */
18: /**
19: * Testing basic clustered singleton behavior, also serve as an example for using the web testing framework.
20: */
21: public class SingletonV2Test extends AbstractTwoServerDeploymentTest {
22:
23: private static final String REMOTE_SERVICE_NAME = "Singleton";
24: private static final String BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory.xml";
25: private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/singleton-tc-config.xml";
26:
27: private ISingleton singleton1;
28: private ISingleton singleton2;
29:
30: protected void setUp() throws Exception {
31: super .setUp();
32:
33: singleton1 = (ISingleton) server0.getProxy(ISingleton.class,
34: REMOTE_SERVICE_NAME);
35: singleton2 = (ISingleton) server1.getProxy(ISingleton.class,
36: REMOTE_SERVICE_NAME);
37: }
38:
39: public void testSharedField() throws Exception {
40:
41: logger.debug("testing shared fields");
42:
43: assertEquals(singleton1.getCounter(), singleton2.getCounter());
44: singleton1.incrementCounter();
45: assertEquals(singleton1.getCounter(), singleton2.getCounter());
46: singleton2.incrementCounter();
47: assertEquals(singleton2.getCounter(), singleton1.getCounter());
48:
49: logger.debug("!!!! Asserts passed !!!");
50: }
51:
52: public void testTransientField() throws Exception {
53:
54: logger.debug("Testing transient fields");
55: assertEquals("aaa", singleton1.getTransientValue());
56: assertEquals("aaa", singleton2.getTransientValue());
57: singleton1.setTransientValue("s1");
58: assertEquals("aaa", singleton2.getTransientValue());
59: singleton2.setTransientValue("s2");
60: assertEquals("s1", singleton1.getTransientValue());
61: assertEquals("s2", singleton2.getTransientValue());
62: logger.debug("done testing transient fields");
63: }
64:
65: public void testSharedBooleanField() throws Exception {
66: assertTrue(singleton1.toggleBoolean());
67: assertFalse(singleton2.toggleBoolean());
68: assertTrue(singleton1.toggleBoolean());
69: }
70:
71: private static class SingletonTestSetup extends
72: SpringTwoServerTestSetup {
73: private SingletonTestSetup() {
74: super (SingletonV2Test.class, CONFIG_FILE_FOR_TEST,
75: "test-singleton");
76: }
77:
78: protected void configureWar(DeploymentBuilder builder) {
79: builder
80: .addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST);
81: builder.addRemoteService(REMOTE_SERVICE_NAME, "singleton",
82: ISingleton.class);
83: }
84:
85: }
86:
87: /**
88: * JUnit test loader entry point
89: */
90: public static Test suite() {
91: return new SingletonTestSetup();
92: }
93:
94: }
|