public static Await logAwait(String matching, int timeoutInSeconds, int occurrences) { Await await = new Await(); await.setStrategy("log"); await.setMatch(matching); await.setTimeout(timeoutInSeconds); await.setStdOut(true); await.setOccurrences(occurrences); return await; }
public DockerHealthAwaitStrategy(Cube<?> cube, DockerClientExecutor dockerClientExecutor, Await params) { super(params.getSleepPollingTime()); this.cube = cube; this.client = dockerClientExecutor.getDockerClient(); this.pollIterations = getIterations(params); this.command = params.getCommand(); }
public StaticAwaitStrategy(Cube<?> cube, Await params) { super(params.getSleepPollingTime()); this.ip = params.getIp(); this.ports.addAll(params.getPorts()); if (params.getIterations() != null) { this.pollIterations = params.getIterations(); } }
public HttpAwaitBuilder(URL url, String messageContent) { this.await = new Await(); await.setStrategy("http"); await.setMatch(messageContent); await.setUrl(url.toExternalForm()); await.setSleepPollingTime(DEFAULT_TIMEOUT + " s"); await.setIterations(10); }
@Test public void should_create_polling_await_strategy_with_specific_type() { Await await = new Await(); await.setStrategy("polling"); await.setType("sscommand"); await.setSleepPollingTime("200 s"); await.setIterations(3); CubeContainer cubeContainer = new CubeContainer(); cubeContainer.setAwait(await); AwaitStrategy strategy = AwaitStrategyFactory.create(null, cube, cubeContainer); assertThat(strategy, instanceOf(PollingAwaitStrategy.class)); assertThat(((PollingAwaitStrategy) strategy).getType(), is("sscommand")); }
@Test public void should_create_static_await_strategy_without_defaults() { Await await = new Await(); await.setStrategy("static"); await.setIp("localhost"); await.setPorts(Arrays.asList(8080, 8089)); await.setSleepPollingTime(200); await.setIterations(3); CubeContainer cubeContainer = new CubeContainer(); cubeContainer.setAwait(await); AwaitStrategy strategy = AwaitStrategyFactory.create(null, cube, cubeContainer); assertThat(strategy, instanceOf(StaticAwaitStrategy.class)); StaticAwaitStrategy staticAwaitStrategy = (StaticAwaitStrategy) strategy; assertThat(staticAwaitStrategy.getIp(), is("localhost")); assertThat(staticAwaitStrategy.getPorts().get(0), is(8080)); assertThat(staticAwaitStrategy.getPorts().get(1), is(8089)); assertThat(staticAwaitStrategy.getPollIterations(), is(3)); assertThat(staticAwaitStrategy.getSleepTime(), is(200)); }
if (awaitPortsFromAnnotation != null && !Arrays.equals(awaitPortsFromAnnotation, Cube.DEFAULT_AWAIT_PORT_BINDING)) { final Await await = new Await(); await.setStrategy(PollingAwaitStrategy.TAG); await.setPorts(Arrays.asList(ArrayUtils.toObject(awaitPortsFromAnnotation))); cubeContainer.setAwait(await);
private static CubeContainer createVideoConverterContainer(Path dockerVolume, String dockerRegistry) { CubeContainer cubeContainer = new CubeContainer(); cubeContainer.setImage(Image.valueOf(dockerRegistry + CONVERSION_IMAGE)); cubeContainer.setBinds( Arrays.asList(convertToBind(dockerVolume, VOLUME_DIR, "Z")) ); // Using log await strategy to match the echo string indicating completion of conversion Await await = new Await(); await.setStrategy("log"); await.setMatch("CONVERSION COMPLETED"); cubeContainer.setAwait(await); // sets container as manual because we need to start and stop cubeContainer.setManual(true); return cubeContainer; }
private static void setDefaultSeleniumCubeProperties(CubeContainer cubeContainer, int seleniumBoundedPort) { cubeContainer.setPortBindings( Arrays.asList(PortBinding.valueOf(seleniumBoundedPort + "-> 4444")) ); Await await = new Await(); await.setStrategy("http"); await.setResponseCode(getSeleniumExpectedResponseCode()); await.setUrl("http://dockerHost:" + seleniumBoundedPort); cubeContainer.setAwait(await); cubeContainer.setKillContainer(true); }
private static CubeContainer createVncContainer(final Path dockerVolume, String seleniumContainerName) { CubeContainer cubeContainer = new CubeContainer(); cubeContainer.setImage(Image.valueOf(VNC_IMAGE)); cubeContainer.setBinds( Arrays.asList(convertToBind(dockerVolume, VOLUME_DIR, "Z")) ); final Link link = Link.valueOf(seleniumContainerName + ":" + VNC_HOSTNAME); cubeContainer.setLinks(Arrays.asList(link)); // Using sleeping strategy since VNC client is a CLI without exposing a port Await await = new Await(); await.setStrategy("sleeping"); await.setSleepTime("100 ms"); cubeContainer.setAwait(await); cubeContainer.setCmd(Arrays.asList(FLVREC_COMMAND)); // sets container as manual because we need to start and stop for each test case cubeContainer.setManual(true); return cubeContainer; }
@Test public void should_create_static_await_strategy() { Await await = new Await(); await.setStrategy("static"); await.setIp("localhost"); await.setPorts(Arrays.asList(8080, 8089)); CubeContainer cubeContainer = new CubeContainer(); cubeContainer.setAwait(await); AwaitStrategy strategy = AwaitStrategyFactory.create(null, cube, cubeContainer); assertThat(strategy, instanceOf(StaticAwaitStrategy.class)); StaticAwaitStrategy staticAwaitStrategy = (StaticAwaitStrategy) strategy; assertThat(staticAwaitStrategy.getIp(), is("localhost")); assertThat(staticAwaitStrategy.getPorts().get(0), is(8080)); assertThat(staticAwaitStrategy.getPorts().get(1), is(8089)); }
private void verifyAwait(String imageId, boolean status, String[] command, String timeout) { String containerId = dockerRun(imageId); containerIds.add(containerId); when(cube.getId()).thenReturn(containerId); when(dockerClientExecutor.getDockerClient()).thenReturn(dockerClient); Await params = new Await(); params.setIterations(2); params.setSleepPollingTime(timeout); params.setCommand(command); DockerHealthAwaitStrategy dockerHealthAwaitStrategy = new DockerHealthAwaitStrategy( cube, dockerClientExecutor, params ); Assert.assertEquals(status, dockerHealthAwaitStrategy.await()); } }
@Test public void should_create_polling_await_strategy() { Await await = new Await(); await.setStrategy("polling"); CubeContainer cubeContainer = new CubeContainer(); cubeContainer.setAwait(await); AwaitStrategy strategy = AwaitStrategyFactory.create(null, cube, cubeContainer); assertThat(strategy, instanceOf(PollingAwaitStrategy.class)); }
public HttpAwaitStrategy(Cube<?> cube, DockerClientExecutor dockerClientExecutor, Await params) { super(params.getSleepPollingTime()); this.cube = cube; this.dockerClientExecutor = dockerClientExecutor; if (params.getIterations() != null) { this.pollIterations = params.getIterations(); } if (params.getUrl() != null) { String url = params.getUrl(); if (url.contains(DOCKER_HOST)) { url = url.replaceAll(DOCKER_HOST, dockerClientExecutor.getDockerServerIp()); } try { this.url = new URL(url); } catch (IOException e) { throw new IllegalArgumentException(e); } } else { throw new IllegalArgumentException("Http Await Strategy requires url field"); } if (params.getResponseCode() != null) { this.responseCode = params.getResponseCode(); } if (params.getHeaders() != null) { this.headers = params.getHeaders(); } if (params.getMatch() != null) { this.matcher = params.getMatch(); } }
public PollingAwaitStrategy(Cube<?> cube, DockerClientExecutor dockerClientExecutor, Await params) { super(params.getSleepPollingTime()); this.cube = cube; this.dockerClientExecutor = dockerClientExecutor; if (params.getIterations() != null) { this.pollIterations = params.getIterations(); } if (params.getType() != null) { this.type = params.getType(); } if (params.getPorts() != null && params.getPorts().size() > 0) { this.ports = params.getPorts(); } }
Await await = options.getAwait(); if (await.getStrategy() != null) { String strategy = await.getStrategy().toLowerCase(); switch (strategy) { case PollingAwaitStrategy.TAG: return new PollingAwaitStrategy(cube, dockerClientExecutor, new Await()); return new PollingAwaitStrategy(cube, dockerClientExecutor, new Await());
Assert.assertEquals("tcp", portBinding2.getExposedPort().getType()); Assert.assertEquals("static", container.getAwait().getStrategy()); Assert.assertEquals("localhost", container.getAwait().getIp()); Assert.assertEquals(2, container.getAwait().getPorts().size());
@Override public int[] getAwaitPorts() { return Optional.ofNullable(configuration.getAwait()) .filter(await -> await.getStrategy().equals(PollingAwaitStrategy.TAG)) .map(Await::getPorts) .map(ports -> ports.stream().mapToInt(Integer::intValue).toArray()) .orElse(null); }
@Test public void shouldCreateContainerForFirefox() { when(cubeDroneConfiguration.isBrowserDockerfileDirectorySet()).thenReturn(false); when(cubeDroneConfiguration.isBrowserImageSet()).thenReturn(false); when(cubeDroneConfiguration.getContainerNameStrategy()).thenReturn(ContainerNameStrategy.STATIC); when(cubeDroneConfiguration.getDockerRegistry()).thenReturn(""); final SeleniumContainers firefox = SeleniumContainers.create("firefox", cubeDroneConfiguration); assertThat(firefox.getBrowser(), is("firefox")); assertThat(firefox.getSeleniumContainer().getImage().toString(), is("selenium/standalone-firefox-debug:2.53.0")); assertThat(firefox.getSeleniumContainer().getPortBindings(), hasItem(PortBinding.valueOf("14444->4444"))); assertThat(firefox.getSeleniumContainer().getAwait().getResponseCode(), is(403)); }
public HttpAwaitBuilder withIterations(int iterations) { await.setIterations(iterations); return this; }