Application implements ModelResult { public ConfigResponse resolveConfig(GetConfigRequest req, ConfigResponseFactory responseFactory) { long start = System.currentTimeMillis(); metricUpdater.incrementRequests(); ConfigKey<?> configKey = req.getConfigKey(); String defMd5 = configKey.getMd5(); if (defMd5 == null || defMd5.isEmpty()) { defMd5 = ConfigUtils.getDefMd5(req.getDefContent().asList()); } ConfigCacheKey cacheKey = new ConfigCacheKey(configKey, defMd5); if (logDebug()) { debug("Resolving config " + cacheKey); } if (useCache(req)) { ConfigResponse config = cache.get(cacheKey); if (config != null) { if (logDebug()) { debug("Found config " + cacheKey + " in cache"); } metricUpdater.incrementProcTime(System.currentTimeMillis() - start); return config; } } ConfigDefinition def = getTargetDef(req); if (def == null) { metricUpdater.incrementFailedRequests(); throw new UnknownConfigDefinitionException("Unable to find config definition for '" + configKey.getNamespace() + "." + configKey.getName()); } if (logDebug()) { debug("Resolving " + configKey + " with config definition " + def); } ConfigPayload payload = model.getConfig(configKey, def); if (payload == null) { metricUpdater.incrementFailedRequests(); throw new ConfigurationRuntimeException("Unable to resolve config " + configKey); } ConfigResponse configResponse = responseFactory.createResponse(payload, applicationGeneration, internalRedeploy); metricUpdater.incrementProcTime(System.currentTimeMillis() - start); if (useCache(req)) { cache.put(cacheKey, configResponse, configResponse.getConfigMd5()); metricUpdater.setCacheConfigElems(cache.configElems()); metricUpdater.setCacheChecksumElems(cache.checkSumElems()); } return configResponse; } Application(Model model, ServerCache cache, long applicationGeneration, boolean internalRedeploy,
                       Version vespaVersion, MetricUpdater metricUpdater, ApplicationId app); Long getApplicationGeneration(); @Override Model getModel(); @Override String toString(); ApplicationInfo toApplicationInfo(); ServerCache getCache(); ApplicationId getId(); Version getVespaVersion(); ConfigResponse resolveConfig(GetConfigRequest req, ConfigResponseFactory responseFactory); Set<ConfigKey<?>> allConfigsProduced(); Set<String> allConfigIds();  }
@Test(expected = UnknownConfigDefinitionException.class) public void require_that_def_file_must_exist() { handler.resolveConfig(createRequest("unknown", "namespace", "a", emptySchema)); }
@Test public void require_that_known_config_defs_are_found() { handler.resolveConfig(createSimpleConfigRequest()); }
@Test public void require_that_configs_are_cached() { ConfigResponse response = handler.resolveConfig(createRequest(ModelConfig.CONFIG_DEF_NAME, ModelConfig.CONFIG_DEF_NAMESPACE, ModelConfig.CONFIG_DEF_MD5, ModelConfig.CONFIG_DEF_SCHEMA)); assertNotNull(response); ConfigResponse cached_response = handler.resolveConfig(createRequest(ModelConfig.CONFIG_DEF_NAME, ModelConfig.CONFIG_DEF_NAMESPACE, ModelConfig.CONFIG_DEF_MD5, ModelConfig.CONFIG_DEF_SCHEMA)); assertNotNull(cached_response); assertTrue(response == cached_response); }