Skip to content

Commit 3429836

Browse files
committed
#22 some minor improvements
1 parent dcc8393 commit 3429836

20 files changed

+156
-151
lines changed

README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Docker provides the greatest flexibility, but it can be slightly slower than the
207207
However, the change of database providers is really easy, so you can try them all.
208208

209209
You can either configure a provider for each class separately by `@AutoConfigureEmbeddedDatabase(provider = ...)` annotation,
210-
or through `embedded-database.provider` property globally.
210+
or through `zonky.test.database.provider` property globally.
211211

212212
| | [Docker][docker-provider] | [Zonky][zonky-provider] | [OpenTable][opentable-provider] | [Yandex][yandex-provider] |
213213
|:---------------------------------:|:------------------------------------:|:-----------------------------------------------:|:-------------------------------:|:-------------------------:|
@@ -231,22 +231,22 @@ The `@AutoConfigureEmbeddedDatabase` annotation can be used for some basic confi
231231
The following configuration keys are used by all providers:
232232

233233
```properties
234-
embedded-database.provider=zonky # Provider used to create the underlying embedded database, see the documentation for the comparision matrix.
235-
embedded-database.postgres.client.properties.*= # Additional properties used to configure the test data source.
236-
embedded-database.postgres.initdb.properties.*= # Additional properties to pass to initdb command during the database initialization.
237-
embedded-database.postgres.server.properties.*= # Additional properties used to configure the embedded PostgreSQL server.
234+
zonky.test.database.provider=zonky # Provider used to create the underlying embedded database, see the documentation for the comparision matrix.
235+
zonky.test.database.postgres.client.properties.*= # Additional properties used to configure the test data source.
236+
zonky.test.database.postgres.initdb.properties.*= # Additional properties to pass to initdb command during the database initialization.
237+
zonky.test.database.postgres.server.properties.*= # Additional properties used to configure the embedded PostgreSQL server.
238238
```
239239

240240
Note that the library includes [configuration metadata](embedded-database-spring-test/src/main/resources/META-INF/spring-configuration-metadata.json) that offer contextual help and code completion as users are working with Spring Boot's `application.properties` or `application.yml` files.
241241

242242
**Example configuration:**
243243
```properties
244-
embedded-database.postgres.client.properties.stringtype=unspecified
245-
embedded-database.postgres.initdb.properties.lc-collate=cs_CZ.UTF-8
246-
embedded-database.postgres.initdb.properties.lc-monetary=cs_CZ.UTF-8
247-
embedded-database.postgres.initdb.properties.lc-numeric=cs_CZ.UTF-8
248-
embedded-database.postgres.server.properties.shared_buffers=512MB
249-
embedded-database.postgres.server.properties.max_connections=100
244+
zonky.test.database.postgres.client.properties.stringtype=unspecified
245+
zonky.test.database.postgres.initdb.properties.lc-collate=cs_CZ.UTF-8
246+
zonky.test.database.postgres.initdb.properties.lc-monetary=cs_CZ.UTF-8
247+
zonky.test.database.postgres.initdb.properties.lc-numeric=cs_CZ.UTF-8
248+
zonky.test.database.postgres.server.properties.shared_buffers=512MB
249+
zonky.test.database.postgres.server.properties.max_connections=100
250250
```
251251

