Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr committed Jun 10, 2024
1 parent d99e2a2 commit a27d434
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public abstract class BaseIntegrationTests {
public static final String DEFAULT_SET_NAME = "aerospike";
public static final String OVERRIDE_SET_NAME = "testSet1";
public static final String DIFFERENT_SET_NAME = "different-set";
public static final String CACHE_WITH_TTL = "CACHE-WITH-TTL";
public static final String DIFFERENT_EXISTING_CACHE = "DIFFERENT-EXISTING-CACHE";
protected static final int MILLIS_TO_NANO = 1_000_000;

@Value("${spring-data-aerospike.connection.namespace}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,21 @@ public void shouldCache() {
}

@Test
public void shouldCacheInDifferentSet() {
public void shouldCacheUsingDefaultSet() {
// default cache configuration is used for cache names not pre-configured via AerospikeCacheManager
CachedObject response1 = cachingComponent.cacheableMethodDefaultCache(KEY);
CachedObject response2 = cachingComponent.cacheableMethod(KEY);

assertThat(response1).isNotNull();
assertThat(response1.getValue()).isEqualTo(VALUE);
assertThat(response2).isNotNull();
assertThat(response2.getValue()).isEqualTo(VALUE);
assertThat(cachingComponent.getNoOfCalls()).isEqualTo(1);
assertThat(aerospikeOperations.count(DEFAULT_SET_NAME)).isEqualTo(1);
}

@Test
public void shouldCacheUsingDifferentSet() {
CachedObject response1 = cachingComponent.cacheableMethodDifferentExistingCache(KEY);
CachedObject response2 = cachingComponent.cacheableMethodDifferentExistingCache(KEY);

Expand All @@ -79,6 +93,8 @@ public void shouldCacheInDifferentSet() {
assertThat(aerospikeOperations.count(DEFAULT_SET_NAME)).isEqualTo(0);

CachedObject response3 = cachingComponent.cacheableMethod(KEY);
assertThat(response3).isNotNull();
assertThat(response3.getValue()).isEqualTo(VALUE);
assertThat(cachingComponent.getNoOfCalls()).isEqualTo(2);
assertThat(aerospikeOperations.count(DIFFERENT_SET_NAME)).isEqualTo(1);
assertThat(aerospikeOperations.count(DEFAULT_SET_NAME)).isEqualTo(1);
Expand Down Expand Up @@ -181,7 +197,7 @@ public void shouldCacheUsingAnotherCacheManager() {
public void shouldNotClearCacheClearingDifferentCache() {
CachedObject response1 = cachingComponent.cacheableMethod(KEY);
assertThat(aerospikeOperations.count(DEFAULT_SET_NAME)).isEqualTo(1);
aerospikeCacheManager.getCache("DIFFERENT-EXISTING-CACHE").clear();
aerospikeCacheManager.getCache(DIFFERENT_EXISTING_CACHE).clear();
AwaitilityUtils.awaitTwoSecondsUntil(() -> {
assertThat(aerospikeOperations.count(DEFAULT_SET_NAME)).isEqualTo(1);
assertThat(response1).isNotNull();
Expand All @@ -203,13 +219,19 @@ public CachedObject cacheableMethod(String key) {
return new CachedObject(VALUE);
}

@Cacheable("DIFFERENT-EXISTING-CACHE")
@Cacheable("TEST12345ABC")
public CachedObject cacheableMethodDefaultCache(String key) {
noOfCalls++;
return new CachedObject(VALUE);
}

@Cacheable(DIFFERENT_EXISTING_CACHE)
public CachedObject cacheableMethodDifferentExistingCache(String key) {
noOfCalls++;
return new CachedObject(VALUE);
}

@Cacheable(value = "CACHE-WITH-TTL")
@Cacheable(value = CACHE_WITH_TTL)
public CachedObject cacheableMethodWithTTL(String key) {
noOfCalls++;
return new CachedObject(VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public class CommonTestConfig {
public CacheManager cacheManager(IAerospikeClient aerospikeClient, MappingAerospikeConverter aerospikeConverter) {
AerospikeCacheConfiguration defaultCacheConfiguration = new AerospikeCacheConfiguration(namespace,
BaseIntegrationTests.DEFAULT_SET_NAME);
AerospikeCacheConfiguration aerospikeCacheConfiguration = new AerospikeCacheConfiguration(namespace,
BaseIntegrationTests.DIFFERENT_SET_NAME);
AerospikeCacheConfiguration configurationWithTTL = new AerospikeCacheConfiguration(namespace,
BaseIntegrationTests.DEFAULT_SET_NAME, 2);
AerospikeCacheConfiguration differentCacheConfiguration = new AerospikeCacheConfiguration(namespace,
BaseIntegrationTests.DIFFERENT_SET_NAME);
Map<String, AerospikeCacheConfiguration> aerospikeCacheConfigurationMap = new HashMap<>();
aerospikeCacheConfigurationMap.put("DIFFERENT-EXISTING-CACHE", aerospikeCacheConfiguration);
aerospikeCacheConfigurationMap.put("CACHE-WITH-TTL", configurationWithTTL);
aerospikeCacheConfigurationMap.put(BaseIntegrationTests.CACHE_WITH_TTL, configurationWithTTL);
aerospikeCacheConfigurationMap.put(BaseIntegrationTests.DIFFERENT_EXISTING_CACHE, differentCacheConfiguration);
return new AerospikeCacheManager(aerospikeClient, aerospikeConverter, defaultCacheConfiguration,
aerospikeCacheConfigurationMap);
}
Expand Down

0 comments on commit a27d434

Please sign in to comment.