DefaultDockerCloudClient extends BuildServerAdapter implements DockerCloudClient { @Override public void dispose() { buildServer.removeListener(buildServerListener); boolean alreadyDisposed = lock.call(() -> { if (state == State.DISPOSED) { LOG.debug("Client already disposed, ignoring request."); return true; } state = State.DISPOSED; return false; }); if (alreadyDisposed) { return; } buildServer.unregisterExtension(AgentNameGenerator.class, agentNameGeneratorUuid.toString()); LOG.info("Starting disposal of client."); for (DockerImage image : getImages()) { for (DockerInstance instance : image.getInstances()) { terminateInstance(instance, true); } } taskScheduler.shutdown(); } DefaultDockerCloudClient(@Nonnull DockerCloudClientConfig clientConfig,
                             @Nonnull final List<DockerImageConfig> imageConfigs,
                             @Nonnull final DockerImageNameResolver resolver,
                             @Nonnull CloudState cloudState,
                             @Nonnull final SBuildServer buildServer); @Nonnull @Override UUID getUuid(); @Nonnull @Override DockerCloudSupport getCloudSupport(); @Override void serverStartup(); @Override boolean isInitialized(); @Nullable @Override DockerImage findImageById(@Nonnull String id); @Nullable @Override DockerInstance findInstanceByAgent(@Nonnull AgentDescription agent); @Nonnull @Override Collection<DockerImage> getImages(); @Nullable @Override CloudErrorInfo getErrorInfo(); @Override boolean canStartNewInstance(@Nonnull CloudImage image); @Nullable @Override String generateAgentName(@Nonnull AgentDescription agent); @Nonnull @Override DockerInstance startNewInstance(@Nonnull final CloudImage image, @Nonnull final CloudInstanceUserData tag); @Override void restartInstance(@Nonnull final CloudInstance instance); @Override void terminateInstance(@Nonnull final CloudInstance instance); @Override void dispose(); Optional<Instant> getLastDockerSyncTime(); @Override void notifyFailure(@Nonnull String msg, @Nullable Throwable throwable);  }
@Test public void dispose() { rmOnExit = false; client = createClient(); DockerImage image = waitForImage(client); DockerInstance instance = client.startNewInstance(image, userData); waitForInstanceStatus(instance, InstanceStatus.RUNNING); client.dispose(); waitUntil(() -> image.getInstances().isEmpty()); assertThat(testCloudSupport.getClientFacade().getAgentHolders().isEmpty()); }