Skip to content

Commit

Permalink
Merge branch 'master' into mww-190404-reverse-up
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-w-williams authored Apr 25, 2019
2 parents ece0416 + 6d63aca commit 9cd9358
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion release.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.87
1.0.91
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@
*/
public class MethodFunctionInvoker implements FunctionInvoker {

/*
* If enabled, print the logging framing content
*/
public void logFramer(FunctionRuntimeContext rctx, InputEvent evt) {
String framer = rctx.getConfigurationByKey("FN_LOGFRAME_NAME").orElse("");

if (framer != "") {
String valueSrc = rctx.getConfigurationByKey("FN_LOGFRAME_HDR").orElse("");

if (valueSrc != "") {
String id = evt.getHeaders().get(valueSrc).orElse("");
if (id != "") {
System.out.println("\n" + framer + "=" + id + "\n");
System.err.println("\n" + framer + "=" + id + "\n");
}
}
}
}


/**
* Invoke the function wrapped by this loader
*
Expand All @@ -33,6 +53,8 @@ public Optional<OutputEvent> tryInvoke(InvocationContext ctx, InputEvent evt) th

Object rawResult;

logFramer(runtimeContext, evt);

try {
rawResult = method.getTargetMethod().invoke(ctx.getRuntimeContext().getInvokeInstance().orElse(null), userFunctionParams);
} catch (IllegalAccessException | InvocationTargetException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,19 @@ public void shouldReadBytesOnDefaultCodec() throws Exception {

}

@Test
public void shouldPrintLogFrame() throws Exception {
fn.setConfig("FN_LOGFRAME_NAME", "containerID");
fn.setConfig("FN_LOGFRAME_HDR", "fnID");
fn.givenEvent().withHeader("fnID", "fnIDVal").withBody( "Hello world!").enqueue();

fn.thenRun(TestFn.class, "fnEcho");
assertThat(fn.getOnlyOutputAsString()).isEqualTo("Hello world!");
// stdout gets redirected to stderr - hence printing out twice
assertThat(fn.getStdErrAsString()).isEqualTo("\ncontainerID=fnIDVal\n\n\ncontainerID=fnIDVal\n\n");

}


@Test
public void shouldWriteBytesOnDefaultCodec() throws Exception {
Expand Down

0 comments on commit 9cd9358

Please sign in to comment.