当前位置: 首页>>代码示例>>Java>>正文


Java AmazonElastiCacheClient类代码示例

本文整理汇总了Java中com.amazonaws.services.elasticache.AmazonElastiCacheClient的典型用法代码示例。如果您正苦于以下问题:Java AmazonElastiCacheClient类的具体用法?Java AmazonElastiCacheClient怎么用?Java AmazonElastiCacheClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AmazonElastiCacheClient类属于com.amazonaws.services.elasticache包,在下文中一共展示了AmazonElastiCacheClient类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getObject_availableCluster_returnsConfiguredMemcachedClient

import com.amazonaws.services.elasticache.AmazonElastiCacheClient; //导入依赖的package包/类
@Test
public 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
    assertNotNull(cache);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:22,代码来源:ElastiCacheFactoryBeanTest.java

示例2: parseInternal_clusterCacheConfigurationWithRegion_returnsConfiguredClusterCacheWithRegion

import com.amazonaws.services.elasticache.AmazonElastiCacheClient; //导入依赖的package包/类
@Test
public void parseInternal_clusterCacheConfigurationWithRegion_returnsConfiguredClusterCacheWithRegion() throws Exception {
    //Arrange
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

    //Load xml file
    XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
    xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-elastiCacheConfigRegionConfigured.xml", getClass()));


    //Act
    BeanDefinition beanDefinition = beanFactory.getBeanDefinition(AmazonWebserviceClientConfigurationUtils.getBeanName(AmazonElastiCacheClient.class.getName()));

    //Assert
    assertNotNull(beanDefinition);
    assertNotNull(beanDefinition.getPropertyValues().get("customRegion"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:18,代码来源:CacheBeanDefinitionParserTest.java

示例3: scanElastiCache

import com.amazonaws.services.elasticache.AmazonElastiCacheClient; //导入依赖的package包/类
/**
 * Collect data for ElastiCache.
 *
 * @param stats
 *            current statistics object.
 * @param account
 *            currently used credentials object.
 * @param region
 *            currently used aws region.
 */
public static void scanElastiCache(AwsStats stats, AwsAccount account, Regions region) {
	if (region == Regions.EU_CENTRAL_1)
		return;

	LOG.debug("Scan for ElastiCache in region " + region.getName() + " in account " + account.getAccountId());

	/*
	 * Amazon ElastiCache
	 */
	try {
		AmazonElastiCache elastiCache = new AmazonElastiCacheClient(account.getCredentials());
		elastiCache.setRegion(Region.getRegion(region));

		List<CacheCluster> list = elastiCache.describeCacheClusters().getCacheClusters();

		int totalItems = list.size();
		for (CacheCluster cluster : list) {
			AwsResource res = new AwsResource(cluster.getCacheClusterId(), account.getAccountId(), AwsResourceType.ElastiCache, region);
			res.addInfo("Engine", cluster.getEngine());
			res.addInfo("EngineVersion", cluster.getEngineVersion());
			res.addInfo("NumCacheNodes", cluster.getNumCacheNodes());
			stats.add(res);
		}

		LOG.info(totalItems + " ElastiCache in region " + region.getName() + " in account " + account.getAccountId());
	} catch (AmazonServiceException ase) {
		LOG.error("Exception of ElastiCache: " + ase.getMessage());
	}
}
 
开发者ID:janloeffler,项目名称:aws-utilization-monitor,代码行数:40,代码来源:AwsScan.java

示例4: getObject_availableClusterWithLogicalName_returnsConfigurationMemcachedClientWithPhysicalName

import com.amazonaws.services.elasticache.AmazonElastiCacheClient; //导入依赖的package包/类
@Test
public 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
    assertNotNull(cache);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:25,代码来源:ElastiCacheFactoryBeanTest.java

示例5: getObject_clusterWithRedisEngineConfigured_reportsError

import com.amazonaws.services.elasticache.AmazonElastiCacheClient; //导入依赖的package包/类
@Test
public void getObject_clusterWithRedisEngineConfigured_reportsError() throws Exception {
    //Arrange
    this.expectedException.expect(IllegalArgumentException.class);
    this.expectedException.expectMessage("engine");

    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)));

    // Act
    elastiCacheFactoryBean.afterPropertiesSet();


    // Assert
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:24,代码来源:ElastiCacheFactoryBeanTest.java

示例6: parseInternal_cacheConfigWithExpiration_returnsConfiguredCacheThatRespectExpiration

import com.amazonaws.services.elasticache.AmazonElastiCacheClient; //导入依赖的package包/类
@Test
public 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
    assertNotNull(cacheManager);
    assertNotNull(cache);
    assertNull(cache.get("foo"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:40,代码来源:CacheBeanDefinitionParserTest.java

示例7: parseInternal_clusterCacheConfiguration_returnsConfiguredClusterCache

import com.amazonaws.services.elasticache.AmazonElastiCacheClient; //导入依赖的package包/类
@Test
public 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
    assertNotNull(cacheManager);
    assertNotNull(cache);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:41,代码来源:CacheBeanDefinitionParserTest.java

示例8: AWSDatabase

import com.amazonaws.services.elasticache.AmazonElastiCacheClient; //导入依赖的package包/类
AWSDatabase(final Map<String, AmazonEC2Client> ec2Clients,
            final Map<String, AmazonRDSClient> rdsClients,
            final Map<String, AmazonDynamoDBClient> dynamoClients,
            final Map<String, AmazonSQSClient> sqsClients,
            final Map<String, AmazonElastiCacheClient> elasticacheClients,
            final AmazonIdentityManagementClient iamClient) {
    this(ec2Clients, rdsClients, dynamoClients, sqsClients, elasticacheClients, iamClient, null);
}
 
开发者ID:airbnb,项目名称:billow,代码行数:9,代码来源:AWSDatabase.java

示例9: amazonElastiCache

import com.amazonaws.services.elasticache.AmazonElastiCacheClient; //导入依赖的package包/类
@Bean
@ConditionalOnMissingAmazonClient(AmazonElastiCache.class)
public AmazonWebserviceClientFactoryBean<AmazonElastiCacheClient> amazonElastiCache() {
    return new AmazonWebserviceClientFactoryBean<>(AmazonElastiCacheClient.class, this.credentialsProvider, this.regionProvider);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:6,代码来源:ElastiCacheCachingConfiguration.java

示例10: parseInternal_mixedCacheConfig_returnsBothCaches

import com.amazonaws.services.elasticache.AmazonElastiCacheClient; //导入依赖的package包/类
@Test
public 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
    assertNotNull(cacheManager);
    assertNotNull(memcached);

    memc.put("foo", "bar");
    memc.evict("foo");

    memcached.put("foo", "bar");
    memcached.evict("foo");
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:54,代码来源:CacheBeanDefinitionParserTest.java

示例11: parseInternal_clusterCacheConfigurationWithLogicalName_returnsConfiguredClusterCacheWithPhysicalName

import com.amazonaws.services.elasticache.AmazonElastiCacheClient; //导入依赖的package包/类
@Test
public 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
    assertNotNull(cacheManager);
    assertNotNull(cache);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:50,代码来源:CacheBeanDefinitionParserTest.java

示例12: AWSDatabaseHolder

import com.amazonaws.services.elasticache.AmazonElastiCacheClient; //导入依赖的package包/类
public AWSDatabaseHolder(Config config) {
    maxAgeInMs = config.getDuration("maxAge", TimeUnit.MILLISECONDS);

    final DefaultAWSCredentialsProviderChain awsCredentialsProviderChain = new DefaultAWSCredentialsProviderChain();

    final ClientConfiguration clientConfig = new ClientConfiguration();
    clientConfig.setRetryPolicy(new RetryPolicy(null, null, config.getInt("maxErrorRetry"), true));

    final AmazonEC2Client bootstrapEC2Client = new AmazonEC2Client(awsCredentialsProviderChain);
    ec2Clients = Maps.newHashMap();
    rdsClients = Maps.newHashMap();
    sqsClients = Maps.newHashMap();
    dynamoDBClients = Maps.newHashMap();
    elasticacheClients = Maps.newHashMap();

    final List<Region> ec2Regions = bootstrapEC2Client.describeRegions().getRegions();
    for (Region region : ec2Regions) {
        final String regionName = region.getRegionName();
        final String endpoint = region.getEndpoint();
        log.debug("Adding ec2 region {}", region);

        final AmazonEC2Client ec2Client = new AmazonEC2Client(awsCredentialsProviderChain, clientConfig);
        ec2Client.setEndpoint(endpoint);
        ec2Clients.put(regionName, ec2Client);

        final AmazonRDSClient rdsClient = new AmazonRDSClient(awsCredentialsProviderChain, clientConfig);
        rdsClient.setEndpoint(endpoint.replaceFirst("ec2\\.", "rds."));
        rdsClients.put(regionName, rdsClient);

        final AmazonDynamoDBClient dynamoDBClient =
            new AmazonDynamoDBClient(awsCredentialsProviderChain, clientConfig);
        dynamoDBClient.setEndpoint(endpoint.replaceFirst("ec2\\.", "dynamodb."));
        dynamoDBClients.put(regionName, dynamoDBClient);

        final AmazonSQSClient sqsClient = new AmazonSQSClient(awsCredentialsProviderChain, clientConfig);
        sqsClient.setEndpoint(endpoint.replaceFirst("ec2\\.", "sqs."));
        sqsClients.put(regionName, sqsClient);

        final AmazonElastiCacheClient elastiCacheClient = new AmazonElastiCacheClient
            (awsCredentialsProviderChain, clientConfig);
        elastiCacheClient.setEndpoint(endpoint.replaceFirst("ec2\\.", "elasticache."));
        elasticacheClients.put(regionName, elastiCacheClient);
    }

    this.iamClient = new AmazonIdentityManagementClient(awsCredentialsProviderChain, clientConfig);

    if (config.hasPath("accountNumber")) {
        this.awsAccountNumber = config.getString("accountNumber");
    } else {
        this.awsAccountNumber = null;
    }

    rebuild();
}
 
开发者ID:airbnb,项目名称:billow,代码行数:55,代码来源:AWSDatabaseHolder.java


注:本文中的com.amazonaws.services.elasticache.AmazonElastiCacheClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。