org.springframework.cloud.aws.core.io.s3.SimpleStorageProtocolResolver Java Examples

The following examples show how to use org.springframework.cloud.aws.core.io.s3.SimpleStorageProtocolResolver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContextResourceLoaderAutoConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void createResourceLoader_withCustomTaskExecutorSettings_executorConfigured() {
	// Arrange
	this.context = new AnnotationConfigApplicationContext();
	this.context.register(ContextResourceLoaderAutoConfiguration.class);

	TestPropertyValues.of("cloud.aws.loader.corePoolSize:10",
			"cloud.aws.loader.maxPoolSize:20", "cloud.aws.loader.queueCapacity:0")
			.applyTo(this.context);

	// Act
	this.context.refresh();

	// Assert
	SimpleStorageProtocolResolver simpleStorageProtocolResolver = (SimpleStorageProtocolResolver) this.context
			.getProtocolResolvers().iterator().next();
	ThreadPoolTaskExecutor taskExecutor = (ThreadPoolTaskExecutor) ReflectionTestUtils
			.getField(simpleStorageProtocolResolver, "taskExecutor");
	assertThat(taskExecutor).isNotNull();

	assertThat(taskExecutor.getCorePoolSize()).isEqualTo(10);
	assertThat(taskExecutor.getMaxPoolSize()).isEqualTo(20);
	assertThat(ReflectionTestUtils.getField(taskExecutor, "queueCapacity"))
			.isEqualTo(0);
}
 
Example #2
Source File: ContextResourceLoaderAutoConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void createResourceLoader_withoutExecutorSettings_executorConfigured() {

	// Arrange
	this.context = new AnnotationConfigApplicationContext();
	this.context.register(ContextResourceLoaderAutoConfiguration.class);

	// Act
	this.context.refresh();

	// Assert
	SimpleStorageProtocolResolver simpleStorageProtocolResolver = (SimpleStorageProtocolResolver) this.context
			.getProtocolResolvers().iterator().next();
	SyncTaskExecutor taskExecutor = (SyncTaskExecutor) ReflectionTestUtils
			.getField(simpleStorageProtocolResolver, "taskExecutor");
	assertThat(taskExecutor).isNotNull();
}
 
Example #3
Source File: SimpleStorageProtocolResolverConfigurerTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
private static void configureApplicationContext(
		StaticApplicationContext staticApplicationContext) {
	AmazonS3 amazonS3Mock = mock(AmazonS3.class);

	AnnotationConfigUtils
			.registerAnnotationConfigProcessors(staticApplicationContext);

	BeanDefinitionBuilder loader = BeanDefinitionBuilder
			.genericBeanDefinition(SimpleStorageProtocolResolver.class);
	loader.addConstructorArgValue(amazonS3Mock);

	BeanDefinitionBuilder builder = BeanDefinitionBuilder
			.genericBeanDefinition(SimpleStorageProtocolResolverConfigurer.class);
	builder.addConstructorArgValue(loader.getBeanDefinition());
	AbstractBeanDefinition definition = builder.getBeanDefinition();

	staticApplicationContext.registerBeanDefinition(
			generateBeanName(definition, staticApplicationContext), definition);
}
 
Example #4
Source File: SimpleStorageProtocolResolverConfigurerTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void postProcessBeans_beanWithFieldInjectedResourceLoader_receivesSimpleStorageResourceLoader() {
	// Arrange
	StaticApplicationContext staticApplicationContext = new StaticApplicationContext();

	configureApplicationContext(staticApplicationContext);

	staticApplicationContext.registerSingleton("client", FieldInjectionTarget.class);
	staticApplicationContext.refresh();

	// Act
	FieldInjectionTarget fieldInjectionTarget = staticApplicationContext
			.getBean(FieldInjectionTarget.class);

	// Assert
	assertThat(fieldInjectionTarget.getResourceLoader()).isNotNull();
	assertThat(DefaultResourceLoader.class
			.isInstance(fieldInjectionTarget.getResourceLoader())).isTrue();

	DefaultResourceLoader defaultResourceLoader = (DefaultResourceLoader) fieldInjectionTarget
			.getResourceLoader();
	assertThat(SimpleStorageProtocolResolver.class.isInstance(
			defaultResourceLoader.getProtocolResolvers().iterator().next())).isTrue();
}
 
