|
34 | 34 | import org.apache.pulsar.common.schema.KeyValue; |
35 | 35 | import org.apache.pulsar.common.schema.KeyValueEncodingType; |
36 | 36 | import org.testng.Assert; |
37 | | -import org.testng.annotations.AfterMethod; |
38 | | -import org.testng.annotations.BeforeMethod; |
39 | 37 | import org.testng.annotations.DataProvider; |
40 | 38 | import org.testng.annotations.Test; |
41 | 39 |
|
|
44 | 42 | */ |
45 | 43 | @Slf4j |
46 | 44 | @Test(groups = "broker") |
47 | | -public class NullValueTest extends BrokerTestBase { |
| 45 | +public class NullValueTest extends SharedPulsarBaseTest { |
48 | 46 |
|
49 | | - @BeforeMethod |
50 | | - @Override |
51 | | - protected void setup() throws Exception { |
52 | | - super.baseSetup(); |
53 | | - } |
54 | | - |
55 | | - @AfterMethod(alwaysRun = true) |
56 | | - @Override |
57 | | - protected void cleanup() throws Exception { |
58 | | - super.internalCleanup(); |
59 | | - } |
60 | | - |
61 | | - @DataProvider(name = "topics") |
62 | | - public static Object[][] topics() { |
| 47 | + @DataProvider(name = "partitions") |
| 48 | + public static Object[][] partitions() { |
63 | 49 | return new Object[][]{ |
64 | | - {"persistent://prop/ns-abc/null-value-test-0", 1}, |
65 | | - {"persistent://prop/ns-abc/null-value-test-1", 3}, |
| 50 | + {1}, |
| 51 | + {3}, |
66 | 52 | }; |
67 | 53 | } |
68 | 54 |
|
69 | | - @Test(dataProvider = "topics") |
70 | | - public void nullValueBytesSchemaTest(String topic, int partitions) |
| 55 | + @Test(dataProvider = "partitions") |
| 56 | + public void nullValueBytesSchemaTest(int partitions) |
71 | 57 | throws PulsarClientException, PulsarAdminException { |
| 58 | + String topic = newTopicName(); |
72 | 59 | admin.topics().createPartitionedTopic(topic, partitions); |
73 | 60 |
|
74 | 61 | @Cleanup |
75 | | - Producer producer = pulsarClient.newProducer() |
| 62 | + Producer<byte[]> producer = pulsarClient.newProducer() |
76 | 63 | .topic(topic) |
77 | 64 | .messageRoutingMode(MessageRoutingMode.SinglePartition) |
78 | 65 | .create(); |
79 | 66 |
|
80 | 67 | @Cleanup |
81 | | - Consumer consumer = pulsarClient.newConsumer() |
| 68 | + Consumer<byte[]> consumer = pulsarClient.newConsumer() |
82 | 69 | .topic(topic) |
83 | 70 | .subscriptionName("test") |
84 | 71 | .subscribe(); |
@@ -93,7 +80,7 @@ public void nullValueBytesSchemaTest(String topic, int partitions) |
93 | 80 | } |
94 | 81 |
|
95 | 82 | for (int i = 0; i < numMessage; i++) { |
96 | | - Message message = consumer.receive(); |
| 83 | + Message<byte[]> message = consumer.receive(); |
97 | 84 | if (i % 2 == 0) { |
98 | 85 | Assert.assertNotNull(message.getData()); |
99 | 86 | Assert.assertNotNull(message.getValue()); |
@@ -114,7 +101,7 @@ public void nullValueBytesSchemaTest(String topic, int partitions) |
114 | 101 | } |
115 | 102 |
|
116 | 103 | for (int i = 0; i < numMessage; i++) { |
117 | | - CompletableFuture<Message> completableFuture = consumer.receiveAsync(); |
| 104 | + CompletableFuture<Message<byte[]>> completableFuture = consumer.receiveAsync(); |
118 | 105 | final int index = i; |
119 | 106 | completableFuture.whenComplete((message, throwable) -> { |
120 | 107 | Assert.assertNull(throwable); |
@@ -133,12 +120,12 @@ public void nullValueBytesSchemaTest(String topic, int partitions) |
133 | 120 | } |
134 | 121 | }); |
135 | 122 | } |
136 | | - |
137 | 123 | } |
138 | 124 |
|
139 | | - @Test(dataProvider = "topics") |
140 | | - public void nullValueBooleanSchemaTest(String topic, int partitions) |
| 125 | + @Test(dataProvider = "partitions") |
| 126 | + public void nullValueBooleanSchemaTest(int partitions) |
141 | 127 | throws PulsarClientException, PulsarAdminException { |
| 128 | + String topic = newTopicName(); |
142 | 129 | admin.topics().createPartitionedTopic(topic, partitions); |
143 | 130 |
|
144 | 131 | @Cleanup |
@@ -163,12 +150,12 @@ public void nullValueBooleanSchemaTest(String topic, int partitions) |
163 | 150 | Assert.assertNull(message.getValue()); |
164 | 151 | Assert.assertNull(message.getData()); |
165 | 152 | } |
166 | | - |
167 | 153 | } |
168 | 154 |
|
169 | | - @Test(dataProvider = "topics") |
170 | | - public void keyValueNullInlineTest(String topic, int partitions) |
| 155 | + @Test(dataProvider = "partitions") |
| 156 | + public void keyValueNullInlineTest(int partitions) |
171 | 157 | throws PulsarClientException, PulsarAdminException { |
| 158 | + String topic = newTopicName(); |
172 | 159 | admin.topics().createPartitionedTopic(topic, partitions); |
173 | 160 |
|
174 | 161 | @Cleanup |
@@ -198,24 +185,24 @@ public void keyValueNullInlineTest(String topic, int partitions) |
198 | 185 | message = consumer.receive(); |
199 | 186 | keyValue = message.getValue(); |
200 | 187 | Assert.assertNull(keyValue.getKey()); |
201 | | - Assert.assertEquals("test", keyValue.getValue()); |
| 188 | + Assert.assertEquals(keyValue.getValue(), "test"); |
202 | 189 |
|
203 | 190 | message = consumer.receive(); |
204 | 191 | keyValue = message.getValue(); |
205 | | - Assert.assertEquals("test", keyValue.getKey()); |
| 192 | + Assert.assertEquals(keyValue.getKey(), "test"); |
206 | 193 | Assert.assertNull(keyValue.getValue()); |
207 | 194 |
|
208 | 195 | message = consumer.receive(); |
209 | 196 | keyValue = message.getValue(); |
210 | 197 | Assert.assertNull(keyValue.getKey()); |
211 | 198 | Assert.assertNull(keyValue.getValue()); |
212 | 199 | } |
213 | | - |
214 | 200 | } |
215 | 201 |
|
216 | | - @Test(dataProvider = "topics") |
217 | | - public void keyValueNullSeparatedTest(String topic, int partitions) |
| 202 | + @Test(dataProvider = "partitions") |
| 203 | + public void keyValueNullSeparatedTest(int partitions) |
218 | 204 | throws PulsarClientException, PulsarAdminException { |
| 205 | + String topic = newTopicName(); |
219 | 206 | admin.topics().createPartitionedTopic(topic, partitions); |
220 | 207 |
|
221 | 208 | @Cleanup |
@@ -252,19 +239,17 @@ public int choosePartition(Message<?> msg, TopicMetadata metadata) { |
252 | 239 | message = consumer.receive(); |
253 | 240 | keyValue = message.getValue(); |
254 | 241 | Assert.assertNull(keyValue.getKey()); |
255 | | - Assert.assertEquals("test", keyValue.getValue()); |
| 242 | + Assert.assertEquals(keyValue.getValue(), "test"); |
256 | 243 |
|
257 | 244 | message = consumer.receive(); |
258 | 245 | keyValue = message.getValue(); |
259 | | - Assert.assertEquals("test", keyValue.getKey()); |
| 246 | + Assert.assertEquals(keyValue.getKey(), "test"); |
260 | 247 | Assert.assertNull(keyValue.getValue()); |
261 | 248 |
|
262 | 249 | message = consumer.receive(); |
263 | 250 | keyValue = message.getValue(); |
264 | 251 | Assert.assertNull(keyValue.getKey()); |
265 | 252 | Assert.assertNull(keyValue.getValue()); |
266 | 253 | } |
267 | | - |
268 | 254 | } |
269 | | - |
270 | 255 | } |