DockerInstance implements CloudInstance, DockerCloudErrorHandler { public void bindWithAgentHolder(@Nonnull NewAgentHolderInfo agentHolderInfo) { DockerCloudUtils.requireNonNull(agentHolderInfo, "Agent holder info cannot be null."); lock.run(() -> { if (this.agentHolderId != null) { assert agentHolderName != null && resolvedImageName != null; throw new IllegalStateException("Docker instance already bound with agent holder."); } this.agentHolderId = agentHolderInfo.getId(); this.agentHolderName = agentHolderInfo.getName(); this.resolvedImageName = agentHolderInfo.getResolvedImage(); }); } DockerInstance(@Nonnull DockerImage img); @Nonnull @Override String getInstanceId(); @Nonnull Optional<String> getTaskId(); @Nonnull @Override String getName(); @Nonnull Optional<String> getAgentHolderName(); @Nonnull Optional<String> getResolvedImageName(); void bindWithAgentHolder(@Nonnull NewAgentHolderInfo agentHolderInfo); @Nonnull @Override String getImageId(); @Nonnull @Override DockerImage getImage(); @Nonnull @Override Date getStartedTime(); @Nullable @Override String getNetworkIdentity(); @Nonnull @Override InstanceStatus getStatus(); @Nullable @Override CloudErrorInfo getErrorInfo(); @Nonnull Optional<AgentHolderInfo> getAgentHolderInfo(); boolean registerOrCompareAgentId(int agentId); @Nonnull Optional<UUID> getAgentRuntimeUuid(); void registerAgentRuntimeUuid(@Nonnull UUID agentRuntimeUuid); void unregisterAgentRuntimeUUid(@Nonnull UUID agentRuntimeUuid); @Override void notifyFailure(@Nonnull String msg, @Nullable Throwable throwable); @Override boolean containsAgent(@Nonnull AgentDescription agent); @Override String toString();  }
@Test public void bindWithAgentHolderInvalidInput() { DockerInstance instance = createInstance(); assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> instance.bindWithAgentHolder(null)); }
@Test public void bindWithAgentHolderTwice() { DockerInstance instance = createInstance(); NewAgentHolderInfo agentHolderInfo = new NewAgentHolderInfo(TestUtils.createRandomSha256(), "", "", Collections.emptyList()); instance.bindWithAgentHolder(agentHolderInfo); assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> instance.bindWithAgentHolder(agentHolderInfo)); }