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;
06:
07: import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier;
08:
09: import com.tc.cluster.ClusterEventListener;
10: import com.tc.object.bytecode.ManagerUtil;
11: import com.tc.object.config.ConfigVisitor;
12: import com.tc.object.config.DSOClientConfigHelper;
13: import com.tc.simulator.app.ApplicationConfig;
14: import com.tc.simulator.listener.ListenerProvider;
15: import com.tc.util.DebugUtil;
16:
17: public class ServerCrashAndRestartTestApp extends ServerCrashingAppBase
18: implements ClusterEventListener {
19:
20: public ServerCrashAndRestartTestApp(String appId,
21: ApplicationConfig config, ListenerProvider listenerProvider) {
22: super (appId, config, listenerProvider);
23: }
24:
25: private final int initialNodeCount = getParticipantCount();
26: private final CyclicBarrier barrier = new CyclicBarrier(
27: initialNodeCount);
28: private String this Node;
29:
30: public void runTest() throws Throwable {
31: ManagerUtil.addClusterEventListener(this );
32: DebugUtil.trace("Before barrier...");
33: final boolean isMasterNode = barrier.barrier() == 0;
34: DebugUtil.trace("AFTER barrier...");
35: if (isMasterNode) {
36: getConfig().getServerControl().crash();
37: getConfig().getServerControl().start();
38: }
39: barrier.barrier();
40: }
41:
42: public void nodeConnected(String nodeId) {
43: trace("nodeConnected");
44: }
45:
46: public void nodeDisconnected(String nodeId) {
47: trace("nodeDisconnected");
48: }
49:
50: public void this NodeConnected(String this NodeId,
51: String[] nodesCurrentlyInCluster) {
52: this .this Node = this NodeId;
53: trace("thisNodeConnected");
54: }
55:
56: public void this NodeDisconnected(String this NodeId) {
57: trace("thisNodeDisconnected");
58: }
59:
60: private void trace(String msg) {
61: System.err.println("### " + msg + " -> nodeId=" + this Node
62: + ", ThreadId=" + Thread.currentThread().getName());
63: }
64:
65: public static void visitL1DSOConfig(ConfigVisitor visitor,
66: DSOClientConfigHelper config) {
67: config.addIncludePattern(ServerCrashAndRestartTestApp.class
68: .getName());
69: config.addRoot("barrier", ServerCrashAndRestartTestApp.class
70: .getName()
71: + ".barrier");
72: config.addWriteAutolock("* "
73: + ServerCrashAndRestartTestApp.class.getName()
74: + ".*(..)");
75:
76: config.addIncludePattern(CyclicBarrier.class.getName());
77: config.addWriteAutolock("* " + CyclicBarrier.class.getName()
78: + ".*(..)");
79: }
80: }
|