KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > restart > system > ClientTerminatingTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tctest.restart.system;
6
7 import com.tc.config.schema.builder.InstrumentedClassConfigBuilder;
8 import com.tc.config.schema.builder.LockConfigBuilder;
9 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 import com.tctest.runner.AbstractTransparentApp;
17
18 public class ClientTerminatingTest extends ServerCrashingTestBase {
19
20   private static final int NODE_COUNT = 2;
21
22   private boolean isSynchronousWrite = false;
23
24   public ClientTerminatingTest() {
25     super(NODE_COUNT);
26   }
27
28   protected void setSynchronousWrite() {
29     isSynchronousWrite = true;
30   }
31
32   protected Class JavaDoc getApplicationClass() {
33     return ClientTerminatingTestApp.class;
34   }
35
36   protected void createConfig(TerracottaConfigBuilder cb) {
37     String JavaDoc testClassName = ClientTerminatingTestApp.class.getName();
38     String JavaDoc testClassSuperName = AbstractTransparentApp.class.getName();
39     String JavaDoc clientClassName = Client.class.getName();
40
41     LockConfigBuilder lock1 = new LockConfigBuilderImpl(LockConfigBuilder.TAG_AUTO_LOCK);
42     lock1.setMethodExpression("* " + testClassName + ".run(..)");
43     setLockLevel(lock1);
44
45     LockConfigBuilder lock2 = new LockConfigBuilderImpl(LockConfigBuilder.TAG_AUTO_LOCK);
46     lock2.setMethodExpression("* " + clientClassName + ".execute(..)");
47     setLockLevel(lock2);
48
49     cb.getApplication().getDSO().setLocks(new LockConfigBuilder[] { lock1, lock2 });
50
51     RootConfigBuilder root = new RootConfigBuilderImpl();
52     root.setFieldName(testClassName + ".queue");
53     // root.setRootName("queue");
54
cb.getApplication().getDSO().setRoots(new RootConfigBuilder[] { root });
55
56     InstrumentedClassConfigBuilder instrumented1 = new InstrumentedClassConfigBuilderImpl();
57     instrumented1.setClassExpression(testClassName + "*");
58
59     InstrumentedClassConfigBuilder instrumented2 = new InstrumentedClassConfigBuilderImpl();
60     instrumented2.setClassExpression(testClassSuperName + "*");
61
62     cb.getApplication().getDSO().setInstrumentedClasses(
63                                                         new InstrumentedClassConfigBuilder[] { instrumented1,
64                                                             instrumented2 });
65   }
66
67   private void setLockLevel(LockConfigBuilder lock) {
68     if (isSynchronousWrite) {
69       lock.setLockLevel(LockConfigBuilder.LEVEL_SYNCHRONOUS_WRITE);
70     } else {
71       lock.setLockLevel(LockConfigBuilder.LEVEL_WRITE);
72     }
73   }
74
75 }
76
Popular Tags