diff --git a/extensions/amazon-lambda/common-runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AbstractLambdaPollLoop.java b/extensions/amazon-lambda/common-runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AbstractLambdaPollLoop.java index 347f0b3d4c8452..3cf3c69583493c 100644 --- a/extensions/amazon-lambda/common-runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AbstractLambdaPollLoop.java +++ b/extensions/amazon-lambda/common-runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AbstractLambdaPollLoop.java @@ -74,8 +74,10 @@ public void run() { } } else { Object input = null; - if (running.get() && getInputReader() != null) { - input = getInputReader().readValue(requestConnection.getInputStream()); + if (running.get()) { + ObjectReader inputReader = getInputReader(); + if (inputReader != null) + input = inputReader.readValue(requestConnection.getInputStream()); Object output = processRequest(input, createContext(requestConnection)); postResponse(url, output); } diff --git a/integration-tests/funqy-amazon-lambda/src/main/java/io/quarkus/funqy/test/NoArgFun.java b/integration-tests/funqy-amazon-lambda/src/main/java/io/quarkus/funqy/test/NoArgFun.java new file mode 100644 index 00000000000000..d5b24028299046 --- /dev/null +++ b/integration-tests/funqy-amazon-lambda/src/main/java/io/quarkus/funqy/test/NoArgFun.java @@ -0,0 +1,10 @@ +package io.quarkus.funqy.test; + +import io.quarkus.funqy.Funq; + +public class NoArgFun { + @Funq + public String noArgFun() { + return "noArgFun"; + } +} diff --git a/integration-tests/funqy-amazon-lambda/src/test/java/io/quarkus/funqy/test/NoArgFunTest.java b/integration-tests/funqy-amazon-lambda/src/test/java/io/quarkus/funqy/test/NoArgFunTest.java new file mode 100644 index 00000000000000..1fb94529c86a88 --- /dev/null +++ b/integration-tests/funqy-amazon-lambda/src/test/java/io/quarkus/funqy/test/NoArgFunTest.java @@ -0,0 +1,19 @@ +package io.quarkus.funqy.test; + +import java.time.Duration; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import io.quarkus.amazon.lambda.test.LambdaClient; +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +@ExtendWith(UseNoArgFunExtension.class) +public class NoArgFunTest { + + @Test + public void testNoArgFun() throws Exception { + LambdaClient.invoke(String.class, null, Duration.ofSeconds(5)); + } +} diff --git a/integration-tests/funqy-amazon-lambda/src/test/java/io/quarkus/funqy/test/UseNoArgFunExtension.java b/integration-tests/funqy-amazon-lambda/src/test/java/io/quarkus/funqy/test/UseNoArgFunExtension.java new file mode 100644 index 00000000000000..b5a608fb332062 --- /dev/null +++ b/integration-tests/funqy-amazon-lambda/src/test/java/io/quarkus/funqy/test/UseNoArgFunExtension.java @@ -0,0 +1,9 @@ +package io.quarkus.funqy.test; + +import org.junit.jupiter.api.extension.Extension; + +public class UseNoArgFunExtension implements Extension { + static { + System.setProperty("quarkus.funqy.export", "noArgFun"); + } +} diff --git a/test-framework/amazon-lambda/src/main/java/io/quarkus/amazon/lambda/test/LambdaClient.java b/test-framework/amazon-lambda/src/main/java/io/quarkus/amazon/lambda/test/LambdaClient.java index 37439a471680c7..60dde79e35a877 100644 --- a/test-framework/amazon-lambda/src/main/java/io/quarkus/amazon/lambda/test/LambdaClient.java +++ b/test-framework/amazon-lambda/src/main/java/io/quarkus/amazon/lambda/test/LambdaClient.java @@ -2,13 +2,13 @@ import java.io.InputStream; import java.io.OutputStream; +import java.time.Duration; +import java.util.AbstractMap; import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import io.quarkus.arc.Arc; @@ -92,44 +92,47 @@ public String setValue(String value) { } public static T invoke(Class returnType, Object input) { + return invoke(returnType, input, Duration.ofNanos(Long.MAX_VALUE)); + } + + public static T invoke(Class returnType, Object input, Duration timeout) { + try { + return invokeAsync(returnType, input).get(timeout.toMillis(), TimeUnit.MILLISECONDS); + } catch (ExecutionException e) { + Throwable ex = e.getCause(); + if (ex instanceof RuntimeException) { + throw (RuntimeException) ex; + } + throw new RuntimeException(ex); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static CompletableFuture invokeAsync(Class returnType, Object input) { if (problem != null) { - throw new RuntimeException(problem); + CompletableFuture failed = new CompletableFuture<>(); + failed.completeExceptionally(problem); + return failed; } + final ObjectMapper mapper = getObjectMapper(); + final String id = "aws-request-" + REQUEST_ID_GENERATOR.incrementAndGet(); + final String requestBody; + final CompletableFuture result = new CompletableFuture<>(); + REQUESTS.put(id, result); try { - final ObjectMapper mapper = getObjectMapper(); - String id = "aws-request-" + REQUEST_ID_GENERATOR.incrementAndGet(); - CompletableFuture result = new CompletableFuture<>(); - REQUESTS.put(id, result); - String requestBody = mapper.writeValueAsString(input); - REQUEST_QUEUE.add(new Map.Entry() { - - @Override - public String getKey() { - return id; - } - - @Override - public String getValue() { - return requestBody; - } - - @Override - public String setValue(String value) { - return null; - } - }); - String output = result.get(); - return mapper.readerFor(returnType).readValue(output); - } catch (Exception e) { - if (e instanceof ExecutionException) { - Throwable ex = e.getCause(); - if (ex instanceof RuntimeException) { - throw (RuntimeException) ex; - } - throw new RuntimeException(ex); - } + requestBody = mapper.writeValueAsString(input); + } catch (JsonProcessingException e) { throw new RuntimeException(e); } + REQUEST_QUEUE.add(new AbstractMap.SimpleImmutableEntry(id, requestBody)); + return result.thenApply(s -> { + try { + return mapper.readerFor(returnType).readValue(s); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + }); } private static ObjectMapper getObjectMapper() {