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