Example #5
Source File: SimpleStorageProtocolResolverConfigurerTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void postProcessBeans_beanWithResourceLoaderAwareInterface_receivesSimpleStorageResourceLoader() {
	StaticApplicationContext staticApplicationContext = new StaticApplicationContext();

	configureApplicationContext(staticApplicationContext);

	staticApplicationContext.registerSingleton("client",
			ResourceLoaderAwareBean.class);
	staticApplicationContext.refresh();

	ResourceLoaderAwareBean resourceLoaderAwareBean = staticApplicationContext
			.getBean(ResourceLoaderAwareBean.class);
	assertThat(resourceLoaderAwareBean.getResourceLoader()).isNotNull();
	assertThat(DefaultResourceLoader.class
			.isInstance(resourceLoaderAwareBean.getResourceLoader())).isTrue();

	assertThat(DefaultResourceLoader.class
			.isInstance(resourceLoaderAwareBean.getResourceLoader())).isTrue();

	DefaultResourceLoader defaultResourceLoader = (DefaultResourceLoader) resourceLoaderAwareBean
			.getResourceLoader();
	assertThat(SimpleStorageProtocolResolver.class.isInstance(
			defaultResourceLoader.getProtocolResolvers().iterator().next())).isTrue();
}
 
Example #6
Source File: ContextResourceLoaderConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void regionProvider_withConfiguredRegion_staticRegionProviderConfigured() {
	// Arrange
	this.context = new AnnotationConfigApplicationContext(
			ApplicationConfigurationWithResourceLoader.class);

	// Act
	ApplicationBean bean = this.context.getBean(ApplicationBean.class);

	// Assert
	assertThat(bean.getResourceLoader()).isNotNull();
	assertThat(DefaultResourceLoader.class.isInstance(bean.getResourceLoader()))
			.isTrue();

	DefaultResourceLoader defaultResourceLoader = (DefaultResourceLoader) bean
			.getResourceLoader();
	assertThat(SimpleStorageProtocolResolver.class.isInstance(
			defaultResourceLoader.getProtocolResolvers().iterator().next())).isTrue();
}
 
Example #7
Source File: S3StoreFactoryBean.java    From spring-content with Apache License 2.0 5 votes vote down vote up
@Override
protected Object getContentStoreImpl() {

	SimpleStorageProtocolResolver s3Protocol = new SimpleStorageProtocolResolver(client);
	s3Protocol.afterPropertiesSet();

	DefaultResourceLoader loader = new DefaultResourceLoader();
	loader.addProtocolResolver(s3Protocol);

	return new DefaultS3StoreImpl(loader, s3StorePlacementService, client);
}
 
Example #8
Source File: WallRideInitializer.java    From wallride with Apache License 2.0 5 votes vote down vote up
public static ResourceLoader createResourceLoader() {
	ClientConfiguration configuration = new ClientConfiguration();
	configuration.setMaxConnections(1000);
	AmazonS3 amazonS3 = new AmazonS3Client(configuration);

	SimpleStorageProtocolResolver protocolResolver = new SimpleStorageProtocolResolver(amazonS3);
	protocolResolver.afterPropertiesSet();
	DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
	resourceLoader.addProtocolResolver(protocolResolver);
	ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(resourceLoader);
	return new PathMatchingSimpleStorageResourcePatternResolver(amazonS3, resourceResolver);
}
 
Example #9
Source File: ContextResourceLoaderConfiguration.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
protected BeanDefinition getProtocolResolver(BeanDefinitionHolder client) {
	BeanDefinitionBuilder resolver = BeanDefinitionBuilder
			.rootBeanDefinition(SimpleStorageProtocolResolver.class);
	resolver.addConstructorArgReference(client.getBeanName());

	BeanDefinition taskExecutor = getTaskExecutorDefinition();
	if (taskExecutor != null) {
		resolver.addPropertyValue("taskExecutor", taskExecutor);
	}
	return resolver.getBeanDefinition();
}
 
Example #10
Source File: SimpleStorageProtocolResolverConfigurerTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void postProcessBeans_beanWithMethodInjectedResourceLoader_receivesSimpleStorageResourceLoader() {
	// Arrange
	StaticApplicationContext staticApplicationContext = new StaticApplicationContext();

	configureApplicationContext(staticApplicationContext);

	staticApplicationContext.registerSingleton("client", MethodInjectionTarget.class);

	staticApplicationContext.refresh();

	// Act
	MethodInjectionTarget methodInjectionTarget = staticApplicationContext
			.getBean(MethodInjectionTarget.class);

	// Assert
	assertThat(methodInjectionTarget.getResourceLoader()).isNotNull();
	assertThat(DefaultResourceLoader.class
			.isInstance(methodInjectionTarget.getResourceLoader())).isTrue();

	assertThat(DefaultResourceLoader.class
			.isInstance(methodInjectionTarget.getResourceLoader())).isTrue();

	DefaultResourceLoader defaultResourceLoader = (DefaultResourceLoader) methodInjectionTarget
			.getResourceLoader();
	assertThat(SimpleStorageProtocolResolver.class.isInstance(
			defaultResourceLoader.getProtocolResolvers().iterator().next())).isTrue();
}
 
