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 @@ -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(framer + "=" + id);
System.err.println(framer + "=" + id);
}
}
}
}


/**
* 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("containerID=fnIDVal\ncontainerID=fnIDVal\n");

}


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