@Override public Map<Long, Long> create(Object... elements) { Map<Long, Long> map = new NonBlockingHashMapLong<>(); for (Object o : elements) { Map.Entry<Long, Long> e = (Map.Entry<Long, Long>) o; map.put(e.getKey(), e.getValue()); } return map; }
@BeforeClass public static void setUp() { _nbhml = new NonBlockingHashMapLong<>(); }
public NonBlockingHashMapLong<TestKey> getMapMultithreaded() throws InterruptedException, ExecutionException { final int threadCount = _items.keySet().size(); final NonBlockingHashMapLong<TestKey> map = new NonBlockingHashMapLong<>(); // use a barrier to open the gate for all threads at once to avoid rolling start and no actual concurrency final CyclicBarrier barrier = new CyclicBarrier(threadCount); final ExecutorService ex = Executors.newFixedThreadPool(threadCount); final CompletionService<Integer> co = new ExecutorCompletionService<>(ex); for (Integer type : _items.keySet()) { // A linked-list of things to insert List<TestKey> items = _items.get(type); TestKeyFeederThread feeder = new TestKeyFeederThread(items, map, barrier); co.submit(feeder); } // wait for all threads to return int itemCount = 0; for (int retCount = 0; retCount < threadCount; retCount++) { final Future<Integer> result = co.take(); itemCount += result.get(); } ex.shutdown(); return map; } }
static void run_till_stable(int num_threads, int num_trials) { NonBlockingHashMapLong<String> HM = new NonBlockingHashMapLong<String>(true); String name = "NonBlockingHashMapLong"; System.out.printf("=== %10.10s %3d cnts/sec=", name, num_threads);
@Test public void testConcurrentSimple() throws InterruptedException final NonBlockingHashMapLong<String> nbhml = new NonBlockingHashMapLong<>();
final int ITEM_COUNT = PER_CNT * THREAD_COUNT; // fix roundoff for odd thread counts NonBlockingHashMapLong<TestKey> nbhml = new NonBlockingHashMapLong<>();
@Test public final void testNonBlockingHashMapSize() NonBlockingHashMapLong<String> items = new NonBlockingHashMapLong<>(); items.put(100L, "100"); items.put(101L, "101");
NonBlockingHashMapLong<Object> map = new NonBlockingHashMapLong<Object>(32); for (int i = 1; i < 32; i++)