Search in sources :

Example 1 with KafkaAbstractSink

use of org.apache.pulsar.io.kafka.KafkaAbstractSink 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 2 with KafkaAbstractSink

use of org.apache.pulsar.io.kafka.KafkaAbstractSink 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)

Example 3 with KafkaAbstractSink

use of org.apache.pulsar.io.kafka.KafkaAbstractSink in project incubator-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 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

ByteBuffer (java.nio.ByteBuffer)3 HashMap (java.util.HashMap)3 SinkContext (org.apache.pulsar.io.core.SinkContext)3 KafkaAbstractSink (org.apache.pulsar.io.kafka.KafkaAbstractSink)3 Test (org.testng.annotations.Test)3