@Test void testEvictCacheService() { AuthenticationCommand command = AuthenticationCommand.EMPTY; Authentication auth = new Authentication(AuthenticationScheme.HTTP_BASIC_PASSTICKET, "applicationId0001"); doReturn(Collections.singletonList(createInstanceInfo("instance0001", auth))).when(discoveryClient).getInstancesById("service0001"); doReturn(Collections.singletonList(createInstanceInfo("instance0002", auth))).when(discoveryClient).getInstancesById("service0002"); doReturn(new ByPassScheme()).when(authenticationSchemeFactory).getSchema(auth.getScheme()); verify(discoveryClient, never()).getInstancesById("service0001"); verify(discoveryClient, never()).getInstancesById("service0002"); assertSame(command, serviceAuthenticationService.getAuthenticationCommand("service0001", "jwt01")); assertSame(command, serviceAuthenticationService.getAuthenticationCommand("service0001", "jwt01")); verify(discoveryClient, times(1)).getApplication("service0001"); verify(discoveryClient, never()).getApplication("service0002"); assertSame(command, serviceAuthenticationService.getAuthenticationCommand("service0001", "jwt02")); assertSame(command, serviceAuthenticationService.getAuthenticationCommand("service0002", "jwt01")); verify(discoveryClient, times(2)).getApplication("service0001"); verify(discoveryClient, times(1)).getApplication("service0002"); serviceAuthenticationService.evictCacheService("service0001"); assertSame(command, serviceAuthenticationService.getAuthenticationCommand("service0001", "jwt01")); verify(discoveryClient, times(3)).getApplication("service0001"); assertSame(command, serviceAuthenticationService.getAuthenticationCommand("service0001", "jwt02")); verify(discoveryClient, times(4)).getApplication("service0001"); assertSame(command, serviceAuthenticationService.getAuthenticationCommand("service0002", "jwt01")); verify(discoveryClient, times(1)).getApplication("service0002"); serviceAuthenticationService.evictCacheAllService(); assertSame(command, serviceAuthenticationService.getAuthenticationCommand("service0001", "jwt01")); verify(discoveryClient, times(5)).getApplication("service0001"); assertSame(command, serviceAuthenticationService.getAuthenticationCommand("service0001", "jwt02")); verify(discoveryClient, times(6)).getApplication("service0001"); assertSame(command, serviceAuthenticationService.getAuthenticationCommand("service0002", "jwt01")); verify(discoveryClient, times(2)).getApplication("service0002"); }
@Override public void evictCacheService(String serviceId) { cacheUtils.evictSubset(cacheManager, CACHE_BY_SERVICE_ID, x -> StringUtils.equalsIgnoreCase((String) x.get(0), serviceId)); }
ServiceAuthenticationServiceImpl implements ServiceAuthenticationService { @Override public void evictCacheService(String serviceId) { cacheUtils.evictSubset(cacheManager, CACHE_BY_SERVICE_ID, x -> StringUtils.equalsIgnoreCase((String) x.get(0), serviceId)); } }
ServiceAuthenticationServiceImpl implements ServiceAuthenticationService { @Override public void evictCacheService(String serviceId) { cacheUtils.evictSubset(cacheManager, CACHE_BY_SERVICE_ID, x -> StringUtils.equalsIgnoreCase((String) x.get(0), serviceId)); }  }
ServiceAuthenticationServiceImpl implements ServiceAuthenticationService { @Override public void evictCacheService(String serviceId) { cacheUtils.evictSubset(cacheManager, CACHE_BY_SERVICE_ID, x -> StringUtils.equalsIgnoreCase((String) x.get(0), serviceId)); }  Authentication getAuthentication(InstanceInfo instanceInfo); @Override @CacheEvict(value = CACHE_BY_AUTHENTICATION, condition = "#result != null && #result.isExpired()") @Cacheable(CACHE_BY_AUTHENTICATION) AuthenticationCommand getAuthenticationCommand(Authentication authentication, String jwtToken); @Override @RetryIfExpired @CacheEvict( value = CACHE_BY_SERVICE_ID, condition = "#result != null && #result.isExpired()", keyGenerator = CacheConfig.COMPOSITE_KEY_GENERATOR ) @Cacheable(value = CACHE_BY_SERVICE_ID, keyGenerator = CacheConfig.COMPOSITE_KEY_GENERATOR) AuthenticationCommand getAuthenticationCommand(String serviceId, String jwtToken); @Override @CacheEvict(value = CACHE_BY_SERVICE_ID, allEntries = true) void evictCacheAllService(); @Override void evictCacheService(String serviceId); }
ServiceAuthenticationServiceImpl implements ServiceAuthenticationService { @Override public void evictCacheService(String serviceId) { cacheUtils.evictSubset(cacheManager, CACHE_BY_SERVICE_ID, x -> StringUtils.equalsIgnoreCase((String) x.get(0), serviceId)); }  Authentication getAuthentication(InstanceInfo instanceInfo); @Override @CacheEvict(value = CACHE_BY_AUTHENTICATION, condition = "#result != null && #result.isExpired()") @Cacheable(CACHE_BY_AUTHENTICATION) AuthenticationCommand getAuthenticationCommand(Authentication authentication, String jwtToken); @Override @RetryIfExpired @CacheEvict( value = CACHE_BY_SERVICE_ID, condition = "#result != null && #result.isExpired()", keyGenerator = CacheConfig.COMPOSITE_KEY_GENERATOR ) @Cacheable(value = CACHE_BY_SERVICE_ID, keyGenerator = CacheConfig.COMPOSITE_KEY_GENERATOR) AuthenticationCommand getAuthenticationCommand(String serviceId, String jwtToken); @Override @CacheEvict(value = CACHE_BY_SERVICE_ID, allEntries = true) void evictCacheAllService(); @Override void evictCacheService(String serviceId); static final String AUTHENTICATION_COMMAND_KEY; }