Skip to content

Commit

Permalink
Fix NPE with tests / mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
lhotari committed Dec 20, 2022
1 parent 9e6ffba commit 81f4852
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public ServerCnx(PulsarService pulsar, String listenerName) {
this.maxSubscriptionPatternLength = conf.getSubscriptionPatternMaxLength();
this.topicListService = new TopicListService(pulsar, this,
enableSubscriptionPatternEvaluation, maxSubscriptionPatternLength);
this.brokerInterceptor = getBrokerService().getInterceptor();
this.brokerInterceptor = this.service != null ? this.service.getInterceptor() : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,20 @@ public void setup() throws Exception {
doReturn(pulsarResources).when(pulsar).getPulsarResources();
});

eventLoopGroup = new NioEventLoopGroup();
brokerService = spyWithClassAndConstructorArgs(BrokerService.class, pulsar, eventLoopGroup);
PulsarServiceMockSupport.mockPulsarServiceProps(pulsar, () -> {
doReturn(brokerService).when(pulsar).getBrokerService();
});

serverCnx = spyWithClassAndConstructorArgs(ServerCnx.class, pulsar);
doReturn(true).when(serverCnx).isActive();
doReturn(true).when(serverCnx).isWritable();
doReturn(new InetSocketAddress("localhost", 1234)).when(serverCnx).clientAddress();
when(serverCnx.getRemoteEndpointProtocolVersion()).thenReturn(ProtocolVersion.v12.getValue());
when(serverCnx.ctx()).thenReturn(mock(ChannelHandlerContext.class));
doReturn(new PulsarCommandSenderImpl(null, serverCnx))
.when(serverCnx).getCommandSender();

eventLoopGroup = new NioEventLoopGroup();
brokerService = spyWithClassAndConstructorArgs(BrokerService.class, pulsar, eventLoopGroup);
PulsarServiceMockSupport.mockPulsarServiceProps(pulsar, () -> {
doReturn(brokerService).when(pulsar).getBrokerService();
});
.when(serverCnx).getCommandSender();

String topicName = TopicName.get("MessageCumulativeAckTest").toString();
PersistentTopic persistentTopic = new PersistentTopic(topicName, mock(ManagedLedger.class), brokerService);
Expand Down

0 comments on commit 81f4852

Please sign in to comment.