18
18
*/
19
19
package org .apache .pulsar .broker .service ;
20
20
21
+ import static org .testng .Assert .assertEquals ;
21
22
import static org .testng .Assert .assertFalse ;
22
23
import static org .testng .Assert .assertTrue ;
23
24
import java .time .Duration ;
24
25
import java .util .Arrays ;
25
26
import java .util .HashSet ;
27
+ import java .util .List ;
26
28
import java .util .Optional ;
27
29
import java .util .concurrent .CompletableFuture ;
28
30
import java .util .concurrent .TimeUnit ;
33
35
import org .apache .pulsar .common .naming .TopicName ;
34
36
import org .apache .pulsar .common .policies .data .TopicType ;
35
37
import org .apache .pulsar .common .util .collections .ConcurrentOpenHashMap ;
38
+ import org .apache .pulsar .common .protocol .schema .StoredSchema ;
36
39
import org .apache .pulsar .zookeeper .LocalBookkeeperEnsemble ;
37
40
import org .apache .pulsar .zookeeper .ZookeeperServerTest ;
38
41
import org .awaitility .Awaitility ;
@@ -172,18 +175,39 @@ public void testRemoveCluster() throws Exception {
172
175
// Initialize.
173
176
final String ns1 = defaultTenant + "/" + "ns_73b1a31afce34671a5ddc48fe5ad7fc8" ;
174
177
final String topic = "persistent://" + ns1 + "/___tp-5dd50794-7af8-4a34-8a0b-06188052c66a" ;
178
+ final String topicP0 = TopicName .get (topic ).getPartition (0 ).toString ();
179
+ final String topicP1 = TopicName .get (topic ).getPartition (1 ).toString ();
175
180
final String topicChangeEvents = "persistent://" + ns1 + "/__change_events-partition-0" ;
176
181
admin1 .namespaces ().createNamespace (ns1 );
177
182
admin1 .namespaces ().setNamespaceReplicationClusters (ns1 , new HashSet <>(Arrays .asList (cluster1 , cluster2 )));
178
- admin1 .topics ().createNonPartitionedTopic (topic );
183
+ admin1 .topics ().createPartitionedTopic (topic , 2 );
184
+ Awaitility .await ().untilAsserted (() -> {
185
+ assertTrue (pulsar2 .getPulsarResources ().getNamespaceResources ().getPartitionedTopicResources ()
186
+ .partitionedTopicExists (TopicName .get (topic )));
187
+ List <CompletableFuture <StoredSchema >> schemaList11
188
+ = pulsar1 .getSchemaStorage ().getAll (TopicName .get (topic ).getSchemaName ()).get ();
189
+ assertEquals (schemaList11 .size (), 0 );
190
+ List <CompletableFuture <StoredSchema >> schemaList21
191
+ = pulsar2 .getSchemaStorage ().getAll (TopicName .get (topic ).getSchemaName ()).get ();
192
+ assertEquals (schemaList21 .size (), 0 );
193
+ });
179
194
180
- // Wait for loading topic up .
195
+ // Wait for copying messages .
181
196
Producer <String > p = client1 .newProducer (Schema .STRING ).topic (topic ).create ();
197
+ p .send ("msg-1" );
198
+ p .close ();
182
199
Awaitility .await ().untilAsserted (() -> {
183
200
ConcurrentOpenHashMap <String , CompletableFuture <Optional <Topic >>> tps =
184
201
pulsar1 .getBrokerService ().getTopics ();
185
- assertTrue (tps .containsKey (topic ));
202
+ assertTrue (tps .containsKey (topicP0 ));
203
+ assertTrue (tps .containsKey (topicP1 ));
186
204
assertTrue (tps .containsKey (topicChangeEvents ));
205
+ List <CompletableFuture <StoredSchema >> schemaList12
206
+ = pulsar1 .getSchemaStorage ().getAll (TopicName .get (topic ).getSchemaName ()).get ();
207
+ assertEquals (schemaList12 .size (), 1 );
208
+ List <CompletableFuture <StoredSchema >> schemaList22
209
+ = pulsar2 .getSchemaStorage ().getAll (TopicName .get (topic ).getSchemaName ()).get ();
210
+ assertEquals (schemaList12 .size (), 1 );
187
211
});
188
212
189
213
// The topics under the namespace of the cluster-1 will be deleted.
@@ -192,18 +216,23 @@ public void testRemoveCluster() throws Exception {
192
216
Awaitility .await ().atMost (Duration .ofSeconds (60 )).ignoreExceptions ().untilAsserted (() -> {
193
217
ConcurrentOpenHashMap <String , CompletableFuture <Optional <Topic >>> tps =
194
218
pulsar1 .getBrokerService ().getTopics ();
195
- assertFalse (tps .containsKey (topic ));
219
+ assertFalse (tps .containsKey (topicP0 ));
220
+ assertFalse (tps .containsKey (topicP1 ));
196
221
assertFalse (tps .containsKey (topicChangeEvents ));
197
- assertFalse (pulsar1 .getNamespaceService ().checkTopicExists (TopicName .get (topic ))
198
- .get (5 , TimeUnit .SECONDS ).isExists ());
199
222
assertFalse (pulsar1 .getNamespaceService ()
200
223
.checkTopicExists (TopicName .get (topicChangeEvents ))
201
224
.get (5 , TimeUnit .SECONDS ).isExists ());
225
+ // Verify: schema will be removed in local cluster, and remote cluster will not.
226
+ List <CompletableFuture <StoredSchema >> schemaList13
227
+ = pulsar1 .getSchemaStorage ().getAll (TopicName .get (topic ).getSchemaName ()).get ();
228
+ assertEquals (schemaList13 .size (), 0 );
229
+ List <CompletableFuture <StoredSchema >> schemaList23
230
+ = pulsar2 .getSchemaStorage ().getAll (TopicName .get (topic ).getSchemaName ()).get ();
231
+ assertEquals (schemaList23 .size (), 1 );
202
232
});
203
233
204
234
// cleanup.
205
- p .close ();
206
- admin2 .topics ().delete (topic );
235
+ admin2 .topics ().deletePartitionedTopic (topic );
207
236
admin2 .namespaces ().deleteNamespace (ns1 );
208
237
}
209
238
}
0 commit comments