42 |
|
/** |
43 |
|
* stream().forEach returns elements in the collection |
44 |
|
*/ |
45 |
< |
public void testForEach() throws Throwable { |
45 |
> |
public void testStreamForEach() throws Throwable { |
46 |
|
final Collection c = impl.emptyCollection(); |
47 |
|
final AtomicLong count = new AtomicLong(0L); |
48 |
|
final Object x = impl.makeElement(1); |
69 |
|
assertTrue(found.isEmpty()); |
70 |
|
} |
71 |
|
|
72 |
< |
public void testForEachConcurrentStressTest() throws Throwable { |
72 |
> |
public void testStreamForEachConcurrentStressTest() throws Throwable { |
73 |
|
if (!impl.isConcurrent()) return; |
74 |
|
final Collection c = impl.emptyCollection(); |
75 |
|
final long testDurationMillis = timeoutMillis(); |
97 |
|
assertNull(f2.get(0L, MILLISECONDS)); |
98 |
|
} |
99 |
|
|
100 |
< |
// public void testCollection8DebugFail() { fail(); } |
100 |
> |
/** |
101 |
> |
* collection.forEach returns elements in the collection |
102 |
> |
*/ |
103 |
> |
public void testForEach() throws Throwable { |
104 |
> |
final Collection c = impl.emptyCollection(); |
105 |
> |
final AtomicLong count = new AtomicLong(0L); |
106 |
> |
final Object x = impl.makeElement(1); |
107 |
> |
final Object y = impl.makeElement(2); |
108 |
> |
final ArrayList found = new ArrayList(); |
109 |
> |
Consumer<Object> spy = (o) -> { found.add(o); }; |
110 |
> |
c.forEach(spy); |
111 |
> |
assertTrue(found.isEmpty()); |
112 |
> |
|
113 |
> |
assertTrue(c.add(x)); |
114 |
> |
c.forEach(spy); |
115 |
> |
assertEquals(Collections.singletonList(x), found); |
116 |
> |
found.clear(); |
117 |
> |
|
118 |
> |
assertTrue(c.add(y)); |
119 |
> |
c.forEach(spy); |
120 |
> |
assertEquals(2, found.size()); |
121 |
> |
assertTrue(found.contains(x)); |
122 |
> |
assertTrue(found.contains(y)); |
123 |
> |
found.clear(); |
124 |
> |
|
125 |
> |
c.clear(); |
126 |
> |
c.forEach(spy); |
127 |
> |
assertTrue(found.isEmpty()); |
128 |
> |
} |
129 |
> |
|
130 |
> |
public void testForEachConcurrentStressTest() throws Throwable { |
131 |
> |
if (!impl.isConcurrent()) return; |
132 |
> |
final Collection c = impl.emptyCollection(); |
133 |
> |
final long testDurationMillis = timeoutMillis(); |
134 |
> |
final AtomicBoolean done = new AtomicBoolean(false); |
135 |
> |
final Object elt = impl.makeElement(1); |
136 |
> |
final Future<?> f1, f2; |
137 |
> |
final ExecutorService pool = Executors.newCachedThreadPool(); |
138 |
> |
try (PoolCleaner cleaner = cleaner(pool, done)) { |
139 |
> |
final CountDownLatch threadsStarted = new CountDownLatch(2); |
140 |
> |
Runnable checkElt = () -> { |
141 |
> |
threadsStarted.countDown(); |
142 |
> |
while (!done.get()) |
143 |
> |
c.forEach((x) -> { assertSame(x, elt); }); }; |
144 |
> |
Runnable addRemove = () -> { |
145 |
> |
threadsStarted.countDown(); |
146 |
> |
while (!done.get()) { |
147 |
> |
assertTrue(c.add(elt)); |
148 |
> |
assertTrue(c.remove(elt)); |
149 |
> |
}}; |
150 |
> |
f1 = pool.submit(checkElt); |
151 |
> |
f2 = pool.submit(addRemove); |
152 |
> |
Thread.sleep(testDurationMillis); |
153 |
> |
} |
154 |
> |
assertNull(f1.get(0L, MILLISECONDS)); |
155 |
> |
assertNull(f2.get(0L, MILLISECONDS)); |
156 |
> |
} |
157 |
> |
|
158 |
> |
// public void testCollection8DebugFail() { |
159 |
> |
// fail(impl.klazz().getSimpleName()); |
160 |
> |
// } |
161 |
|
} |