1 4 package com.tctest.spring.aj; 5 6 import com.tc.test.TestConfigObject; 7 import com.tctest.spring.integrationtests.framework.AbstractDeploymentTest; 8 import com.tctest.spring.integrationtests.framework.Deployment; 9 import com.tctest.spring.integrationtests.framework.DeploymentBuilder; 10 import com.tctest.spring.integrationtests.framework.Server; 11 import com.tctest.spring.integrationtests.framework.WebApplicationServer; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 18 public class AspectJTest extends AbstractDeploymentTest { 19 20 private static final String REMOTE_SERVICE_NAME = "InstrumentedBean"; 21 22 private Deployment deployment; 23 private String context = "test-aspectj"; 24 25 public AspectJTest() { 26 this.disableVariant(TestConfigObject.SPRING_VARIANT, "128"); 27 } 28 29 protected void setUp() throws Exception { 30 super.setUp(); 31 32 DeploymentBuilder builder = makeDeploymentBuilder(context+".war"); 33 34 builder.addRemoteService(REMOTE_SERVICE_NAME, "instrumentedBean", IInstrumentedBean.class); 35 36 builder.addDirectoryOrJARContainingClass(IInstrumentedBean.class); 37 builder.addDirectoryOrJARContainingClass(org.aspectj.lang.Aspects.class); 38 40 builder.addBeanDefinitionFile("classpath:/com/tctest/spring/aj/beanfactory-aspectj.xml"); 41 builder.addDirectoryContainingResource("/tc-config-files/aspectj-tc-config.xml"); 42 43 deployment = builder.makeDeployment(); 44 } 45 46 public void testSingleton2() throws Exception { 47 List <WebApplicationServer> servers = new ArrayList <WebApplicationServer>(); 48 49 int nodeCount = 2; 50 for (int i = 0; i < nodeCount; i++) { 51 WebApplicationServer server = makeWebApplicationServer("/tc-config-files/aspectj-tc-config.xml"); 52 server.addWarDeployment(deployment, context); 53 server.start(); 54 servers.add(server); 55 } 56 57 59 for (Iterator it1 = servers.iterator(); it1.hasNext();) { 60 WebApplicationServer server1 = (WebApplicationServer) it1.next(); 61 for(Iterator it2 = servers.iterator(); it2.hasNext();) { 62 WebApplicationServer server2 = (WebApplicationServer) it2.next(); 63 if(server1==server2) continue; 64 65 assertShared(server1, server2, REMOTE_SERVICE_NAME); 66 assertTransient(server1, server2, REMOTE_SERVICE_NAME); 67 } 68 } 69 } 70 71 72 private static void assertShared(Server server1, Server server2, String remoteServiceName) throws Exception { 73 IInstrumentedBean bean1 = (IInstrumentedBean) server1.getProxy(IInstrumentedBean.class, remoteServiceName); 74 IInstrumentedBean bean2 = (IInstrumentedBean) server2.getProxy(IInstrumentedBean.class, remoteServiceName); 75 76 assertEquals("1", bean1.getProperty1()); 77 assertEquals("2", bean1.getProperty2()); 78 79 assertEquals(bean1.getValue(), bean2.getValue()); 80 81 bean1.setValue("AA1"+System.currentTimeMillis()); 82 assertEquals("Should be shared", bean1.getValue(), bean2.getValue()); 83 84 bean2.setValue("AA2"+System.currentTimeMillis()); 85 assertEquals("Should be shared", bean2.getValue(), bean1.getValue()); 86 } 87 88 private static void assertTransient(Server server1, Server server2, String remoteServiceName) throws Exception { 89 IInstrumentedBean bean1 = (IInstrumentedBean) server1.getProxy(IInstrumentedBean.class, remoteServiceName); 90 IInstrumentedBean bean2 = (IInstrumentedBean) server2.getProxy(IInstrumentedBean.class, remoteServiceName); 91 92 String originalValue = "aaa"; 93 assertEquals(originalValue, bean1.getTransientValue()); 94 assertEquals(originalValue, bean2.getTransientValue()); 95 96 bean1.setTransientValue("s1"); 97 assertEquals(originalValue, bean2.getTransientValue()); 98 99 bean2.setTransientValue("s2"); 100 assertEquals("s1", bean1.getTransientValue()); 101 assertEquals("s2", bean2.getTransientValue()); 102 103 bean1.setTransientValue(originalValue); 104 bean2.setTransientValue(originalValue); 105 } 106 107 120 } 121 | Popular Tags |