Jennifer88huang commented on a change in pull request #4485: add docs on how to 
debug Pulsar Functions
URL: https://github.com/apache/pulsar/pull/4485#discussion_r291824705
 
 

 ##########
 File path: site2/docs/functions-debugging.md
 ##########
 @@ -0,0 +1,121 @@
+---
+id: functions-debugging
+title: Debugging Pulsar Functions
+sidebar_label: Debugging functions
+---
+
+A Pulsar Function at its core is just a function with inputs and outputs, thus 
testing a Pulsar Function can be done in a similar way as testing any function.
+
+For example, if a user has the following Pulsar Function:
+
+```java
+import java.util.function.Function;
+
+public class JavaNativeExclamationFunction implements Function<String, String> 
{
+   @Override
+   public String apply(String input) {
+       return String.format("%s!", input);
+   }
+}
+```
+
+The user can write a simple unit test to test this Pulsar function:
+
+```java
+@Test
+public void testJavaNativeExclamationFunction() {
+   JavaNativeExclamationFunction exclamation = new 
JavaNativeExclamationFunction();
+   String output = exclamation.apply("foo");
+   Assert.assertEquals(output, "foo!");
+}
+```
+
+Consequently, if a user has a Pulsar Function that implements the 
```org.apache.pulsar.functions.api.Function``` interface:
+
+```java
+import org.apache.pulsar.functions.api.Context;
+import org.apache.pulsar.functions.api.Function;
+
+public class ExclamationFunction implements Function<String, String> {
+   @Override
+   public String process(String input, Context context) {
+       return String.format("%s!", input);
+   }
+}
+```
+
+The user can write a unit test for this function as well. Just be remember to 
mock out the ```Context``` parameter.
+
+For example:
+
+```java
+@Test
+public void testExclamationFunction() {
+   ExclamationFunction exclamation = new ExclamationFunction();
+   String output = exclamation.process("foo", mock(Context.class));
+   Assert.assertEquals(output, "foo!");
+}
+```
+
+## Debugging with localrun mode
 
 Review comment:
   ```suggestion
   ## Debug with the localrun mode
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to