Search in sources :

Example 1 with Endpoint

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;
    }
}
Also used : Endpoint(com.amazonaws.services.elasticache.model.Endpoint) EntityNotFoundException(com.amazonaws.services.glue.model.EntityNotFoundException) CloudFormationClient(com.amazonaws.athena.connector.integ.clients.CloudFormationClient) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with Endpoint

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();
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) Endpoint(com.amazonaws.services.elasticache.model.Endpoint) DescribeCacheClustersResult(com.amazonaws.services.elasticache.model.DescribeCacheClustersResult) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) AmazonElastiCache(com.amazonaws.services.elasticache.AmazonElastiCache) DescribeCacheClustersRequest(com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest) CacheManager(org.springframework.cache.CacheManager) CacheCluster(com.amazonaws.services.elasticache.model.CacheCluster) ClassPathResource(org.springframework.core.io.ClassPathResource) Cache(org.springframework.cache.Cache) AmazonElastiCache(com.amazonaws.services.elasticache.AmazonElastiCache) Test(org.junit.jupiter.api.Test)

Example 3 with Endpoint

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();
}
Also used : Endpoint(com.amazonaws.services.elasticache.model.Endpoint) DescribeCacheClustersResult(com.amazonaws.services.elasticache.model.DescribeCacheClustersResult) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) AmazonElastiCache(com.amazonaws.services.elasticache.AmazonElastiCache) DescribeCacheClustersRequest(com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest) CacheManager(org.springframework.cache.CacheManager) CacheCluster(com.amazonaws.services.elasticache.model.CacheCluster) ClassPathResource(org.springframework.core.io.ClassPathResource) Cache(org.springframework.cache.Cache) AmazonElastiCache(com.amazonaws.services.elasticache.AmazonElastiCache) Test(org.junit.jupiter.api.Test)

Example 4 with Endpoint

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();
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) Endpoint(com.amazonaws.services.elasticache.model.Endpoint) DescribeCacheClustersResult(com.amazonaws.services.elasticache.model.DescribeCacheClustersResult) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) AmazonElastiCache(com.amazonaws.services.elasticache.AmazonElastiCache) DescribeCacheClustersRequest(com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest) CacheManager(org.springframework.cache.CacheManager) CacheCluster(com.amazonaws.services.elasticache.model.CacheCluster) ClassPathResource(org.springframework.core.io.ClassPathResource) Cache(org.springframework.cache.Cache) AmazonElastiCache(com.amazonaws.services.elasticache.AmazonElastiCache) Test(org.junit.jupiter.api.Test)

Example 5 with Endpoint

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();
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) ResourceIdResolver(io.awspring.cloud.core.env.ResourceIdResolver) Endpoint(com.amazonaws.services.elasticache.model.Endpoint) DescribeCacheClustersResult(com.amazonaws.services.elasticache.model.DescribeCacheClustersResult) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) AmazonElastiCache(com.amazonaws.services.elasticache.AmazonElastiCache) DescribeCacheClustersRequest(com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest) CacheManager(org.springframework.cache.CacheManager) CacheCluster(com.amazonaws.services.elasticache.model.CacheCluster) ClassPathResource(org.springframework.core.io.ClassPathResource) Cache(org.springframework.cache.Cache) AmazonElastiCache(com.amazonaws.services.elasticache.AmazonElastiCache) Test(org.junit.jupiter.api.Test)

Aggregations

Endpoint (com.amazonaws.services.elasticache.model.Endpoint)10 CacheCluster (com.amazonaws.services.elasticache.model.CacheCluster)9 DescribeCacheClustersRequest (com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest)9 DescribeCacheClustersResult (com.amazonaws.services.elasticache.model.DescribeCacheClustersResult)9 AmazonElastiCache (com.amazonaws.services.elasticache.AmazonElastiCache)8 Test (org.junit.jupiter.api.Test)8 Cache (org.springframework.cache.Cache)7 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)5 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)5 CacheManager (org.springframework.cache.CacheManager)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)4 ResourceIdResolver (io.awspring.cloud.core.env.ResourceIdResolver)2 CloudFormationClient (com.amazonaws.athena.connector.integ.clients.CloudFormationClient)1 CacheNode (com.amazonaws.services.elasticache.model.CacheNode)1 EntityNotFoundException (com.amazonaws.services.glue.model.EntityNotFoundException)1 BeforeClass (org.testng.annotations.BeforeClass)1