@Test public void testAddAndGetTile() throws InterruptedException, FileNotFoundException, IOException { // Input stream to use ImageInputStream stream_in = null; try { stream_in = new FileImageInputStream(TestData.file(this, "world.tiff")); // Input RenderedImage to use final RenderedOp input = ImageReadDescriptor.create( stream_in, 0, false, false, false, null, null, null, null, null); // Boolean used for checking if the conditions are passed final AtomicBoolean passed = new AtomicBoolean(true); // Cache creation final ConcurrentTileCacheMultiMap cache = new ConcurrentTileCacheMultiMap(1000 * 1000, false, 1f, 4); // Selection of one tile from the image Raster data = input.getTile(input.getMinTileX(), input.getMinTileY()); // Setting the tile inside the cache cache.add(input, input.getMinTileX(), input.getMinTileY(), data); // Thread pool to use for doing concurrent access on the cache ThreadPoolExecutor executor = new ThreadPoolExecutor( TOTAL, TOTAL, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1000000)); // Latch used for waiting all the threads to end their work final CountDownLatch latch = new CountDownLatch(TOTAL); // Cycle for launching various requests int counter = TOTAL; while (counter > 0) { executor.execute( new Runnable() { public void run() { // Get the tile to use Raster data = cache.getTile(input, input.getMinTileX(), input.getMinTileY()); if (data == null) { passed.getAndSet(false); } latch.countDown(); } }); // Counter update counter--; } // Waiting all threads to finish latch.await(); // Ensure that all the threads have found the tile Assert.assertTrue(passed.get()); } finally { try { if (stream_in != null) { stream_in.flush(); stream_in.close(); } } catch (Throwable t) { // } } }