01: /*
02: * All content copyright (c) 2003-2007 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 com.tc.object.config.ConfigVisitor;
08: import com.tc.object.config.DSOClientConfigHelper;
09: import com.tc.object.config.TransparencyClassSpec;
10: import com.tc.simulator.app.ApplicationConfig;
11: import com.tc.simulator.listener.ListenerProvider;
12:
13: import java.util.ArrayList;
14: import java.util.List;
15:
16: public class ArrayMutateValidateTestApp extends
17: AbstractMutateValidateTransparentApp {
18:
19: private String[] myArrayTestRoot;
20: private List validationArray;
21: private int iterationCount1;
22: private int iterationCount2;
23: private int iterationCount3;
24: private final String appId;
25:
26: public ArrayMutateValidateTestApp(String appId,
27: ApplicationConfig cfg, ListenerProvider listenerProvider) {
28: super (appId, cfg, listenerProvider);
29: this .appId = appId;
30: myArrayTestRoot = new String[] { "hee", "hoo", "haa" };
31: iterationCount1 = 9;
32: iterationCount2 = 9;
33: iterationCount3 = 9;
34: validationArray = new ArrayList();
35: }
36:
37: protected void mutate() throws Throwable {
38: synchronized (validationArray) {
39: for (int i = 0; i < iterationCount1; i++) {
40: int index = (i + 1) % myArrayTestRoot.length;
41: String val = myArrayTestRoot[index];
42: validationArray.add(val);
43:
44: Thread.sleep(1000);
45: }
46: }
47: synchronized (validationArray) {
48: for (int i = 0; i < iterationCount2; i++) {
49: int index = (i + 1) % myArrayTestRoot.length;
50: String val = myArrayTestRoot[index];
51: validationArray.add(val);
52:
53: Thread.sleep(1000);
54: }
55: }
56: synchronized (validationArray) {
57: for (int i = 0; i < iterationCount3; i++) {
58: int index = (i + 1) % myArrayTestRoot.length;
59: String val = myArrayTestRoot[index];
60: validationArray.add(val);
61:
62: Thread.sleep(1000);
63: }
64: }
65: }
66:
67: protected void validate() throws Throwable {
68: synchronized (validationArray) {
69: for (int i = 0; i < (iterationCount1 + iterationCount2 + iterationCount3)
70: * getParticipantCount(); i++) {
71:
72: boolean val = myArrayTestRoot[(i + 1)
73: % myArrayTestRoot.length]
74: .equals(validationArray.get(i));
75: if (!val) {
76: notifyError("Expecting <"
77: + myArrayTestRoot[(i + 1)
78: % myArrayTestRoot.length]
79: + "> but got <" + validationArray.get(i)
80: + ">");
81: }
82: }
83: }
84: }
85:
86: public static void visitL1DSOConfig(ConfigVisitor visitor,
87: DSOClientConfigHelper config) {
88: String testClass = ArrayMutateValidateTestApp.class.getName();
89: TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
90:
91: String methodExpression = "* " + testClass + "*.*(..)";
92: config.addWriteAutolock(methodExpression);
93: spec.addRoot("myArrayTestRoot", "myArrayTestRoot");
94: spec.addRoot("validationArray", "validationArray");
95: }
96:
97: }
|