01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tctest;
05:
06: import com.tc.util.Assert;
07:
08: import java.util.HashMap;
09: import java.util.Map;
10:
11: /**
12: * @author steve
13: */
14: public class AsmMethodInfoTestHelper {
15: AsmMethodInfoTestHelper(int countStart) {
16: this .count = countStart;
17: try {
18: myRoot = new HashMap();
19: } catch (Exception e) {
20: e.printStackTrace();
21: }
22: }
23:
24: private static Map myRoot; // = new HashMap();
25: private long count;
26:
27: private int commits = 0;
28:
29: public long test4(int i, Object foo) {
30: synchronized (myRoot) {
31: long start = System.currentTimeMillis();
32: commits++;
33: int s = myRoot.size();
34: long c = count++;
35: if (myRoot.containsKey(new Long(c))) {
36: Assert.eval(false);
37: }
38: myRoot.put(new Long(c), new TestObj(new TestObj(null)));
39: if (myRoot.size() != s + 1)
40: System.out.println("Wrong size!:" + s + " new size:"
41: + myRoot.size());
42: Assert.eval(myRoot.size() == s + 1);
43: // System.out.println("^^^TOTAL SIZE ADD:" + myRoot.size() + "^^^:" + this);
44: return System.currentTimeMillis() - start;
45: }
46: }
47:
48: public long test5(int i, Object foo) {
49: synchronized (myRoot) {
50: long start = System.currentTimeMillis();
51: commits++;
52: int s = myRoot.size();
53: myRoot.remove(new Long(count - 1));
54: if (myRoot.size() != s - 1)
55: System.out.println("Wrong size!:" + s + " new size:"
56: + myRoot.size());
57: Assert.eval(myRoot.size() == s - 1);
58: // System.out.println("^^^TOTAL SIZE REMOVE:" + myRoot.size() + "^^^:" + this);
59: return System.currentTimeMillis() - start;
60: }
61: }
62:
63: public static class TestObj {
64: private TestObj obj;
65: private String string = "Steve";
66: private int integer = 22;
67: private boolean bool = false;
68: private Map map = new HashMap();
69:
70: private TestObj() {
71: //
72: }
73:
74: public TestObj(TestObj obj) {
75: this .obj = obj;
76: for (int i = 0; i < 30; i++) {
77: map.put(new Long(i), new TestObj());
78: }
79: }
80:
81: public Object getObject() {
82: return this .obj;
83: }
84:
85: public boolean check() {
86: return string.equals("Steve") && integer == 22
87: && bool == false;
88: }
89: }
90: }
|