Skip to content
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
Expand Up @@ -130,6 +130,11 @@ public final void handleRequest(InputStream inputStream, OutputStream outputStre
var inputString = new String(inputStream.readAllBytes());
logger.debug("Raw input from durable handler: {}", inputString);
var input = serDes.deserialize(inputString, TypeToken.get(DurableExecutionInput.class));
// Durable function inputs must contain DurableExecutionArn and CheckpointToken
if (input.durableExecutionArn() == null || input.checkpointToken() == null) {
throw new IllegalStateException(
"Unexpected payload provided to start the durable execution. DurableConfig must be set in Lambda function configuration.");
}
var output = DurableExecutor.execute(input, context, inputType, this::handleRequest, config);
outputStream.write(serDes.serialize(output).getBytes());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;

class DurableHandlerTest {
Expand Down Expand Up @@ -47,6 +52,19 @@ public Object handleRequest(Object input, DurableContext context) {
}
}

@Test
void testNonDurableFunctionThrowsUserFriendlyError() throws Exception {
var handler = new TestDurableHandler();
// Durable function inputs must contain DurableExecutionArn and CheckpointToken
var nonDurableInput = "{\"input\": \"non-durable\"}";
var inputStream = new ByteArrayInputStream(nonDurableInput.getBytes(StandardCharsets.UTF_8));
var outputStream = new ByteArrayOutputStream();

var exception =
assertThrows(IllegalStateException.class, () -> handler.handleRequest(inputStream, outputStream, null));
assertTrue(exception.getMessage().contains("Unexpected payload provided to start the durable execution"));
}

// Test handler implementation
private static class TestDurableHandler extends DurableHandler<String, String> {
@Override
Expand Down