|
38 | 38 |
|
39 | 39 | import java.lang.reflect.Field;
|
40 | 40 | import java.lang.reflect.Modifier;
|
41 |
| -import java.util.Arrays; |
42 |
| -import java.util.Collections; |
43 |
| -import java.util.HashMap; |
44 |
| -import java.util.HashSet; |
45 | 41 | import java.util.List;
|
46 | 42 | import java.util.Locale;
|
| 43 | +import java.util.Map; |
47 | 44 | import java.util.Optional;
|
48 | 45 | import java.util.Set;
|
49 | 46 |
|
@@ -82,11 +79,12 @@ public class Neo4jExtension implements BeforeAllCallback, BeforeEachCallback {
|
82 | 79 | private static final String SYS_PROPERTY_NEO4J_ACCEPT_COMMERCIAL_EDITION = "SDN_NEO4J_ACCEPT_COMMERCIAL_EDITION";
|
83 | 80 | private static final String SYS_PROPERTY_NEO4J_REPOSITORY = "SDN_NEO4J_REPOSITORY";
|
84 | 81 | private static final String SYS_PROPERTY_NEO4J_VERSION = "SDN_NEO4J_VERSION";
|
| 82 | + private static final String SYS_PROPERTY_FORCE_CONTAINER_REUSE = "SDN_FORCE_REUSE_OF_CONTAINERS"; |
85 | 83 | private static final Log log = org.apache.commons.logging.LogFactory.getLog(Neo4jExtension.class);
|
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 {
|
@@ -295,35 +293,36 @@ public void close() {
|
295 | 293 |
|
296 | 294 | static class ContainerAdapter implements ExtensionContext.Store.CloseableResource {
|
297 | 295 |
|
298 |
| - private final String repository = Optional.ofNullable(System.getenv(SYS_PROPERTY_NEO4J_REPOSITORY)).orElse("neo4j"); |
| 296 | + private static final String repository = Optional.ofNullable(System.getenv(SYS_PROPERTY_NEO4J_REPOSITORY)).orElse("neo4j"); |
299 | 297 |
|
300 |
| - private final String imageVersion = Optional.ofNullable(System.getenv(SYS_PROPERTY_NEO4J_VERSION)).orElse("5"); |
| 298 | + private static final String imageVersion = Optional.ofNullable(System.getenv(SYS_PROPERTY_NEO4J_VERSION)).orElse("5"); |
301 | 299 |
|
302 |
| - private final boolean containerReuseSupported = TestcontainersConfiguration |
| 300 | + private static final boolean containerReuseSupported = TestcontainersConfiguration |
303 | 301 | .getInstance().environmentSupportsReuse();
|
304 | 302 |
|
305 |
| - private final Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>(repository + ":" + imageVersion) |
| 303 | + private static final boolean forceReuse = Boolean.parseBoolean(System.getenv(SYS_PROPERTY_FORCE_CONTAINER_REUSE)); |
| 304 | + |
| 305 | + private static final Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>(repository + ":" + imageVersion) |
306 | 306 | .withoutAuthentication()
|
307 | 307 | .withEnv("NEO4J_ACCEPT_LICENSE_AGREEMENT",
|
308 | 308 | Optional.ofNullable(System.getenv(SYS_PROPERTY_NEO4J_ACCEPT_COMMERCIAL_EDITION)).orElse("no"))
|
309 |
| - .withTmpFs(new HashMap<String, String>() {{ // K.W. Gedächtnis-Double-Brace-Initialization |
310 |
| - put("/log", "rw"); |
311 |
| - put("/data", "rw"); |
312 |
| - }}) |
| 309 | + .withTmpFs(Map.of("/log", "rw", "/data", "rw")) |
313 | 310 | .withReuse(containerReuseSupported);
|
314 | 311 |
|
315 | 312 | public String getBoltUrl() {
|
316 | 313 | return neo4jContainer.getBoltUrl();
|
317 | 314 | }
|
318 | 315 |
|
319 | 316 | public void start() {
|
320 |
| - neo4jContainer.start(); |
| 317 | + if (!neo4jContainer.isRunning()) { |
| 318 | + neo4jContainer.start(); |
| 319 | + } |
321 | 320 | }
|
322 | 321 |
|
323 | 322 | @Override
|
324 | 323 | public void close() {
|
325 |
| - if (!containerReuseSupported) { |
326 |
| - this.neo4jContainer.close(); |
| 324 | + if (!(containerReuseSupported || forceReuse)) { |
| 325 | + neo4jContainer.close(); |
327 | 326 | }
|
328 | 327 | }
|
329 | 328 | }
|
|
0 commit comments