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;
05:
06: import org.springframework.context.support.ClassPathXmlApplicationContext;
07:
08: import com.tc.simulator.app.ApplicationConfig;
09: import com.tc.simulator.listener.ListenerProvider;
10: import com.tcspring.BeanContainer;
11: import com.tcspring.ComplexBeanId;
12: import com.tcspring.DistributableBeanFactory;
13: import com.tctest.TransparentTestBase;
14: import com.tctest.runner.AbstractTransparentApp;
15:
16: public abstract class SimpleTransparentTestBase extends
17: TransparentTestBase {
18:
19: protected abstract int getNodeCount();
20:
21: protected void setUp() throws Exception {
22: super .setUp();
23: getTransparentAppConfig().setClientCount(getNodeCount())
24: .setApplicationInstancePerClientCount(
25: getExecutionCount()).setIntensity(
26: getLoopIterations());
27: initializeTestRunner();
28: }
29:
30: protected final int getLoopIterations() {
31: return 1;
32: }
33:
34: protected final int getExecutionCount() {
35: return 1;
36: }
37:
38: public abstract static class AbstractSimpleTransparentApp extends
39: AbstractTransparentApp {
40: public AbstractSimpleTransparentApp(String appId,
41: ApplicationConfig cfg, ListenerProvider listenerProvider) {
42: super (appId, cfg, listenerProvider);
43: }
44:
45: public final void run() {
46: Thread t = Thread.currentThread();
47: ClassLoader cl = t.getContextClassLoader();
48:
49: try {
50: t.setContextClassLoader(getClass().getClassLoader());
51:
52: doIt();
53:
54: } catch (Throwable e) {
55: notifyError(e);
56:
57: } finally {
58: t.setContextClassLoader(cl);
59:
60: }
61: }
62:
63: protected abstract void doIt() throws Throwable;
64:
65: }
66:
67: protected static void assertDistributed(
68: ClassPathXmlApplicationContext ctx, String beanName,
69: Object bean) {
70: DistributableBeanFactory distributableBeanFactory = (DistributableBeanFactory) ctx
71: .getBeanFactory();
72: BeanContainer container = distributableBeanFactory
73: .getBeanContainer(new ComplexBeanId(beanName));
74: assertNotNull("Bean " + beanName
75: + " is not in distributed cache", container);
76: assertSame("Bean " + beanName
77: + " don't match instance from distributed cache", bean,
78: container.getBean());
79: }
80:
81: }
|