01: /*
02: * All content copyright (c) 2003-2006 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.simulator.app.ApplicationConfig;
08: import com.tc.simulator.listener.ListenerProvider;
09: import com.tctest.runner.AbstractErrorCatchingTransparentApp;
10:
11: import java.util.Hashtable;
12:
13: /*
14: * Assert some things about Hashtable instances that are not shared
15: *
16: * This test was first written in response to DEV-958 -- it should evolve
17: */
18: public class UnsharedHashtableTest extends TransparentTestBase {
19: private final static int NODE_COUNT = 1;
20:
21: public void setUp() throws Exception {
22: super .setUp();
23:
24: getTransparentAppConfig().setClientCount(NODE_COUNT);
25: initializeTestRunner();
26: }
27:
28: protected Class getApplicationClass() {
29: return App.class;
30: }
31:
32: public static class App extends AbstractErrorCatchingTransparentApp {
33:
34: public App(String appId, ApplicationConfig cfg,
35: ListenerProvider listenerProvider) {
36: super (appId, cfg, listenerProvider);
37: }
38:
39: protected void runTest() throws Throwable {
40: final Hashtable ht = new Hashtable();
41: final int size = 500;
42:
43: for (int i = 0; i < size; i++) {
44: Integer I = new Integer(i);
45: ht.put(I, I);
46: }
47:
48: final Stop stop = new Stop();
49:
50: Thread mutator = new Thread() {
51: public void run() {
52: Integer I = new Integer(ht.size());
53: while (!stop.stop) {
54: ht.remove(I);
55: ht.put(I, I);
56: }
57: }
58: };
59: mutator.start();
60:
61: final long end = System.currentTimeMillis() + 60000;
62:
63: try {
64: while (System.currentTimeMillis() < end) {
65: Object[] array = ht.values().toArray();
66:
67: // this code here to make sure the call to toArray() above can never be optimized out
68: if (array.hashCode() == end) {
69: System.err.println("some useless printing");
70: }
71: }
72: } finally {
73: stop.stop = true;
74: try {
75: mutator.join();
76: } catch (Throwable t) {
77: notifyError(t);
78: }
79: }
80: }
81:
82: }
83:
84: private static class Stop {
85: volatile boolean stop;
86: }
87:
88: }
|