merlimat closed pull request #1340: Make default processing guarantee 
AT_LEAST_ONCE
URL: https://github.com/apache/incubator-pulsar/pull/1340
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java
 
b/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java
index 8f642e364..06904cf1d 100644
--- 
a/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java
+++ 
b/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java
@@ -32,6 +32,7 @@
 import java.util.Map;
 import java.util.concurrent.LinkedBlockingDeque;
 import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
 import lombok.AccessLevel;
 import lombok.Getter;
 import lombok.Setter;
@@ -57,7 +58,6 @@
 import org.apache.pulsar.functions.proto.Function.FunctionConfig;
 import 
org.apache.pulsar.functions.proto.Function.FunctionConfig.ProcessingGuarantees;
 import org.apache.pulsar.functions.proto.InstanceCommunication;
-import org.apache.pulsar.functions.instance.InstanceConfig;
 import org.apache.pulsar.functions.utils.functioncache.FunctionCacheManager;
 import org.apache.pulsar.functions.api.SerDe;
 import 
org.apache.pulsar.functions.instance.producers.MultiConsumersOneSinkTopicProducers;
@@ -66,8 +66,6 @@
 import org.apache.pulsar.functions.instance.state.StateContextImpl;
 import org.apache.pulsar.functions.utils.FunctionConfigUtils;
 import org.apache.pulsar.functions.utils.Reflections;
-
-import java.util.function.Function;
 import org.apache.pulsar.functions.utils.Utils;
 
 /**
@@ -132,9 +130,7 @@ public JavaInstanceRunnable(InstanceConfig instanceConfig,
                                 PulsarClient pulsarClient,
                                 String stateStorageServiceUrl) {
         this.instanceConfig = instanceConfig;
-        this.processingGuarantees = 
instanceConfig.getFunctionConfig().getProcessingGuarantees() == null
-                ? FunctionConfig.ProcessingGuarantees.ATMOST_ONCE
-                : instanceConfig.getFunctionConfig().getProcessingGuarantees();
+        this.processingGuarantees = 
instanceConfig.getFunctionConfig().getProcessingGuarantees();
         this.fnCache = fnCache;
         this.queue = new 
LinkedBlockingDeque<>(instanceConfig.getMaxBufferedTuples());
         this.jarFile = jarFile;
diff --git a/pulsar-functions/proto/src/main/proto/Function.proto 
b/pulsar-functions/proto/src/main/proto/Function.proto
index 6027200ab..2beab1283 100644
--- a/pulsar-functions/proto/src/main/proto/Function.proto
+++ b/pulsar-functions/proto/src/main/proto/Function.proto
@@ -25,8 +25,8 @@ option java_outer_classname = "Function";
 
 message FunctionConfig {
     enum ProcessingGuarantees {
-        ATMOST_ONCE = 0;
-        ATLEAST_ONCE = 1;
+        ATLEAST_ONCE = 0; // [default value]
+        ATMOST_ONCE = 1;
         EFFECTIVELY_ONCE = 2;
     }
     enum SubscriptionType {
diff --git 
a/pulsar-functions/proto/src/test/java/org/apache/pulsar/functions/proto/FunctionConfigTest.java
 
b/pulsar-functions/proto/src/test/java/org/apache/pulsar/functions/proto/FunctionConfigTest.java
new file mode 100644
index 000000000..b4cb287b6
--- /dev/null
+++ 
b/pulsar-functions/proto/src/test/java/org/apache/pulsar/functions/proto/FunctionConfigTest.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.functions.proto;
+
+import static org.testng.Assert.assertEquals;
+
+import org.apache.pulsar.functions.proto.Function.FunctionConfig;
+import 
org.apache.pulsar.functions.proto.Function.FunctionConfig.ProcessingGuarantees;
+import org.testng.annotations.Test;
+
+/**
+ * Unit test for {@link FunctionConfig}.
+ */
+public class FunctionConfigTest {
+
+    /**
+     * Make sure the default processing guarantee is always `ATLEAST_ONCE`.
+     */
+    @Test
+    public void testDefaultProcessingGuarantee() {
+        FunctionConfig fc = FunctionConfig.newBuilder().build();
+        assertEquals(ProcessingGuarantees.ATLEAST_ONCE, 
fc.getProcessingGuarantees());
+    }
+
+}
diff --git 
a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/ProcessRuntime.java
 
b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/ProcessRuntime.java
index 03bcb3b6a..d1ec87aa7 100644
--- 
a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/ProcessRuntime.java
+++ 
b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/ProcessRuntime.java
@@ -153,11 +153,7 @@
             
args.add(instanceConfig.getFunctionConfig().getOutputSerdeClassName());
         }
         args.add("--processing_guarantees");
-        if (instanceConfig.getFunctionConfig().getProcessingGuarantees() != 
null) {
-            
args.add(String.valueOf(instanceConfig.getFunctionConfig().getProcessingGuarantees()));
-        } else {
-            args.add("ATMOST_ONCE");
-        }
+        
args.add(String.valueOf(instanceConfig.getFunctionConfig().getProcessingGuarantees()));
         args.add("--pulsar_serviceurl");
         args.add(pulsarServiceUrl);
         args.add("--max_buffered_tuples");
diff --git 
a/pulsar-functions/runtime/src/test/java/org/apache/pulsar/functions/runtime/ProcessRuntimeTest.java
 
b/pulsar-functions/runtime/src/test/java/org/apache/pulsar/functions/runtime/ProcessRuntimeTest.java
index 941babf48..5b149af1a 100644
--- 
a/pulsar-functions/runtime/src/test/java/org/apache/pulsar/functions/runtime/ProcessRuntimeTest.java
+++ 
b/pulsar-functions/runtime/src/test/java/org/apache/pulsar/functions/runtime/ProcessRuntimeTest.java
@@ -115,7 +115,7 @@ public void testJavaConstructor() {
                 + " --auto_ack false"
                 + " --sink_topic " + config.getFunctionConfig().getOutput()
                 + " --output_serde_classname " + 
config.getFunctionConfig().getOutputSerdeClassName()
-                + " --processing_guarantees ATMOST_ONCE"
+                + " --processing_guarantees ATLEAST_ONCE"
                 + " --pulsar_serviceurl " + pulsarServiceUrl
                 + " --max_buffered_tuples 1024 --port";
         assertEquals(expectedArgs, String.join(" ", args));
@@ -141,7 +141,7 @@ public void testPythonConstructor() {
                 + " --auto_ack false"
                 + " --sink_topic " + config.getFunctionConfig().getOutput()
                 + " --output_serde_classname " + 
config.getFunctionConfig().getOutputSerdeClassName()
-                + " --processing_guarantees ATMOST_ONCE"
+                + " --processing_guarantees ATLEAST_ONCE"
                 + " --pulsar_serviceurl " + pulsarServiceUrl
                 + " --max_buffered_tuples 1024 --port";
         assertEquals(expectedArgs, String.join(" ", args));


 

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


With regards,
Apache Git Services

Reply via email to