use of com.github.nosan.embedded.cassandra.commons.web.JdkHttpClient in project embedded-cassandra by nosan.
the class WebCassandraDirectoryProviderTests method beforeAll.
@BeforeAll
static void beforeAll() throws IOException {
httpServer = HttpServer.create(new InetSocketAddress(0), 0);
httpServer.createContext("/", exchange -> {
String uri = exchange.getRequestURI().toString();
ClassPathResource resource = new ClassPathResource(uri.substring(uri.lastIndexOf('/')));
long size = Files.size(Paths.get(resource.toURI()));
exchange.sendResponseHeaders(200, size);
try (InputStream inputStream = resource.getInputStream()) {
StreamUtils.copy(inputStream, exchange.getResponseBody());
} finally {
exchange.close();
}
});
httpServer.setExecutor(Executors.newCachedThreadPool());
httpServer.start();
httpClient = new JdkHttpClient(Duration.ofSeconds(1), Duration.ofSeconds(1));
}
use of com.github.nosan.embedded.cassandra.commons.web.JdkHttpClient in project embedded-cassandra by nosan.
the class WebCassandraDirectoryProviderTests method construct2.
@Test
void construct2() {
JdkHttpClient httpClient = new JdkHttpClient();
WebCassandraDirectoryProvider wcdp = new WebCassandraDirectoryProvider(httpClient);
assertThat(wcdp).hasFieldOrPropertyWithValue("httpClient", httpClient);
assertThat(wcdp).hasFieldOrPropertyWithValue("downloadDirectory", Paths.get(System.getProperty("user.home")));
}
use of com.github.nosan.embedded.cassandra.commons.web.JdkHttpClient in project embedded-cassandra by nosan.
the class CassandraBuilder method build.
/**
* Build a new {@link Cassandra} instance.
*
* @return a {@link Cassandra} instance.
*/
public Cassandra build() {
String name = (this.name != null) ? this.name : "cassandra-" + CASSANDRA_ID.getAndIncrement();
Version version = (this.version != null) ? this.version : DEFAULT_VERSION;
Path workingDirectory;
try {
IOSupplier<? extends Path> workingDirectorySupplier = this.workingDirectorySupplier;
if (workingDirectorySupplier != null) {
workingDirectory = workingDirectorySupplier.get();
Objects.requireNonNull(workingDirectory, "Working Directory must not be null");
} else {
workingDirectory = Files.createTempDirectory("");
}
} catch (IOException ex) {
throw new UncheckedIOException("Unable to get a working directory", ex);
}
WorkingDirectoryInitializer workingDirectoryInitializer = this.workingDirectoryInitializer;
if (workingDirectoryInitializer == null) {
workingDirectoryInitializer = new DefaultWorkingDirectoryInitializer(new WebCassandraDirectoryProvider(new JdkHttpClient(Duration.ofSeconds(30), Duration.ofSeconds(30))));
}
WorkingDirectoryDestroyer workingDirectoryDestroyer = this.workingDirectoryDestroyer;
if (workingDirectoryDestroyer == null) {
workingDirectoryDestroyer = WorkingDirectoryDestroyer.deleteOnly("bin", "pylib", "lib", "tools", "doc", "javadoc", "interface");
}
Duration startupTimeout = this.startupTimeout;
if (startupTimeout == null) {
startupTimeout = Duration.ofMinutes(2);
}
Logger logger = this.logger;
if (logger == null) {
logger = Logger.get(Cassandra.class);
}
Map<String, Object> environmentVariables = new LinkedHashMap<>(this.environmentVariables);
environmentVariables.values().removeIf(Objects::isNull);
Map<String, Object> systemProperties = new LinkedHashMap<>(this.systemProperties);
systemProperties.values().removeIf(Objects::isNull);
Set<String> jvmOptions = new LinkedHashSet<>(this.jvmOptions);
jvmOptions.removeIf(Objects::isNull);
Set<WorkingDirectoryCustomizer> workingDirectoryCustomizers = new LinkedHashSet<>(this.workingDirectoryCustomizers);
workingDirectoryCustomizers.removeIf(Objects::isNull);
Map<String, Object> configProperties = new LinkedHashMap<>(this.configProperties);
CassandraDatabaseFactory databaseFactory = new DefaultCassandraDatabaseFactory(name, version, environmentVariables, configProperties, systemProperties, jvmOptions);
return new DefaultCassandra(name, version, workingDirectory.normalize().toAbsolutePath(), this.registerShutdownHook, workingDirectoryInitializer, workingDirectoryDestroyer, startupTimeout, workingDirectoryCustomizers, databaseFactory, logger);
}
Aggregations