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

Workaround Groovy conflicts in Debug examples as daily build is failing #1196

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
@@ -1,20 +1,30 @@
package io.quarkus.qe.debug;

import io.quarkus.test.bootstrap.RestService;
import io.quarkus.test.scenarios.QuarkusScenario;
import io.restassured.RestAssured;
import org.hamcrest.Matchers;
import io.quarkus.test.services.QuarkusApplication;
import io.vertx.mutiny.ext.web.client.HttpResponse;
import io.vertx.mutiny.ext.web.client.predicate.ResponsePredicate;
import org.junit.jupiter.api.Test;

import java.net.HttpURLConnection;

import static org.junit.jupiter.api.Assertions.assertEquals;

@QuarkusScenario
public class HelloIT {

@QuarkusApplication
static final RestService app = new RestService(false);

@Test
public void test() {
RestAssured
.get("/hello")
.then()
.statusCode(200)
.body(Matchers.is("hello"));
String response = app.mutiny().get("/hello")
gtroitsk marked this conversation as resolved.
Show resolved Hide resolved
.expect(ResponsePredicate.status(HttpURLConnection.HTTP_OK))
.send()
.map(HttpResponse::bodyAsString)
.await().indefinitely();
assertEquals("hello", response);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,23 @@ public class RestService extends BaseService<RestService> {
private static final int BUFFER_SIZE = 1024;
private static final String BASE_PATH = "/";

private final boolean setupRestAssured;
private WebClient webClient;

public RestService() {
this(true);
}

/**
* @param setupRestAssured whether RestAssured base URI, path and port should be configured;
* usually you don't mind as setting up RestAssured doesn't hurt you, but it can be useful
* when you want to avoid Groovy which RestAssured relies on (like when this framework
* is build with a different Quarkus version than it is tested in Maven invoker tests).
*/
public RestService(boolean setupRestAssured) {
this.setupRestAssured = setupRestAssured;
}

public RequestSpecification given() {
var host = getURI(Protocol.HTTP);
return RestAssured.given()
Expand Down Expand Up @@ -154,9 +169,11 @@ public WebClient mutinyHttps(boolean verifyHost, String clientCertificateCn, boo
public void start() {
super.start();
var host = getURI(Protocol.HTTP);
RestAssured.baseURI = host.getRestAssuredStyleUri();
RestAssured.basePath = BASE_PATH;
RestAssured.port = host.getPort();
if (setupRestAssured) {
RestAssured.baseURI = host.getRestAssuredStyleUri();
RestAssured.basePath = BASE_PATH;
RestAssured.port = host.getPort();
}
}

private static byte[] getFileContent(String path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.nio.file.Path;
import java.util.stream.Collectors;

import org.apache.commons.io.FileUtils;

public final class SureFireCommunicationHelper {

private static final String EXIT_PREFIX = "quarkus-fw-debug-mode-exit-";
Expand All @@ -25,12 +23,7 @@ private SureFireCommunicationHelper(boolean performLookup) {
}

void closeCommunication() {
try {
// recursively delete directory with all its content
FileUtils.deleteDirectory(exitTmpDir.toFile());
} catch (IOException e) {
throw new RuntimeException("Failed to delete exit directory", e);
}
deleteDirectory(exitTmpDir);
}

void sendExitSignal() {
Expand Down Expand Up @@ -95,14 +88,7 @@ private static void deletePreviousExitTmpDirs() {
tmpFiles
.filter(Files::isDirectory)
.filter(SureFireCommunicationHelper::isExitTmpDir)
.forEach(path -> {
try {
// recursively delete directory with all its content
FileUtils.deleteDirectory(path.toFile());
} catch (IOException e) {
throw new IllegalStateException("Failed to delete previous exit directory", e);
}
});
.forEach(SureFireCommunicationHelper::deleteDirectory);
} catch (IOException e) {
throw new IllegalStateException("Failed to delete previous exit directories", e);
}
Expand All @@ -111,4 +97,31 @@ private static void deletePreviousExitTmpDirs() {
private static Path tmpDirPath() {
return Path.of(System.getProperty("java.io.tmpdir"));
}

/**
* Recursively deletes directory with all its content.
*/
private static void deleteDirectory(Path directoryPath) {
if (Files.exists(directoryPath)) {
var dirFiles = directoryPath.toFile().listFiles();
if (dirFiles != null) {
for (File dirFile : dirFiles) {
if (dirFile.isDirectory()) {
deleteDirectory(dirFile.toPath());
} else {
deletePath(dirFile.toPath());
}
}
}
deletePath(directoryPath);
}
}

private static void deletePath(Path path) {
try {
Files.delete(path);
} catch (IOException e) {
throw new IllegalStateException("Failed to delete: " + path, e);
}
}
}