1 5 package com.tctest; 6 7 import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier; 8 9 import com.tc.cluster.ClusterEventListener; 10 import com.tc.object.bytecode.ManagerUtil; 11 import com.tc.simulator.app.ApplicationConfig; 12 import com.tc.simulator.listener.ListenerProvider; 13 14 public class ServerCrashAndRestartTestApp extends ServerCrashingAppBase implements ClusterEventListener { 15 16 public ServerCrashAndRestartTestApp(String appId, ApplicationConfig config, ListenerProvider listenerProvider) { 17 super(appId, config, listenerProvider); 18 } 19 20 private final int initialNodeCount = getParticipantCount(); 21 private final CyclicBarrier barrier = new CyclicBarrier(initialNodeCount); 22 private String thisNode; 23 24 public void run() { 25 try { 26 runTest(); 27 } catch (Throwable t) { 28 notifyError(t); 29 } 30 } 31 32 private void runTest() throws Throwable { 33 ManagerUtil.addClusterEventListener(this); 34 final boolean isMasterNode = barrier.barrier() == 0; 35 if (isMasterNode) { 36 getConfig().getServerControl().crash(); 37 getConfig().getServerControl().start(30 * 1000); 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 thisNodeConnected(String thisNodeId, String [] nodesCurrentlyInCluster) { 51 this.thisNode = thisNodeId; 52 trace("thisNodeConnected"); 53 } 54 55 public void thisNodeDisconnected(String thisNodeId) { 56 trace("thisNodeDisconnected"); 57 } 58 59 private void trace(String msg) { 60 System.err.println("### " + msg + " -> nodeId=" + thisNode + ", ThreadId=" + Thread.currentThread().getName()); 61 } 62 } 63
| Popular Tags
|