BUG-7464: Update pom.xml
[yangtools.git] / third-party / triemap / src / test / java / org / opendaylight / yangtools / triemap / TestMultiThreadInserts.java
1 package org.opendaylight.yangtools.triemap;
2
3 import java.util.concurrent.ExecutorService;
4 import java.util.concurrent.Executors;
5 import java.util.concurrent.TimeUnit;
6
7 import org.junit.Test;
8
9 public class TestMultiThreadInserts {
10     @Test
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 () {
18                 @Override
19                 public void run () {
20                     for (int j = 0; j < 500 * 1000; j++) {
21                         if (j % nThreads == threadNo) {
22                             bt.put (Integer.valueOf (j), Integer.valueOf (j));
23                         }
24                     }
25                 }
26             });
27         }
28
29         es.shutdown ();
30         try {
31             es.awaitTermination (3600L, TimeUnit.SECONDS);
32         } catch (final InterruptedException e) {
33             e.printStackTrace ();
34         }
35         
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);
39         }
40     }
41 }