use of org.apache.pulsar.functions.proto.Request.ServiceRequest in project incubator-pulsar by apache.
the class ServiceRequestManagerTest method testSubmitRequest.
@Test
public void testSubmitRequest() throws Exception {
ServiceRequest request = ServiceRequest.newBuilder().build();
MessageId msgId = mock(MessageId.class);
when(producer.sendAsync(any(byte[].class))).thenReturn(CompletableFuture.completedFuture(msgId));
CompletableFuture<MessageId> submitFuture = reqMgr.submitRequest(request);
assertSame(msgId, submitFuture.get());
verify(producer, times(1)).sendAsync(any(byte[].class));
}
use of org.apache.pulsar.functions.proto.Request.ServiceRequest in project incubator-pulsar by apache.
the class FunctionMetaDataTopicTailerTest method testUpdate.
@Test
public void testUpdate() throws Exception {
ServiceRequest request = ServiceRequestUtils.getUpdateRequest(TEST_NAME, FunctionMetaData.newBuilder().build());
Message msg = mock(Message.class);
when(msg.getData()).thenReturn(request.toByteArray());
CompletableFuture<Message> receiveFuture = CompletableFuture.completedFuture(msg);
when(reader.readNextAsync()).thenReturn(receiveFuture).thenReturn(new CompletableFuture<>());
fsc.start();
// wait for receive future to complete
receiveFuture.thenApply(Function.identity()).get();
verify(reader, times(2)).readNextAsync();
verify(fsm, times(1)).processRequest(any(MessageId.class), any(ServiceRequest.class));
}
use of org.apache.pulsar.functions.proto.Request.ServiceRequest in project incubator-pulsar by apache.
the class FunctionMetaDataTopicTailer method processRequest.
public void processRequest(Message msg) {
ServiceRequest serviceRequest;
try {
serviceRequest = ServiceRequest.parseFrom(msg.getData());
} catch (IOException e) {
log.error("Received bad service request at message {}", msg.getMessageId(), e);
// TODO: find a better way to handle bad request
throw new RuntimeException(e);
}
if (log.isDebugEnabled()) {
log.debug("Received Service Request: {}", serviceRequest);
}
this.functionMetaDataManager.processRequest(msg.getMessageId(), serviceRequest);
}
Aggregations