1/*
2 * Copyright (C) 2012 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package libcore.java.util;
18
19import java.io.Serializable;
20import java.util.AbstractCollection;
21import java.util.concurrent.atomic.AtomicBoolean;
22import java.util.concurrent.ConcurrentHashMap;
23import junit.framework.TestCase;
24
25public final class AbstractCollectionTest extends TestCase {
26  // http://code.google.com/p/android/issues/detail?id=36519
27  public void test_toArray() throws Exception {
28    final ConcurrentHashMap<Integer, Integer> m = new ConcurrentHashMap<Integer, Integer>();
29    final AtomicBoolean finished = new AtomicBoolean(false);
30
31    Thread reader = new Thread(new Runnable() {
32      @Override public void run() {
33        while (!finished.get()) {
34          m.values().toArray();
35          m.values().toArray(new Integer[m.size()]);
36        }
37      }
38    });
39
40    Thread mutator = new Thread(new Runnable() {
41      @Override public void run() {
42        for (int i = 0; i < 100; ++i) {
43          m.put(-i, -i);
44        }
45        for (int i = 0; i < 4096; ++i) {
46          m.put(i, i);
47          m.remove(i);
48        }
49        finished.set(true);
50      }
51    });
52
53    reader.start();
54    mutator.start();
55    reader.join();
56    mutator.join();
57  }
58}
59