Search in sources :

Example 1 with SinkContext

use of org.apache.pulsar.io.core.SinkContext in project pulsar by apache.

the class ContextImplTest method testGetSubscriptionType.

@Test
public void testGetSubscriptionType() {
    SinkContext ctx = context;
    // make sure SinkContext can get SubscriptionType.
    Assert.assertEquals(ctx.getSubscriptionType(), SubscriptionType.Shared);
}
Also used : SinkContext(org.apache.pulsar.io.core.SinkContext) Test(org.testng.annotations.Test)

Example 2 with SinkContext

use of org.apache.pulsar.io.core.SinkContext in project pulsar by apache.

the class KafkaAbstractSinkTest method testInvalidConfigWillThrownException.

@Test
public void testInvalidConfigWillThrownException() throws Exception {
    KafkaAbstractSink sink = new DummySink();
    Map<String, Object> config = new HashMap<>();
    SinkContext sc = new SinkContext() {

        @Override
        public int getInstanceId() {
            return 0;
        }

        @Override
        public int getNumInstances() {
            return 0;
        }

        @Override
        public void recordMetric(String metricName, double value) {
        }

        @Override
        public Collection<String> getInputTopics() {
            return null;
        }

        @Override
        public String getTenant() {
            return null;
        }

        @Override
        public String getNamespace() {
            return null;
        }

        @Override
        public String getSinkName() {
            return null;
        }

        @Override
        public Logger getLogger() {
            return null;
        }

        @Override
        public String getSecret(String key) {
            return null;
        }

        @Override
        public void incrCounter(String key, long amount) {
        }

        @Override
        public CompletableFuture<Void> incrCounterAsync(String key, long amount) {
            return null;
        }

        @Override
        public long getCounter(String key) {
            return 0;
        }

        @Override
        public CompletableFuture<Long> getCounterAsync(String key) {
            return null;
        }

        @Override
        public void putState(String key, ByteBuffer value) {
        }

        @Override
        public CompletableFuture<Void> putStateAsync(String key, ByteBuffer value) {
            return null;
        }

        @Override
        public ByteBuffer getState(String key) {
            return null;
        }

        @Override
        public CompletableFuture<ByteBuffer> getStateAsync(String key) {
            return null;
        }

        @Override
        public void deleteState(String key) {
        }

        @Override
        public CompletableFuture<Void> deleteStateAsync(String key) {
            return null;
        }

        @Override
        public PulsarClient getPulsarClient() {
            return null;
        }
    };
    ThrowingRunnable openAndClose = () -> {
        try {
            sink.open(config, sc);
            fail();
        } finally {
            sink.close();
        }
    };
    expectThrows(NullPointerException.class, "Kafka topic is not set", openAndClose);
    config.put("topic", "topic_2");
    expectThrows(NullPointerException.class, "Kafka bootstrapServers is not set", openAndClose);
    config.put("bootstrapServers", "localhost:6667");
    expectThrows(NullPointerException.class, "Kafka acks mode is not set", openAndClose);
    config.put("acks", "1");
    config.put("batchSize", "-1");
    expectThrows(IllegalArgumentException.class, "Invalid Kafka Producer batchSize : -1", openAndClose);
    config.put("batchSize", "16384");
    config.put("maxRequestSize", "-1");
    expectThrows(IllegalArgumentException.class, "Invalid Kafka Producer maxRequestSize : -1", openAndClose);
    config.put("maxRequestSize", "1048576");
    config.put("acks", "none");
    expectThrows(ConfigException.class, "Invalid value none for configuration acks: String must be one of: all, -1, 0, 1", openAndClose);
    config.put("acks", "1");
    sink.open(config, sc);
    sink.close();
}
Also used : HashMap(java.util.HashMap) SinkContext(org.apache.pulsar.io.core.SinkContext) KafkaAbstractSink(org.apache.pulsar.io.kafka.KafkaAbstractSink) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Example 3 with SinkContext

use of org.apache.pulsar.io.core.SinkContext in project pulsar by apache.

the class KinesisSinkConfigTests method loadFromMapTest.

@Test
public final void loadFromMapTest() throws IOException {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("awsEndpoint", "https://some.endpoint.aws");
    map.put("awsRegion", "us-east-1");
    map.put("awsKinesisStreamName", "my-stream");
    map.put("awsCredentialPluginParam", "{\"accessKey\":\"myKey\",\"secretKey\":\"my-Secret\"}");
    SinkContext sinkContext = Mockito.mock(SinkContext.class);
    KinesisSinkConfig config = IOConfigUtils.loadWithSecrets(map, KinesisSinkConfig.class, sinkContext);
    assertNotNull(config);
    assertEquals(config.getAwsEndpoint(), "https://some.endpoint.aws");
    assertEquals(config.getAwsRegion(), "us-east-1");
    assertEquals(config.getAwsKinesisStreamName(), "my-stream");
    assertEquals(config.getAwsCredentialPluginParam(), "{\"accessKey\":\"myKey\",\"secretKey\":\"my-Secret\"}");
}
Also used : HashMap(java.util.HashMap) SinkContext(org.apache.pulsar.io.core.SinkContext) Test(org.testng.annotations.Test)

Example 4 with SinkContext

use of org.apache.pulsar.io.core.SinkContext in project pulsar by yahoo.

the class KinesisSinkConfigTests method loadFromMapTest.

