79436614

Date: 2025-02-13 15:08:09
Score: 2
Natty:
Report link

Yes, agreed with answer above ^ please provide more information on what functionality you want to test and what your expected outcome is. PubSub is very hard to implement testing for unless you're unit testing and can mock EVERYTHING. IF it were me writing this test case I would structure things very differently. A good pubsub architecture Ive implemented recently used a Factory for each topic to publish or subscribe. This would look something like:

    public class TopicFactory{

      @Value("${path.to.topicName}")
      private TopicName topicName;
      
      @Value("${path.to.subscriptionName}")
      private SubscriptionName subscriptionName;
      
      private PubsubTemplate pubsubTemplate;
      

      @AutoWired
      private void TopicFactory(PubSubTemplate template, 
                                ObjectMapper mapper){
        this.pubsubTemplate = template;
        this.mapper = mapper;
      }
      
      
     public String publish(String json){
      PubsubMessage message = new PubSubMessage.data(json.getBytes());
      ListenableFuture<String> id = pubsubTemplate.publish(topicName, message);
      return id.get();
     }
    }
Reasons:
  • RegEx Blacklisted phrase (2.5): please provide
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: damesdev