use of org.apache.pulsar.io.core.SinkContext in project incubator-pulsar by apache.
the class KinesisSinkTest method testWrite.
@Test
public void testWrite() throws Exception {
AtomicBoolean ackCalled = new AtomicBoolean();
AtomicLong sequenceCounter = new AtomicLong(0);
Message<GenericObject> message = mock(Message.class);
when(message.getData()).thenReturn("hello".getBytes(StandardCharsets.UTF_8));
final Record<GenericObject> pulsarRecord = new Record<GenericObject>() {
@Override
public Optional<String> getKey() {
return Optional.of("key-" + sequenceCounter.incrementAndGet());
}
@Override
public GenericObject getValue() {
// Value comes from the message raw data, not the GenericObject
return null;
}
@Override
public void ack() {
ackCalled.set(true);
}
@Override
public Optional<Message<GenericObject>> getMessage() {
return Optional.of(message);
}
};
try (final KinesisSink sink = new KinesisSink()) {
Map<String, Object> map = createConfig();
SinkContext mockSinkContext = mock(SinkContext.class);
sink.open(map, mockSinkContext);
for (int i = 0; i < 10; i++) {
sink.write(pulsarRecord);
}
Awaitility.await().untilAsserted(() -> {
assertTrue(ackCalled.get());
});
final GetRecordsResponse getRecords = getStreamRecords();
assertEquals(getRecords.records().size(), 10);
for (software.amazon.awssdk.services.kinesis.model.Record record : getRecords.records()) {
assertEquals(record.data().asString(StandardCharsets.UTF_8), "hello");
}
}
}
use of org.apache.pulsar.io.core.SinkContext 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();
}
use of org.apache.pulsar.io.core.SinkContext in project pulsar by yahoo.
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 yahoo.
the class KinesisSinkConfigTests method loadFromMapCredentialFromSecretTest.
@Test
public final void loadFromMapCredentialFromSecretTest() 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");
SinkContext sinkContext = Mockito.mock(SinkContext.class);
Mockito.when(sinkContext.getSecret("awsCredentialPluginParam")).thenReturn("{\"accessKey\":\"myKey\",\"secretKey\":\"my-Secret\"}");
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 KinesisSinkTest method testWrite.
@Test
public void testWrite() throws Exception {
AtomicBoolean ackCalled = new AtomicBoolean();
AtomicLong sequenceCounter = new AtomicLong(0);
Message<GenericObject> message = mock(Message.class);
when(message.getData()).thenReturn("hello".getBytes(StandardCharsets.UTF_8));
final Record<GenericObject> pulsarRecord = new Record<GenericObject>() {
@Override
public Optional<String> getKey() {
return Optional.of("key-" + sequenceCounter.incrementAndGet());
}
@Override
public GenericObject getValue() {
// Value comes from the message raw data, not the GenericObject
return null;
}
@Override
public void ack() {
ackCalled.set(true);
}
@Override
public Optional<Message<GenericObject>> getMessage() {
return Optional.of(message);
}
};
try (final KinesisSink sink = new KinesisSink()) {
Map<String, Object> map = createConfig();
SinkContext mockSinkContext = mock(SinkContext.class);
sink.open(map, mockSinkContext);
for (int i = 0; i < 10; i++) {
sink.write(pulsarRecord);
}
Awaitility.await().untilAsserted(() -> {
assertTrue(ackCalled.get());
});
final GetRecordsResponse getRecords = getStreamRecords();
assertEquals(getRecords.records().size(), 10);
for (software.amazon.awssdk.services.kinesis.model.Record record : getRecords.records()) {
assertEquals(record.data().asString(StandardCharsets.UTF_8), "hello");
}
}
}
Aggregations