@Test
public final void loadFromMapTest() throws IOException {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("awsEndpoint", "https://some.endpoint.aws");
    map.put("awsRegion", "us-east-1");
    map.put("awsKinesisStreamName", "my-stream");
    map.put("awsCredentialPluginParam", "{\"accessKey\":\"myKey\",\"secretKey\":\"my-Secret\"}");
    SinkContext sinkContext = Mockito.mock(SinkContext.class);
    KinesisSinkConfig config = IOConfigUtils.loadWithSecrets(map, KinesisSinkConfig.class, sinkContext);
    assertNotNull(config);
    assertEquals(config.getAwsEndpoint(), "https://some.endpoint.aws");
    assertEquals(config.getAwsRegion(), "us-east-1");
    assertEquals(config.getAwsKinesisStreamName(), "my-stream");
    assertEquals(config.getAwsCredentialPluginParam(), "{\"accessKey\":\"myKey\",\"secretKey\":\"my-Secret\"}");
}
Also used : HashMap(java.util.HashMap) SinkContext(org.apache.pulsar.io.core.SinkContext) Test(org.testng.annotations.Test)

Example 5 with SinkContext

use of org.apache.pulsar.io.core.SinkContext in project pulsar by yahoo.

the class KafkaAbstractSinkTest method testInvalidConfigWillThrownException.

@Test
public void testInvalidConfigWillThrownException() throws Exception {
    KafkaAbstractSink sink = new DummySink();
    Map<String, Object> config = new HashMap<>();
    SinkContext sc = new SinkContext() {

        @Override
        public int getInstanceId() {
            return 0;
        }

        @Override
        public int getNumInstances() {
            return 0;
        }

        @Override
        public void recordMetric(String metricName, double value) {
        }

        @Override
        public Collection<String> getInputTopics() {
            return null;
        }

        @Override
        public SinkConfig getSinkConfig() {
            return null;
        }

        @Override
        public String getTenant() {
            return null;
        }

        @Override
        public String getNamespace() {
            return null;
        }

        @Override
        public String getSinkName() {
            return null;
        }

        @Override
        public Logger getLogger() {
            return null;
        }

        @Override
        public String getSecret(String key) {
            return null;
        }

        @Override
        public void incrCounter(String key, long amount) {
        }

        @Override
        public CompletableFuture<Void> incrCounterAsync(String key, long amount) {
            return null;
        }

        @Override
        public long getCounter(String key) {
            return 0;
        }

        @Override
        public CompletableFuture<Long> getCounterAsync(String key) {
            return null;
        }

        @Override
        public void putState(String key, ByteBuffer value) {
        }

        @Override
        public CompletableFuture<Void> putStateAsync(String key, ByteBuffer value) {
            return null;
        }

        @Override
        public ByteBuffer getState(String key) {
            return null;
        }

        @Override
        public CompletableFuture<ByteBuffer> getStateAsync(String key) {
            return null;
        }

        @Override
        public void deleteState(String key) {
        }

        @Override
        public CompletableFuture<Void> deleteStateAsync(String key) {
            return null;
        }

        @Override
        public PulsarClient getPulsarClient() {
            return null;
        }
    };
    ThrowingRunnable openAndClose = () -> {
        try {
            sink.open(config, sc);
            fail();
        } finally {
            sink.close();
        }
    };
    expectThrows(NullPointerException.class, "Kafka topic is not set", openAndClose);
    config.put("topic", "topic_2");
    expectThrows(NullPointerException.class, "Kafka bootstrapServers is not set", openAndClose);
    config.put("bootstrapServers", "localhost:6667");
    expectThrows(NullPointerException.class, "Kafka acks mode is not set", openAndClose);
    config.put("acks", "1");
    config.put("batchSize", "-1");
    expectThrows(IllegalArgumentException.class, "Invalid Kafka Producer batchSize : -1", openAndClose);
    config.put("batchSize", "16384");
    config.put("maxRequestSize", "-1");
    expectThrows(IllegalArgumentException.class, "Invalid Kafka Producer maxRequestSize : -1", openAndClose);
    config.put("maxRequestSize", "1048576");
    config.put("acks", "none");
    expectThrows(ConfigException.class, "Invalid value none for configuration acks: String must be one of: all, -1, 0, 1", openAndClose);
    config.put("acks", "1");
    sink.open(config, sc);
    sink.close();
}
Also used : HashMap(java.util.HashMap) SinkContext(org.apache.pulsar.io.core.SinkContext) KafkaAbstractSink(org.apache.pulsar.io.kafka.KafkaAbstractSink) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Aggregations

SinkContext (org.apache.pulsar.io.core.SinkContext)17 Test (org.testng.annotations.Test)16 HashMap (java.util.HashMap)10 ByteBuffer (java.nio.ByteBuffer)3 KafkaAbstractSink (org.apache.pulsar.io.kafka.KafkaAbstractSink)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Message (org.apache.pulsar.client.api.Message)2 GenericObject (org.apache.pulsar.client.api.schema.GenericObject)2 SinkConfig (org.apache.pulsar.common.io.SinkConfig)2 Record (org.apache.pulsar.functions.api.Record)2 GetRecordsResponse (software.amazon.awssdk.services.kinesis.model.GetRecordsResponse)2 CloudStorageSinkConfig (org.apache.pulsar.io.jcloud.sink.CloudStorageSinkConfig)1 Test (org.junit.Test)1