LayerBuilder { protected List<ModuleBuildFuture> collectFutures(ModuleList moduleList, HttpServletRequest request) throws IOException { final String sourceMethod = "collectFutures"; final boolean isTraceLogging = log.isLoggable(Level.FINER); if (isTraceLogging) { log.entering(sourceClass, sourceMethod, new Object[]{moduleList, request}); } IAggregator aggr = (IAggregator)request.getAttribute(IAggregator.AGGREGATOR_REQATTRNAME); List<ModuleBuildFuture> futures = new ArrayList<ModuleBuildFuture>(); IModuleCache moduleCache = aggr.getCacheManager().getCache().getModules(); for(ModuleList.ModuleListEntry moduleListEntry : moduleList) { IModule module = moduleListEntry.getModule(); Future<ModuleBuildReader> future = null; try { future = moduleCache.getBuild(request, module); } catch (NotFoundException e) { if (log.isLoggable(Level.FINER)) { log.logp(Level.FINER, sourceClass, sourceMethod, moduleListEntry.getModule().getModuleId() + " not found."); } future = new NotFoundModule(module.getModuleId(), module.getURI()).getBuild(request); if (!moduleListEntry.isServerExpanded()) { if (options.isDevelopmentMode() || options.isDebugMode()) { request.setAttribute(ILayer.NOCACHE_RESPONSE_REQATTRNAME, Boolean.TRUE); } else { throw e; } } else { if (options.isDevelopmentMode() || options.isDebugMode()) { try { nonErrorMessages.add(future.get().getErrorMessage()); } catch (Exception ex) { throw new RuntimeException(ex); } } if (isTraceLogging) { log.logp(Level.FINER, sourceClass, sourceMethod, "Ignoring exception for server expanded module " + e.getMessage(), e); } continue; } } catch (UnsupportedOperationException ex) { if (moduleListEntry.isServerExpanded()) { if (isTraceLogging) { log.logp(Level.FINER, sourceClass, sourceMethod, "Ignoring exception for server expanded module " + ex.getMessage(), ex); } continue; } else { throw ex; } } futures.add(new ModuleBuildFuture( module, future, moduleListEntry.getSource() )); } if (isTraceLogging) { log.exiting(sourceClass, sourceMethod, futures); } return futures; } LayerBuilder(HttpServletRequest request, List<ICacheKeyGenerator> keyGens,
			ModuleList moduleList);   }
@Test public void testCollectFutures() throws Exception { IAggregator mockAggregator = TestUtils.createMockAggregator(); HttpServletRequest mockRequest = TestUtils.createMockRequest(mockAggregator); ICache mockCache = createMock(ICache.class); IModuleCache mockModuleCache = createMock(IModuleCache.class); expect(mockCache.getModules()).andReturn(mockModuleCache).anyTimes(); expect(mockModuleCache.getBuild(eq(mockRequest), isA(IModule.class))).andAnswer(new IAnswer<Future<ModuleBuildReader>>() { @Override public Future<ModuleBuildReader> answer() throws Throwable { IModule module = (IModule)getCurrentArguments()[1]; if (module.getModuleName().equals("notfound")) { throw new NotFoundException(module.getModuleName()); } return new CompletedFuture<ModuleBuildReader>( new ModuleBuildReader(new StringReader(module.getModuleId() + " build"), true) ); } }).anyTimes(); replay(mockAggregator, mockRequest, mockCache, mockModuleCache); ((TestCacheManager)mockAggregator.getCacheManager()).setCache(mockCache); ModuleList moduleList = new ModuleList(); IModule module1 = new ModuleImpl("module1", new URI("file: module2 = new ModuleImpl("module2", new URI("file: notfound = new ModuleImpl("notfound", new URI("file: moduleList.add(new ModuleListEntry(module1, ModuleSpecifier.MODULES, true)); moduleList.add(new ModuleListEntry(module2, ModuleSpecifier.LAYER, true)); moduleList.add(new ModuleListEntry(notfound, ModuleSpecifier.LAYER, true )); LayerBuilder builder = new LayerBuilder(mockRequest, null, moduleList); List<ModuleBuildFuture> futures = builder.collectFutures(moduleList, mockRequest); Assert.assertEquals(2, futures.size()); ModuleBuildFuture future = futures.get(0); Assert.assertEquals("module1", future.getModule().getModuleId()); Assert.assertEquals(ModuleSpecifier.MODULES, future.getModuleSpecifier()); Assert.assertEquals("module1 build", toString(future.get())); future = futures.get(1); Assert.assertEquals("module2", future.getModule().getModuleId()); Assert.assertEquals(ModuleSpecifier.LAYER, future.getModuleSpecifier()); Assert.assertEquals("module2 build", toString(future.get())); moduleList = new ModuleList(); moduleList.add(new ModuleListEntry(module1, ModuleSpecifier.LAYER, true)); moduleList.add(new ModuleListEntry(module2, ModuleSpecifier.LAYER, true)); moduleList.add(new ModuleListEntry(notfound, ModuleSpecifier.MODULES, false )); builder = new LayerBuilder(mockRequest, null, moduleList); boolean exceptionCaught = false; try { builder.collectFutures(moduleList, mockRequest); } catch (NotFoundException e) { exceptionCaught = true; } Assert.assertTrue(exceptionCaught); }