From c5651736017eb909771b723b7f8aab259fced080 Mon Sep 17 00:00:00 2001 From: Tian Baoqiang Date: Sun, 29 Jan 2017 21:32:10 +0800 Subject: [PATCH] fix ConcurrentMapTests failed test (#1070) * add concurrentmap tests * fix ConcurrentMapTests#givenConcurrentMap_whenKeyWithSameHashCode_thenPerformanceDegrades --- .../java/concurrentmap/ConcurrentMapPerformanceTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core-java/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapPerformanceTest.java b/core-java/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapPerformanceTest.java index 3275a47b90..040434f73b 100644 --- a/core-java/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapPerformanceTest.java +++ b/core-java/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapPerformanceTest.java @@ -9,7 +9,6 @@ import java.util.Map; import java.util.concurrent.*; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; public class ConcurrentMapPerformanceTest { @@ -24,11 +23,11 @@ public class ConcurrentMapPerformanceTest { long syncHashMapAvgRuntime = timeElapseForGetPut(synchronizedHashMap); long concurrentHashMapAvgRuntime = timeElapseForGetPut(concurrentHashMap); + System.out.println(String.format("Hashtable: %s, syncHashMap: %s, ConcurrentHashMap: %s", hashtableAvgRuntime, syncHashMapAvgRuntime, concurrentHashMapAvgRuntime)); + assertTrue(hashtableAvgRuntime > concurrentHashMapAvgRuntime); assertTrue(syncHashMapAvgRuntime > concurrentHashMapAvgRuntime); - System.out.println(String.format("Hashtable: %s, syncHashMap: %s, ConcurrentHashMap: %s", hashtableAvgRuntime, syncHashMapAvgRuntime, concurrentHashMapAvgRuntime)); - } private long timeElapseForGetPut(Map map) throws InterruptedException { @@ -90,7 +89,7 @@ public class ConcurrentMapPerformanceTest { long mapOfDefaultHashDuration = System.currentTimeMillis() - defaultHashStartTime; assertEquals(executeTimes * 2, mapOfDefaultHash.size()); - assertNotEquals(executeTimes * 2, mapOfSameHash.size()); + assertEquals(executeTimes * 2, mapOfSameHash.size()); System.out.println(String.format("same-hash: %s, default-hash: %s", mapOfSameHashDuration, mapOfDefaultHashDuration)); assertTrue("same hashCode() should greatly degrade performance", mapOfSameHashDuration > mapOfDefaultHashDuration * 10); }