Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle void return type from Function clients #6771

Merged
merged 1 commit into from Jan 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -88,6 +88,9 @@ public O invoke(FunctionDefinition definition, I input, Argument<O> outputType)
return ConversionService.SHARED.convert(publisher, outputType).orElseThrow(() ->
new FunctionExecutionException("Unsupported Reactive type: " + outputJavaType)
);
} else if (outputType.isVoid()) {
httpClient.toBlocking().exchange(request);
return null;
} else {
return (O) httpClient.toBlocking().retrieve(request, outputType);
}
Expand Down
@@ -0,0 +1,47 @@
package io.micronaut.function.web

import io.micronaut.context.ApplicationContext
import io.micronaut.context.annotation.Requires
import io.micronaut.context.env.Environment
import io.micronaut.function.FunctionBean
import io.micronaut.function.client.FunctionClient
import io.micronaut.runtime.server.EmbeddedServer
import jakarta.inject.Named
import spock.lang.Issue
import spock.lang.Specification

import java.util.function.Consumer

class NullReturningConsumerFunctionSpec extends Specification {

@Issue("https://github.com/micronaut-projects/micronaut-core/issues/2024")
def "test a client with a void return type"() {
given:
def embeddedServer = ApplicationContext.run(EmbeddedServer)
def client = embeddedServer.applicationContext.getBean(MicronautFunctionProblemsClient)

when:
client.sendVoid("woo")

then:
PojoConsumer.LAST_VALUE == "woo"
}

@FunctionClient
static interface MicronautFunctionProblemsClient {

@Named("consumer/void")
void sendVoid(String message)
}

@FunctionBean("consumer/void")
static class PojoConsumer implements Consumer<String> {

static String LAST_VALUE

@Override
void accept(String book) {
LAST_VALUE = book
}
}
}