|
22 | 22 | import static org.testng.Assert.assertFalse; |
23 | 23 | import static org.testng.Assert.assertTrue; |
24 | 24 | import static org.testng.Assert.fail; |
25 | | - |
26 | 25 | import io.netty.channel.ChannelHandlerContext; |
27 | | - |
| 26 | +import java.util.Map; |
28 | 27 | import java.util.concurrent.CountDownLatch; |
29 | 28 | import java.util.concurrent.TimeUnit; |
30 | 29 | import java.util.concurrent.atomic.AtomicBoolean; |
31 | 30 | import java.util.concurrent.atomic.AtomicInteger; |
32 | 31 | import java.util.concurrent.atomic.AtomicReference; |
33 | | - |
34 | 32 | import lombok.Cleanup; |
| 33 | +import org.apache.bookkeeper.common.util.JsonUtil; |
35 | 34 | import org.apache.pulsar.client.impl.ConsumerBase; |
36 | 35 | import org.apache.pulsar.client.impl.PartitionedProducerImpl; |
37 | 36 | import org.apache.pulsar.client.impl.ProducerBase; |
@@ -831,4 +830,28 @@ public void testConsumerReconnect() throws Exception { |
831 | 830 | mockBrokerService.resetHandleConnect(); |
832 | 831 | mockBrokerService.resetHandleSubscribe(); |
833 | 832 | } |
| 833 | + |
| 834 | + @Test |
| 835 | + public void testCommandErrorMessageIsNull() throws Exception { |
| 836 | + @Cleanup |
| 837 | + PulsarClient client = PulsarClient.builder().serviceUrl(mockBrokerService.getBrokerAddress()).build(); |
| 838 | + |
| 839 | + mockBrokerService.setHandleProducer((ctx, producer) -> { |
| 840 | + try { |
| 841 | + ctx.writeAndFlush(Commands.newError(producer.getRequestId(), ServerError.AuthorizationError, null)); |
| 842 | + } catch (Exception e) { |
| 843 | + fail("Send error command failed", e); |
| 844 | + } |
| 845 | + }); |
| 846 | + |
| 847 | + try { |
| 848 | + client.newProducer().topic("persistent://prop/use/ns/t1").create(); |
| 849 | + fail(); |
| 850 | + } catch (Exception e) { |
| 851 | + assertTrue(e instanceof PulsarClientException.AuthorizationException); |
| 852 | + Map<String, String> map = JsonUtil.fromJson(e.getMessage(), Map.class); |
| 853 | + assertEquals(map.get("errorMsg"), ""); |
| 854 | + } |
| 855 | + mockBrokerService.resetHandleProducer(); |
| 856 | + } |
834 | 857 | } |
0 commit comments