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