|
Java example source code file (ConcurrentAssociateTest.java)
The ConcurrentAssociateTest.java Java example source code/* * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ import org.testng.annotations.Test; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ThreadLocalRandom; import java.util.function.BiConsumer; import java.util.function.Supplier; import java.util.stream.IntStream; import java.util.stream.Stream; /** * @test * @bug 8028564 * @run testng ConcurrentAssociateTest * @summary Test that association operations, such as put and compute, * place entries in the map */ @Test public class ConcurrentAssociateTest { // The number of entries for each thread to place in a map private static final int N = Integer.getInteger("n", 128); // The number of iterations of the test private static final int I = Integer.getInteger("i", 256); // Object to be placed in the concurrent map static class X { // Limit the hash code to trigger collisions int hc = ThreadLocalRandom.current().nextInt(1, 9); public int hashCode() { return hc; } } @Test public void testPut() { test("CHM.put", (m, o) -> m.put(o, o)); } @Test public void testCompute() { test("CHM.compute", (m, o) -> m.compute(o, (k, v) -> o)); } @Test public void testComputeIfAbsent() { test("CHM.computeIfAbsent", (m, o) -> m.computeIfAbsent(o, (k) -> o)); } @Test public void testMerge() { test("CHM.merge", (m, o) -> m.merge(o, o, (v1, v2) -> v1)); } @Test public void testPutAll() { test("CHM.putAll", (m, o) -> { Map<Object, Object> hm = new HashMap<>(); hm.put(o, o); m.putAll(hm); }); } private static void test(String desc, BiConsumer<ConcurrentMap Other Java examples (source code examples)Here is a short list of links related to this Java ConcurrentAssociateTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.