Skip to content

Commit

Permalink
GH-578 Fix FunctionRegistration lookup
Browse files Browse the repository at this point in the history
The root of the issue was in implementation of  equals() and hashCode() of FunctionInvocationWrapper

Resolves #578
  • Loading branch information
olegz committed Sep 21, 2020
1 parent c8ae76d commit 9f700bf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Expand Up @@ -20,7 +20,6 @@
import java.util.Set;

import org.springframework.cloud.function.context.FunctionRegistration;
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
import org.springframework.cloud.function.context.config.RoutingFunction;

/**
Expand All @@ -33,9 +32,12 @@ public interface FunctionInspector {

default boolean isMessage(Object function) {
FunctionRegistration<?> registration = getRegistration(function);
if (registration != null && registration.getTarget() instanceof FunctionInvocationWrapper
&& ((FunctionInvocationWrapper) registration.getTarget()).getTarget() instanceof RoutingFunction) {
// we always want to give routing function as much information as possible
// if (registration != null && registration.getTarget() instanceof FunctionInvocationWrapper
// && ((FunctionInvocationWrapper) registration.getTarget()).getTarget() instanceof RoutingFunction) {
// // we always want to give routing function as much information as possible
// return true;
// }
if (registration != null && registration.getTarget() instanceof RoutingFunction) {
return true;
}
return registration == null ? false : registration.getType().isMessage();
Expand Down
Expand Up @@ -456,15 +456,21 @@ public int hashCode() {
if (this.delegate != null) {
return this.delegate.hashCode();
}
return super.hashCode();
else {
return this.target.hashCode();
}
//return super.hashCode();
}

@Override
public boolean equals(Object o) {
if (this.delegate != null) {
return this.delegate.equals(o);
}
return super.equals(o);
else {
return this.target.equals(o);
}
// return super.equals(o);
}

public String getFunctionDefinition() {
Expand Down
Expand Up @@ -89,6 +89,12 @@ public void testFunctionPrimitive() throws Exception {
.contentType(MediaType.TEXT_PLAIN)
.header("spring.cloud.function.definition", "echo")
.body("{\"name\":\"Bob\",\"age\":25}"), String.class);
postForEntity = this.rest
.exchange(RequestEntity.post(new URI("/functions/" + RoutingFunction.FUNCTION_NAME))
.contentType(MediaType.TEXT_PLAIN)
.header("spring.cloud.function.definition", "echo")
.body("{\"name\":\"Bob\",\"age\":25}"), String.class);

assertThat(postForEntity.getBody()).isEqualTo("{\"name\":\"Bob\",\"age\":25}");
assertThat(postForEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
}
Expand Down

0 comments on commit 9f700bf

Please sign in to comment.