@Test void getResponseReturnsEmptyOptionalIfPrimingDoesNotExistForAppRequest() throws Exception { final Optional<AppResponse> got = primingContext.getResponse(zombiePriming.getRequest()); assertThat(got.isPresent()).isFalse(); }
synchronized public Optional<AppResponse> getResponse(AppRequest appRequest) { final HeaderlessAppRequest headerlessAppRequest = new HeaderlessAppRequest(appRequest); final Optional<MapAppRequestAndQueue> mapAppRequestAndQueue = findMapAndQueue(appRequest); if (!mapAppRequestAndQueue.isPresent()) return empty(); return mapAppRequestAndQueue.map(m -> { final DefaultingQueue responseQueue = m.getQueue(); final Map<AppRequest, DefaultingQueue> mapping = m.getMap(); final AppResponse appResponse = responseQueue.poll(); if(responseQueue.hasSize() == 0 && !responseQueue.getDefault().isPresent()) mapping.remove(m.getAppRequest()); if(mapping.isEmpty()) primedMappings.remove(headerlessAppRequest); return appResponse; }); }
PrimingContext { synchronized public Optional<AppResponse> getResponse(AppRequest appRequest) { final HeaderlessAppRequest headerlessAppRequest = new HeaderlessAppRequest(appRequest); final Optional<MapAppRequestAndQueue> mapAppRequestAndQueue = findMapAndQueue(appRequest); if (!mapAppRequestAndQueue.isPresent()) return empty(); return mapAppRequestAndQueue.map(m -> { final DefaultingQueue responseQueue = m.getQueue(); final Map<AppRequest, DefaultingQueue> mapping = m.getMap(); final AppResponse appResponse = responseQueue.poll(); if(responseQueue.hasSize() == 0 && !responseQueue.getDefault().isPresent()) mapping.remove(m.getAppRequest()); if(mapping.isEmpty()) primedMappings.remove(headerlessAppRequest); return appResponse; }); } }
PrimingContext { synchronized public Optional<AppResponse> getResponse(AppRequest appRequest) { final HeaderlessAppRequest headerlessAppRequest = new HeaderlessAppRequest(appRequest); final Optional<MapAppRequestAndQueue> mapAppRequestAndQueue = findMapAndQueue(appRequest); if (!mapAppRequestAndQueue.isPresent()) return empty(); return mapAppRequestAndQueue.map(m -> { final DefaultingQueue responseQueue = m.getQueue(); final Map<AppRequest, DefaultingQueue> mapping = m.getMap(); final AppResponse appResponse = responseQueue.poll(); if(responseQueue.hasSize() == 0 && !responseQueue.getDefault().isPresent()) mapping.remove(m.getAppRequest()); if(mapping.isEmpty()) primedMappings.remove(headerlessAppRequest); return appResponse; }); } PrimingContext(List<Priming> priming);  PrimingContext(); }
PrimingContext { synchronized public Optional<AppResponse> getResponse(AppRequest appRequest) { final HeaderlessAppRequest headerlessAppRequest = new HeaderlessAppRequest(appRequest); final Optional<MapAppRequestAndQueue> mapAppRequestAndQueue = findMapAndQueue(appRequest); if (!mapAppRequestAndQueue.isPresent()) return empty(); return mapAppRequestAndQueue.map(m -> { final DefaultingQueue responseQueue = m.getQueue(); final Map<AppRequest, DefaultingQueue> mapping = m.getMap(); final AppResponse appResponse = responseQueue.poll(); if(responseQueue.hasSize() == 0 && !responseQueue.getDefault().isPresent()) mapping.remove(m.getAppRequest()); if(mapping.isEmpty()) primedMappings.remove(headerlessAppRequest); return appResponse; }); } PrimingContext(List<Priming> priming);  PrimingContext(); synchronized List<PrimedMapping> getCurrentPriming(); PrimingContext add(ZombiePriming zombiePriming); synchronized PrimingContext add(AppRequest appRequest, AppResponse appResponse); synchronized PrimingContext addDefault(AppRequest appRequest, DefaultAppResponse defaultAppResponse); synchronized Optional<AppResponse> getResponse(AppRequest appRequest); synchronized void reset(); }
PrimingContext { synchronized public Optional<AppResponse> getResponse(AppRequest appRequest) { final HeaderlessAppRequest headerlessAppRequest = new HeaderlessAppRequest(appRequest); final Optional<MapAppRequestAndQueue> mapAppRequestAndQueue = findMapAndQueue(appRequest); if (!mapAppRequestAndQueue.isPresent()) return empty(); return mapAppRequestAndQueue.map(m -> { final DefaultingQueue responseQueue = m.getQueue(); final Map<AppRequest, DefaultingQueue> mapping = m.getMap(); final AppResponse appResponse = responseQueue.poll(); if(responseQueue.hasSize() == 0 && !responseQueue.getDefault().isPresent()) mapping.remove(m.getAppRequest()); if(mapping.isEmpty()) primedMappings.remove(headerlessAppRequest); return appResponse; }); } PrimingContext(List<Priming> priming);  PrimingContext(); synchronized List<PrimedMapping> getCurrentPriming(); PrimingContext add(ZombiePriming zombiePriming); synchronized PrimingContext add(AppRequest appRequest, AppResponse appResponse); synchronized PrimingContext addDefault(AppRequest appRequest, DefaultAppResponse defaultAppResponse); synchronized Optional<AppResponse> getResponse(AppRequest appRequest); synchronized void reset();  }