use of com.amazonaws.services.elasticache.model.Endpoint in project aws-athena-query-federation by awslabs.
the class RedisIntegTest method setUp.
/**
* Creates a Redis cluster used for the integration tests.
*/
@BeforeClass
@Override
protected void setUp() {
cloudFormationClient = new CloudFormationClient(theApp, getRedisStack());
try {
// Create the CloudFormation stack for the Redis instances.
cloudFormationClient.createStack();
// Get host and port information
Endpoint standaloneEndpoint = getRedisInstanceData(redisStandaloneName, false);
logger.info("Got Endpoint: " + standaloneEndpoint.toString());
redisEndpoints.put(STANDALONE_KEY, String.format("%s:%s", standaloneEndpoint.getAddress(), standaloneEndpoint.getPort()));
Endpoint clusterEndpoint = getRedisInstanceData(redisClusterName, true);
logger.info("Got Endpoint: " + clusterEndpoint.toString());
redisEndpoints.put(CLUSTER_KEY, String.format("%s:%s:%s", clusterEndpoint.getAddress(), clusterEndpoint.getPort(), redisPassword));
// Get endpoint information and set the connection string environment var for Lambda.
environmentVars.put("standalone_connection", redisEndpoints.get(STANDALONE_KEY));
environmentVars.put("cluster_connection", redisEndpoints.get(CLUSTER_KEY));
// Invoke the framework's setUp().
super.setUp();
} catch (Exception e) {
// Delete the partially formed CloudFormation stack.
cloudFormationClient.deleteStack();
throw e;
}
}
use of com.amazonaws.services.elasticache.model.Endpoint 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.Endpoint 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.Endpoint 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.Endpoint 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();
}
Aggregations