public static ContainerVerificationHost create(int port, String id, DockerClientConfig dockerClientConfig) throws Throwable { ServiceHost.Arguments args = buildDefaultServiceHostArguments(port); if (id != null) { args.id = id; } return (ContainerVerificationHost) initialize(new ContainerVerificationHost(dockerClientConfig), args); }
public static ContainerVerificationHost create(int port) throws Throwable { return create(port, null); }
@Override public void setUpLocalPeersHosts(int localHostCount, Long maintIntervalMillis) { testStart(localHostCount); if (maintIntervalMillis == null) { maintIntervalMillis = this.maintenanceIntervalMillis; } final long intervalMicros = TimeUnit.MILLISECONDS.toMicros(maintIntervalMillis); for (int i = 0; i < localHostCount; i++) { String location = this.isMultiLocationTest ? ((i < localHostCount / 2) ? LOCATION1 : LOCATION2) : null; run(() -> { try { this.setUpLocalPeerHostInContainer(null, intervalMicros, location); } catch (Throwable e) { failIteration(e); } }); } testWait(); }
@Test public void longRunSync() throws Throwable { this.host.setUpPeerHosts(this.nodeCount); this.host.joinNodesAndVerifyConvergence(this.nodeCount); this.host.log(Level.INFO, "example services %d / %d", this.serviceCount - remain, this.serviceCount); this.host.createExampleServices(this.host.getPeerHost(), Integer.min(this.batch, remain), null, this.factoryLink); Thread.sleep(this.cacheCleanDelay); this.host.log(Level.INFO, "example services created"); for (int i = 0; i < this.iteration; i ++) { long start = Utils.getNowMicrosUtc(); this.host.setNodeGroupQuorum(this.nodeCount - 1); ContainerVerificationHost h0 = this.host.getPeerHost(); this.host.stopHost(h0); this.host.waitForNodeUnavailable(ServiceUriPaths.DEFAULT_NODE_GROUP, this.host.getInProcessHostMap().values(), h0); this.host.waitForNodeGroupConvergence(this.nodeCount - 1); Random rand = new Random(); int r = rand.nextInt(this.sleepDuration) + 1; Thread.sleep(TimeUnit.SECONDS.toMillis(r)); this.host.setUpPeerHosts(1); this.host.joinNodesAndVerifyConvergence(this.nodeCount); r = rand.nextInt(this.sleepDuration) + 1; Thread.sleep(TimeUnit.SECONDS.toMillis(r)); this.host.setNodeGroupQuorum(this.nodeCount - 1);
public CreateContainerResponse setUpLocalPeerHostInContainer(Collection<String> containerIds, long maintIntervalMicros, String location) throws Throwable { CreateContainerResponse c; try { c = createAndStartContainer(maintIntervalMicros, location); ContainerVerificationHost h = setUpLocalPeerHost(c.getId()); URI clusterUri = this.networkMapping.get(h.getPublicUri()); if (this.logContainer) { logContainer(h.getId(), clusterUri, 0); } if (this.statsContainer) { statsContainer(h.getId(), clusterUri, null); } if (containerIds != null) { containerIds.add(c.getId()); } } catch (Throwable e) { throw new Exception(e); } this.completeIteration(); return c; }
URI clusterUri = UriUtils.buildUri(UriUtils.HTTP_SCHEME, cn.getIpAddress(), this.containerExposedPort, null, null, null); this.waitFor("node selector available timeout", () -> { Operation get = Operation.createGet(UriUtils.buildUri(publicUri, ServiceUriPaths.DEFAULT_NODE_SELECTOR)) .setExpiration(TimeUnit.MINUTES.toMicros(1)); try { this.getTestRequestSender().sendAndWait(get); } catch (Exception e) { return false; ContainerVerificationHost h = ContainerVerificationHost.create(0, id); h.setPublicUri(publicUri); h.uri = publicUri; h.isStarted = true; addPeerNode(h);
public void resumeHostInContainer(ContainerVerificationHost host) { String id = host.getId(); InspectContainerResponse icr = null; try { URI clusterUri = UriUtils.buildUri(UriUtils.HTTP_SCHEME, cn.getIpAddress(), this.containerExposedPort, null, null, null); this.waitFor("node selector available timeout", () -> { Operation get = Operation.createGet(UriUtils.buildUri(publicUri, ServiceUriPaths.DEFAULT_NODE_SELECTOR)) .setExpiration(TimeUnit.MINUTES.toMicros(1)); try { this.getTestRequestSender().sendAndWait(get); } catch (Exception e) { return false; host.setPublicUri(publicUri); host.uri = publicUri; host.isStarted = true; addPeerNode(host);
@Before public void setUp() throws Throwable { CommandLineArgumentParser.parseFromProperties(this); // create verification host which create xenon node in docker container this.host = ContainerVerificationHost.create(0); if (!this.host.isContainerImageAvailable()) { Assume.assumeTrue(false); return; } int timeout = this.host.getTimeoutSeconds(); this.host.testDurationSeconds = this.expireDuration - timeout; this.host.start(); }
public void waitForFactoryAvailable() { this.host.waitFor("Factory availability timeout", () -> { URI uri = UriUtils.buildUri(this.host.getPeerHost(), SynchronizationManagementService.class); ServiceDocumentQueryResult result = null; try { result = this.host.getTestRequestSender().sendAndWait(Operation.createGet(uri), ServiceDocumentQueryResult.class); } catch (RuntimeException e) { // receive failed response return false; } SynchronizationManagementService.SynchronizationManagementState state = Utils.fromJson(result.documents.get(this.factoryLink), SynchronizationManagementService.SynchronizationManagementState.class); if (state.owner == null) { return false; } if (!this.host.containPeerId(state.owner)) { return false; } if (state.status != SynchronizationManagementService.SynchronizationManagementState.Status.AVAILABLE) { return false; } return true; }); }
@Override public void joinNodeGroup(URI newNodeGroupService, URI nodeGroup, Integer quorum) { if (nodeGroup.equals(newNodeGroupService)) { return; } // map from public to cluster space URI publicUri = UriUtils.buildUri(nodeGroup.getScheme(), nodeGroup.getHost(), nodeGroup.getPort(), null, null, null); String nodeGroupService = nodeGroup.getPath(); URI clusterUri = this.networkMapping.get(publicUri); URI clusterNodeGroup = UriUtils.buildUri(clusterUri, nodeGroupService); // to become member of a group of nodes, you send a POST to self // (the local node group service) with the URI of the remote node // group you wish to join NodeGroupService.JoinPeerRequest joinBody = NodeGroupService.JoinPeerRequest.create(clusterNodeGroup, quorum); log("Joining %s through %s(%s)", newNodeGroupService, nodeGroup, clusterNodeGroup); // send the request to the node group instance we have picked as the // "initial" one send(Operation.createPost(newNodeGroupService) .setBody(joinBody) .setCompletion(getCompletion())); }
public static ContainerVerificationHost create(int port, String id) throws Throwable { return create(port, id, null); }