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));
}
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));
}
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));
}
}
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));
}
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));
}
Aggregations