Skip to content

Commit

Permalink
Add checks for the following issues:
Browse files Browse the repository at this point in the history
quarkusio/quarkus#24402
quarkusio/quarkus#24405
quarkusio/quarkus#24415
quarkusio/quarkus#25028
Additionally: delete temporary files to speed up local execution
  • Loading branch information
fedinskiy committed Jun 6, 2022
1 parent 0a5a477 commit 82dfd2f
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ interface AuthorClient {
@Produces(MediaType.TEXT_PLAIN)
interface ProfessionClient {
@GET
@Path("/name")
Uni<String> getName();
@Path("/title")
Uni<String> getTitle();

@Path("/wage")
WageClient getWage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Uni<String> getSubResource(@QueryParam("author") String author) {
@GET
@Path("/profession")
public Uni<String> getSubSubResource() {
return bookInterface.getAuthor().getProfession().getName();
return bookInterface.getAuthor().getProfession().getTitle();
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ public interface FileClient {
@GET
@Produces(MediaType.MULTIPART_FORM_DATA)
@Path("/download-multipart")
FileWrapper downloadMultipart();
Uni<FileWrapper> downloadMultipart();

@GET
@Produces(MediaType.MULTIPART_FORM_DATA)
@Path("/download-broken-multipart")
Uni<FileWrapper> brokenMultipart();

@POST
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,52 @@

import java.io.IOException;
import java.nio.file.Files;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;

import javax.inject.Inject;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.jboss.resteasy.reactive.RestResponse;

import io.quarkus.logging.Log;
import io.smallrye.common.annotation.Blocking;
import io.smallrye.mutiny.Uni;

@Path("/file-client")
public class FileClientResource {
private static final String BIGGER_THAN_TWO_GIGABYTES = OsUtils.SIZE_2049MiB;
private final java.nio.file.Path FILE = Files.createTempFile("upload", ".txt").toAbsolutePath();

private final java.nio.file.Path file;
private final List<java.nio.file.Path> deathRow = new LinkedList<>();
private final FileClient client;
private final OsUtils utils;

@Inject
public FileClientResource(@RestClient FileClient client) throws IOException {
public FileClientResource(@RestClient FileClient client,
@ConfigProperty(name = "client.filepath") Optional<String> folder) {
utils = OsUtils.get();
utils.createFile(FILE.toString(), BIGGER_THAN_TWO_GIGABYTES);
file = folder
.stream()
.map(existing -> java.nio.file.Path.of(existing).resolve("upload.txt").toAbsolutePath())
.peek(path -> {
utils.createFile(path.toString(), BIGGER_THAN_TWO_GIGABYTES);
})
.findFirst().orElse(null);
this.client = client;
}

@GET
@Path("/client-hash")
@Blocking
public Uni<String> calculateHash() {
return utils.getSum(FILE.toString());
return utils.getSum(file.toString());
}

@GET
Expand All @@ -43,28 +59,60 @@ public Uni<String> hash() {
@GET
@Path("/download")
public Uni<String> download() {
return client.download().onItem().transformToUni(file -> utils.getSum(file.getAbsolutePath()));
return client.download()
.map(file -> {
java.nio.file.Path path = file.toPath().toAbsolutePath();
deathRow.add(path);
return path.toString();
})
.onItem()
.transformToUni(utils::getSum);
}

@GET
@Path("/download-multipart")
public Uni<String> downloadMultipart() {
FileWrapper wrapper = client.downloadMultipart();
String path = wrapper.file.getAbsolutePath();
return utils.getSum(path);
return client.downloadMultipart()
.map(wrapper -> wrapper.file.toPath())
.map(java.nio.file.Path::toAbsolutePath)
.invoke(deathRow::add)
.map(java.nio.file.Path::toString)
.flatMap(utils::getSum);
}

@GET
@Path("/download-broken-multipart")
public Uni<String> downloadMultipartResponse() {
return client.brokenMultipart()
.map(wrapper -> wrapper.file.getAbsolutePath())
.flatMap(utils::getSum);
}

@POST
@Path("/multipart")
public Uni<String> uploadMultipart() {
FileWrapper wrapper = new FileWrapper();
wrapper.file = FILE.toFile();
wrapper.file = file.toFile();
wrapper.name = file.toString();
return client.sendMultipart(wrapper);
}

@POST
@Path("/upload-file")
public Uni<String> upload() {
return client.sendFile(FILE.toFile());
return client.sendFile(file.toFile());
}

@DELETE
@Path("/")
public RestResponse drop() {
for (java.nio.file.Path path : deathRow) {
try {
Files.delete(path);
} catch (IOException e) {
Log.warn(e);
}
}
return RestResponse.noContent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,55 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.resteasy.reactive.MultipartForm;
import org.jboss.resteasy.reactive.RestResponse;

import io.quarkus.logging.Log;
import io.smallrye.common.annotation.Blocking;
import io.smallrye.mutiny.Uni;

@Path("/file")
public class FileResource {
private static final String BIGGER_THAN_TWO_GIGABYTES = OsUtils.SIZE_2049MiB;
private final File FILE = Files.createTempFile("server", ".txt").toAbsolutePath().toFile();
private final File file;
private final OsUtils utils;
private final List<File> deathRow = new LinkedList<>();

public FileResource() throws IOException {
public FileResource(@ConfigProperty(name = "client.filepath") Optional<String> folder) {
utils = OsUtils.get();
utils.createFile(FILE.getAbsolutePath(), BIGGER_THAN_TWO_GIGABYTES);
file = folder
.stream()
.map(existing -> java.nio.file.Path.of(existing).resolve("server.txt").toAbsolutePath())
.peek(path -> {
utils.createFile(path.toString(), BIGGER_THAN_TWO_GIGABYTES);
})
.map(java.nio.file.Path::toFile)
.findFirst().orElse(null);
}

@GET
@Path("/download")
public Uni<File> download() {
return Uni.createFrom().item(FILE);
return Uni.createFrom().item(file);
}

@POST
@Path("/upload")
public Uni<String> upload(File body) {
deathRow.add(body);
return utils.getSum(body.getAbsolutePath());
}

Expand All @@ -45,23 +60,47 @@ public Uni<String> upload(File body) {
@Produces(MediaType.TEXT_PLAIN)
@Path("/upload-multipart")
public Uni<String> uploadMultipart(@MultipartForm FileWrapper body) {
deathRow.add(body.file);
return utils.getSum(body.file.getAbsolutePath());
}

@GET
@Produces(MediaType.MULTIPART_FORM_DATA)
@Path("/download-multipart")
public RestResponse<FileWrapper> downloadMultipart() {
@Blocking //https://github.com/quarkusio/quarkus/issues/25909
public Uni<FileWrapper> downloadMultipart() {
FileWrapper wrapper = new FileWrapper();
wrapper.file = FILE;
return RestResponse.ok(wrapper);
wrapper.file = file;
wrapper.name = file.getName();
return Uni.createFrom().item(() -> wrapper);
}

@GET
@Produces(MediaType.MULTIPART_FORM_DATA)
@Path("/download-broken-multipart")
@Blocking //https://github.com/quarkusio/quarkus/issues/25909
public Uni<RestResponse> brokenMultipart() {
return Uni.createFrom().item(() -> RestResponse.ok("Not a multipart message"));
}

@GET
@Path("/hash")
@Produces(MediaType.TEXT_PLAIN)
public Uni<String> hash() {
Log.info("Hashing path " + FILE.getAbsolutePath());
return utils.getSum(FILE.getAbsolutePath());
Log.info("Hashing path " + file.getAbsolutePath());
return utils.getSum(file.getAbsolutePath());
}

@DELETE
@Path("/")
public RestResponse drop() {
for (File path : deathRow) {
try {
Files.delete(path.toPath().toAbsolutePath());
} catch (IOException e) {
Log.warn(e);
}
}
return RestResponse.noContent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

import java.io.File;

import javax.ws.rs.FormParam;
import javax.ws.rs.core.MediaType;

import org.jboss.resteasy.reactive.PartType;
import org.jboss.resteasy.reactive.RestForm;

import io.quarkus.runtime.annotations.RegisterForReflection;

@RegisterForReflection
public class FileWrapper {
@FormParam("file")
@RestForm("file")
@PartType(MediaType.APPLICATION_OCTET_STREAM)
public File file;

@RestForm("name")
@PartType(MediaType.TEXT_PLAIN)
public String name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.ExecutionException;
import java.util.function.Predicate;

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;

import io.quarkus.test.bootstrap.RestService;
import io.quarkus.test.scenarios.QuarkusScenario;
import io.quarkus.test.scenarios.annotations.DisabledOnNative;
import io.quarkus.test.services.QuarkusApplication;
import io.quarkus.ts.http.restclient.reactive.files.OsUtils;
import io.restassured.response.Response;
Expand All @@ -26,17 +31,19 @@
public class LargeFileHandlingIT {

private static final String BIGGER_THAN_TWO_GIGABYTES = OsUtils.SIZE_2049MiB;
private static final Path files = getTempDirectory();
private final Path downloaded;
private final Path uploaded;
private final OsUtils utils = OsUtils.get();

@QuarkusApplication
static RestService app = new RestService().withProperties("modern.properties");
static RestService app = new RestService()
.withProperty("client.filepath", () -> files.toAbsolutePath().toString())
.withProperties("modern.properties");

public LargeFileHandlingIT() throws IOException {
downloaded = Files.createTempFile("downloaded", ".txt").toAbsolutePath();
Files.delete(downloaded);
uploaded = Files.createTempFile("uploaded", ".txt").toAbsolutePath();
public LargeFileHandlingIT() {
downloaded = files.resolve("downloaded.txt");
uploaded = files.resolve("uploaded.txt");
}

@Test
Expand Down Expand Up @@ -65,7 +72,6 @@ public void downloadDirectly() throws IOException, ExecutionException, Interrupt
}

@Test
@Disabled("https://github.com/quarkusio/quarkus/issues/24402")
@DisabledOnOs(value = OS.WINDOWS, disabledReason = "https://github.com/quarkusio/quarkus/issues/24763")
public void downloadThroughClient() {
Response hashSum = app.given().get("/file/hash");
Expand Down Expand Up @@ -123,8 +129,8 @@ public void uploadFile() throws ExecutionException, InterruptedException {
}

@Test
@Disabled("https://github.com/quarkusio/quarkus/issues/24405")
@DisabledOnOs(value = OS.WINDOWS, disabledReason = "https://github.com/quarkusio/quarkus/issues/24763")
@DisabledOnNative(reason = "https://github.com/quarkusio/quarkus/issues/25973")
public void uploadFileThroughClient() {
Response hashSum = app.given().get("/file-client/client-hash");
assertEquals(HttpStatus.SC_OK, hashSum.statusCode());
Expand All @@ -150,4 +156,33 @@ public void uploadMultipart() {

assertEquals(before, after);
}

@Test
@DisabledOnOs(value = OS.WINDOWS, disabledReason = "https://github.com/quarkusio/quarkus/issues/24763")
public void multipartError() {
Response download = app.given().get("/file-client/download-broken-multipart");
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, download.statusCode());
Predicate<String> containsError = line -> line.contains("Unable to parse multipart response - No delimiter specified");
Assertions.assertTrue(app.getLogs().stream().anyMatch(containsError));
}

private static Path getTempDirectory() {
try {
return Files.createTempDirectory("large_files");
} catch (IOException e) {
throw new IllegalStateException(e);
}
}

@AfterAll
static void afterAll() throws IOException {
try (DirectoryStream<Path> paths = Files.newDirectoryStream(files)) {
for (Path path : paths) {
Files.delete(path);
}
}
app.given().delete("/file-client/");
app.given().delete("/file/");
Files.delete(files);
}
}
Loading

0 comments on commit 82dfd2f

Please sign in to comment.