|
21 | 21 |
|
22 | 22 | import java.lang.reflect.Field;
|
23 | 23 | import java.lang.reflect.Modifier;
|
24 |
| -import java.util.Arrays; |
25 |
| -import java.util.Collections; |
26 |
| -import java.util.HashMap; |
27 |
| -import java.util.HashSet; |
28 | 24 | import java.util.List;
|
29 | 25 | import java.util.Locale;
|
| 26 | +import java.util.Map; |
30 | 27 | import java.util.Optional;
|
31 | 28 | import java.util.Set;
|
32 | 29 |
|
@@ -83,10 +80,11 @@ public class Neo4jExtension implements BeforeAllCallback, BeforeEachCallback {
|
83 | 80 | private static final String SYS_PROPERTY_NEO4J_ACCEPT_COMMERCIAL_EDITION = "SDN_NEO4J_ACCEPT_COMMERCIAL_EDITION";
|
84 | 81 | private static final String SYS_PROPERTY_NEO4J_REPOSITORY = "SDN_NEO4J_REPOSITORY";
|
85 | 82 | private static final String SYS_PROPERTY_NEO4J_VERSION = "SDN_NEO4J_VERSION";
|
| 83 | + private static final String SYS_PROPERTY_FORCE_CONTAINER_REUSE = "SDN_FORCE_REUSE_OF_CONTAINERS"; |
86 | 84 |
|
87 |
| - private static Set<String> COMMUNITY_EDITION_INDICATOR = Collections.singleton("community"); |
| 85 | + private static Set<String> COMMUNITY_EDITION_INDICATOR = Set.of("community"); |
88 | 86 |
|
89 |
| - private static Set<String> COMMERCIAL_EDITION_INDICATOR = new HashSet<>(Arrays.asList("commercial", "enterprise")); |
| 87 | + private static Set<String> COMMERCIAL_EDITION_INDICATOR = Set.of("commercial", "enterprise"); |
90 | 88 |
|
91 | 89 | @Override
|
92 | 90 | public void beforeAll(ExtensionContext context) throws Exception {
|
@@ -291,35 +289,36 @@ public void close() {
|
291 | 289 |
|
292 | 290 | static class ContainerAdapter implements ExtensionContext.Store.CloseableResource {
|
293 | 291 |
|
294 |
| - private final String repository = Optional.ofNullable(System.getenv(SYS_PROPERTY_NEO4J_REPOSITORY)).orElse("neo4j"); |
| 292 | + private static final String repository = Optional.ofNullable(System.getenv(SYS_PROPERTY_NEO4J_REPOSITORY)).orElse("neo4j"); |
295 | 293 |
|
296 |
| - private final String imageVersion = Optional.ofNullable(System.getenv(SYS_PROPERTY_NEO4J_VERSION)).orElse("5"); |
| 294 | + private static final String imageVersion = Optional.ofNullable(System.getenv(SYS_PROPERTY_NEO4J_VERSION)).orElse("5"); |
297 | 295 |
|
298 |
| - private final boolean containerReuseSupported = TestcontainersConfiguration |
| 296 | + private static final boolean containerReuseSupported = TestcontainersConfiguration |
299 | 297 | .getInstance().environmentSupportsReuse();
|
300 | 298 |
|
301 |
| - private final Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>(repository + ":" + imageVersion) |
| 299 | + private static final boolean forceReuse = Boolean.parseBoolean(System.getenv(SYS_PROPERTY_FORCE_CONTAINER_REUSE)); |
| 300 | + |
| 301 | + private static final Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>(repository + ":" + imageVersion) |
302 | 302 | .withoutAuthentication()
|
303 | 303 | .withEnv("NEO4J_ACCEPT_LICENSE_AGREEMENT",
|
304 | 304 | Optional.ofNullable(System.getenv(SYS_PROPERTY_NEO4J_ACCEPT_COMMERCIAL_EDITION)).orElse("no"))
|
305 |
| - .withTmpFs(new HashMap<String, String>() {{ // K.W. Gedächtnis-Double-Brace-Initialization |
306 |
| - put("/log", "rw"); |
307 |
| - put("/data", "rw"); |
308 |
| - }}) |
| 305 | + .withTmpFs(Map.of("/log", "rw", "/data", "rw")) |
309 | 306 | .withReuse(containerReuseSupported);
|
310 | 307 |
|
311 | 308 | public String getBoltUrl() {
|
312 | 309 | return neo4jContainer.getBoltUrl();
|
313 | 310 | }
|
314 | 311 |
|
315 | 312 | public void start() {
|
316 |
| - neo4jContainer.start(); |
| 313 | + if (!neo4jContainer.isRunning()) { |
| 314 | + neo4jContainer.start(); |
| 315 | + } |
317 | 316 | }
|
318 | 317 |
|
319 | 318 | @Override
|
320 | 319 | public void close() {
|
321 |
| - if (!containerReuseSupported) { |
322 |
| - this.neo4jContainer.close(); |
| 320 | + if (!(containerReuseSupported || forceReuse)) { |
| 321 | + neo4jContainer.close(); |
323 | 322 | }
|
324 | 323 | }
|
325 | 324 | }
|
|
0 commit comments