DefaultDockerCloudClient extends BuildServerAdapter implements DockerCloudClient { @Nullable @Override public CloudErrorInfo getErrorInfo() { return errorInfo; } 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 discardUnregisteredAgents() { TestSBuildAgent agentWithCloudAndInstanceIds = new TestSBuildAgent(). environmentVariable(DockerCloudUtils.ENV_CLIENT_ID, TestUtils.TEST_UUID.toString()). environmentVariable(DockerCloudUtils.ENV_INSTANCE_ID, TestUtils.TEST_UUID_2.toString()); TestSBuildAgent agentWithCloudIdOnly = new TestSBuildAgent(). environmentVariable(DockerCloudUtils.ENV_CLIENT_ID, TestUtils.TEST_UUID.toString()); TestSBuildAgent agentWithCloudAndInstanceIdsNotRemovable = new TestSBuildAgent(). environmentVariable(DockerCloudUtils.ENV_CLIENT_ID, TestUtils.TEST_UUID.toString()). environmentVariable(DockerCloudUtils.ENV_INSTANCE_ID, TestUtils.TEST_UUID_2.toString()). removable(false); TestSBuildAgent otherAgent = new TestSBuildAgent(); buildServer.getTestBuildAgentManager(). unregisteredAgent(agentWithCloudAndInstanceIds). unregisteredAgent(agentWithCloudIdOnly). unregisteredAgent(agentWithCloudAndInstanceIdsNotRemovable). unregisteredAgent(otherAgent); DefaultDockerCloudClient client = createClient(); waitUntil(() -> buildServer.getBuildAgentManager().getUnregisteredAgents().size() == 2); List<TestSBuildAgent> unregisteredAgents = buildServer.getBuildAgentManager().getUnregisteredAgents(); assertThat(unregisteredAgents).containsOnly(agentWithCloudAndInstanceIdsNotRemovable, otherAgent); assertThat(client.getErrorInfo()).isNull(); }