18 |
|
} |
19 |
|
|
20 |
|
/** |
21 |
< |
* |
21 |
> |
* constructor initializes to given value |
22 |
|
*/ |
23 |
|
public void testConstructor(){ |
24 |
|
AtomicInteger ai = new AtomicInteger(1); |
26 |
|
} |
27 |
|
|
28 |
|
/** |
29 |
< |
* |
29 |
> |
* default constructed intializes to zero |
30 |
|
*/ |
31 |
|
public void testConstructor2(){ |
32 |
|
AtomicInteger ai = new AtomicInteger(); |
34 |
|
} |
35 |
|
|
36 |
|
/** |
37 |
< |
* |
37 |
> |
* get returns the last value set |
38 |
|
*/ |
39 |
|
public void testGetSet(){ |
40 |
|
AtomicInteger ai = new AtomicInteger(1); |
46 |
|
|
47 |
|
} |
48 |
|
/** |
49 |
< |
* |
49 |
> |
* compareAndSet succeeds in changing value if equal to expected else fails |
50 |
|
*/ |
51 |
|
public void testCompareAndSet(){ |
52 |
|
AtomicInteger ai = new AtomicInteger(1); |
60 |
|
} |
61 |
|
|
62 |
|
/** |
63 |
< |
* |
63 |
> |
* compareAndSet in one thread enables another waiting for value |
64 |
> |
* to succeed |
65 |
> |
*/ |
66 |
> |
public void testCompareAndSetInMultipleThreads() { |
67 |
> |
final AtomicInteger ai = new AtomicInteger(1); |
68 |
> |
Thread t = new Thread(new Runnable() { |
69 |
> |
public void run() { |
70 |
> |
while(!ai.compareAndSet(2, 3)) Thread.yield(); |
71 |
> |
}}); |
72 |
> |
try { |
73 |
> |
t.start(); |
74 |
> |
assertTrue(ai.compareAndSet(1, 2)); |
75 |
> |
t.join(LONG_DELAY_MS); |
76 |
> |
assertFalse(t.isAlive()); |
77 |
> |
assertEquals(ai.get(), 3); |
78 |
> |
} |
79 |
> |
catch(Exception e) { |
80 |
> |
unexpectedException(); |
81 |
> |
} |
82 |
> |
} |
83 |
> |
|
84 |
> |
/** |
85 |
> |
* repeated weakCompareAndSet succeeds in changing value when equal |
86 |
> |
* to expected |
87 |
|
*/ |
88 |
|
public void testWeakCompareAndSet(){ |
89 |
|
AtomicInteger ai = new AtomicInteger(1); |
95 |
|
} |
96 |
|
|
97 |
|
/** |
98 |
< |
* |
98 |
> |
* getAndSet returns previous value and sets to given value |
99 |
|
*/ |
100 |
|
public void testGetAndSet(){ |
101 |
|
AtomicInteger ai = new AtomicInteger(1); |
105 |
|
} |
106 |
|
|
107 |
|
/** |
108 |
< |
* |
108 |
> |
* getAndAdd returns previous value and adds given value |
109 |
|
*/ |
110 |
|
public void testGetAndAdd(){ |
111 |
|
AtomicInteger ai = new AtomicInteger(1); |
116 |
|
} |
117 |
|
|
118 |
|
/** |
119 |
< |
* |
119 |
> |
* getAndDecrement returns previous value and decrements |
120 |
|
*/ |
121 |
|
public void testGetAndDecrement(){ |
122 |
|
AtomicInteger ai = new AtomicInteger(1); |
126 |
|
} |
127 |
|
|
128 |
|
/** |
129 |
< |
* |
129 |
> |
* getAndIncrement returns previous value and increments |
130 |
|
*/ |
131 |
|
public void testGetAndIncrement(){ |
132 |
|
AtomicInteger ai = new AtomicInteger(1); |
140 |
|
} |
141 |
|
|
142 |
|
/** |
143 |
< |
* |
143 |
> |
* addAndGet adds given value to current, and returns current value |
144 |
|
*/ |
145 |
|
public void testAddAndGet(){ |
146 |
|
AtomicInteger ai = new AtomicInteger(1); |
151 |
|
} |
152 |
|
|
153 |
|
/** |
154 |
< |
* |
154 |
> |
* decrementAndGet decrements and returns current value |
155 |
|
*/ |
156 |
|
public void testDecrementAndGet(){ |
157 |
|
AtomicInteger ai = new AtomicInteger(1); |
162 |
|
} |
163 |
|
|
164 |
|
/** |
165 |
< |
* |
165 |
> |
* incrementAndGet increments and returns current value |
166 |
|
*/ |
167 |
|
public void testIncrementAndGet(){ |
168 |
|
AtomicInteger ai = new AtomicInteger(1); |
176 |
|
} |
177 |
|
|
178 |
|
/** |
179 |
< |
* |
179 |
> |
* a deserialized serialized atomic holds same value |
180 |
|
*/ |
181 |
|
public void testSerialization() { |
182 |
|
AtomicInteger l = new AtomicInteger(); |