01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tctest.restart.system;
06:
07: import com.tc.config.schema.builder.InstrumentedClassConfigBuilder;
08: import com.tc.config.schema.builder.LockConfigBuilder;
09: import com.tc.config.schema.builder.RootConfigBuilder;
10: import com.tc.config.schema.test.InstrumentedClassConfigBuilderImpl;
11: import com.tc.config.schema.test.LockConfigBuilderImpl;
12: import com.tc.config.schema.test.RootConfigBuilderImpl;
13: import com.tc.config.schema.test.TerracottaConfigBuilder;
14: import com.tctest.ServerCrashingTestBase;
15: import com.tctest.restart.system.ClientTerminatingTestApp.Client;
16:
17: public class ClientTerminatingTest extends ServerCrashingTestBase {
18:
19: private static final int NODE_COUNT = 2;
20:
21: private boolean isSynchronousWrite = false;
22:
23: public ClientTerminatingTest() {
24: super (NODE_COUNT);
25: }
26:
27: protected void setSynchronousWrite() {
28: isSynchronousWrite = true;
29: }
30:
31: protected Class getApplicationClass() {
32: ClientTerminatingTestApp
33: .setSynchronousWrite(isSynchronousWrite);
34: return ClientTerminatingTestApp.class;
35: }
36:
37: protected void createConfig(TerracottaConfigBuilder cb) {
38: String testClassName = ClientTerminatingTestApp.class.getName();
39: String clientClassName = Client.class.getName();
40:
41: LockConfigBuilder lock1 = new LockConfigBuilderImpl(
42: LockConfigBuilder.TAG_AUTO_LOCK);
43: lock1.setMethodExpression("* " + testClassName + "*.*(..)");
44: setLockLevel(lock1);
45:
46: LockConfigBuilder lock2 = new LockConfigBuilderImpl(
47: LockConfigBuilder.TAG_AUTO_LOCK);
48: lock2.setMethodExpression("* " + clientClassName + "*.*(..)");
49: setLockLevel(lock2);
50:
51: cb.getApplication().getDSO().setLocks(
52: new LockConfigBuilder[] { lock1, lock2 });
53:
54: RootConfigBuilder root = new RootConfigBuilderImpl();
55: root.setFieldName(testClassName + ".queue");
56: root.setRootName("queue");
57: RootConfigBuilder root2 = new RootConfigBuilderImpl();
58: root2.setFieldName(clientClassName + ".clientQueue");
59: root2.setRootName("queue");
60: cb.getApplication().getDSO().setRoots(
61: new RootConfigBuilder[] { root, root2 });
62:
63: InstrumentedClassConfigBuilder instrumented1 = new InstrumentedClassConfigBuilderImpl();
64: instrumented1.setClassExpression(testClassName + "*");
65:
66: InstrumentedClassConfigBuilder instrumented2 = new InstrumentedClassConfigBuilderImpl();
67: instrumented2.setClassExpression(clientClassName + "*");
68:
69: cb.getApplication().getDSO().setInstrumentedClasses(
70: new InstrumentedClassConfigBuilder[] { instrumented1,
71: instrumented2 });
72: }
73:
74: private void setLockLevel(LockConfigBuilder lock) {
75: if (isSynchronousWrite) {
76: lock
77: .setLockLevel(LockConfigBuilder.LEVEL_SYNCHRONOUS_WRITE);
78: } else {
79: lock.setLockLevel(LockConfigBuilder.LEVEL_WRITE);
80: }
81: }
82:
83: }
|