You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/04/25 21:10:34 UTC

[GitHub] [pulsar] david-streamlio commented on a change in pull request #10369: Added more unit tests to the JavaInstanceTest class

david-streamlio commented on a change in pull request #10369:
URL: https://github.com/apache/pulsar/pull/10369#discussion_r619878659



##########
File path: pulsar-functions/instance/src/test/java/org/apache/pulsar/functions/instance/JavaInstanceTest.java
##########
@@ -54,6 +55,52 @@ public void testLambda() throws Exception {
         assertEquals(new String(testString + "-lambda"), result.get().getResult());
         instance.close();
     }
+    
+    @Test
+    public void testNullReturningFunction() throws Exception  {
+    	JavaInstance instance = new JavaInstance(
+                mock(ContextImpl.class),
+                (Function<String, String>) (input, context) -> null,
+                new InstanceConfig());
+    	String testString = "ABC123";
+    	CompletableFuture<JavaExecutionResult> result = instance.handleMessage(mock(Record.class), testString);
+    	assertNull(result.get().getResult());
+    	instance.close();
+    }
+
+    @Test
+    public void testUserExceptionThrowingFunction() throws Exception  {
+    	Function<String, String> func = (input, context) -> {
+    		throw new UserException("Boom");
+    	};
+
+    	JavaInstance instance = new JavaInstance(
+                mock(ContextImpl.class),
+                func,
+                new InstanceConfig());
+    	String testString = "ABC123";
+    	CompletableFuture<JavaExecutionResult> result = instance.handleMessage(mock(Record.class), testString);
+    	assertNull(result.get().getResult());
+    	assertNotNull(result.get().getUserException());

Review comment:
       I have updated the code to use assertSame




-- 
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:
users@infra.apache.org