org.springframework.cache.interceptor.SimpleKeyGenerator Java Examples
The following examples show how to use
org.springframework.cache.interceptor.SimpleKeyGenerator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JCacheErrorHandlerTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void getFailPutExceptionFail() { UnsupportedOperationException exceptionOnPut = new UnsupportedOperationException("Test exception on put"); Object key = SimpleKeyGenerator.generateKey(0L); given(this.cache.get(key)).willReturn(null); willThrow(exceptionOnPut).given(this.errorCache).put(key, SimpleService.TEST_EXCEPTION); try { this.simpleService.getFail(0L); } catch (IllegalStateException ex) { assertEquals("Test exception", ex.getMessage()); } verify(this.errorHandler).handleCachePutError( exceptionOnPut, this.errorCache, key, SimpleService.TEST_EXCEPTION); }
Example #2
Source File: JCacheErrorHandlerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void getFailPutExceptionFail() { UnsupportedOperationException exceptionOnPut = new UnsupportedOperationException("Test exception on put"); Object key = SimpleKeyGenerator.generateKey(0L); given(this.cache.get(key)).willReturn(null); willThrow(exceptionOnPut).given(this.errorCache).put(key, SimpleService.TEST_EXCEPTION); try { this.simpleService.getFail(0L); } catch (IllegalStateException ex) { assertEquals("Test exception", ex.getMessage()); } verify(this.errorHandler).handleCachePutError( exceptionOnPut, this.errorCache, key, SimpleService.TEST_EXCEPTION); }
Example #3
Source File: AnnotatedJCacheableService.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override @CachePut(afterInvocation = false) public void earlyPut(String id, @CacheValue Object value) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper == null) { throw new AssertionError("Excepted value to be put in cache with key " + key); } Object actual = valueWrapper.get(); if (value != actual) { // instance check on purpose throw new AssertionError("Wrong value set in cache with key " + key + ". " + "Expected=" + value + ", but got=" + actual); } }
Example #4
Source File: JCacheErrorHandlerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void evictFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict"); Object key = SimpleKeyGenerator.generateKey(0L); willThrow(exception).given(this.cache).evict(key); this.simpleService.evict(0L); verify(this.errorHandler).handleCacheEvictError(exception, this.cache, key); }
Example #5
Source File: AnnotatedJCacheableService.java From java-technology-stack with MIT License | 5 votes |
@Override @CachePut(afterInvocation = false) public void earlyPut(String id, @CacheValue Object value) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper == null) { throw new AssertionError("Excepted value to be put in cache with key " + key); } Object actual = valueWrapper.get(); if (value != actual) { // instance check on purpose throw new AssertionError("Wrong value set in cache with key " + key + ". " + "Expected=" + value + ", but got=" + actual); } }
Example #6
Source File: AnnotatedJCacheableService.java From java-technology-stack with MIT License | 5 votes |
@Override @CacheRemove(afterInvocation = false) public void earlyRemove(String id) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper != null) { throw new AssertionError("Value with key " + key + " expected to be already remove from cache"); } }
Example #7
Source File: AnnotatedJCacheableService.java From java-technology-stack with MIT License | 5 votes |
@Override @CachePut(afterInvocation = false) public void earlyPut(String id, @CacheValue Object value) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper == null) { throw new AssertionError("Excepted value to be put in cache with key " + key); } Object actual = valueWrapper.get(); if (value != actual) { // instance check on purpose throw new AssertionError("Wrong value set in cache with key " + key + ". " + "Expected=" + value + ", but got=" + actual); } }
Example #8
Source File: AnnotatedJCacheableService.java From java-technology-stack with MIT License | 5 votes |
@Override @CacheRemove(afterInvocation = false) public void earlyRemove(String id) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper != null) { throw new AssertionError("Value with key " + key + " expected to be already remove from cache"); } }
Example #9
Source File: JCacheErrorHandlerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void getFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get"); Object key = SimpleKeyGenerator.generateKey(0L); willThrow(exception).given(cache).get(key); this.simpleService.get(0L); verify(errorHandler).handleCacheGetError(exception, cache, key); }
Example #10
Source File: JCacheErrorHandlerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void putFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put"); Object key = SimpleKeyGenerator.generateKey(0L); willThrow(exception).given(cache).put(key, 234L); this.simpleService.put(0L, 234L); verify(errorHandler).handleCachePutError(exception, cache, key, 234L); }
Example #11
Source File: JCacheErrorHandlerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void evictFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict"); Object key = SimpleKeyGenerator.generateKey(0L); willThrow(exception).given(cache).evict(key); this.simpleService.evict(0L); verify(errorHandler).handleCacheEvictError(exception, cache, key); }
Example #12
Source File: DefaultJCacheOperationSource.java From spring-analysis-note with MIT License | 5 votes |
/** * Construct a new {@code DefaultJCacheOperationSource} with the given cache manager, * cache resolver and key generator suppliers, applying the corresponding default * if a supplier is not resolvable. * @since 5.1 */ public DefaultJCacheOperationSource( @Nullable Supplier<CacheManager> cacheManager, @Nullable Supplier<CacheResolver> cacheResolver, @Nullable Supplier<CacheResolver> exceptionCacheResolver, @Nullable Supplier<KeyGenerator> keyGenerator) { this.cacheManager = SingletonSupplier.ofNullable(cacheManager); this.cacheResolver = SingletonSupplier.ofNullable(cacheResolver); this.exceptionCacheResolver = SingletonSupplier.ofNullable(exceptionCacheResolver); this.keyGenerator = new SingletonSupplier<>(keyGenerator, SimpleKeyGenerator::new); }
Example #13
Source File: AnnotatedJCacheableService.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override @CacheRemove(afterInvocation = false) public void earlyRemove(String id) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper != null) { throw new AssertionError("Value with key " + key + " expected to be already remove from cache"); } }
Example #14
Source File: AnnotatedJCacheableService.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override @CachePut(afterInvocation = false) public void earlyPut(String id, @CacheValue Object value) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper == null) { throw new AssertionError("Excepted value to be put in cache with key " + key); } Object actual = valueWrapper.get(); if (value != actual) { // instance check on purpose throw new AssertionError("Wrong value set in cache with key " + key + ". " + "Expected=" + value + ", but got=" + actual); } }
Example #15
Source File: AnnotatedJCacheableService.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override @CacheRemove(afterInvocation = false) public void earlyRemove(String id) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper != null) { throw new AssertionError("Value with key " + key + " expected to be already remove from cache"); } }
Example #16
Source File: SystemManagementCacheKeyGenerator.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
@Override // Exception squid:S923 - override @SuppressWarnings({ "squid:S923" }) public Object generate(final Object target, final Method method, final Object... params) { final String initialTenantCreation = createInitialTenant.get(); if (initialTenantCreation == null) { return SimpleKeyGenerator.generateKey(tenantAware.getCurrentTenant().toUpperCase(), tenantAware.getCurrentTenant().toUpperCase()); } return SimpleKeyGenerator.generateKey(initialTenantCreation.toUpperCase(), initialTenantCreation.toUpperCase()); }
Example #17
Source File: CachingConfig.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public Object generate(Object target, Method method, Object... params) { if (params.length == 1) { if (params[0] == null) { return SimpleKey.EMPTY; } CacheDefinition cacheDefinition = classCacheDefinitionMap.get(params[0].getClass()); if (cacheDefinition != null) { return cacheDefinition.generateKey(target, method, params); } } return SimpleKeyGenerator.generateKey(params); }
Example #18
Source File: CachingConfig.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public Object generate(Object target, Method method, Object... params) { if (params.length == 1) { if (params[0] == null) { return SimpleKey.EMPTY; } CacheDefinition cacheDefinition = classCacheDefinitionMap.get(params[0].getClass()); if (cacheDefinition != null) { return cacheDefinition.generateKey(target, method, params); } } return SimpleKeyGenerator.generateKey(params); }
Example #19
Source File: CachingConfig.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public Object generate(Object target, Method method, Object... params) { if (params.length == 1) { if (params[0] == null) { return SimpleKey.EMPTY; } CacheDefinition cacheDefinition = classCacheDefinitionMap.get(params[0].getClass()); if (cacheDefinition != null) { return cacheDefinition.generateKey(target, method, params); } } return SimpleKeyGenerator.generateKey(params); }
Example #20
Source File: JCacheErrorHandlerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void getPutNewElementFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put"); Object key = SimpleKeyGenerator.generateKey(0L); given(this.cache.get(key)).willReturn(null); willThrow(exception).given(this.cache).put(key, 0L); this.simpleService.get(0L); verify(this.errorHandler).handleCachePutError(exception, this.cache, key, 0L); }
Example #21
Source File: JCacheErrorHandlerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void getFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get"); Object key = SimpleKeyGenerator.generateKey(0L); willThrow(exception).given(this.cache).get(key); this.simpleService.get(0L); verify(this.errorHandler).handleCacheGetError(exception, this.cache, key); }
Example #22
Source File: JCacheErrorHandlerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void getPutNewElementFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put"); Object key = SimpleKeyGenerator.generateKey(0L); given(this.cache.get(key)).willReturn(null); willThrow(exception).given(this.cache).put(key, 0L); this.simpleService.get(0L); verify(this.errorHandler).handleCachePutError(exception, this.cache, key, 0L); }
Example #23
Source File: JCacheErrorHandlerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void putFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put"); Object key = SimpleKeyGenerator.generateKey(0L); willThrow(exception).given(this.cache).put(key, 234L); this.simpleService.put(0L, 234L); verify(this.errorHandler).handleCachePutError(exception, this.cache, key, 234L); }
Example #24
Source File: JCacheErrorHandlerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void evictFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict"); Object key = SimpleKeyGenerator.generateKey(0L); willThrow(exception).given(this.cache).evict(key); this.simpleService.evict(0L); verify(this.errorHandler).handleCacheEvictError(exception, this.cache, key); }
Example #25
Source File: AnnotatedJCacheableService.java From spring-analysis-note with MIT License | 5 votes |
@Override @CachePut(afterInvocation = false) public void earlyPut(String id, @CacheValue Object value) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper == null) { throw new AssertionError("Excepted value to be put in cache with key " + key); } Object actual = valueWrapper.get(); if (value != actual) { // instance check on purpose throw new AssertionError("Wrong value set in cache with key " + key + ". " + "Expected=" + value + ", but got=" + actual); } }
Example #26
Source File: AnnotatedJCacheableService.java From spring-analysis-note with MIT License | 5 votes |
@Override @CacheRemove(afterInvocation = false) public void earlyRemove(String id) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper != null) { throw new AssertionError("Value with key " + key + " expected to be already remove from cache"); } }
Example #27
Source File: AnnotatedJCacheableService.java From spring-analysis-note with MIT License | 5 votes |
@Override @CachePut(afterInvocation = false) public void earlyPut(String id, @CacheValue Object value) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper == null) { throw new AssertionError("Excepted value to be put in cache with key " + key); } Object actual = valueWrapper.get(); if (value != actual) { // instance check on purpose throw new AssertionError("Wrong value set in cache with key " + key + ". " + "Expected=" + value + ", but got=" + actual); } }
Example #28
Source File: AnnotatedJCacheableService.java From spring-analysis-note with MIT License | 5 votes |
@Override @CacheRemove(afterInvocation = false) public void earlyRemove(String id) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper != null) { throw new AssertionError("Value with key " + key + " expected to be already remove from cache"); } }
Example #29
Source File: DefaultJCacheOperationSource.java From java-technology-stack with MIT License | 5 votes |
/** * Construct a new {@code DefaultJCacheOperationSource} with the given cache manager, * cache resolver and key generator suppliers, applying the corresponding default * if a supplier is not resolvable. * @since 5.1 */ public DefaultJCacheOperationSource( @Nullable Supplier<CacheManager> cacheManager, @Nullable Supplier<CacheResolver> cacheResolver, @Nullable Supplier<CacheResolver> exceptionCacheResolver, @Nullable Supplier<KeyGenerator> keyGenerator) { this.cacheManager = SingletonSupplier.ofNullable(cacheManager); this.cacheResolver = SingletonSupplier.ofNullable(cacheResolver); this.exceptionCacheResolver = SingletonSupplier.ofNullable(exceptionCacheResolver); this.keyGenerator = new SingletonSupplier<>(keyGenerator, SimpleKeyGenerator::new); }
Example #30
Source File: JCacheErrorHandlerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void putFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put"); Object key = SimpleKeyGenerator.generateKey(0L); willThrow(exception).given(this.cache).put(key, 234L); this.simpleService.put(0L, 234L); verify(this.errorHandler).handleCachePutError(exception, this.cache, key, 234L); }