pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [pulsar] prasanthkumar2392 commented on issue #6642: Context in Pulsar functions not getting mocked
Date Fri, 03 Apr 2020 05:44:12 GMT
prasanthkumar2392 commented on issue #6642: Context in Pulsar functions not getting mocked
URL: https://github.com/apache/pulsar/issues/6642#issuecomment-608241467
   - I am using functions api 2.5.0 and I am using context to set the key and value inside
functions and sending it to the output topic.
   - But in my test class, I am trying to mock the context and i am unsuccesfull.
   (Also tried context configuration of puslar test container to see if context is not null)
   My function class to process the messages 
   import org.apache.pulsar.client.api.PulsarClientException;
   import org.apache.pulsar.client.api.Schema;
   import org.apache.pulsar.functions.api.Context;
   import org.apache.pulsar.functions.api.Function;
   import org.slf4j.Logger;
   public class MyFunction implements Function<byte[], Void> {
       public Void process(byte[] input, Context context) throws Exception {
           Logger log = context.getLogger();
           log.debug("Entered ");
           //Initialize Required classes to process message
           if (input != null) {
               try {
                   // assign the key and value and send it to output topic
                   log.debug("Key  :");
                   log.debug("Value ");
                   context.newOutputMessage(context.getOutputTopic(), Schema.STRING)
               } catch (PulsarClientException e) {
                   log.error("error in " + e.toString());
           return null;
   and my sample test class 
   `import com.ericsson.iota.dm.function.MyFunction;
   import org.apache.pulsar.functions.api.Context;
   import org.junit.jupiter.api.Test;
   import static org.mockito.Mockito.mock;
   public class FunctionTest {
       public void functionProcessing() throws Exception {
           String message ="{\n" +
                   "   \"name\": \"XXXXX\",\n" +
                   "   \"email\": \"xxxxx@xxx.com\"\n" +
           MyFunction myFunction =new MyFunction();
           myFunction.process(message.getBytes(), mock(Context.class));
           // Assert conditions

This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:

With regards,
Apache Git Services

View raw message