Skip to content

Commit f599356

Browse files
committed
feat(sdk): support indirect DurableHandler inheritance
1 parent d8fd15d commit f599356

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

sdk/src/main/java/software/amazon/lambda/durable/DurableHandler.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ protected DurableHandler() {
3535
this.config = createConfiguration();
3636
}
3737

38+
/**
39+
* Constructs a handler with an explicitly provided input type. Use this when the input type cannot be inferred from
40+
* the generic superclass, such as when extending {@link DurableHandler} indirectly through an intermediate class.
41+
*
42+
* @param inputType the token capturing the handler's input type
43+
*/
44+
protected DurableHandler(TypeToken<I> inputType) {
45+
this.inputType = inputType;
46+
this.config = createConfiguration();
47+
}
48+
3849
/**
3950
* Gets the configuration used by this handler. This allows test frameworks and other tools to access the handler's
4051
* configuration for testing purposes.

sdk/src/test/java/software/amazon/lambda/durable/DurableHandlerTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,38 @@ void testNonDurableFunctionThrowsUserFriendlyError() throws Exception {
6565
assertTrue(exception.getMessage().contains("Unexpected payload provided to start the durable execution"));
6666
}
6767

68+
@Test
69+
void testIndirectDurableHandlerInheritance() {
70+
// Handler reaching DurableHandler through an intermediate class resolves
71+
// its input type via the explicit constructor.
72+
var handler = new ConcreteIndirectHandler();
73+
74+
assertNotNull(handler);
75+
76+
var result = handler.handleRequest("test-input", null);
77+
assertEquals("indirect: test-input", result);
78+
}
79+
6880
// Test handler implementation
6981
private static class TestDurableHandler extends DurableHandler<String, String> {
7082
@Override
7183
public String handleRequest(String input, DurableContext context) {
7284
return "processed: " + input;
7385
}
7486
}
87+
88+
// Intermediate handler that forwards an explicit input type
89+
private abstract static class AbstractIndirectHandler<O> extends DurableHandler<String, O> {
90+
protected AbstractIndirectHandler() {
91+
super(TypeToken.get(String.class));
92+
}
93+
}
94+
95+
// Inherits DurableHandler indirectly
96+
private static class ConcreteIndirectHandler extends AbstractIndirectHandler<String> {
97+
@Override
98+
public String handleRequest(String input, DurableContext context) {
99+
return "indirect: " + input;
100+
}
101+
}
75102
}

0 commit comments

Comments
 (0)