Search in sources :

Example 1 with ConsumerConfig

use of org.apache.pulsar.common.functions.ConsumerConfig in project pulsar by apache.

the class FunctionConfigUtilsTest method testMergeDifferentInputSpecWithRegexChange.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "isRegexPattern for input topic test-input cannot be altered")
public void testMergeDifferentInputSpecWithRegexChange() {
    FunctionConfig functionConfig = createFunctionConfig();
    Map<String, ConsumerConfig> inputSpecs = new HashMap<>();
    inputSpecs.put("test-input", ConsumerConfig.builder().isRegexPattern(false).serdeClassName("my-serde").build());
    FunctionConfig newFunctionConfig = createUpdatedFunctionConfig("inputSpecs", inputSpecs);
    FunctionConfigUtils.validateUpdate(functionConfig, newFunctionConfig);
}
Also used : FunctionConfig(org.apache.pulsar.common.functions.FunctionConfig) HashMap(java.util.HashMap) ConsumerConfig(org.apache.pulsar.common.functions.ConsumerConfig) Test(org.testng.annotations.Test)

Example 2 with ConsumerConfig

use of org.apache.pulsar.common.functions.ConsumerConfig in project pulsar by apache.

the class FunctionConfigUtilsTest method createFunctionConfig.

private FunctionConfig createFunctionConfig() {
    FunctionConfig functionConfig = new FunctionConfig();
    functionConfig.setTenant("test-tenant");
    functionConfig.setNamespace("test-namespace");
    functionConfig.setName("test-function");
    functionConfig.setParallelism(1);
    functionConfig.setClassName(IdentityFunction.class.getName());
    Map<String, ConsumerConfig> inputSpecs = new HashMap<>();
    inputSpecs.put("test-input", ConsumerConfig.builder().isRegexPattern(true).serdeClassName("test-serde").build());
    functionConfig.setInputSpecs(inputSpecs);
    functionConfig.setOutput("test-output");
    functionConfig.setOutputSerdeClassName("test-serde");
    functionConfig.setOutputSchemaType("json");
    functionConfig.setRuntime(FunctionConfig.Runtime.JAVA);
    functionConfig.setProcessingGuarantees(FunctionConfig.ProcessingGuarantees.ATLEAST_ONCE);
    functionConfig.setRetainOrdering(false);
    functionConfig.setRetainKeyOrdering(false);
    functionConfig.setSubscriptionPosition(SubscriptionInitialPosition.Earliest);
    functionConfig.setBatchBuilder("DEFAULT");
    functionConfig.setForwardSourceMessageProperty(false);
    functionConfig.setUserConfig(new HashMap<>());
    functionConfig.setAutoAck(true);
    functionConfig.setTimeoutMs(2000l);
    functionConfig.setWindowConfig(new WindowConfig().setWindowLengthCount(10));
    functionConfig.setCleanupSubscription(true);
    functionConfig.setRuntimeFlags("-Dfoo=bar");
    return functionConfig;
}
Also used : FunctionConfig(org.apache.pulsar.common.functions.FunctionConfig) WindowConfig(org.apache.pulsar.common.functions.WindowConfig) HashMap(java.util.HashMap) IdentityFunction(org.apache.pulsar.functions.api.utils.IdentityFunction) ConsumerConfig(org.apache.pulsar.common.functions.ConsumerConfig)

Example 3 with ConsumerConfig

use of org.apache.pulsar.common.functions.ConsumerConfig in project pulsar by apache.

the class FunctionConfigUtilsTest method testConvertBackFidelity.

