/** * Handles cancellation of leases for this particular instance. * * @param isReplication * a header parameter containing information whether this is * replicated from other nodes. * @return response indicating whether the operation was a success or * failure. */ @DELETE public Response cancelLease( @HeaderParam(PeerEurekaNode.HEADER_REPLICATION) String isReplication) { try { boolean isSuccess = registry.cancel(app.getName(), id, "true".equals(isReplication)); if (isSuccess) { logger.debug("Found (Cancel): {} - {}", app.getName(), id); return Response.ok().build(); } else { logger.info("Not Found (Cancel): {} - {}", app.getName(), id); return Response.status(Status.NOT_FOUND).build(); } } catch (Throwable e) { logger.error("Error (cancel): {} - {}", app.getName(), id, e); return Response.serverError().build(); } }
@Test public void testInvalidateWithRemoteRegion() throws Exception { ResponseCacheImpl cache = (ResponseCacheImpl) testRegistry.getResponseCache(); Key key = new Key( Key.EntityType.Application, REMOTE_REGION_APP_NAME, Key.KeyType.JSON, Version.V1, EurekaAccept.full, new String[]{REMOTE_REGION} ); Assert.assertNotNull("Cache get returned null.", cache.get(key, false)); testRegistry.cancel(REMOTE_REGION_APP_NAME, REMOTE_REGION_INSTANCE_1_HOSTNAME, true); Assert.assertNull("Cache after invalidate did not return null.", cache.get(key)); }
@Test public void testInvalidate() throws Exception { ResponseCacheImpl cache = (ResponseCacheImpl) testRegistry.getResponseCache(); Key key = new Key(Key.EntityType.Application, REMOTE_REGION_APP_NAME, Key.KeyType.JSON, Version.V1, EurekaAccept.full); String response = cache.get(key, false); Assert.assertNotNull("Cache get returned null.", response); testRegistry.cancel(REMOTE_REGION_APP_NAME, REMOTE_REGION_INSTANCE_1_HOSTNAME, true); Assert.assertNull("Cache after invalidate did not return null for write view.", cache.get(key, true)); }
@Test public void testInvalidateWithMultipleRemoteRegions() throws Exception { ResponseCacheImpl cache = (ResponseCacheImpl) testRegistry.getResponseCache(); Key key1 = new Key( Key.EntityType.Application, REMOTE_REGION_APP_NAME, Key.KeyType.JSON, Version.V1, EurekaAccept.full, new String[]{REMOTE_REGION, "myregion2"} ); Key key2 = new Key( Key.EntityType.Application, REMOTE_REGION_APP_NAME, Key.KeyType.JSON, Version.V1, EurekaAccept.full, new String[]{REMOTE_REGION} ); Assert.assertNotNull("Cache get returned null.", cache.get(key1, false)); Assert.assertNotNull("Cache get returned null.", cache.get(key2, false)); testRegistry.cancel(REMOTE_REGION_APP_NAME, REMOTE_REGION_INSTANCE_1_HOSTNAME, true); Assert.assertNull("Cache after invalidate did not return null.", cache.get(key1, true)); Assert.assertNull("Cache after invalidate did not return null.", cache.get(key2, true)); } }
/** * Handles cancellation of leases for this particular instance. * * @param isReplication * a header parameter containing information whether this is * replicated from other nodes. * @return response indicating whether the operation was a success or * failure. */ @DELETE public Response cancelLease( @HeaderParam(PeerEurekaNode.HEADER_REPLICATION) String isReplication) { try { boolean isSuccess = registry.cancel(app.getName(), id, "true".equals(isReplication)); if (isSuccess) { logger.debug("Found (Cancel): {} - {}", app.getName(), id); return Response.ok().build(); } else { logger.info("Not Found (Cancel): {} - {}", app.getName(), id); return Response.status(Status.NOT_FOUND).build(); } } catch (Throwable e) { logger.error("Error (cancel): {} - {}", app.getName(), id, e); return Response.serverError().build(); } }