use of org.jsr166.ConcurrentLinkedHashMap in project ignite by apache.
the class TaskCommandHandlerSelfTest method testManyTasksRun.
/**
* @throws Exception If failed.
*/
public void testManyTasksRun() throws Exception {
GridClientCompute compute = client.compute();
for (int i = 0; i < 1000; i++) assertEquals(new Integer("executing".length()), compute.execute(TestTask.class.getName(), "executing"));
GridClientFactory.stop(client.id(), true);
IgniteKernal g = (IgniteKernal) grid(0);
Map<GridRestCommand, GridRestCommandHandler> handlers = U.field(g.context().rest(), "handlers");
GridTaskCommandHandler taskHnd = (GridTaskCommandHandler) F.find(handlers.values(), null, new P1<GridRestCommandHandler>() {
@Override
public boolean apply(GridRestCommandHandler e) {
return e instanceof GridTaskCommandHandler;
}
});
assertNotNull("GridTaskCommandHandler was not found", taskHnd);
ConcurrentLinkedHashMap taskDesc = U.field(taskHnd, "taskDescs");
assertTrue("Task result map size exceeded max value [mapSize=" + taskDesc.sizex() + ", " + "maxSize=" + MAX_TASK_RESULTS + ']', taskDesc.sizex() <= MAX_TASK_RESULTS);
}
use of org.jsr166.ConcurrentLinkedHashMap in project ignite by apache.
the class GridConcurrentLinkedHashMapMultiThreadedSelfTest method testInsertOrderIterator.
/**
* @throws Exception If failed.
*/
public void testInsertOrderIterator() throws Exception {
final AtomicBoolean run = new AtomicBoolean(true);
info(">>> Test grid concurrent linked hash map iterator...");
final Map<Integer, String> linkedMap = new ConcurrentLinkedHashMap<>();
Set<Integer> original = new HashSet<>();
final int keyCnt = 10000;
for (int i = 0; i < keyCnt; i++) {
linkedMap.put(i, "value" + i);
original.add(i);
}
long start = System.currentTimeMillis();
// Updater threads.
IgniteInternalFuture<?> fut = multithreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
Random rnd = new Random();
while (run.get()) {
int key = rnd.nextInt(keyCnt);
linkedMap.put(key, "value" + key);
}
return null;
}
}, 10, "updater");
try {
// Check that iterator always contains all the values.
int iterCnt = 10000;
for (int i = 0; i < iterCnt; i++) {
Collection<Integer> cp = new HashSet<>(original);
cp.removeAll(linkedMap.keySet());
assertTrue("Keys disappeared from map: " + cp, cp.isEmpty());
}
info(">>> Iterator test complete [duration = " + (System.currentTimeMillis() - start) + ']');
} finally {
run.set(false);
fut.get();
}
}
use of org.jsr166.ConcurrentLinkedHashMap in project ignite by apache.
the class GridCacheWriteBehindStoreSelfTest method testBatchApply.
/**
* Tests that all values will be written to the underlying store
* right in the same order as they were put into the store.
*
* @param writeCoalescing Write coalescing flag.
* @throws Exception If failed.
*/
private void testBatchApply(boolean writeCoalescing) throws Exception {
delegate = new GridCacheTestStore(new ConcurrentLinkedHashMap<Integer, String>());
initStore(1, writeCoalescing);
List<Integer> intList = new ArrayList<>(CACHE_SIZE);
try {
for (int i = 0; i < CACHE_SIZE; i++) {
store.write(new CacheEntryImpl<>(i, "val" + i));
intList.add(i);
}
} finally {
shutdownStore();
}
Map<Integer, String> underlyingMap = delegate.getMap();
assertTrue("Store map key set: " + underlyingMap.keySet(), F.eqOrdered(underlyingMap.keySet(), intList));
}
use of org.jsr166.ConcurrentLinkedHashMap in project ignite by apache.
the class GridConcurrentLinkedHashMapBenchmark method test.
/**
* Test a generic access method on map.
*
* @param readOp Access method to test.
* @param threadCnt Number of threads to run.
* @param writeProportion Amount of writes from total number of iterations.
*/
@SuppressWarnings({ "BusyWait" })
private static void test(C2<Integer, ConcurrentLinkedHashMap<Integer, Integer>, Integer> readOp, int threadCnt, double writeProportion) {
assert writeProportion < 1;
ConcurrentLinkedHashMap<Integer, Integer> map = new ConcurrentLinkedHashMap<>();
CyclicBarrier barrier = new CyclicBarrier(threadCnt + 1);
Collection<TestThread> threads = new ArrayList<>(threadCnt);
for (int i = 0; i < threadCnt; i++) {
TestThread thread = new TestThread(readOp, map, writeProportion, barrier);
threads.add(thread);
thread.start();
}
long start;
try {
// Wait threads warm-up.
while (barrier.getNumberWaiting() != threadCnt) Thread.sleep(1);
// Starting test and letting it run for 1 minute.
barrier.await();
start = System.currentTimeMillis();
Thread.sleep(60000);
} catch (InterruptedException ignored) {
return;
} catch (BrokenBarrierException e) {
e.printStackTrace();
return;
}
for (TestThread th : threads) th.interrupt();
try {
for (TestThread th : threads) th.join();
} catch (InterruptedException ignored) {
return;
}
long time = System.currentTimeMillis() - start;
long iters = 0;
for (TestThread th : threads) iters += th.iterations();
System.out.printf("%8s, %8d, %12d, %12d, %12d, %8.3f, %8.2f\n", readOp.toString(), threadCnt, 1000 * iters / time, 1000 * iters / (time * threadCnt), iters, time / (double) 1000, writeProportion);
}
use of org.jsr166.ConcurrentLinkedHashMap in project ignite by apache.
the class GridConcurrentLinkedHashMapMultiThreadedSelfTest method testGetRemovePutIterator.
/**
* Test multithreaded operations in concurrent linked hash map and iterator consistency.
*
* @throws Exception If failed.
*/
public void testGetRemovePutIterator() throws Exception {
info(">>> Test grid concurrent linked hash map iterator...");
final ConcurrentLinkedHashMap<Integer, String> linkedMap = new ConcurrentLinkedHashMap<>();
Collection<Integer> original = new HashSet<>();
final int keyCnt = 10000;
for (int i = 0; i < keyCnt; i++) {
linkedMap.put(i, "value" + i);
original.add(i);
}
final AtomicBoolean run = new AtomicBoolean(true);
long start = System.currentTimeMillis();
// Updater threads.
IgniteInternalFuture<?> fut = multithreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
Random rnd = new Random();
while (run.get()) {
int key = rnd.nextInt(keyCnt);
linkedMap.get(key);
linkedMap.remove(key);
linkedMap.put(key, "value" + key);
}
info(">>> Exiting updater thread");
return null;
}
}, 10, "updater");
int iterCnt = 10000;
for (int i = 0; i < iterCnt; i++) {
Iterator<Integer> it = linkedMap.keySet().iterator();
Collection<Integer> keys = new HashSet<>();
// Since we have 10 running threads, iterator should show not less then keyCnt - 10 elements.
while (it.hasNext()) {
int key = it.next();
assertFalse("Duplicate key: " + key, keys.contains(key));
keys.add(key);
}
if (i % 500 == 0)
info(">>> Run " + i + " iterations in " + (System.currentTimeMillis() - start) + "ms");
}
info(">>> Stopping updater threads");
run.set(false);
fut.get();
info(">>> Updater threads stopped, will verify integrity of result map");
Set<Integer> keys = linkedMap.keySet();
original.removeAll(keys);
assertTrue("Keys must be in map: " + original, original.isEmpty());
info(">>> put get remove test complete [duration = " + (System.currentTimeMillis() - start) + ']');
}
Aggregations