KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > AsmMethodInfoTestHelper


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tctest;
5
6 import com.tc.util.Assert;
7
8 import java.util.HashMap JavaDoc;
9 import java.util.Map JavaDoc;
10
11 /**
12  * @author steve
13  */

14 public class AsmMethodInfoTestHelper {
15   AsmMethodInfoTestHelper(int countStart) {
16     this.count = countStart;
17     try {
18       myRoot = new HashMap JavaDoc();
19     } catch (Exception JavaDoc e) {
20       e.printStackTrace();
21     }
22   }
23
24   private static Map JavaDoc myRoot; // = new HashMap();
25
private long count;
26
27   private int commits = 0;
28
29   public long test4(int i, Object JavaDoc 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 JavaDoc(c))) {
36         Assert.eval(false);
37       }
38       myRoot.put(new Long JavaDoc(c), new TestObj(new TestObj(null)));
39       if (myRoot.size() != s + 1) System.out.println("Wrong size!:" + s + " new size:" + myRoot.size());
40       Assert.eval(myRoot.size() == s + 1);
41       // System.out.println("^^^TOTAL SIZE ADD:" + myRoot.size() + "^^^:" + this);
42
return System.currentTimeMillis() - start;
43     }
44   }
45
46   public long test5(int i, Object JavaDoc foo) {
47     synchronized (myRoot) {
48       long start = System.currentTimeMillis();
49       commits++;
50       int s = myRoot.size();
51       myRoot.remove(new Long JavaDoc(count - 1));
52       if (myRoot.size() != s - 1) System.out.println("Wrong size!:" + s + " new size:" + myRoot.size());
53       Assert.eval(myRoot.size() == s - 1);
54       // System.out.println("^^^TOTAL SIZE REMOVE:" + myRoot.size() + "^^^:" + this);
55
return System.currentTimeMillis() - start;
56     }
57   }
58
59   public static class TestObj {
60     private TestObj obj;
61     private String JavaDoc string = "Steve";
62     private int integer = 22;
63     private boolean bool = false;
64     private Map JavaDoc map = new HashMap JavaDoc();
65
66     private TestObj() {
67       //
68
}
69
70     public TestObj(TestObj obj) {
71       this.obj = obj;
72       for (int i = 0; i < 30; i++) {
73         map.put(new Long JavaDoc(i), new TestObj());
74       }
75     }
76
77     public Object JavaDoc getObject() {
78       return this.obj;
79     }
80
81     public boolean check() {
82       return string.equals("Steve") && integer == 22 && bool == false;
83     }
84   }
85 }
Popular Tags