Skip to content
This repository has been archived by the owner on Mar 13, 2021. It is now read-only.

Commit

Permalink
Throw a more informative exception if function does not exist
Browse files Browse the repository at this point in the history
Fixes gh-36
  • Loading branch information
dsyer committed Mar 8, 2018
1 parent 23bf491 commit e455911
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/io/projectriff/invoker/ApplicationRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ public Object getBean(String name) {
if (containsBeanByName(name)) {
return getBeanByName(name);
}
return getBeanByType(name);
try {
return getBeanByType(name);
}
catch (Exception e) {
// not there
}
}
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/projectriff/invoker/GrpcConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public void start() throws IOException {
try {
Function<Flux<?>, Flux<?>> function = catalog.lookup(Function.class,
functions.getFunctionName());
if (function == null) {
throw new IllegalStateException(
"No such function: " + functions.getFunctionName());
}
this.server = ServerBuilder.forPort(this.port)
.addService(new JavaFunctionInvokerServer(function, this.mapper,
inspector.getInputType(function),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ private void checkStatus(Throwable cause, Status.Code expectedCode) {
assertThat(s.getCause()).isEqualTo(cause);
}

@SuppressWarnings("serial")
private static class TestException extends Throwable {
TestException(String message) {
super(message);
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/io/projectriff/invoker/GrpcIsolatedTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ public void fluxFunctionNotIsolated() throws Exception {
+ "?handler=io.projectriff.functions.FluxDoubler");
}

@Test
public void nonExistentFunction() throws Exception {
expected.expect(BeanCreationException.class);
SpringApplication.run(JavaFunctionInvokerApplication.class, "--server.port=0",
"--grpc.port=" + port, "--function.uri=file:target/test-classes"
+ "?handler=io.projectriff.functions.NotHere");
}

@Test
public void fluxFunction() throws Exception {
runner.run("--server.port=0", "--grpc.port=" + port,
Expand Down Expand Up @@ -151,6 +159,13 @@ public void appClassPath() throws Exception {
assertThat(result).contains("10");
}

@Test(expected = IllegalStateException.class)
public void nonExistentFunctionWithMain() throws Exception {
runner.run("--server.port=0", "--grpc.port=" + port,
"--function.uri=app:classpath?" + "handler=notThere&"
+ "main=io.projectriff.functions.FunctionApp");
}

@Test
public void mainClassBeanName() throws Exception {
runner.run("--server.port=0", "--grpc.port=" + port,
Expand Down

0 comments on commit e455911

Please sign in to comment.