1 4 package com.tctest.spring; 5 6 import org.springframework.context.support.ClassPathXmlApplicationContext; 7 8 import com.tc.object.config.ConfigVisitor; 9 import com.tc.object.config.DSOClientConfigHelper; 10 import com.tc.object.config.DSOSpringConfigHelper; 11 import com.tc.object.config.StandardDSOSpringConfigHelper; 12 import com.tc.simulator.app.ApplicationConfig; 13 import com.tc.simulator.listener.ListenerProvider; 14 import com.tctest.TransparentTestBase; 15 import com.tctest.runner.AbstractTransparentApp; 16 import com.tctest.spring.bean.Singleton; 17 18 import java.util.ArrayList ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 25 public class Singleton2_Test extends TransparentTestBase { 26 private static final int LOOP_ITERATIONS = 1; 27 private static final int EXECUTION_COUNT = 1; 28 private static final int NODE_COUNT = 4; 29 30 public Singleton2_Test() { 31 disableAllUntil("2008-01-01"); } 33 34 protected void setUp() throws Exception { 35 super.setUp(); 36 getTransparentAppConfig().setClientCount(NODE_COUNT).setApplicationInstancePerClientCount(EXECUTION_COUNT) 37 .setIntensity(LOOP_ITERATIONS); 38 initializeTestRunner(); 39 } 40 41 protected Class getApplicationClass() { 42 return SingletonApp.class; 43 } 44 45 public static class SingletonApp extends AbstractTransparentApp { 46 private List sharedSingletons1 = new ArrayList (); 47 private List sharedSingletons2 = new ArrayList (); 48 49 public SingletonApp(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 50 super(appId, cfg, listenerProvider); 51 } 52 53 public void run() { 54 try { 55 ClassPathXmlApplicationContext ctx1 = new ClassPathXmlApplicationContext("com/tctest/spring/beanfactory.xml"); 56 ClassPathXmlApplicationContext ctx2 = new ClassPathXmlApplicationContext("com/tctest/spring/beanfactory2.xml"); 57 58 Singleton singleton1 = (Singleton) ctx1.getBean("singleton"); 59 Singleton singleton2 = (Singleton) ctx2.getBean("singleton"); 60 61 synchronized (sharedSingletons1) { 62 sharedSingletons1.add(singleton1); 63 } 64 synchronized (sharedSingletons2) { 65 sharedSingletons2.add(singleton2); 66 } 67 68 moveToStageAndWait(1); 69 70 synchronized (sharedSingletons1) { 71 73 for (Iterator it = sharedSingletons1.iterator(); it.hasNext();) { 74 Object o = it.next(); 75 assertTrue("Found non-singleton object", o == singleton1); 76 if (o == singleton2) { 77 notifyError("Distinct objects expected"); 78 } 79 } 80 } 81 82 synchronized (sharedSingletons2) { 83 85 for (Iterator it = sharedSingletons2.iterator(); it.hasNext();) { 86 Object o = it.next(); 87 assertTrue("Found non-singleton object", o == singleton2); 88 if (o == singleton1) { 89 notifyError("Distinct objects expected"); 90 } 91 } 92 } 93 94 } catch (Throwable e) { 95 moveToStage(1); 96 notifyError(e); 97 98 } 99 } 100 101 public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) { 102 config.addRoot("com.tctest.spring.Singleton_Test$SingletonApp", "sharedSingletons1", "sharedSingletons1", false); 103 config.addRoot("com.tctest.spring.Singleton_Test$SingletonApp", "sharedSingletons2", "sharedSingletons2", false); 104 105 DSOSpringConfigHelper springConfig = new StandardDSOSpringConfigHelper(); 106 springConfig.addApplicationNamePattern(SpringTestConstants.APPLICATION_NAME); springConfig.addConfigPattern("*/beanfactory.xml"); 109 springConfig.addConfigPattern("*/beanfactory2.xml"); 110 springConfig.addBean("singleton"); 111 config.addDSOSpringConfig(springConfig); 112 } 113 114 } 115 } 116 | Popular Tags |