use of com.github.nosan.embedded.cassandra.commons.UrlResource in project embedded-cassandra by nosan.
the class DefaultCassandraDatabaseFactoryTests method setConfigPropertyUriResource.
@Test
void setConfigPropertyUriResource(@TempDir Path workingDirectory) throws Exception {
UrlResource resource = new UrlResource(new URL("http://localhost:8080/cassandra.yaml"));
this.configProperties.put("test", resource);
CassandraDatabase database = create(Version.parse("4.0"), workingDirectory);
Map<String, Object> configProperties = database.getConfigProperties();
assertThat(configProperties.get("test")).isEqualTo(resource.toURI().toString());
}
use of com.github.nosan.embedded.cassandra.commons.UrlResource in project embedded-cassandra-spring-boot-starter by nosan.
the class EmbeddedCassandraAutoConfiguration method embeddedCassandraBuilder.
@Bean
@ConditionalOnMissingBean
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
CassandraBuilder embeddedCassandraBuilder(EmbeddedCassandraProperties properties, ObjectProvider<CassandraBuilderConfigurator> configurators) throws IOException {
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
CassandraBuilder builder = new CassandraBuilder();
builder.addEnvironmentVariables(properties.getEnvironmentVariables());
builder.addSystemProperties(properties.getSystemProperties());
builder.addConfigProperties(properties.getConfigProperties());
builder.addJvmOptions(properties.getJvmOptions());
map.from(properties::getRegisterShutdownHook).to(builder::registerShutdownHook);
map.from(properties::getVersion).whenHasText().to(builder::version);
map.from(properties::getLogger).whenHasText().as(Logger::get).to(builder::logger);
map.from(properties::getName).whenHasText().to(builder::name);
map.from(properties::getWorkingDirectory).to(workingDirectory -> builder.workingDirectory(() -> workingDirectory));
map.from(properties::getStartupTimeout).whenNot(Duration::isNegative).whenNot(Duration::isZero).to(builder::startupTimeout);
Resource configFile = properties.getConfigFile();
if (configFile != null) {
builder.configFile(new UrlResource(configFile.getURL()));
}
for (Map.Entry<String, Resource> entry : properties.getWorkingDirectoryResources().entrySet()) {
builder.addWorkingDirectoryResource(new UrlResource(entry.getValue().getURL()), entry.getKey());
}
configurators.orderedStream().forEach(builder::configure);
return builder;
}
use of com.github.nosan.embedded.cassandra.commons.UrlResource in project embedded-cassandra-spring-boot-starter by nosan.
the class EmbeddedCassandraAutoConfigurationTests method configureProperties.
@Test
void configureProperties() {
this.runner.withUserConfiguration(ExcludeCassandraBeanDefinitionRegistryPostProcessor.class).withPropertyValues("cassandra.embedded.config-file=classpath:cassandra.yaml", "cassandra.embedded.config-properties.start_rpc=true", "cassandra.embedded.environment-variables.JVM_OPTS=-Xmx512m", "cassandra.embedded.jvm-options=-Xmx256m", "cassandra.embedded.logger=MyLogger", "cassandra.embedded.version=3.11.3", "cassandra.embedded.name=MyCassandra", "cassandra.embedded.register-shutdown-hook=false", "cassandra.embedded.system-properties.cassandra.start_rpc=true", "cassandra.embedded.startup-timeout=1m", "cassandra.embedded.working-directory-resources.[conf/cassandra.yaml]=classpath:cassandra.yaml", "cassandra.embedded.working-directory=target/embeddedCassandra").withBean(CassandraBuilderConfigurator.class, () -> (builder) -> builder.addJvmOptions("-Xmx1024m")).run(context -> {
assertThat(context).hasSingleBean(CassandraBuilder.class);
Cassandra cassandra = context.getBean(CassandraBuilder.class).build();
assertThat(cassandra).hasFieldOrPropertyWithValue("databaseFactory.jvmOptions", new LinkedHashSet<>(Arrays.asList("-Xmx256m", "-Xmx1024m")));
assertThat(cassandra).hasFieldOrPropertyWithValue("logger", Logger.get("MyLogger"));
assertThat(cassandra).hasFieldOrPropertyWithValue("name", "MyCassandra");
assertThat(cassandra).hasFieldOrPropertyWithValue("version", Version.parse("3.11.3"));
assertThat(cassandra).hasFieldOrPropertyWithValue("registerShutdownHook", false);
assertThat(cassandra).hasFieldOrPropertyWithValue("startupTimeout", Duration.ofMinutes(1));
assertThat(cassandra).hasFieldOrPropertyWithValue("workingDirectory", Paths.get("target/embeddedCassandra").toAbsolutePath());
assertThat(cassandra).hasFieldOrPropertyWithValue("databaseFactory.environmentVariables", Collections.singletonMap("JVM_OPTS", "-Xmx512m"));
Map<String, Object> systemProperties = new LinkedHashMap<>();
systemProperties.put("cassandra.start_rpc", "true");
systemProperties.put("cassandra.config", new UrlResource(new ClassPathResource("cassandra.yaml").getURL()));
assertThat(cassandra).hasFieldOrPropertyWithValue("databaseFactory.systemProperties", systemProperties);
assertThat((Collection<?>) ReflectionTestUtils.getField(cassandra, "workingDirectoryCustomizers")).hasSize(1);
});
}
Aggregations