Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test for Win & filter tests requiring remote resources #1127

Merged
merged 7 commits into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -51,7 +52,7 @@ public void shouldGetCachedResult() throws IOException {
CacheUrlAsset cacheUrlAsset = new CacheUrlAsset(new URL("http://arquillian.org/images/arq.txt"));
CacheUrlAsset.TEMP_LOCATION = newFolder.getAbsolutePath();
final Path path = Paths.get(newFolder.getAbsolutePath(), "arq.txt");
Files.write(path, "Hello".getBytes("UTF-8"));
Files.write(path, "Hello".getBytes(StandardCharsets.UTF_8));
InputStream is = cacheUrlAsset.openStream();
String content = slurp(is);

Expand All @@ -62,7 +63,7 @@ public void shouldGetCachedResult() throws IOException {
public void shouldDownloadFileIfExpired() throws IOException, InterruptedException {
final File newFolder = temporaryFolder.newFolder();
final Path path = Paths.get(newFolder.getAbsolutePath(), "arquillian_crown_icon_glossy_256.png");
Files.write(path, "invalidchunk".getBytes("UTF-8"));
Files.write(path, "invalidchunk".getBytes(StandardCharsets.UTF_8));
Thread.sleep(3000);
CacheUrlAsset cacheUrlAsset =
new CacheUrlAsset(new URL("http://arquillian.org/images/arquillian_crown_icon_glossy_256.png"), 2,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.arquillian.cube.docker.impl.client;

import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -37,7 +37,7 @@ public class CubeDockerConfiguration {
public static final String CLEAN = "clean";
public static final String REMOVE_VOLUMES = "removeVolumes";
public static final String CLEAN_BUILD_IMAGE = "cleanBuildImage";
static final String DIND_RESOLUTION = "dockerInsideDockerResolution";
public static final String DIND_RESOLUTION = "dockerInsideDockerResolution";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required outside

private static final String DOCKER_VERSION = "serverVersion";
private static final String USERNAME = "username";
private static final String PASSWORD = "password";
Expand Down Expand Up @@ -185,8 +185,8 @@ public static CubeDockerConfiguration fromMap(Map<String, String> map, Injector
if (stream != null) {
cubeConfiguration.dockerContainersContent =
DockerContainerDefinitionParser.convert(
IOUtil.asStringPreservingNewLines(stream),
cubeConfiguration.definitionFormat);
IOUtil.asStringPreservingNewLines(stream),
cubeConfiguration.definitionFormat);
} else {
throw new IllegalArgumentException("Resource " + resource + " not found in classpath");
}
Expand Down Expand Up @@ -379,7 +379,8 @@ public boolean isCleanBuildImage() {
return cleanBuildImage;
}

@Override public String toString() {
@Override
public String toString() {
String lineSeparator = System.lineSeparator();
StringBuilder content = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Optional;
import java.util.Random;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.arquillian.cube.docker.impl.client.CubeDockerConfigurator.DOCKER_HOST;
Expand Down Expand Up @@ -100,15 +101,18 @@ private Map<String, String> resolveDownloadDockerMachine(Map<String, String> con
String machineVersion = GitHubUtil.getDockerMachineLatestVersion();
String machineCustomPath = config.get(CubeDockerConfiguration.DOCKER_MACHINE_CUSTOM_PATH);
File dockerMachineFile = CubeDockerConfiguration.resolveMachinePath(machineCustomPath, machineVersion);
String dockerMachinePath = dockerMachineFile.getPath();

boolean dockerMachineFileExist = dockerMachineFile != null && dockerMachineFile.exists();
boolean dockerMachineFileExist = dockerMachineFile.exists();
String dockerMachinePath = dockerMachineFile.getPath();

String machineName = config.get(CubeDockerConfiguration.DOCKER_MACHINE_NAME);
String machineUrl = CubeDockerConfiguration.resolveUrl(machineVersion);

if (!dockerMachineFileExist) {
dockerMachineFile.getParentFile().mkdirs();
final File parentFile = dockerMachineFile.getParentFile();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safer

if(!parentFile.exists() && !parentFile.mkdirs()){
log.log(Level.SEVERE, "Failed to create directory: " + parentFile);
}
Spacelift.task(DownloadTool.class)
.from(machineUrl)
.to(dockerMachineFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class CubeSuiteLifecycleController {
private Instance<DockerClientExecutor> dockerClientExecutor;

public void startAutoContainers(@Observes(precedence = 100) BeforeSuite event, CubeConfiguration cubeConfiguration,
CubeDockerConfiguration dockerConfiguration) {
CubeDockerConfiguration dockerConfiguration) {
beforeAutoStartEvent.fire(new BeforeAutoStart());
final DockerAutoStartOrder dockerAutoStartOrder = dockerConfiguration.getDockerAutoStartOrder();
List<String[]> autoStartSteps = dockerAutoStartOrder.getAutoStartOrder(dockerConfiguration);
Expand Down Expand Up @@ -104,10 +104,10 @@ private void waitForCompletion(Map<String, Future<RuntimeException>> stepStatus,
try {
RuntimeException e = result.getValue().get();
if (e != null) {
Logger.getLogger(CubeSuiteLifecycleController.class.getName()).log(Level.SEVERE, message + ": " + result.getKey(), e);
Logger.getLogger(CubeSuiteLifecycleController.class.getName()).log(Level.SEVERE, message + " - Error starting: " + result.getKey(), e);
}
} catch (Exception e) {
Logger.getLogger(CubeSuiteLifecycleController.class.getName()).log(Level.SEVERE, message + " process: " + result.getKey(), e);
Logger.getLogger(CubeSuiteLifecycleController.class.getName()).log(Level.SEVERE, message + " - Failed to start: " + result.getKey(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ public void createCubeSystemProperties(@Observes AfterStart afterStart, CubeRegi

final Binding bindings = cube.bindings();
final String cubePrefix = String.format("%s.%s", PREFIX, cubeId);
System.setProperty(String.format("%s.ip", cubePrefix), bindings.getIP());
System.setProperty(String.format("%s.internal.ip", cubePrefix), bindings.getInternalIP());

final String ip = bindings.getIP();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value or empty string

final String internalIP = bindings.getInternalIP();
System.setProperty(String.format("%s.ip", cubePrefix), null != ip ? ip : "");
System.setProperty(String.format("%s.internal.ip", cubePrefix), null != internalIP ? internalIP : "");

for (Binding.PortBinding portBinding : bindings.getPortBindings()) {
final int exposedPort = portBinding.getExposedPort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.apache.commons.lang3.ArrayUtils;
Expand Down Expand Up @@ -83,7 +84,7 @@ public class DockerContainerObjectBuilder<T> {
private DockerCube dockerCube;

public DockerContainerObjectBuilder(DockerClientExecutor dockerClientExecutor, CubeController cubeController,
CubeRegistry cubeRegistry) {
CubeRegistry cubeRegistry) {
this.dockerClientExecutor = dockerClientExecutor;
this.cubeController = cubeController;
this.cubeRegistry = cubeRegistry;
Expand Down Expand Up @@ -161,11 +162,8 @@ private static String cubeNameFromCubeAnnotatedField(Field cubeField) {
* is stored as part of the metadata of the container object. This object is expected to control the lifecycle of
* the container object
*
* @param containerObjectContainer
* the container object's container
*
* @param containerObjectContainer the container object's container
* @return the current builder instance
*
* @see IsContainerObject
*/
public DockerContainerObjectBuilder<T> withContainerObjectContainer(Object containerObjectContainer) {
Expand All @@ -176,9 +174,7 @@ public DockerContainerObjectBuilder<T> withContainerObjectContainer(Object conta
/**
* Specifies the container object class to be instantiated
*
* @param containerObjectClass
* container object class to be instantiated
*
* @param containerObjectClass container object class to be instantiated
* @return the current builder instance
*/
public DockerContainerObjectBuilder<T> withContainerObjectClass(Class<T> containerObjectClass) {
Expand Down Expand Up @@ -247,11 +243,8 @@ public DockerContainerObjectBuilder<T> withContainerObjectClass(Class<T> contain
* <p>
* Currently only supports instances of {@link CubeContainerObjectConfiguration}
*
* @param configuration
* partial configuration to override default container object cube configuration
*
* @param configuration partial configuration to override default container object cube configuration
* @return the current builder instance
*
* @see CubeContainerObjectConfiguration
* @see CubeContainer
*/
Expand All @@ -274,9 +267,7 @@ public DockerContainerObjectBuilder<T> withContainerObjectConfiguration(Containe
/**
* Specifies the list of enrichers that will be used to enrich the container object.
*
* @param enrichers
* list of enrichers that will be used to enrich the container object
*
* @param enrichers list of enrichers that will be used to enrich the container object
* @return the current builder instance
*/
public DockerContainerObjectBuilder<T> withEnrichers(Collection<TestEnricher> enrichers) {
Expand All @@ -292,9 +283,7 @@ public DockerContainerObjectBuilder<T> withEnrichers(Collection<TestEnricher> en
* by the cube controller. Callers must use this callback to register anything necesary for the controller to work
* and also if they want to keep an instance of the created cube.
*
* @param cubeCreatedCallback
* consumer that will be called when the cube instance is created
*
* @param cubeCreatedCallback consumer that will be called when the cube instance is created
* @return the current builder instance
*/
public DockerContainerObjectBuilder<T> onCubeCreated(Consumer<DockerCube> cubeCreatedCallback) {
Expand All @@ -307,13 +296,9 @@ public DockerContainerObjectBuilder<T> onCubeCreated(Consumer<DockerCube> cubeCr
* container object, creates the container object and returns it
*
* @return the created container object
*
* @throws IllegalAccessException
* if there is an error accessing the container object fields
* @throws IOException
* if there is an I/O error while preparing the docker build
* @throws InvocationTargetException
* if there is an error while calling the DockerFile archive creation
* @throws IllegalAccessException if there is an error accessing the container object fields
* @throws IOException if there is an I/O error while preparing the docker build
* @throws InvocationTargetException if there is an error while calling the DockerFile archive creation
*/
public T build() throws IllegalAccessException, IOException, InvocationTargetException {
generatedConfigutation = new CubeContainer();
Expand Down Expand Up @@ -519,6 +504,8 @@ private void initializeCube() {
}
cubeController.create(containerName);
cubeController.start(containerName);
logger.log(Level.INFO, "Started container:\n" +
dockerClientExecutor.getDockerClient().inspectContainerCmd(containerName).exec().toString());
}
}

Expand All @@ -534,7 +521,7 @@ private void enrichContainerObjectWithCube() throws IllegalAccessException {
}

private <T extends Annotation> void enrichAnnotatedPortBuildingFields(Class<T> annotationType,
BiFunction<T, HasPortBindings, ?> fieldEnricher) throws IllegalAccessException {
BiFunction<T, HasPortBindings, ?> fieldEnricher) throws IllegalAccessException {
final List<Field> annotatedFields = ReflectionUtil.getFieldsWithAnnotation(containerObjectClass, annotationType);
if (annotatedFields.isEmpty()) return;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.arquillian.cube.docker.impl.util;

import org.arquillian.cube.docker.impl.docker.DockerClientExecutor;
import org.arquillian.cube.spi.CubeOutput;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.arquillian.cube.docker.impl.docker.DockerClientExecutor;
import org.arquillian.cube.spi.CubeOutput;

public final class Ping {

Expand All @@ -17,19 +18,23 @@ private Ping() {
}

public static boolean ping(int totalIterations, long sleep, TimeUnit timeUnit, PingCommand command) {
boolean result = false;
boolean result;
boolean loop;
int iteration = 0;

do {
result = command.call();
if (!result) {
iteration++;
iteration++;
loop = !result && iteration < totalIterations;
if (loop) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only wait if we're going to loop again

try {
timeUnit.sleep(sleep);
} catch (InterruptedException e) {
} catch (InterruptedException ignore) {
break;
}
}
} while (!result && iteration < totalIterations);

} while (loop);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package org.arquillian.cube.docker.impl.client;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.SystemUtils;
import org.arquillian.cube.docker.impl.util.Boot2Docker;
import org.arquillian.cube.docker.impl.util.CommandLineExecutor;
import org.arquillian.cube.docker.impl.util.DockerMachine;
import org.arquillian.cube.docker.impl.util.OperatingSystem;
import org.arquillian.cube.docker.impl.util.OperatingSystemFamily;
import org.arquillian.cube.docker.impl.util.OperatingSystemFamilyInterface;
import org.arquillian.cube.docker.impl.util.OperatingSystemInterface;
Expand All @@ -15,7 +22,6 @@
import org.hamcrest.core.StringEndsWith;
import org.jboss.arquillian.config.descriptor.api.ArquillianDescriptor;
import org.jboss.arquillian.config.descriptor.api.ExtensionDef;
import org.jboss.arquillian.core.api.InstanceProducer;
import org.jboss.arquillian.core.api.annotation.ApplicationScoped;
import org.jboss.arquillian.core.test.AbstractManagerTestBase;
import org.junit.Assume;
Expand All @@ -25,20 +31,16 @@
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.collection.IsMapContaining.hasEntry;
import static org.hamcrest.collection.IsMapContaining.hasKey;
import static org.junit.Assert.assertThat;
import static org.junit.Assume.assumeThat;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class CubeConfiguratorTest extends AbstractManagerTestBase {
Expand All @@ -57,11 +59,11 @@ public class CubeConfiguratorTest extends AbstractManagerTestBase {
Top top;

private static Matcher<String> defaultDockerMachineCertPath() {
return containsString(".docker/machine/machines");
return containsString(".docker" + File.separator + "machine" + File.separator + "machines");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Win fix, really need to ensure such paths are independent everywhere.

}

private static Matcher<String> defaultBootToDockerCertPath() {
return containsString(".boot2docker/certs");
return containsString(".boot2docker" + File.separator + "certs");
}

private static Matcher<String> pathEndsWith(String suffix) {
Expand Down
Loading