use of com.google.gerrit.util.http.testutil.FakeHttpServletResponse in project gerrit by GerritCodeReview.
the class ResourceServletTest method largeFileBypassesCacheRegardlessOfRefreshParamter.
@Test
public void largeFileBypassesCacheRegardlessOfRefreshParamter() throws Exception {
for (boolean refresh : Lists.newArrayList(true, false)) {
Cache<Path, Resource> cache = newCache(1);
Servlet servlet = new Servlet(fs, cache, refresh, 3);
writeFile("/foo", "foo1");
FakeHttpServletResponse res = new FakeHttpServletResponse();
servlet.doGet(request("/foo"), res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getActualBodyString()).isEqualTo("foo1");
assertThat(res.getHeader("Last-Modified")).isNotNull();
assertCacheable(res, refresh);
assertHasLastModified(res);
assertCacheHits(cache, 0, 1);
writeFile("/foo", "foo1");
res = new FakeHttpServletResponse();
servlet.doGet(request("/foo"), res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getActualBodyString()).isEqualTo("foo1");
assertThat(res.getHeader("Last-Modified")).isNotNull();
assertCacheable(res, refresh);
assertHasLastModified(res);
assertCacheHits(cache, 0, 2);
writeFile("/foo", "foo2");
res = new FakeHttpServletResponse();
servlet.doGet(request("/foo"), res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getActualBodyString()).isEqualTo("foo2");
assertThat(res.getHeader("Last-Modified")).isNotNull();
assertCacheable(res, refresh);
assertHasLastModified(res);
assertCacheHits(cache, 0, 3);
}
}
use of com.google.gerrit.util.http.testutil.FakeHttpServletResponse in project gerrit by GerritCodeReview.
the class ResourceServletTest method notFoundWithoutRefresh.
@Test
public void notFoundWithoutRefresh() throws Exception {
Cache<Path, Resource> cache = newCache(1);
Servlet servlet = new Servlet(fs, cache, false);
FakeHttpServletResponse res = new FakeHttpServletResponse();
servlet.doGet(request("/notfound"), res);
assertThat(res.getStatus()).isEqualTo(SC_NOT_FOUND);
assertNotCacheable(res);
assertCacheHits(cache, 0, 1);
res = new FakeHttpServletResponse();
servlet.doGet(request("/notfound"), res);
assertThat(res.getStatus()).isEqualTo(SC_NOT_FOUND);
assertNotCacheable(res);
assertCacheHits(cache, 1, 1);
}
use of com.google.gerrit.util.http.testutil.FakeHttpServletResponse in project gerrit by GerritCodeReview.
the class ResourceServletTest method smallFileWithoutRefresh.
@Test
public void smallFileWithoutRefresh() throws Exception {
Cache<Path, Resource> cache = newCache(1);
Servlet servlet = new Servlet(fs, cache, false);
writeFile("/foo", "foo1");
FakeHttpServletResponse res = new FakeHttpServletResponse();
servlet.doGet(request("/foo"), res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getActualBodyString()).isEqualTo("foo1");
assertCacheable(res, false);
assertHasETag(res);
// Miss on getIfPresent, miss on get.
assertCacheHits(cache, 0, 2);
res = new FakeHttpServletResponse();
servlet.doGet(request("/foo"), res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getActualBodyString()).isEqualTo("foo1");
assertCacheable(res, false);
assertHasETag(res);
assertCacheHits(cache, 1, 2);
writeFile("/foo", "foo2");
res = new FakeHttpServletResponse();
servlet.doGet(request("/foo"), res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getActualBodyString()).isEqualTo("foo1");
assertCacheable(res, false);
assertHasETag(res);
assertCacheHits(cache, 2, 2);
}
Aggregations