252252
### Using Zonky Provider (default)
@@ -394,12 +394,12 @@ public class DockerProviderIntegrationTest {
394394

395395
#### Docker-specific provider configuration
396396

397-
The provider configuration can be controlled by properties in the `embedded-database.postgres.docker` group.
397+
The provider configuration can be controlled by properties in the `zonky.test.database.postgres.docker` group.
398398

399399
```properties
400-
embedded-database.postgres.docker.image=postgres:10.6-alpine # Docker image containing PostgreSQL database.
401-
embedded-database.postgres.docker.tmpfs.enabled=false # Whether to mount postgres data directory as tmpfs.
402-
embedded-database.postgres.docker.tmpfs.options=rw,noexec,nosuid # Mount options used to configure the tmpfs filesystem.
400+
zonky.test.database.postgres.docker.image=postgres:10.6-alpine # Docker image containing PostgreSQL database.
401+
zonky.test.database.postgres.docker.tmpfs.enabled=false # Whether to mount postgres data directory as tmpfs.
402+
zonky.test.database.postgres.docker.tmpfs.options=rw,noexec,nosuid # Mount options used to configure the tmpfs filesystem.
403403
```
404404

405405
### Using OpenTable Provider
@@ -477,20 +477,20 @@ public class YandexProviderIntegrationTest {
477477

478478
#### Yandex-specific provider configuration
479479

480-
The provider configuration can be controlled by properties in the `embedded-database.postgres.yandex-provider` group.
480+
The provider configuration can be controlled by properties in the `zonky.test.database.postgres.yandex-provider` group.
481481

482482
```properties
483-
embedded-database.postgres.yandex-provider.postgres-version=10.6-1 # Version of EnterpriseDB PostgreSQL binaries (https://www.enterprisedb.com/download-postgresql-binaries).
483+
zonky.test.database.postgres.yandex-provider.postgres-version=10.6-1 # Version of EnterpriseDB PostgreSQL binaries (https://www.enterprisedb.com/download-postgresql-binaries).
484484
```
485485

486486
### Database Prefetching
487487

488-
Database prefetching is used to speed up the database initialization. It can be customized by properties in the `embedded-database.prefetching` group.
488+
Database prefetching is used to speed up the database initialization. It can be customized by properties in the `zonky.test.database.prefetching` group.
489489

490490
```properties
491-
embedded-database.prefetching.thread-name-prefix=prefetching- # Prefix to use for the names of database prefetching threads.
492-
embedded-database.prefetching.concurrency=3 # Maximum number of concurrently running database prefetching threads.
493-
embedded-database.prefetching.pipeline-cache-size=3 # Maximum number of prepared databases per pipeline.
491+
zonky.test.database.prefetching.thread-name-prefix=prefetching- # Prefix to use for the names of database prefetching threads.
492+
zonky.test.database.prefetching.concurrency=3 # Maximum number of concurrently running database prefetching threads.
493+
zonky.test.database.prefetching.pipeline-cache-size=3 # Maximum number of prepared databases per pipeline.
494494
```
495495

496496
### Disabling auto-configuration
@@ -620,7 +620,7 @@ Since version 1.4.0, database prefetching has been improved. All databases are s
620620
It speeds up the preparation of databases, but in some rare cases, if your database scripts use some global objects inappropriately, this change can cause problems. If necessary, you can change this behavior back by setting the following property:
621621

622622
```properties
623-
embedded-database.postgres.zonky-provider.preparer-isolation=cluster
623+
zonky.test.database.postgres.zonky-provider.preparer-isolation=cluster
624624
```
625625

626626
## Building from Source

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ ext {
2929

3030
[core: '5.0.7', test: '5.0.0'] // default version
3131
]
32-
embeddedPostgresVersions = ['9.3.25', '9.4.20', '9.5.15', '9.6.11', '10.6.0', '11.1.0']
32+
// embeddedPostgresVersions = ['9.3.25', '9.4.20', '9.5.15', '9.6.11', '10.6.0', '11.1.0']
33+
embeddedPostgresVersions = ['9.3.25', '9.4.20', '9.5.15', '9.6.11', '10.6.0'] // TODO: OpenTable and Yandex providers don't support Postgres11+ on Linux Platform
3334

3435
flywayCoreVersion = flywayVersions.last().core
3536
flywayTestVersion = flywayVersions.last().test

embedded-database-spring-test/src/main/java/io/zonky/test/db/AutoConfigureEmbeddedDatabase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
* Provider used to create the underlying embedded database,
7070
* see the documentation for the comparision matrix.
7171
* Note that the provider can also be configured
72-
* through {@code embedded-database.provider} property.
72+
* through {@code zonky.test.database.provider} property.
7373
*
7474
* @return the provider of an embedded database
7575
*/

embedded-database-spring-test/src/main/java/io/zonky/test/db/postgres/EmbeddedPostgresContextCustomizerFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161

6262
import javax.sql.DataSource;
6363
import java.lang.reflect.AnnotatedElement;
64+
import java.util.LinkedHashSet;
6465
import java.util.List;
6566
import java.util.Set;
6667
import java.util.concurrent.ConcurrentHashMap;
@@ -94,7 +95,7 @@ public ContextCustomizer createContextCustomizer(Class<?> testClass, List<Contex
9495
.filter(distinctByKey(AutoConfigureEmbeddedDatabase::beanName))
9596
.filter(databaseAnnotation -> databaseAnnotation.type() == EmbeddedDatabaseType.POSTGRES)
9697
.filter(databaseAnnotation -> databaseAnnotation.replace() != Replace.NONE)
97-
.collect(Collectors.toSet());
98+
.collect(Collectors.toCollection(LinkedHashSet::new));
9899

99100
if (!databaseAnnotations.isEmpty()) {
100101
return new PreloadableEmbeddedPostgresContextCustomizer(databaseAnnotations);
@@ -253,7 +254,7 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
253254

254255
protected DatabaseDescriptor resolveDatabaseDescriptor(Environment environment, AutoConfigureEmbeddedDatabase databaseAnnotation) {
255256
String providerName = databaseAnnotation.provider() != DEFAULT ? databaseAnnotation.provider().name() :
256-
environment.getProperty("embedded-database.provider", ProviderType.ZONKY.toString());
257+
environment.getProperty("zonky.test.database.provider", ProviderType.ZONKY.toString());
257258
return new DatabaseDescriptor(DatabaseType.POSTGRES, ProviderType.valueOf(providerName));
258259
}
259260
}

embedded-database-spring-test/src/main/java/io/zonky/test/db/provider/impl/DockerPostgresDatabaseProvider.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ public DatabaseInstance load(DatabaseConfig config) {
6565
private final ClientConfig clientConfig;
6666

6767
public DockerPostgresDatabaseProvider(Environment environment) {
68-
String dockerImage = environment.getProperty("embedded-database.postgres.docker.image", "postgres:10.6-alpine");
69-
String tmpfsOptions = environment.getProperty("embedded-database.postgres.docker.tmpfs.options", "rw,noexec,nosuid");
70-
boolean tmpfsEnabled = environment.getProperty("embedded-database.postgres.docker.tmpfs.enabled", boolean.class, false);
68+
String dockerImage = environment.getProperty("zonky.test.database.postgres.docker.image", "postgres:10.6-alpine");
69+
String tmpfsOptions = environment.getProperty("zonky.test.database.postgres.docker.tmpfs.options", "rw,noexec,nosuid");
70+
boolean tmpfsEnabled = environment.getProperty("zonky.test.database.postgres.docker.tmpfs.enabled", boolean.class, false);
7171

72-
Map<String, String> initdbProperties = PropertyUtils.extractAll(environment, "embedded-database.postgres.initdb.properties");
73-
Map<String, String> configProperties = PropertyUtils.extractAll(environment, "embedded-database.postgres.server.properties");
74-
Map<String, String> connectProperties = PropertyUtils.extractAll(environment, "embedded-database.postgres.client.properties");
72+
Map<String, String> initdbProperties = PropertyUtils.extractAll(environment, "zonky.test.database.postgres.initdb.properties");
73+
Map<String, String> configProperties = PropertyUtils.extractAll(environment, "zonky.test.database.postgres.server.properties");
74+
Map<String, String> connectProperties = PropertyUtils.extractAll(environment, "zonky.test.database.postgres.client.properties");
7575

7676
this.databaseConfig = new DatabaseConfig(dockerImage, tmpfsOptions, tmpfsEnabled, initdbProperties, configProperties);
7777
this.clientConfig = new ClientConfig(connectProperties);

embedded-database-spring-test/src/main/java/io/zonky/test/db/provider/impl/OpenTablePostgresDatabaseProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ public DatabaseInstance load(DatabaseConfig config) throws IOException {
6464
private final ClientConfig clientConfig;
6565

6666
public OpenTablePostgresDatabaseProvider(Environment environment, ObjectProvider<List<Consumer<EmbeddedPostgres.Builder>>> databaseCustomizers) {
67-
Map<String, String> initdbProperties = PropertyUtils.extractAll(environment, "embedded-database.postgres.initdb.properties");
68-
Map<String, String> configProperties = PropertyUtils.extractAll(environment, "embedded-database.postgres.server.properties");
69-
Map<String, String> connectProperties = PropertyUtils.extractAll(environment, "embedded-database.postgres.client.properties");
67+
Map<String, String> initdbProperties = PropertyUtils.extractAll(environment, "zonky.test.database.postgres.initdb.properties");
68+
Map<String, String> configProperties = PropertyUtils.extractAll(environment, "zonky.test.database.postgres.server.properties");
69+
Map<String, String> connectProperties = PropertyUtils.extractAll(environment, "zonky.test.database.postgres.client.properties");
7070
List<Consumer<EmbeddedPostgres.Builder>> customizers = Optional.ofNullable(databaseCustomizers.getIfAvailable()).orElse(emptyList());
7171

7272
this.databaseConfig = new DatabaseConfig(initdbProperties, configProperties, customizers);

embedded-database-spring-test/src/main/java/io/zonky/test/db/provider/impl/PrefetchingDatabaseProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ public PrefetchingDatabaseProvider(ObjectProvider<List<DatabaseProvider>> databa
7979
this.databaseProviders = Optional.ofNullable(databaseProviders.getIfAvailable()).orElse(emptyList()).stream()
8080
.collect(Collectors.toMap(p -> new DatabaseDescriptor(p.getDatabaseType(), p.getProviderType()), identity()));
8181

82-
String threadNamePrefix = environment.getProperty("embedded-database.prefetching.thread-name-prefix", "prefetching-");
83-
int concurrency = environment.getProperty("embedded-database.prefetching.concurrency", int.class, 3);
84-
pipelineCacheSize = environment.getProperty("embedded-database.prefetching.pipeline-cache-size", int.class, 3);
82+
String threadNamePrefix = environment.getProperty("zonky.test.database.prefetching.thread-name-prefix", "prefetching-");
83+
int concurrency = environment.getProperty("zonky.test.database.prefetching.concurrency", int.class, 3);
84+
pipelineCacheSize = environment.getProperty("zonky.test.database.prefetching.pipeline-cache-size", int.class, 3);
8585

8686
taskExecutor.setThreadNamePrefix(threadNamePrefix);
8787
taskExecutor.setCorePoolSize(concurrency);

embedded-database-spring-test/src/main/java/io/zonky/test/db/provider/impl/YandexPostgresDatabaseProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ public DatabaseInstance load(DatabaseConfig config) throws IOException {
6868
private final ClientConfig clientConfig;
6969

7070
public YandexPostgresDatabaseProvider(Environment environment) {
71-
String postgresVersion = environment.getProperty("embedded-database.postgres.yandex-provider.postgres-version", "10.6-1");
71+
String postgresVersion = environment.getProperty("zonky.test.database.postgres.yandex-provider.postgres-version", "10.6-1");
7272

73-
Map<String, String> initdbProperties = PropertyUtils.extractAll(environment, "embedded-database.postgres.initdb.properties");
74-
Map<String, String> configProperties = PropertyUtils.extractAll(environment, "embedded-database.postgres.server.properties");
75-
Map<String, String> connectProperties = PropertyUtils.extractAll(environment, "embedded-database.postgres.client.properties");
73+
Map<String, String> initdbProperties = PropertyUtils.extractAll(environment, "zonky.test.database.postgres.initdb.properties");
74+
Map<String, String> configProperties = PropertyUtils.extractAll(environment, "zonky.test.database.postgres.server.properties");
75+
Map<String, String> connectProperties = PropertyUtils.extractAll(environment, "zonky.test.database.postgres.client.properties");
7676

7777
this.databaseConfig = new DatabaseConfig(new GenericVersion(postgresVersion), initdbProperties, configProperties);
7878
this.clientConfig = new ClientConfig(connectProperties);

embedded-database-spring-test/src/main/java/io/zonky/test/db/provider/impl/ZonkyPostgresDatabaseProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ public DatabaseInstance load(ClusterKey key) throws IOException {
6464
private final ClientConfig clientConfig;
6565

6666
public ZonkyPostgresDatabaseProvider(Environment environment, ObjectProvider<List<Consumer<EmbeddedPostgres.Builder>>> databaseCustomizers) {
67-
String preparerIsolation = environment.getProperty("embedded-database.postgres.zonky-provider.preparer-isolation", "database");
67+
String preparerIsolation = environment.getProperty("zonky.test.database.postgres.zonky-provider.preparer-isolation", "database");
6868
PreparerIsolation isolation = PreparerIsolation.valueOf(preparerIsolation.toUpperCase());
6969

70-
Map<String, String> initdbProperties = PropertyUtils.extractAll(environment, "embedded-database.postgres.initdb.properties");
71-
Map<String, String> configProperties = PropertyUtils.extractAll(environment, "embedded-database.postgres.server.properties");
72-
Map<String, String> connectProperties = PropertyUtils.extractAll(environment, "embedded-database.postgres.client.properties");
70+
Map<String, String> initdbProperties = PropertyUtils.extractAll(environment, "zonky.test.database.postgres.initdb.properties");
71+
Map<String, String> configProperties = PropertyUtils.extractAll(environment, "zonky.test.database.postgres.server.properties");
72+
Map<String, String> connectProperties = PropertyUtils.extractAll(environment, "zonky.test.database.postgres.client.properties");
7373
List<Consumer<EmbeddedPostgres.Builder>> customizers = Optional.ofNullable(databaseCustomizers.getIfAvailable()).orElse(emptyList());
7474

7575
this.databaseConfig = new DatabaseConfig(initdbProperties, configProperties, customizers, isolation);

0 commit comments

Comments
 (0)