use of com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest in project spring-cloud-aws by awspring.
the class ElastiCacheFactoryBeanTest method getObject_availableClusterWithLogicalName_returnsConfigurationMemcachedClientWithPhysicalName.
@Test
void getObject_availableClusterWithLogicalName_returnsConfigurationMemcachedClientWithPhysicalName() throws Exception {
// Arrange
AmazonElastiCache amazonElastiCache = mock(AmazonElastiCacheClient.class);
DescribeCacheClustersRequest testCache = new DescribeCacheClustersRequest().withCacheClusterId("testCache");
testCache.setShowCacheNodeInfo(true);
when(amazonElastiCache.describeCacheClusters(testCache)).thenReturn(new DescribeCacheClustersResult().withCacheClusters(new CacheCluster().withConfigurationEndpoint(new Endpoint().withAddress("localhost").withPort(45678)).withCacheClusterStatus("available").withEngine("memcached")));
ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);
when(resourceIdResolver.resolveToPhysicalResourceId("test")).thenReturn("testCache");
ElastiCacheFactoryBean elastiCacheFactoryBean = new ElastiCacheFactoryBean(amazonElastiCache, "test", resourceIdResolver, Collections.<CacheFactory>singletonList(new TestCacheFactory("test", "localhost", 45678)));
// Act
elastiCacheFactoryBean.afterPropertiesSet();
Cache cache = elastiCacheFactoryBean.getObject();
// Assert
assertThat(cache).isNotNull();
}
use of com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest in project spring-cloud-aws by awspring.
the class ElastiCacheFactoryBeanTest method getObject_availableCluster_returnsConfiguredMemcachedClient.
@Test
void getObject_availableCluster_returnsConfiguredMemcachedClient() throws Exception {
// Arrange
AmazonElastiCache amazonElastiCache = mock(AmazonElastiCacheClient.class);
DescribeCacheClustersRequest testCache = new DescribeCacheClustersRequest().withCacheClusterId("testCache");
testCache.setShowCacheNodeInfo(true);
when(amazonElastiCache.describeCacheClusters(testCache)).thenReturn(new DescribeCacheClustersResult().withCacheClusters(new CacheCluster().withConfigurationEndpoint(new Endpoint().withAddress("localhost").withPort(45678)).withCacheClusterStatus("available").withEngine("memcached")));
ElastiCacheFactoryBean elasticCacheFactoryBean = new ElastiCacheFactoryBean(amazonElastiCache, "testCache", Collections.singletonList(new TestCacheFactory("testCache", "localhost", 45678)));
// Act
elasticCacheFactoryBean.afterPropertiesSet();
Cache cache = elasticCacheFactoryBean.getObject();
// Assert
assertThat(cache).isNotNull();
}
use of com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest in project spring-cloud-aws by awspring.
the class ElastiCacheFactoryBean method createInstance.
@Override
protected Cache createInstance() throws Exception {
DescribeCacheClustersRequest describeCacheClustersRequest = new DescribeCacheClustersRequest().withCacheClusterId(getCacheClusterName());
describeCacheClustersRequest.setShowCacheNodeInfo(true);
DescribeCacheClustersResult describeCacheClustersResult = this.amazonElastiCache.describeCacheClusters(describeCacheClustersRequest);
CacheCluster cacheCluster = describeCacheClustersResult.getCacheClusters().get(0);
if (!"available".equals(cacheCluster.getCacheClusterStatus())) {
LOGGER.warn("Cache cluster is not available now. Connection may fail during cache access. Current status is {}", cacheCluster.getCacheClusterStatus());
}
Endpoint configurationEndpoint = getEndpointForCache(cacheCluster);
for (CacheFactory cacheFactory : this.cacheFactories) {
if (cacheFactory.isSupportingCacheArchitecture(cacheCluster.getEngine())) {
return cacheFactory.createCache(this.cacheClusterId, configurationEndpoint.getAddress(), configurationEndpoint.getPort());
}
}
throw new IllegalArgumentException("No CacheFactory configured for engine: " + cacheCluster.getEngine());
}
use of com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest in project spring-cloud-aws by awspring.
the class CacheBeanDefinitionParserTest method parseInternal_mixedCacheConfig_returnsBothCaches.
@Test
void parseInternal_mixedCacheConfig_returnsBothCaches() throws Exception {
// Arrange
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
// Register a mock object which will be used to replay service calls
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(Mockito.class);
beanDefinitionBuilder.setFactoryMethod("mock");
beanDefinitionBuilder.addConstructorArgValue(AmazonElastiCache.class);
beanFactory.registerBeanDefinition(AmazonWebserviceClientConfigurationUtils.getBeanName(AmazonElastiCacheClient.class.getName()), beanDefinitionBuilder.getBeanDefinition());
BeanDefinitionBuilder cacheBuilder = BeanDefinitionBuilder.rootBeanDefinition(Mockito.class);
cacheBuilder.setFactoryMethod("mock");
cacheBuilder.addConstructorArgValue(AmazonElastiCache.class);
beanFactory.registerBeanDefinition(AmazonWebserviceClientConfigurationUtils.getBeanName(AmazonElastiCacheClient.class.getName()), cacheBuilder.getBeanDefinition());
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-mixedCacheConfig.xml", getClass()));
AmazonElastiCache client = beanFactory.getBean(AmazonWebserviceClientConfigurationUtils.getBeanName(AmazonElastiCacheClient.class.getName()), AmazonElastiCache.class);
// Replay invocation that will be called
DescribeCacheClustersRequest memcached1 = new DescribeCacheClustersRequest().withCacheClusterId("memcached");
memcached1.setShowCacheNodeInfo(true);
when(client.describeCacheClusters(memcached1)).thenReturn(new DescribeCacheClustersResult().withCacheClusters(new CacheCluster().withCacheClusterId("memcached").withConfigurationEndpoint(new Endpoint().withAddress("localhost").withPort(Integer.parseInt(System.getProperty("memcachedPort")))).withCacheClusterStatus("available").withEngine("memcached")));
Cache cache = beanFactory.getBean("memc", Cache.class);
when(cache.getName()).thenReturn("memc");
// Act
CacheManager cacheManager = beanFactory.getBean(CacheManager.class);
Cache memc = cacheManager.getCache("memc");
Cache memcached = cacheManager.getCache("memcached");
// Assert
assertThat(cacheManager).isNotNull();
assertThat(memcached).isNotNull();
memc.put("foo", "bar");
memc.evict("foo");
memcached.put("foo", "bar");
memcached.evict("foo");
}
Aggregations