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 3, 2022
1 parent 0a5a477 commit d5771a7
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface AuthorClient {
@Produces(MediaType.TEXT_PLAIN)
interface ProfessionClient {
@GET
@Path("/name")
@Path("/title")
Uni<String> getName();

@Path("/wage")
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,55 @@

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

import javax.enterprise.event.Observes;
import javax.inject.Inject;
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 io.quarkus.runtime.ShutdownEvent;
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
.map(existing -> java.nio.file.Path.of(existing).resolve("upload.txt").toAbsolutePath())
.orElseGet(() -> {
try {
return Files.createTempFile("upload", ".txt");
} catch (IOException e) {
throw new IllegalStateException(e);
}
});
utils.createFile(file.toString(), BIGGER_THAN_TWO_GIGABYTES);
deathRow.add(file);
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 +62,53 @@ 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());
}

void onStop(@Observes ShutdownEvent ev) throws IOException {
for (java.nio.file.Path path : deathRow) {
Files.delete(path);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,50 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Optional;

import javax.enterprise.event.Observes;
import javax.ws.rs.Consumes;
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.quarkus.runtime.ShutdownEvent;
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;

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
.map(existing -> java.nio.file.Path.of(existing).resolve("server.txt").toAbsolutePath())
.orElseGet(() -> {
try {
return Files.createTempFile("server", ".txt");
} catch (IOException e) {
throw new IllegalStateException(e);
}
})
.toFile();
utils.createFile(file.getAbsolutePath(), BIGGER_THAN_TWO_GIGABYTES);
}

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

@POST
Expand All @@ -51,17 +66,31 @@ public Uni<String> uploadMultipart(@MultipartForm FileWrapper body) {
@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());
}

void onStop(@Observes ShutdownEvent ev) throws IOException {
Files.delete(file.toPath().toAbsolutePath());
}
}
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,11 +6,15 @@
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;
Expand All @@ -26,17 +30,20 @@
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,7 +129,6 @@ 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")
public void uploadFileThroughClient() {
Response hashSum = app.given().get("/file-client/client-hash");
Expand All @@ -150,4 +155,31 @@ 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);
}
}
Files.delete(files);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
Expand Down Expand Up @@ -96,7 +95,6 @@ public void deepestLevelDirectly() {
}

@Test
@Disabled("https://github.com/quarkusio/quarkus/issues/25028")
public void subResource() {
Response response = app.given().get("/client/book/author/?author=Heller");
assertEquals(HttpStatus.SC_OK, response.statusCode());
Expand All @@ -108,11 +106,10 @@ public void subResource() {
}

@Test
@Disabled("https://github.com/quarkusio/quarkus/issues/25028")
public void deepLevel() {
Response response = app.given().get("/client/book/currency");
assertEquals(HttpStatus.SC_OK, response.statusCode());
assertEquals("Heller", response.getBody().asString());
assertEquals("USD", response.getBody().asString());
}

@DisabledOnQuarkusVersion(version = DISABLE_IF_NOT_QUARKUS_2_7_6_OR_2_8_3_OR_HIGHER, reason = FIXED_IN_2_7_6_AND_2_8_3)
Expand Down

0 comments on commit d5771a7

Please sign in to comment.