Search in sources :

Example 16 with SinkConfig

use of org.apache.pulsar.common.io.SinkConfig 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 17 with SinkConfig

use of org.apache.pulsar.common.io.SinkConfig in project pulsar by apache.

the class SinkConfigUtilsTest method testMergeDifferentUserConfig.

@Test
public void testMergeDifferentUserConfig() {
    SinkConfig sinkConfig = createSinkConfig();
    Map<String, String> myConfig = new HashMap<>();
    myConfig.put("MyKey", "MyValue");
    SinkConfig newSinkConfig = createUpdatedSinkConfig("configs", myConfig);
    SinkConfig mergedConfig = SinkConfigUtils.validateUpdate(sinkConfig, newSinkConfig);
    assertEquals(mergedConfig.getConfigs(), myConfig);
    mergedConfig.setConfigs(sinkConfig.getConfigs());
    assertEquals(new Gson().toJson(sinkConfig), new Gson().toJson(mergedConfig));
}
Also used : SinkConfig(org.apache.pulsar.common.io.SinkConfig) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) Test(org.testng.annotations.Test)

Example 18 with SinkConfig

use of org.apache.pulsar.common.io.SinkConfig in project pulsar by apache.

the class SinkConfigUtilsTest method testParseKeyRetainOrderingField.

@Test
public void testParseKeyRetainOrderingField() throws IOException {
    List<Boolean> testcases = Lists.newArrayList(true, false, null);
    for (Boolean testcase : testcases) {
        SinkConfig sinkConfig = createSinkConfig();
        sinkConfig.setRetainKeyOrdering(testcase);
        Function.FunctionDetails functionDetails = SinkConfigUtils.convert(sinkConfig, new SinkConfigUtils.ExtractedSinkDetails(null, null));
        SinkConfig result = SinkConfigUtils.convertFromDetails(functionDetails);
        assertEquals(result.getRetainKeyOrdering(), testcase != null ? testcase : Boolean.valueOf(false));
    }
}
Also used : IdentityFunction(org.apache.pulsar.functions.api.utils.IdentityFunction) Function(org.apache.pulsar.functions.proto.Function) SinkConfig(org.apache.pulsar.common.io.SinkConfig) Test(org.testng.annotations.Test)

Example 19 with SinkConfig

use of org.apache.pulsar.common.io.SinkConfig in project pulsar by apache.

the class SinkConfigUtilsTest method testMergeDifferentClassName.

@Test
public void testMergeDifferentClassName() {
    SinkConfig sinkConfig = createSinkConfig();
    SinkConfig newSinkConfig = createUpdatedSinkConfig("className", "Different");
    SinkConfig mergedConfig = SinkConfigUtils.validateUpdate(sinkConfig, newSinkConfig);
    assertEquals(mergedConfig.getClassName(), "Different");
    mergedConfig.setClassName(sinkConfig.getClassName());
    assertEquals(new Gson().toJson(sinkConfig), new Gson().toJson(mergedConfig));
}
Also used : SinkConfig(org.apache.pulsar.common.io.SinkConfig) Gson(com.google.gson.Gson) Test(org.testng.annotations.Test)

Example 20 with SinkConfig

use of org.apache.pulsar.common.io.SinkConfig in project pulsar by apache.

the class SinkConfigUtilsTest method testMergeDifferentCleanupSubscription.

@Test
public void testMergeDifferentCleanupSubscription() {
    SinkConfig sinkConfig = createSinkConfig();
    SinkConfig newSinkConfig = createUpdatedSinkConfig("cleanupSubscription", false);
    SinkConfig mergedConfig = SinkConfigUtils.validateUpdate(sinkConfig, newSinkConfig);
    assertFalse(mergedConfig.getCleanupSubscription());
    mergedConfig.setCleanupSubscription(sinkConfig.getCleanupSubscription());
    assertEquals(new Gson().toJson(sinkConfig), new Gson().toJson(mergedConfig));
}
Also used : SinkConfig(org.apache.pulsar.common.io.SinkConfig) Gson(com.google.gson.Gson) Test(org.testng.annotations.Test)

Aggregations

SinkConfig (org.apache.pulsar.common.io.SinkConfig)223 Test (org.testng.annotations.Test)165 Gson (com.google.gson.Gson)42 HashMap (java.util.HashMap)33 Function (org.apache.pulsar.functions.proto.Function)27 File (java.io.File)24 ConsumerConfig (org.apache.pulsar.common.functions.ConsumerConfig)24 IdentityFunction (org.apache.pulsar.functions.api.utils.IdentityFunction)24 NarClassLoader (org.apache.pulsar.common.nar.NarClassLoader)21 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)19 IOException (java.io.IOException)18 Resources (org.apache.pulsar.common.functions.Resources)15 FileInputStream (java.io.FileInputStream)12 WebTarget (javax.ws.rs.client.WebTarget)12 ObjectMapperFactory (org.apache.pulsar.common.util.ObjectMapperFactory)12 TopicStats (org.apache.pulsar.common.policies.data.TopicStats)10 List (java.util.List)9 Map (java.util.Map)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 Cleanup (lombok.Cleanup)9