//  Copyright 2016 The Minorminor Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package jdktest;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

public class ConcurrentHashMapTest {
    private Map<String, AtomicLong> accounts = new ConcurrentHashMap();

    public ConcurrentHashMapTest() {
        accounts.put("account1", new AtomicLong(0l));
        accounts.put("account2", new AtomicLong(0l));
        accounts.put("account3", new AtomicLong(0l));
    }

    public void increaseIt() {
        for (int i = 0; i < 50; i++) {
            for (String acount : accounts.keySet()) {
                //accounts.get(acount).getAndIncrement();
                accounts.put(acount, new AtomicLong(accounts.get(acount).longValue()+1));
            }
        }
    }

    public void test() {
        ExecutorService tpool = Executors.newFixedThreadPool(2);
        tpool.submit(new Runnable() {
            @Override
            public void run() {
                increaseIt();
            }
        });
        tpool.submit(new Runnable() {
            @Override
            public void run() {
                increaseIt();
            }
        });
        try {
            tpool.awaitTermination(1, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        tpool.shutdown();
        System.out.println(accounts);

    }

    public static void main(String[] args) throws InterruptedException {
        int i = 0;
        while (i < 10) {
            new ConcurrentHashMapTest().test();
            i++;
        }
    }
}

@@ -627,16 +627,65 @@
 ktest;%0A%0A
+import org.junit.Assert;%0Aimport org.junit.Test;%0A%0A
 import j
@@ -741,24 +741,68 @@
 entHashMap;%0A
+import java.util.concurrent.CountDownLatch;%0A
 import java.
@@ -877,46 +877,8 @@
 rs;%0A
-import java.util.concurrent.TimeUnit;%0A
 impo
@@ -1264,19 +1264,188 @@
 reaseIt(
-) %7B
+CountDownLatch start, CountDownLatch done) %7B%0A        try %7B%0A            start.await();%0A        %7D catch (InterruptedException e) %7B%0A            e.printStackTrace();%0A        %7D%0A
 %0A       
@@ -1546,18 +1546,16 @@
         
-//
 accounts
@@ -1594,32 +1594,34 @@
                 
+//
 accounts.put(aco
@@ -1698,24 +1698,50 @@
 %7D%0A        %7D%0A
+        done.countDown();%0A
     %7D%0A%0A    p
@@ -1746,20 +1746,22 @@
  public 
-void
+String
  test() 
@@ -1754,32 +1754,151 @@
 String test() %7B%0A
+        final CountDownLatch start = new CountDownLatch(1);%0A        final CountDownLatch done = new CountDownLatch(2);%0A
         Executor
@@ -2057,32 +2057,43 @@
      increaseIt(
+start, done
 );%0A            %7D
@@ -2224,16 +2224,27 @@
 reaseIt(
+start, done
 );%0A     
@@ -2255,32 +2255,60 @@
    %7D%0A        %7D);
+%0A%0A        start.countDown();
 %0A        try %7B%0A 
@@ -2322,50 +2322,19 @@
     
-tpool
+done
 .await
-Termination(1, TimeUnit.SECONDS
+(
 );%0A 
@@ -2410,32 +2410,33 @@
 ce();%0A        %7D%0A
+%0A
         tpool.sh
@@ -2457,39 +2457,36 @@
     
-System.out.println(accounts
+return accounts.toString(
 );%0A
-%0A
     
@@ -2496,74 +2496,83 @@
     
-public static void main(String%5B%5D args) throws InterruptedException
+@Test(timeout = 3000L, expected = Test.None.class)%0A    public void testit()
  %7B%0A 
@@ -2626,16 +2626,36 @@
         
+Assert.assertEquals(
 new Conc
@@ -2680,16 +2680,63 @@
 ).test()
+, %22%7Baccount3=100, account1=100, account2=100%7D%22)
 ;%0A      

Add test case for ConcurrentHashMapTest.java