Search in sources :

Example 1 with ServiceRequest

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));
}
Also used : ServiceRequest(org.apache.pulsar.functions.proto.Request.ServiceRequest) MessageId(org.apache.pulsar.client.api.MessageId) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with ServiceRequest

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));
}
Also used : Message(org.apache.pulsar.client.api.Message) ServiceRequest(org.apache.pulsar.functions.proto.Request.ServiceRequest) MessageId(org.apache.pulsar.client.api.MessageId) Test(org.testng.annotations.Test)

Example 3 with ServiceRequest

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);
}
Also used : IOException(java.io.IOException) ServiceRequest(org.apache.pulsar.functions.proto.Request.ServiceRequest)

Aggregations

ServiceRequest (org.apache.pulsar.functions.proto.Request.ServiceRequest)3 MessageId (org.apache.pulsar.client.api.MessageId)2 Test (org.testng.annotations.Test)2 IOException (java.io.IOException)1 Message (org.apache.pulsar.client.api.Message)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1