001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tctest;
006:
007: import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier;
008:
009: import com.tc.object.config.ConfigVisitor;
010: import com.tc.object.config.DSOClientConfigHelper;
011: import com.tc.object.config.TransparencyClassSpec;
012: import com.tc.simulator.app.ApplicationConfig;
013: import com.tc.simulator.listener.ListenerProvider;
014: import com.tc.util.Assert;
015: import com.tctest.runner.AbstractErrorCatchingTransparentApp;
016:
017: import java.util.ArrayList;
018: import java.util.List;
019:
020: /**
021: * Test for CDV-138
022: *
023: * @author hhuynh
024: */
025: public class MassCloneTestApp extends
026: AbstractErrorCatchingTransparentApp {
027: private static final int COUNT = 6000;
028: private static final int RUN_TIME = 3 * 60 * 1000;
029:
030: private List root = new ArrayList();
031: private CyclicBarrier barrier;
032:
033: public MassCloneTestApp(String appId, ApplicationConfig cfg,
034: ListenerProvider listenerProvider) {
035: super (appId, cfg, listenerProvider);
036: barrier = new CyclicBarrier(getParticipantCount());
037: }
038:
039: protected void runTest() throws Throwable {
040: if (barrier.barrier() == 0) {
041: System.err.println("creating " + COUNT + " objects...");
042: int batch = 20;
043: for (int i = 0; i < COUNT; i += batch) {
044: synchronized (root) {
045: for (int j = 0; j < batch; j++) {
046: root.add(new MyStuff());
047: }
048: }
049: }
050: System.err.println("created " + root.size() + " objects.");
051: }
052: barrier.barrier();
053:
054: System.err.println("Validating clondes...");
055: long timeout = System.currentTimeMillis() + RUN_TIME;
056: int index = 0;
057: while (System.currentTimeMillis() < timeout) {
058: synchronized (root) {
059: MyStuff cloned = (MyStuff) ((MyStuff) root.get(index))
060: .clone();
061: Assert.assertTrue(cloned.allFieldsSet());
062: }
063: if (++index >= COUNT) {
064: index = 0;
065: }
066: }
067: }
068:
069: public static void visitL1DSOConfig(ConfigVisitor visitor,
070: DSOClientConfigHelper config) {
071: String testClass = MassCloneTestApp.class.getName();
072: TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
073: config.addIncludePattern(MyStuff.class.getName());
074: config.addWriteAutolock("* " + MyStuff.class.getName()
075: + "*.*(..)");
076:
077: config.addWriteAutolock("* " + testClass + "*.runTest(..)");
078:
079: spec.addRoot("root", "root");
080: spec.addRoot("barrier", "barrier");
081:
082: spec = config.getOrCreateSpec(CyclicBarrier.class.getName());
083: config.addWriteAutolock("* " + CyclicBarrier.class.getName()
084: + "*.*(..)");
085: }
086:
087: private static class MyStuff implements Cloneable {
088: public Object[] array;
089: public List list;
090:
091: public MyStuff() {
092: int size = 2;
093: array = new Object[size];
094: list = new ArrayList();
095:
096: for (int i = 0; i < size; i++) {
097: array[i] = new Object();
098: list.add(new Object());
099: }
100: }
101:
102: public boolean allFieldsSet() {
103: return array != null && list != null;
104: }
105:
106: protected Object clone() throws CloneNotSupportedException {
107: return super.clone();
108: }
109: }
110:
111: }
|