|
19 | 19 | package org.apache.pulsar.functions.utils; |
20 | 20 |
|
21 | 21 | import static org.apache.pulsar.common.functions.FunctionConfig.ProcessingGuarantees.EFFECTIVELY_ONCE; |
| 22 | +import static org.apache.pulsar.common.functions.FunctionConfig.Runtime.GO; |
22 | 23 | import static org.apache.pulsar.common.functions.FunctionConfig.Runtime.PYTHON; |
23 | 24 | import static org.testng.Assert.assertEquals; |
24 | 25 | import static org.testng.Assert.assertFalse; |
|
29 | 30 | import java.lang.reflect.Field; |
30 | 31 | import java.util.Arrays; |
31 | 32 | import java.util.Collection; |
| 33 | +import java.util.Collections; |
32 | 34 | import java.util.HashMap; |
33 | 35 | import java.util.Map; |
34 | 36 | import java.util.concurrent.atomic.AtomicReference; |
@@ -763,4 +765,69 @@ public void testConvertProducerSpecToProducerConfigAndBackToProducerSpec() { |
763 | 765 | producerSpec.getCryptoSpec().getProducerEncryptionKeyNameAt(i)); |
764 | 766 | } |
765 | 767 | } |
| 768 | + |
| 769 | + private static FunctionConfig minimalGoFunctionConfig() { |
| 770 | + FunctionConfig functionConfig = new FunctionConfig(); |
| 771 | + functionConfig.setTenant("test-tenant"); |
| 772 | + functionConfig.setNamespace("test-namespace"); |
| 773 | + functionConfig.setName("test-function"); |
| 774 | + functionConfig.setInputs(Collections.singletonList("persistent://public/default/input")); |
| 775 | + functionConfig.setRuntime(GO); |
| 776 | + functionConfig.setGo("/path/to/function"); |
| 777 | + return functionConfig; |
| 778 | + } |
| 779 | + |
| 780 | + @Test |
| 781 | + public void testGoFunctionAcceptsRetainKeyOrdering() { |
| 782 | + FunctionConfig functionConfig = minimalGoFunctionConfig(); |
| 783 | + functionConfig.setRetainKeyOrdering(true); |
| 784 | + |
| 785 | + FunctionConfigUtils.validateNonJavaFunction(functionConfig); |
| 786 | + |
| 787 | + // The KeyShared subscription the Go runtime selects has to survive conversion, otherwise the |
| 788 | + // instance never sees it. |
| 789 | + assertEquals(FunctionConfigUtils.convert(functionConfig).getSource().getSubscriptionType(), |
| 790 | + SubscriptionType.KEY_SHARED); |
| 791 | + } |
| 792 | + |
| 793 | + @Test |
| 794 | + public void testGoFunctionAcceptsRetainOrdering() { |
| 795 | + FunctionConfig functionConfig = minimalGoFunctionConfig(); |
| 796 | + functionConfig.setRetainOrdering(true); |
| 797 | + |
| 798 | + FunctionConfigUtils.validateNonJavaFunction(functionConfig); |
| 799 | + |
| 800 | + assertEquals(FunctionConfigUtils.convert(functionConfig).getSource().getSubscriptionType(), |
| 801 | + SubscriptionType.FAILOVER); |
| 802 | + } |
| 803 | + |
| 804 | + @Test(expectedExceptions = IllegalArgumentException.class, |
| 805 | + expectedExceptionsMessageRegExp = "Only one of retain ordering or retain key ordering can be set") |
| 806 | + public void testGoFunctionRejectsBothOrderingModes() { |
| 807 | + FunctionConfig functionConfig = minimalGoFunctionConfig(); |
| 808 | + functionConfig.setRetainOrdering(true); |
| 809 | + functionConfig.setRetainKeyOrdering(true); |
| 810 | + |
| 811 | + FunctionConfigUtils.validateNonJavaFunction(functionConfig); |
| 812 | + } |
| 813 | + |
| 814 | + @Test(expectedExceptions = IllegalArgumentException.class, |
| 815 | + expectedExceptionsMessageRegExp = |
| 816 | + "When effectively once processing guarantee is specified, retain Key ordering cannot be set") |
| 817 | + public void testGoFunctionRejectsRetainKeyOrderingWithEffectivelyOnce() { |
| 818 | + FunctionConfig functionConfig = minimalGoFunctionConfig(); |
| 819 | + functionConfig.setRetainKeyOrdering(true); |
| 820 | + functionConfig.setProcessingGuarantees(EFFECTIVELY_ONCE); |
| 821 | + |
| 822 | + FunctionConfigUtils.validateNonJavaFunction(functionConfig); |
| 823 | + } |
| 824 | + |
| 825 | + @Test(expectedExceptions = IllegalArgumentException.class, |
| 826 | + expectedExceptionsMessageRegExp = "Message retries not yet supported in Go function") |
| 827 | + public void testGoFunctionStillRejectsMessageRetries() { |
| 828 | + FunctionConfig functionConfig = minimalGoFunctionConfig(); |
| 829 | + functionConfig.setMaxMessageRetries(3); |
| 830 | + |
| 831 | + FunctionConfigUtils.validateNonJavaFunction(functionConfig); |
| 832 | + } |
766 | 833 | } |
0 commit comments