Skip to content

Commit c565173

Browse files
Tian Baoqiangpivovarit
authored andcommitted
fix ConcurrentMapTests failed test (eugenp#1070)
* add concurrentmap tests * fix ConcurrentMapTests#givenConcurrentMap_whenKeyWithSameHashCode_thenPerformanceDegrades
1 parent b852e2e commit c565173

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

‎core-java/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapPerformanceTest.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.concurrent.*;
1010

1111
import static org.junit.Assert.assertEquals;
12-
import static org.junit.Assert.assertNotEquals;
1312
import static org.junit.Assert.assertTrue;
1413

1514
public class ConcurrentMapPerformanceTest {
@@ -24,11 +23,11 @@ public void givenMaps_whenGetPut500KTimes_thenConcurrentMapFaster() throws Excep
2423
long syncHashMapAvgRuntime = timeElapseForGetPut(synchronizedHashMap);
2524
long concurrentHashMapAvgRuntime = timeElapseForGetPut(concurrentHashMap);
2625

26+
System.out.println(String.format("Hashtable: %s, syncHashMap: %s, ConcurrentHashMap: %s", hashtableAvgRuntime, syncHashMapAvgRuntime, concurrentHashMapAvgRuntime));
27+
2728
assertTrue(hashtableAvgRuntime > concurrentHashMapAvgRuntime);
2829
assertTrue(syncHashMapAvgRuntime > concurrentHashMapAvgRuntime);
2930

30-
System.out.println(String.format("Hashtable: %s, syncHashMap: %s, ConcurrentHashMap: %s", hashtableAvgRuntime, syncHashMapAvgRuntime, concurrentHashMapAvgRuntime));
31-
3231
}
3332

3433
private long timeElapseForGetPut(Map<String, Object> map) throws InterruptedException {
@@ -90,7 +89,7 @@ public int hashCode() {
9089

9190
long mapOfDefaultHashDuration = System.currentTimeMillis() - defaultHashStartTime;
9291
assertEquals(executeTimes * 2, mapOfDefaultHash.size());
93-
assertNotEquals(executeTimes * 2, mapOfSameHash.size());
92+
assertEquals(executeTimes * 2, mapOfSameHash.size());
9493
System.out.println(String.format("same-hash: %s, default-hash: %s", mapOfSameHashDuration, mapOfDefaultHashDuration));
9594
assertTrue("same hashCode() should greatly degrade performance", mapOfSameHashDuration > mapOfDefaultHashDuration * 10);
9695
}

0 commit comments

Comments
 (0)