use of org.apache.pulsar.common.api.proto.MessageMetadata in project flink by apache.
the class PulsarDeserializationSchemaTest method getMessage.
/**
* Create a test message by given bytes. The message don't contains any meta data.
*/
private <T> Message<byte[]> getMessage(T message, FunctionWithException<T, byte[], Exception> decoder) throws Exception {
byte[] bytes = decoder.apply(message);
MessageMetadata metadata = new MessageMetadata();
ByteBuffer payload = ByteBuffer.wrap(bytes);
return MessageImpl.create(metadata, payload, Schema.BYTES, "");
}
use of org.apache.pulsar.common.api.proto.MessageMetadata in project athenz by yahoo.
the class MockAthenzPulsarClient method getPulsarClient.
protected PulsarClientImpl getPulsarClient(String serviceUrl, ClientConfigurationData config) throws PulsarClientException {
try {
CompletableFuture asyncProducerResult = null;
if (serviceUrl == null || serviceUrl.isEmpty()) {
asyncProducerResult = FutureUtil.failedFuture(new PulsarClientException.InvalidConfigurationException("Producer configuration undefined"));
}
PulsarClientImpl pulsarClient = Mockito.mock(PulsarClientImpl.class);
Producer producer = Mockito.mock(Producer.class);
Consumer consumer = Mockito.mock(Consumer.class);
MessageMetadata meta = new MessageMetadata();
DomainChangeMessage roleChange = new DomainChangeMessage().setDomainName("domain").setObjectType(DomainChangeMessage.ObjectType.ROLE).setApiName("putRole").setObjectName("role1");
MessageImpl<byte[]> msg = MessageImpl.create(meta, ByteBuffer.wrap(new ObjectMapper().writeValueAsBytes(roleChange)), Schema.BYTES, null);
Mockito.when(consumer.receive(1, TimeUnit.SECONDS)).thenReturn(msg);
CompletableFuture finalAsyncProducerResult = asyncProducerResult;
Mockito.when(pulsarClient.createProducerAsync(any(ProducerConfigurationData.class), any(Schema.class))).thenAnswer(invocation -> {
if (serviceUrl != null) {
return ((ProducerConfigurationData) invocation.getArgument(0)).getTopicName() == null ? finalAsyncProducerResult : CompletableFuture.completedFuture(producer);
}
return finalAsyncProducerResult;
});
Mockito.when(pulsarClient.subscribeAsync(any(ConsumerConfigurationData.class), any(Schema.class), any())).thenReturn(CompletableFuture.completedFuture(consumer));
return pulsarClient;
} catch (Exception e) {
fail();
}
return null;
}
Aggregations