@Test
public void testConvertBackFidelity() {
    FunctionConfig functionConfig = new FunctionConfig();
    functionConfig.setTenant("test-tenant");
    functionConfig.setNamespace("test-namespace");
    functionConfig.setName("test-function");
    functionConfig.setParallelism(1);
    functionConfig.setClassName(IdentityFunction.class.getName());
    Map<String, ConsumerConfig> inputSpecs = new HashMap<>();
    inputSpecs.put("test-input", ConsumerConfig.builder().isRegexPattern(true).serdeClassName("test-serde").poolMessages(true).build());
    functionConfig.setInputSpecs(inputSpecs);
    functionConfig.setOutput("test-output");
    functionConfig.setOutputSerdeClassName("test-serde");
    functionConfig.setRuntime(FunctionConfig.Runtime.JAVA);
    functionConfig.setProcessingGuarantees(FunctionConfig.ProcessingGuarantees.ATLEAST_ONCE);
    functionConfig.setRetainOrdering(false);
    functionConfig.setRetainKeyOrdering(false);
    functionConfig.setForwardSourceMessageProperty(true);
    functionConfig.setUserConfig(new HashMap<>());
    functionConfig.setAutoAck(true);
    functionConfig.setTimeoutMs(2000l);
    functionConfig.setRuntimeFlags("-DKerberos");
    ProducerConfig producerConfig = new ProducerConfig();
    producerConfig.setMaxPendingMessages(100);
    producerConfig.setMaxPendingMessagesAcrossPartitions(1000);
    producerConfig.setUseThreadLocalProducers(true);
    producerConfig.setBatchBuilder("DEFAULT");
    functionConfig.setProducerConfig(producerConfig);
    Function.FunctionDetails functionDetails = FunctionConfigUtils.convert(functionConfig, null);
    FunctionConfig convertedConfig = FunctionConfigUtils.convertFromDetails(functionDetails);
    // add default resources
    functionConfig.setResources(Resources.getDefaultResources());
    // set default cleanupSubscription config
    functionConfig.setCleanupSubscription(true);
    assertEquals(new Gson().toJson(functionConfig), new Gson().toJson(convertedConfig));
}
Also used : FunctionConfig(org.apache.pulsar.common.functions.FunctionConfig) IdentityFunction(org.apache.pulsar.functions.api.utils.IdentityFunction) Function(org.apache.pulsar.functions.proto.Function) HashMap(java.util.HashMap) IdentityFunction(org.apache.pulsar.functions.api.utils.IdentityFunction) FunctionDetails(org.apache.pulsar.functions.proto.Function.FunctionDetails) ProducerConfig(org.apache.pulsar.common.functions.ProducerConfig) Gson(com.google.gson.Gson) ConsumerConfig(org.apache.pulsar.common.functions.ConsumerConfig) Test(org.testng.annotations.Test)

Example 4 with ConsumerConfig

use of org.apache.pulsar.common.functions.ConsumerConfig in project pulsar by apache.

the class SinkConfigUtilsTest method testConvertBackFidelity.

@Test
public void testConvertBackFidelity() throws IOException {
    SinkConfig sinkConfig = new SinkConfig();
    sinkConfig.setTenant("test-tenant");
    sinkConfig.setNamespace("test-namespace");
    sinkConfig.setName("test-source");
    sinkConfig.setParallelism(1);
    sinkConfig.setArchive("builtin://jdbc");
    sinkConfig.setSourceSubscriptionName("test-subscription");
    Map<String, ConsumerConfig> inputSpecs = new HashMap<>();
    inputSpecs.put("test-input", ConsumerConfig.builder().isRegexPattern(true).receiverQueueSize(532).serdeClassName("test-serde").poolMessages(true).build());
    sinkConfig.setInputs(Collections.singleton("test-input"));
    sinkConfig.setInputSpecs(inputSpecs);
    sinkConfig.setProcessingGuarantees(FunctionConfig.ProcessingGuarantees.ATLEAST_ONCE);
    Map<String, String> producerConfigs = new HashMap<>();
    producerConfigs.put("security.protocal", "SASL_PLAINTEXT");
    Map<String, Object> configs = new HashMap<>();
    configs.put("topic", "kafka");
    configs.put("bootstrapServers", "server-1,server-2");
    configs.put("producerConfigProperties", producerConfigs);
    sinkConfig.setConfigs(configs);
    sinkConfig.setRetainOrdering(false);
    sinkConfig.setRetainKeyOrdering(false);
    sinkConfig.setAutoAck(true);
    sinkConfig.setCleanupSubscription(false);
    sinkConfig.setTimeoutMs(2000l);
    sinkConfig.setRuntimeFlags("-DKerberos");
    sinkConfig.setCleanupSubscription(true);
    sinkConfig.setResources(Resources.getDefaultResources());
    Function.FunctionDetails functionDetails = SinkConfigUtils.convert(sinkConfig, new SinkConfigUtils.ExtractedSinkDetails(null, null));
    assertEquals(Function.SubscriptionType.SHARED, functionDetails.getSource().getSubscriptionType());
    SinkConfig convertedConfig = SinkConfigUtils.convertFromDetails(functionDetails);
    assertEquals(new Gson().toJson(convertedConfig), new Gson().toJson(sinkConfig));
    sinkConfig.setRetainOrdering(true);
    sinkConfig.setRetainKeyOrdering(false);
    functionDetails = SinkConfigUtils.convert(sinkConfig, new SinkConfigUtils.ExtractedSinkDetails(null, null));
    assertEquals(Function.SubscriptionType.FAILOVER, functionDetails.getSource().getSubscriptionType());
    convertedConfig = SinkConfigUtils.convertFromDetails(functionDetails);
    assertEquals(new Gson().toJson(convertedConfig), new Gson().toJson(sinkConfig));
    sinkConfig.setRetainOrdering(false);
    sinkConfig.setRetainKeyOrdering(true);
    functionDetails = SinkConfigUtils.convert(sinkConfig, new SinkConfigUtils.ExtractedSinkDetails(null, null));
    assertEquals(Function.SubscriptionType.KEY_SHARED, functionDetails.getSource().getSubscriptionType());
    convertedConfig = SinkConfigUtils.convertFromDetails(functionDetails);
    assertEquals(new Gson().toJson(convertedConfig), new Gson().toJson(sinkConfig));
}
Also used : HashMap(java.util.HashMap) Gson(com.google.gson.Gson) IdentityFunction(org.apache.pulsar.functions.api.utils.IdentityFunction) Function(org.apache.pulsar.functions.proto.Function) SinkConfig(org.apache.pulsar.common.io.SinkConfig) ConsumerConfig(org.apache.pulsar.common.functions.ConsumerConfig) Test(org.testng.annotations.Test)

