use of com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest in project spring-cloud-aws by awspring.
the class CacheBeanDefinitionParserTest method parseInternal_clusterCacheConfiguration_returnsConfiguredClusterCache.
@Test
void parseInternal_clusterCacheConfiguration_returnsConfiguredClusterCache() 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());
// Load xml file
XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-elastiCacheConfig.xml", getClass()));
AmazonElastiCache client = beanFactory.getBean(AmazonWebserviceClientConfigurationUtils.getBeanName(AmazonElastiCacheClient.class.getName()), AmazonElastiCache.class);
// Replay invocation that will be called
DescribeCacheClustersRequest memcached = new DescribeCacheClustersRequest().withCacheClusterId("memcached");
memcached.setShowCacheNodeInfo(true);
when(client.describeCacheClusters(memcached)).thenReturn(new DescribeCacheClustersResult().withCacheClusters(new CacheCluster().withCacheClusterId("memcached").withConfigurationEndpoint(new Endpoint().withAddress("localhost").withPort(Integer.parseInt(System.getProperty("memcachedPort")))).withCacheClusterStatus("available").withEngine("memcached")));
// Act
CacheManager cacheManager = beanFactory.getBean(CacheManager.class);
Cache cache = cacheManager.getCache("memcached");
cache.put("foo", "bar");
cache.evict("foo");
// Assert
assertThat(cacheManager).isNotNull();
assertThat(cache).isNotNull();
}
use of com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest in project spring-cloud-aws by awspring.
the class CacheBeanDefinitionParserTest method parseInternal_clusterCacheConfigurationWithCustomElastiCacheClient_returnsConfigurationWithCustomClient.
@Test
void parseInternal_clusterCacheConfigurationWithCustomElastiCacheClient_returnsConfigurationWithCustomClient() throws Exception {
// Arrange
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
// Load xml file
XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-elastiCacheConfigWithCustomElastiCacheClient.xml", getClass()));
AmazonElastiCache amazonElastiCacheMock = beanFactory.getBean("customClient", AmazonElastiCache.class);
DescribeCacheClustersRequest memcached = new DescribeCacheClustersRequest().withCacheClusterId("memcached");
memcached.setShowCacheNodeInfo(true);
when(amazonElastiCacheMock.describeCacheClusters(memcached)).thenReturn(new DescribeCacheClustersResult().withCacheClusters(new CacheCluster().withCacheClusterId("memcached").withConfigurationEndpoint(new Endpoint().withAddress("localhost").withPort(Integer.parseInt(System.getProperty("memcachedPort")))).withCacheClusterStatus("available").withEngine("memcached")));
// Act
CacheManager cacheManager = beanFactory.getBean(CacheManager.class);
Cache cache = cacheManager.getCache("memcached");
cache.put("foo", "bar");
cache.evict("foo");
// Assert
assertThat(cacheManager).isNotNull();
assertThat(cache).isNotNull();
}
use of com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest in project spring-cloud-aws by awspring.
the class CacheBeanDefinitionParserTest method parseInternal_cacheConfigWithExpiration_returnsConfiguredCacheThatRespectExpiration.
@Test
void parseInternal_cacheConfigWithExpiration_returnsConfiguredCacheThatRespectExpiration() 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());
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-cacheConfigWithExpiration.xml", getClass()));
AmazonElastiCache client = beanFactory.getBean(AmazonWebserviceClientConfigurationUtils.getBeanName(AmazonElastiCacheClient.class.getName()), AmazonElastiCache.class);
// Replay invocation that will be called
DescribeCacheClustersRequest memcached = new DescribeCacheClustersRequest().withCacheClusterId("memcached");
memcached.setShowCacheNodeInfo(true);
when(client.describeCacheClusters(memcached)).thenReturn(new DescribeCacheClustersResult().withCacheClusters(new CacheCluster().withCacheClusterId("memcached").withConfigurationEndpoint(new Endpoint().withAddress("localhost").withPort(Integer.parseInt(System.getProperty("memcachedPort")))).withCacheClusterStatus("available").withEngine("memcached")));
// Act
CacheManager cacheManager = beanFactory.getBean(CacheManager.class);
Cache cache = cacheManager.getCache("memcached");
cache.put("foo", "bar");
Thread.sleep(2000);
// Assert
assertThat(cacheManager).isNotNull();
assertThat(cache).isNotNull();
assertThat(cache.get("foo")).isNull();
}
use of com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest in project spring-cloud-aws by awspring.
the class CacheBeanDefinitionParserTest method parseInternal_clusterCacheConfigurationWithLogicalName_returnsConfiguredClusterCacheWithPhysicalName.
@Test
void parseInternal_clusterCacheConfigurationWithLogicalName_returnsConfiguredClusterCacheWithPhysicalName() 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 resourceIdBuilder = BeanDefinitionBuilder.rootBeanDefinition(Mockito.class);
resourceIdBuilder.setFactoryMethod("mock");
resourceIdBuilder.addConstructorArgValue(ResourceIdResolver.class);
beanFactory.registerBeanDefinition(GlobalBeanDefinitionUtils.RESOURCE_ID_RESOLVER_BEAN_NAME, resourceIdBuilder.getBeanDefinition());
// Load xml file
XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-elastiCacheConfigStackConfigured.xml", getClass()));
AmazonElastiCache client = beanFactory.getBean(AmazonWebserviceClientConfigurationUtils.getBeanName(AmazonElastiCacheClient.class.getName()), AmazonElastiCache.class);
ResourceIdResolver resourceIdResolver = beanFactory.getBean(GlobalBeanDefinitionUtils.RESOURCE_ID_RESOLVER_BEAN_NAME, ResourceIdResolver.class);
when(resourceIdResolver.resolveToPhysicalResourceId("testMemcached")).thenReturn("memcached");
// Replay invocation that will be called
DescribeCacheClustersRequest memcached = new DescribeCacheClustersRequest().withCacheClusterId("memcached");
memcached.setShowCacheNodeInfo(true);
when(client.describeCacheClusters(memcached)).thenReturn(new DescribeCacheClustersResult().withCacheClusters(new CacheCluster().withCacheClusterId("memcached").withConfigurationEndpoint(new Endpoint().withAddress("localhost").withPort(Integer.parseInt(System.getProperty("memcachedPort")))).withCacheClusterStatus("available").withEngine("memcached")));
// Act
CacheManager cacheManager = beanFactory.getBean(CacheManager.class);
Cache cache = cacheManager.getCache("testMemcached");
cache.put("foo", "bar");
cache.evict("foo");
// Assert
assertThat(cacheManager).isNotNull();
assertThat(cache).isNotNull();
}
use of com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest in project spring-cloud-aws by awspring.
the class ElastiCacheFactoryBeanTest method getObject_clusterWithRedisEngineConfigured_reportsError.
@Test
void getObject_clusterWithRedisEngineConfigured_reportsError() throws Exception {
// Arrange
AmazonElastiCache amazonElastiCache = mock(AmazonElastiCacheClient.class);
DescribeCacheClustersRequest memcached = new DescribeCacheClustersRequest().withCacheClusterId("memcached");
memcached.setShowCacheNodeInfo(true);
when(amazonElastiCache.describeCacheClusters(memcached)).thenReturn(new DescribeCacheClustersResult().withCacheClusters(new CacheCluster().withEngine("redis").withCacheNodes(new CacheNode().withEndpoint(new Endpoint().withAddress("localhost").withPort(45678)))));
ElastiCacheFactoryBean elastiCacheFactoryBean = new ElastiCacheFactoryBean(amazonElastiCache, "memcached", Collections.singletonList(new TestCacheFactory("testCache", "localhost", 45678)));
// Assert
assertThatThrownBy(elastiCacheFactoryBean::afterPropertiesSet).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("engine");
}
Aggregations