1 package org.opendaylight.yangtools.triemap;
3 import java.util.concurrent.ExecutorService;
4 import java.util.concurrent.Executors;
5 import java.util.concurrent.TimeUnit;
9 public class TestMultiThreadInserts {
11 public void testMultiThreadInserts () {
12 final int nThreads = 2;
13 final ExecutorService es = Executors.newFixedThreadPool (nThreads);
14 final TrieMap<Object, Object> bt = new TrieMap<Object, Object> ();
15 for (int i = 0; i < nThreads; i++) {
16 final int threadNo = i;
17 es.execute (new Runnable () {
20 for (int j = 0; j < 500 * 1000; j++) {
21 if (j % nThreads == threadNo) {
22 bt.put (Integer.valueOf (j), Integer.valueOf (j));
31 es.awaitTermination (3600L, TimeUnit.SECONDS);
32 } catch (final InterruptedException e) {
36 for (int j = 0; j < 500 * 1000; j++) {
37 final Object lookup = bt.lookup (Integer.valueOf (j));
38 TestHelper.assertEquals (Integer.valueOf (j), lookup);