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 @@ -35,6 +35,17 @@ protected DurableHandler() {
this.config = createConfiguration();
Comment thread
zhongkechen marked this conversation as resolved.
}

/**
* Constructs a handler with an explicitly provided input type. Use this when the input type cannot be inferred from
* the generic superclass, such as when extending {@link DurableHandler} indirectly through an intermediate class.
*
* @param inputType the token capturing the handler's input type
*/
protected DurableHandler(TypeToken<I> inputType) {
this.inputType = inputType;
this.config = createConfiguration();
}

/**
* Gets the configuration used by this handler. This allows test frameworks and other tools to access the handler's
* configuration for testing purposes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,38 @@ void testNonDurableFunctionThrowsUserFriendlyError() throws Exception {
assertTrue(exception.getMessage().contains("Unexpected payload provided to start the durable execution"));
}

@Test
void testIndirectDurableHandlerInheritance() {
// Handler reaching DurableHandler through an intermediate class resolves
// its input type via the explicit constructor.
var handler = new ConcreteIndirectHandler();

assertNotNull(handler);

var result = handler.handleRequest("test-input", null);
assertEquals("indirect: test-input", result);
}

// Test handler implementation
private static class TestDurableHandler extends DurableHandler<String, String> {
@Override
public String handleRequest(String input, DurableContext context) {
return "processed: " + input;
}
}

// Intermediate handler that forwards an explicit input type
private abstract static class AbstractIndirectHandler<O> extends DurableHandler<String, O> {
protected AbstractIndirectHandler() {
super(TypeToken.get(String.class));
}
}

// Inherits DurableHandler indirectly
private static class ConcreteIndirectHandler extends AbstractIndirectHandler<String> {
@Override
public String handleRequest(String input, DurableContext context) {
return "indirect: " + input;
}
}
}