Example 5 with ConsumerConfig

use of org.apache.pulsar.common.functions.ConsumerConfig in project pulsar by apache.

the class SinkConfigUtilsTest method testPoolMessages.

@Test
public void testPoolMessages() throws IOException {
    SinkConfig sinkConfig = createSinkConfig();
    Function.FunctionDetails functionDetails = SinkConfigUtils.convert(sinkConfig, new SinkConfigUtils.ExtractedSinkDetails(null, null));
    assertFalse(functionDetails.getSource().getInputSpecsMap().get("test-input").getPoolMessages());
    SinkConfig convertedConfig = SinkConfigUtils.convertFromDetails(functionDetails);
    assertFalse(convertedConfig.getInputSpecs().get("test-input").isPoolMessages());
    Map<String, ConsumerConfig> inputSpecs = new HashMap<>();
    inputSpecs.put("test-input", ConsumerConfig.builder().poolMessages(true).build());
    sinkConfig.setInputSpecs(inputSpecs);
    functionDetails = SinkConfigUtils.convert(sinkConfig, new SinkConfigUtils.ExtractedSinkDetails(null, null));
    assertTrue(functionDetails.getSource().getInputSpecsMap().get("test-input").getPoolMessages());
    convertedConfig = SinkConfigUtils.convertFromDetails(functionDetails);
    assertTrue(convertedConfig.getInputSpecs().get("test-input").isPoolMessages());
}
Also used : IdentityFunction(org.apache.pulsar.functions.api.utils.IdentityFunction) Function(org.apache.pulsar.functions.proto.Function) SinkConfig(org.apache.pulsar.common.io.SinkConfig) HashMap(java.util.HashMap) ConsumerConfig(org.apache.pulsar.common.functions.ConsumerConfig) Test(org.testng.annotations.Test)

Aggregations

ConsumerConfig (org.apache.pulsar.common.functions.ConsumerConfig)66 HashMap (java.util.HashMap)54 Test (org.testng.annotations.Test)36 FunctionConfig (org.apache.pulsar.common.functions.FunctionConfig)33 IdentityFunction (org.apache.pulsar.functions.api.utils.IdentityFunction)27 Function (org.apache.pulsar.functions.proto.Function)27 Gson (com.google.gson.Gson)21 SinkConfig (org.apache.pulsar.common.io.SinkConfig)21 FunctionDetails (org.apache.pulsar.functions.proto.Function.FunctionDetails)18 Map (java.util.Map)15 IOException (java.io.IOException)12 Type (java.lang.reflect.Type)12 ProducerConfig (org.apache.pulsar.common.functions.ProducerConfig)12 Resources (org.apache.pulsar.common.functions.Resources)12 WindowConfig (org.apache.pulsar.common.functions.WindowConfig)12 TypeReference (com.fasterxml.jackson.core.type.TypeReference)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 TypeToken (com.google.gson.reflect.TypeToken)6 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)6