use of org.apache.pulsar.functions.source.PulsarRecord in project incubator-pulsar by apache.
the class SinkRecord method individualAck.
/**
* Some sink sometimes wants to control the ack type.
*/
public void individualAck() {
if (sourceRecord instanceof PulsarRecord) {
PulsarRecord pulsarRecord = (PulsarRecord) sourceRecord;
pulsarRecord.individualAck();
} else {
throw new RuntimeException("SourceRecord class type must be PulsarRecord");
}
}
use of org.apache.pulsar.functions.source.PulsarRecord in project incubator-pulsar by apache.
the class KafkaConnectSinkTest method genericRecordCastTest.
@Test
public void genericRecordCastTest() throws Exception {
props.put("kafkaConnectorSinkClass", SchemaedFileStreamSinkConnector.class.getCanonicalName());
KafkaConnectSink sink = new KafkaConnectSink();
sink.open(props, context);
AvroSchema<PulsarSchemaToKafkaSchemaTest.StructWithAnnotations> pulsarAvroSchema = AvroSchema.of(PulsarSchemaToKafkaSchemaTest.StructWithAnnotations.class);
final GenericData.Record obj = new GenericData.Record(pulsarAvroSchema.getAvroSchema());
// schema type INT32
obj.put("field1", (byte) 10);
// schema type STRING
obj.put("field2", "test");
// schema type INT64
obj.put("field3", (short) 100);
final GenericRecord rec = getGenericRecord(obj, pulsarAvroSchema);
Message msg = mock(MessageImpl.class);
when(msg.getValue()).thenReturn(rec);
when(msg.getKey()).thenReturn("key");
when(msg.hasKey()).thenReturn(true);
when(msg.getMessageId()).thenReturn(new MessageIdImpl(1, 0, 0));
final AtomicInteger status = new AtomicInteger(0);
Record<GenericObject> record = PulsarRecord.<String>builder().topicName("fake-topic").message(msg).schema(pulsarAvroSchema).ackFunction(status::incrementAndGet).failFunction(status::decrementAndGet).build();
SinkRecord sinkRecord = sink.toSinkRecord(record);
Struct out = (Struct) sinkRecord.value();
Assert.assertEquals(out.get("field1").getClass(), Integer.class);
Assert.assertEquals(out.get("field2").getClass(), String.class);
Assert.assertEquals(out.get("field3").getClass(), Long.class);
Assert.assertEquals(out.get("field1"), 10);
Assert.assertEquals(out.get("field2"), "test");
Assert.assertEquals(out.get("field3"), 100L);
sink.close();
}
use of org.apache.pulsar.functions.source.PulsarRecord in project incubator-pulsar by apache.
the class SinkRecordTest method testCustomAck.
@Test
public void testCustomAck() {
PulsarRecord pulsarRecord = Mockito.mock(PulsarRecord.class);
SinkRecord sinkRecord = new SinkRecord<>(pulsarRecord, new Object());
sinkRecord.cumulativeAck();
Mockito.verify(pulsarRecord, Mockito.times(1)).cumulativeAck();
sinkRecord = new SinkRecord(Mockito.mock(Record.class), new Object());
try {
sinkRecord.individualAck();
Assert.fail("Should throw runtime exception");
} catch (Exception e) {
Assert.assertTrue(e instanceof RuntimeException);
Assert.assertEquals(e.getMessage(), "SourceRecord class type must be PulsarRecord");
}
}
use of org.apache.pulsar.functions.source.PulsarRecord in project incubator-pulsar by apache.
the class SinkRecord method cumulativeAck.
/**
* Some sink sometimes wants to control the ack type.
*/
public void cumulativeAck() {
if (sourceRecord instanceof PulsarRecord) {
PulsarRecord pulsarRecord = (PulsarRecord) sourceRecord;
pulsarRecord.cumulativeAck();
} else {
throw new RuntimeException("SourceRecord class type must be PulsarRecord");
}
}
use of org.apache.pulsar.functions.source.PulsarRecord in project pulsar by yahoo.
the class KafkaConnectSinkTest method genericRecordCastTest.
@Test
public void genericRecordCastTest() throws Exception {
props.put("kafkaConnectorSinkClass", SchemaedFileStreamSinkConnector.class.getCanonicalName());
KafkaConnectSink sink = new KafkaConnectSink();
sink.open(props, context);
AvroSchema<PulsarSchemaToKafkaSchemaTest.StructWithAnnotations> pulsarAvroSchema = AvroSchema.of(PulsarSchemaToKafkaSchemaTest.StructWithAnnotations.class);
final GenericData.Record obj = new GenericData.Record(pulsarAvroSchema.getAvroSchema());
// schema type INT32
obj.put("field1", (byte) 10);
// schema type STRING
obj.put("field2", "test");
// schema type INT64
obj.put("field3", (short) 100);
final GenericRecord rec = getGenericRecord(obj, pulsarAvroSchema);
Message msg = mock(MessageImpl.class);
when(msg.getValue()).thenReturn(rec);
when(msg.getKey()).thenReturn("key");
when(msg.hasKey()).thenReturn(true);
when(msg.getMessageId()).thenReturn(new MessageIdImpl(1, 0, 0));
final AtomicInteger status = new AtomicInteger(0);
Record<GenericObject> record = PulsarRecord.<String>builder().topicName("fake-topic").message(msg).schema(pulsarAvroSchema).ackFunction(status::incrementAndGet).failFunction(status::decrementAndGet).build();
SinkRecord sinkRecord = sink.toSinkRecord(record);
Struct out = (Struct) sinkRecord.value();
Assert.assertEquals(out.get("field1").getClass(), Integer.class);
Assert.assertEquals(out.get("field2").getClass(), String.class);
Assert.assertEquals(out.get("field3").getClass(), Long.class);
Assert.assertEquals(out.get("field1"), 10);
Assert.assertEquals(out.get("field2"), "test");
Assert.assertEquals(out.get("field3"), 100L);
sink.close();
}
Aggregations