org.testcontainers.lifecycle.Startable Java Examples
The following examples show how to use
org.testcontainers.lifecycle.Startable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestcontainersR2DBCConnectionFactory.java From testcontainers-java with MIT License | 5 votes |
@Override public Publisher<Void> close() { return s -> { CompletableFuture<R2DBCDatabaseContainer> futureRef; synchronized (this) { futureRef = this.future; this.future = null; } CancellableSubscription subscription = new CancellableSubscription(); s.onSubscribe(subscription); if (futureRef == null) { if (!subscription.isCancelled()) { s.onComplete(); } } else { futureRef.thenAcceptAsync(Startable::stop, EXECUTOR); EXECUTOR.execute(() -> { futureRef.cancel(true); if (!subscription.isCancelled()) { s.onComplete(); } }); } }; }
Example #2
Source File: TestcontainersExtension.java From testcontainers-java with MIT License | 5 votes |
private static Predicate<Field> isContainer() { return field -> { boolean isAnnotatedWithContainer = AnnotationSupport.isAnnotated(field, Container.class); if (isAnnotatedWithContainer) { boolean isStartable = Startable.class.isAssignableFrom(field.getType()); if (!isStartable) { throw new ExtensionConfigurationException(String.format("FieldName: %s does not implement Startable", field.getName())); } return true; } return false; }; }
Example #3
Source File: TestcontainersExtension.java From testcontainers-java with MIT License | 5 votes |
private static StoreAdapter getContainerInstance(final Object testInstance, final Field field) { try { field.setAccessible(true); Startable containerInstance = Preconditions.notNull((Startable) field.get(testInstance), "Container " + field.getName() + " needs to be initialized"); return new StoreAdapter(field.getDeclaringClass(), field.getName(), containerInstance); } catch (IllegalAccessException e) { throw new ExtensionConfigurationException("Can not access container defined in field " + field.getName()); } }
Example #4
Source File: DependenciesTest.java From testcontainers-java with MIT License | 5 votes |
@Test public void shouldHandleParallelStream() throws Exception { List<Startable> startables = Stream.generate(InvocationCountingStartable::new) .limit(10) .collect(Collectors.toList()); for (int i = 1; i < startables.size(); i++) { startables.get(0).getDependencies().add(startables.get(i)); } Startables.deepStart(startables.parallelStream()).get(1, TimeUnit.SECONDS); }
Example #5
Source File: TestcontainersExtension.java From testcontainers-java with MIT License | 4 votes |
private StoreAdapter(Class<?> declaringClass, String fieldName, Startable container) { this.key = declaringClass.getName() + "." + fieldName; this.container = container; }
Example #6
Source File: GenericContainer.java From testcontainers-java with MIT License | 4 votes |
/** * @see #dependsOn(Iterable) */ public SELF dependsOn(Startable... startables) { Collections.addAll(dependencies, startables); return self(); }
Example #7
Source File: GenericContainer.java From testcontainers-java with MIT License | 4 votes |
/** * @see #dependsOn(Iterable) */ public SELF dependsOn(List<? extends Startable> startables) { return this.dependsOn((Iterable<? extends Startable>) startables); }
Example #8
Source File: GenericContainer.java From testcontainers-java with MIT License | 2 votes |
/** * Delays this container's creation and start until provided {@link Startable}s start first. * Note that the circular dependencies are not supported. * * @param startables a list of {@link Startable} to depend on * @see Startables#deepStart(Iterable) */ public SELF dependsOn(Iterable<? extends Startable> startables) { startables.forEach(dependencies::add); return self(); }