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