@Test public void testHashCodeError() { verifyHash(HttpResponse.error(), 1, "qgeopmcf02p09qc016cepu22fo"); }
@Test public void testHashCodeError() { verifyHash(HttpResponse.error(), 1, "qgeopmcf02p09qc016cepu22fo"); }
@Test(expected=GadgetException.class) public void badResponsePropagatesException() throws Exception { HttpResponse badResponse = HttpResponse.error(); expect(pipeline.execute(isA(HttpRequest.class))) .andReturn(badResponse).once(); replay(pipeline); bundleFactory.getBundle(gadgetSpec, LOCALE, false, ContainerConfig.DEFAULT_CONTAINER, null); }
@Test(expected = GadgetException.class) public void badFetchThrows() throws Exception { HttpRequest request = createIgnoreCacheRequest(); expect(pipeline.execute(request)).andReturn(HttpResponse.error()); replay(pipeline); specFactory.getGadgetSpec(createContext(SPEC_URL, true)); }
@Test(expected=GadgetException.class) public void badResponsePropagatesException() throws Exception { HttpResponse badResponse = HttpResponse.error(); expect(pipeline.execute(isA(HttpRequest.class))) .andReturn(badResponse).once(); replay(pipeline); bundleFactory.getBundle(gadgetSpec, LOCALE, false, ContainerConfig.DEFAULT_CONTAINER); }
@Test(expected = GadgetException.class) public void badFetchThrows() throws Exception { HttpRequest request = createIgnoreCacheRequest(); expect(pipeline.execute(request)).andReturn(HttpResponse.error()); replay(pipeline); specFactory.getGadgetSpec(createContext(SPEC_URL, true)); }
@Test(expected=GadgetException.class) public void badResponsePropagatesException() throws Exception { HttpResponse badResponse = HttpResponse.error(); expect(pipeline.execute(isA(HttpRequest.class))) .andReturn(badResponse).once(); replay(pipeline); bundleFactory.getBundle(gadgetSpec, LOCALE, false, ContainerConfig.DEFAULT_CONTAINER, null); }
@Test(expected = GadgetException.class) public void badFetchThrows() throws Exception { HttpRequest request = createIgnoreCacheRequest(); expect(pipeline.execute(request)).andReturn(HttpResponse.error()); replay(pipeline); specFactory.getGadgetSpec(createContext(SPEC_URL, true)); }
@Test public void testServeInvalidatedContentWithFetcherError() throws Exception { oauth.httpResponse = CACHEABLE; HttpResponse httpResponse = requestPipeline.execute(signedRequest); // Invalidate by owner service.invalidateUserResources(ImmutableSet.of("OwnerX"), appxToken); // Next request returns error oauth.httpResponse = HttpResponse.error(); httpResponse = requestPipeline.execute(signedRequest); assertEquals(CACHEABLE, httpResponse); } }
@Test public void testServeInvalidatedContentWithFetcherError() throws Exception { oauth.httpResponse = CACHEABLE; HttpResponse httpResponse = requestPipeline.execute(signedRequest); // Invalidate by owner service.invalidateUserResources(ImmutableSet.of("OwnerX"), appxToken); // Next request returns error oauth.httpResponse = HttpResponse.error(); httpResponse = requestPipeline.execute(signedRequest); assertEquals(CACHEABLE, httpResponse); } }
@Test public void testServeInvalidatedContentWithFetcherError() throws Exception { oauth.httpResponse = CACHEABLE; HttpResponse httpResponse = requestPipeline.execute(signedRequest); // Invalidate by owner service.invalidateUserResources(ImmutableSet.of("OwnerX"), appxToken); // Next request returns error oauth.httpResponse = HttpResponse.error(); httpResponse = requestPipeline.execute(signedRequest); assertEquals(CACHEABLE, httpResponse); } }
@Test public void testBadHttpResponseIsPropagated() throws Exception { HttpRequest internalRequest = new HttpRequest(REQUEST_URL); expect(pipeline.execute(internalRequest)).andReturn(HttpResponse.error()); replay(); handler.fetch(request, recorder); JSONObject results = extractJsonFromResponse(); assertEquals(HttpResponse.SC_INTERNAL_SERVER_ERROR, results.getInt("rc")); assertTrue(rewriter.responseWasRewritten()); }
@Test public void testBadHttpResponseIsPropagated() throws Exception { HttpRequest internalRequest = new HttpRequest(REQUEST_URL); expect(pipeline.execute(internalRequest)).andReturn(HttpResponse.error()); replay(); handler.fetch(request, recorder); JSONObject results = extractJsonFromResponse(); assertEquals(HttpResponse.SC_INTERNAL_SERVER_ERROR, results.getInt("rc")); assertTrue(rewriter.responseWasRewritten()); }
@Test public void testBadHttpResponseIsPropagated() throws Exception { HttpRequest internalRequest = new HttpRequest(REQUEST_URL); expect(pipeline.execute(internalRequest)).andReturn(HttpResponse.error()); replay(); handler.fetch(request, recorder); JSONObject results = extractJsonFromResponse(); assertEquals(HttpResponse.SC_INTERNAL_SERVER_ERROR, results.getInt("rc")); assertTrue(rewriter.responseWasRewritten()); }
@Test public void authTypeNoneStaleConditionalGetNoLastModified() throws Exception { // Cached response is stale and has no Last-Modified header on it. Test that an // If-Modified-Since header is not issued. HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.NONE); HttpResponse cached = new HttpResponseBuilder() .setCacheTtl(-1) .create(); cache.data.put(DEFAULT_URI, cached); fetcher.response = HttpResponse.error(); // Really don't care what this is. pipeline.execute(request); assertEquals(null, fetcher.request.getHeader(HttpHeaders.IF_MODIFIED_SINCE)); }
@Test public void testNegativeCaching() { assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.error().getCacheExpiration() > timeSource.currentTimeMillis()); assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.notFound().getCacheExpiration() > timeSource.currentTimeMillis()); assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.timeout().getCacheExpiration() > timeSource.currentTimeMillis()); long ttl = HttpResponse.error().getCacheTtl(); assertTrue(ttl <= HttpResponse.DEFAULT_TTL && ttl > 0); }
@Test public void testNegativeCaching() { assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.error().getCacheExpiration() > timeSource.currentTimeMillis()); assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.notFound().getCacheExpiration() > timeSource.currentTimeMillis()); assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.timeout().getCacheExpiration() > timeSource.currentTimeMillis()); long ttl = HttpResponse.error().getCacheTtl(); assertTrue(ttl <= HttpResponse.DEFAULT_TTL && ttl > 0); }
@Test public void testNegativeCaching() { assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.error().getCacheExpiration() > timeSource.currentTimeMillis()); assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.notFound().getCacheExpiration() > timeSource.currentTimeMillis()); assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.timeout().getCacheExpiration() > timeSource.currentTimeMillis()); long ttl = HttpResponse.error().getCacheTtl(); assertTrue(ttl <= HttpResponse.DEFAULT_TTL && ttl > 0); }
@Test public void authTypeNoneStaleCachedServed() throws Exception { HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.NONE); HttpResponse cached = new HttpResponseBuilder().setCacheTtl(-1).create(); cache.data.put(DEFAULT_URI, cached); fetcher.response = HttpResponse.error(); HttpResponse response = pipeline.execute(request); assertEquals(cached, response); // cached item is served instead of 500 assertEquals(request, fetcher.request); assertEquals(1, cache.readCount); assertEquals(0, cache.writeCount); assertEquals(1, fetcher.fetchCount); }
@Test public void authTypeNoneStaleCachedServed() throws Exception { HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.NONE); HttpResponse cached = new HttpResponseBuilder().setCacheTtl(-1).create(); cache.data.put(DEFAULT_URI, cached); fetcher.response = HttpResponse.error(); HttpResponse response = pipeline.execute(request); assertEquals(cached, response); // cached item is served instead of 500 assertEquals(request, fetcher.request); assertEquals(1, cache.readCount); assertEquals(0, cache.writeCount); assertEquals(1, fetcher.fetchCount); }