@Test public void testFetchContentSignedOwner() throws Exception { oauth.httpResponse = CACHEABLE; signedRequest.getOAuthArguments().setSignViewer(false); HttpResponse httpResponse = requestPipeline.execute(signedRequest); assertEquals(CACHEABLE, httpResponse); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); // Invalidate by owner only service.invalidateUserResources(ImmutableSet.of("OwnerX"), appxToken); oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT1").create(); httpResponse = requestPipeline.execute(signedRequest); assertEquals("NEWCONTENT1", httpResponse.getResponseAsString()); assertEquals("o=1;", httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER)); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); // Invalidating viewer has no effect service.invalidateUserResources(ImmutableSet.of("ViewerX"), appxToken); oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT2").create(); httpResponse = requestPipeline.execute(signedRequest); assertEquals("NEWCONTENT1", httpResponse.getResponseAsString()); assertEquals("o=1;", httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER)); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); }
@Test public void testInvalidateUrl() throws Exception { cache.addResponse(new HttpRequest(URI), CACHEABLE); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); service.invalidateApplicationResources(ImmutableSet.of(URI), appxToken); assertEquals(0, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); }
@Test public void testFetchContentWithMarker() throws Exception { oauth.httpResponse = CACHEABLE; // First entry added to cache is unmarked HttpResponse httpResponse = requestPipeline.execute(signedRequest); assertEquals(CACHEABLE, httpResponse); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); // Invalidate content for OwnerX. Next entry will have owner mark service.invalidateUserResources(ImmutableSet.of("OwnerX"), appxToken); oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT1").create(); httpResponse = requestPipeline.execute(signedRequest); assertEquals("NEWCONTENT1", httpResponse.getResponseAsString()); assertEquals("o=1;", httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER)); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); // Invalidate content for ViewerX. Next entry will have both owner and viewer mark service.invalidateUserResources(ImmutableSet.of("ViewerX"), appxToken); oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT2").create(); httpResponse = requestPipeline.execute(signedRequest); assertEquals("NEWCONTENT2", httpResponse.getResponseAsString()); assertEquals( "o=1;v=2;", httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER)); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); }
@Test public void testInvalidateUsers() throws Exception { service.invalidateUserResources(ImmutableSet.of("example.org:1", "example.org:2"), appxToken); service.invalidateUserResources(ImmutableSet.of("example.org:1", "example.org:2"), appyToken); assertEquals(4, cacheProvider.createCache(DefaultInvalidationService.CACHE_NAME).getSize()); assertNotNull( cacheProvider .createCache(DefaultInvalidationService.CACHE_NAME) .getElement("INV_TOK:AppX:1")); assertNotNull( cacheProvider .createCache(DefaultInvalidationService.CACHE_NAME) .getElement("INV_TOK:AppX:2")); assertNotNull( cacheProvider .createCache(DefaultInvalidationService.CACHE_NAME) .getElement("INV_TOK:AppY:1")); assertNotNull( cacheProvider .createCache(DefaultInvalidationService.CACHE_NAME) .getElement("INV_TOK:AppY:2")); }