use of com.google.gerrit.httpd.raw.ResourceServlet.Resource in project gerrit by GerritCodeReview.
the class ResourceServletTest method notFoundWithRefresh.
@Test
public void notFoundWithRefresh() throws Exception {
Cache<Path, Resource> cache = newCache(1);
Servlet servlet = new Servlet(fs, cache, true);
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.httpd.raw.ResourceServlet.Resource in project gerrit by GerritCodeReview.
the class ResourceServletTest method verySmallFileDoesntBotherWithGzip.
@Test
public void verySmallFileDoesntBotherWithGzip() throws Exception {
Cache<Path, Resource> cache = newCache(1);
Servlet servlet = new Servlet(fs, cache, true);
writeFile("/foo", "foo1");
FakeHttpServletRequest req = request("/foo").addHeader("Accept-Encoding", "gzip");
FakeHttpServletResponse res = new FakeHttpServletResponse();
servlet.doGet(req, res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getHeader("Content-Encoding")).isNull();
assertThat(res.getActualBodyString()).isEqualTo("foo1");
assertHasETag(res);
assertCacheable(res, true);
}
use of com.google.gerrit.httpd.raw.ResourceServlet.Resource in project gerrit by GerritCodeReview.
the class ResourceServletTest method smallFileWithGzip.
@Test
public void smallFileWithGzip() throws Exception {
Cache<Path, Resource> cache = newCache(1);
Servlet servlet = new Servlet(fs, cache, true);
String content = Strings.repeat("a", 100);
writeFile("/foo", content);
FakeHttpServletRequest req = request("/foo").addHeader("Accept-Encoding", "gzip");
FakeHttpServletResponse res = new FakeHttpServletResponse();
servlet.doGet(req, res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getHeader("Content-Encoding")).isEqualTo("gzip");
assertThat(gunzip(res.getActualBody())).isEqualTo(content);
assertHasETag(res);
assertCacheable(res, true);
}
use of com.google.gerrit.httpd.raw.ResourceServlet.Resource in project gerrit by GerritCodeReview.
the class ResourceServletTest method smallFileWithoutClientCache.
@Test
public void smallFileWithoutClientCache() throws Exception {
Cache<Path, Resource> cache = newCache(1);
Servlet servlet = new Servlet(fs, cache, false, false);
writeFile("/foo", "foo1");
FakeHttpServletResponse res = new FakeHttpServletResponse();
servlet.doGet(request("/foo"), res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getActualBodyString()).isEqualTo("foo1");
assertNotCacheable(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");
assertNotCacheable(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");
assertNotCacheable(res);
assertCacheHits(cache, 2, 2);
}
use of com.google.gerrit.httpd.raw.ResourceServlet.Resource in project gerrit by GerritCodeReview.
the class ResourceServletTest method smallFileWithRefresh.
@Test
public void smallFileWithRefresh() throws Exception {
Cache<Path, Resource> cache = newCache(1);
Servlet servlet = new Servlet(fs, cache, true);
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, true);
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, true);
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("foo2");
assertCacheable(res, true);
assertHasETag(res);
// Hit, invalidate, miss.
assertCacheHits(cache, 2, 3);
}
Aggregations