Example #11
Source File: SimpleStorageProtocolResolverConfigurerTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void postProcessBeans_beanWithConstructorInjectedResourceLoader_receivesSimpleStorageResourceLoader() {
	// Arrange
	StaticApplicationContext staticApplicationContext = new StaticApplicationContext();

	configureApplicationContext(staticApplicationContext);

	staticApplicationContext.registerSingleton("client",
			ConstructorInjectionTarget.class);
	staticApplicationContext.refresh();

	// Act
	ConstructorInjectionTarget constructorInjectionTarget = staticApplicationContext
			.getBean(ConstructorInjectionTarget.class);

	// Assert
	assertThat(constructorInjectionTarget.getResourceLoader()).isNotNull();
	assertThat(DefaultResourceLoader.class
			.isInstance(constructorInjectionTarget.getResourceLoader())).isTrue();

	assertThat(DefaultResourceLoader.class
			.isInstance(constructorInjectionTarget.getResourceLoader())).isTrue();

	DefaultResourceLoader defaultResourceLoader = (DefaultResourceLoader) constructorInjectionTarget
			.getResourceLoader();
	assertThat(SimpleStorageProtocolResolver.class.isInstance(
			defaultResourceLoader.getProtocolResolvers().iterator().next())).isTrue();
}
 
Example #12
Source File: S3ProtocolResolverRegistrar.java    From genie with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * Add the {@link S3ProtocolResolver} to the set of protocol resolvers in the application context. Remove any
 * instances of {@link SimpleStorageProtocolResolver}.
 */
@Override
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
    if (applicationContext instanceof ConfigurableApplicationContext) {
        final ConfigurableApplicationContext configurableApplicationContext
            = (ConfigurableApplicationContext) applicationContext;

        if (configurableApplicationContext instanceof AbstractApplicationContext) {
            final AbstractApplicationContext abstractApplicationContext
                = (AbstractApplicationContext) configurableApplicationContext;

            final Collection<ProtocolResolver> protocolResolvers
                = abstractApplicationContext.getProtocolResolvers();

            final Set<ProtocolResolver> simpleStorageProtocolResolvers = protocolResolvers
                .stream()
                .filter(SimpleStorageProtocolResolver.class::isInstance)
                .collect(Collectors.toSet());

            protocolResolvers.removeAll(simpleStorageProtocolResolvers);
        }

        log.info(
            "Adding instance of {} to the set of protocol resolvers",
            this.s3ProtocolResolver.getClass().getCanonicalName()
        );
        configurableApplicationContext.addProtocolResolver(this.s3ProtocolResolver);
    }
}
 
Example #13
Source File: AwsAutoConfigurationTest.java    From genie with Apache License 2.0 5 votes vote down vote up
/**
 * Test expected context.
 */
@Test
void testExpectedContext() {
    this.contextRunner.run(
        (context) -> {
            Assertions.assertThat(context).hasSingleBean(AwsRegionProvider.class);
            Assertions.assertThat(context).hasSingleBean(S3ClientFactory.class);
            Assertions.assertThat(context).hasSingleBean(AwsS3ResourceLoaderProperties.class);
            Assertions.assertThat(context).hasSingleBean(S3ProtocolResolver.class);
            Assertions.assertThat(context).hasSingleBean(S3ProtocolResolverRegistrar.class);
            Assertions.assertThat(context).hasSingleBean(S3JobArchiverImpl.class);
            Assertions.assertThat(context).hasSingleBean(JobArchiver.class);

            // Verify that Spring Cloud AWS still would try to register their S3 protocol resolver
            Assertions.assertThat(context).hasSingleBean(SimpleStorageProtocolResolverConfigurer.class);

            // And Make sure we ripped out the one from Spring Cloud AWS and put ours in instead
            if (context instanceof AbstractApplicationContext) {
                final AbstractApplicationContext aac = (AbstractApplicationContext) context;
                final Collection<ProtocolResolver> protocolResolvers = aac.getProtocolResolvers();
                Assertions.assertThat(protocolResolvers).contains(context.getBean(S3ProtocolResolver.class));
                Assertions
                    .assertThat(protocolResolvers)
                    .doesNotHaveAnyElementsOfTypes(SimpleStorageProtocolResolver.class);
            }
        }
    );
}
 
Example #14
Source File: SimpleStorageProtocolResolverConfigurer.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
public SimpleStorageProtocolResolverConfigurer(
		SimpleStorageProtocolResolver simpleStorageProtocolResolver) {
	this.resourceLoader = simpleStorageProtocolResolver;
}