44
44
import java .util .SortedSet ;
45
45
import java .util .TreeSet ;
46
46
import java .util .UUID ;
47
- import java .util .concurrent .Callable ;
48
47
import java .util .concurrent .CompletableFuture ;
49
48
import java .util .concurrent .ConcurrentHashMap ;
50
49
import java .util .concurrent .CountDownLatch ;
51
50
import java .util .concurrent .ExecutorService ;
52
51
import java .util .concurrent .Executors ;
53
- import java .util .concurrent .Future ;
54
52
import java .util .concurrent .TimeUnit ;
55
53
import java .util .concurrent .atomic .AtomicBoolean ;
56
54
import java .util .stream .Collectors ;
68
66
import org .apache .bookkeeper .mledger .impl .PositionImpl ;
69
67
import org .apache .pulsar .broker .BrokerTestUtil ;
70
68
import org .apache .pulsar .broker .PulsarService ;
69
+ import org .apache .pulsar .broker .auth .MockedPulsarServiceBaseTest ;
71
70
import org .apache .pulsar .broker .service .BrokerServiceException .NamingException ;
72
71
import org .apache .pulsar .broker .service .persistent .PersistentReplicator ;
73
72
import org .apache .pulsar .broker .service .persistent .PersistentTopic ;
@@ -154,88 +153,6 @@ public Object[][] partitionedTopicProvider() {
154
153
return new Object [][] { { Boolean .TRUE }, { Boolean .FALSE } };
155
154
}
156
155
157
- @ Test (priority = Integer .MAX_VALUE )
158
- public void testConfigChange () throws Exception {
159
- log .info ("--- Starting ReplicatorTest::testConfigChange ---" );
160
- // This test is to verify that the config change on global namespace is successfully applied in broker during
161
- // runtime.
162
- // Run a set of producer tasks to create the topics
163
- List <Future <Void >> results = new ArrayList <>();
164
- for (int i = 0 ; i < 10 ; i ++) {
165
- final TopicName dest = TopicName .get (BrokerTestUtil .newUniqueName ("persistent://pulsar/ns/topic-" + i ));
166
-
167
- results .add (executor .submit (new Callable <Void >() {
168
- @ Override
169
- public Void call () throws Exception {
170
-
171
- @ Cleanup
172
- MessageProducer producer = new MessageProducer (url1 , dest );
173
- log .info ("--- Starting producer --- " + url1 );
174
-
175
- @ Cleanup
176
- MessageConsumer consumer = new MessageConsumer (url1 , dest );
177
- log .info ("--- Starting Consumer --- " + url1 );
178
-
179
- producer .produce (2 );
180
- consumer .receive (2 );
181
- return null ;
182
- }
183
- }));
184
- }
185
-
186
- for (Future <Void > result : results ) {
187
- try {
188
- result .get ();
189
- } catch (Exception e ) {
190
- log .error ("exception in getting future result " , e );
191
- fail (String .format ("replication test failed with %s exception" , e .getMessage ()));
192
- }
193
- }
194
-
195
- Thread .sleep (1000L );
196
- // Make sure that the internal replicators map contains remote cluster info
197
- ConcurrentOpenHashMap <String , PulsarClient > replicationClients1 = ns1 .getReplicationClients ();
198
- ConcurrentOpenHashMap <String , PulsarClient > replicationClients2 = ns2 .getReplicationClients ();
199
- ConcurrentOpenHashMap <String , PulsarClient > replicationClients3 = ns3 .getReplicationClients ();
200
-
201
- Assert .assertNotNull (replicationClients1 .get ("r2" ));
202
- Assert .assertNotNull (replicationClients1 .get ("r3" ));
203
- Assert .assertNotNull (replicationClients2 .get ("r1" ));
204
- Assert .assertNotNull (replicationClients2 .get ("r3" ));
205
- Assert .assertNotNull (replicationClients3 .get ("r1" ));
206
- Assert .assertNotNull (replicationClients3 .get ("r2" ));
207
-
208
- // Case 1: Update the global namespace replication configuration to only contains the local cluster itself
209
- admin1 .namespaces ().setNamespaceReplicationClusters ("pulsar/ns" , Sets .newHashSet ("r1" ));
210
-
211
- // Wait for config changes to be updated.
212
- Thread .sleep (1000L );
213
-
214
- // Make sure that the internal replicators map still contains remote cluster info
215
- Assert .assertNotNull (replicationClients1 .get ("r2" ));
216
- Assert .assertNotNull (replicationClients1 .get ("r3" ));
217
- Assert .assertNotNull (replicationClients2 .get ("r1" ));
218
- Assert .assertNotNull (replicationClients2 .get ("r3" ));
219
- Assert .assertNotNull (replicationClients3 .get ("r1" ));
220
- Assert .assertNotNull (replicationClients3 .get ("r2" ));
221
-
222
- // Case 2: Update the configuration back
223
- admin1 .namespaces ().setNamespaceReplicationClusters ("pulsar/ns" , Sets .newHashSet ("r1" , "r2" , "r3" ));
224
-
225
- // Wait for config changes to be updated.
226
- Thread .sleep (1000L );
227
-
228
- // Make sure that the internal replicators map still contains remote cluster info
229
- Assert .assertNotNull (replicationClients1 .get ("r2" ));
230
- Assert .assertNotNull (replicationClients1 .get ("r3" ));
231
- Assert .assertNotNull (replicationClients2 .get ("r1" ));
232
- Assert .assertNotNull (replicationClients2 .get ("r3" ));
233
- Assert .assertNotNull (replicationClients3 .get ("r1" ));
234
- Assert .assertNotNull (replicationClients3 .get ("r2" ));
235
-
236
- // Case 3: TODO: Once automatic cleanup is implemented, add tests case to verify auto removal of clusters
237
- }
238
-
239
156
@ Test (timeOut = 10000 )
240
157
public void activeBrokerParse () throws Exception {
241
158
pulsar1 .getConfiguration ().setAuthorizationEnabled (true );
@@ -253,6 +170,32 @@ public void activeBrokerParse() throws Exception {
253
170
pulsar1 .getConfiguration ().setAuthorizationEnabled (false );
254
171
}
255
172
173
+ @ Test
174
+ public void testForcefullyTopicDeletion () throws Exception {
175
+ log .info ("--- Starting ReplicatorTest::testForcefullyTopicDeletion ---" );
176
+
177
+ final String namespace = BrokerTestUtil .newUniqueName ("pulsar/removeClusterTest" );
178
+ admin1 .namespaces ().createNamespace (namespace );
179
+ admin1 .namespaces ().setNamespaceReplicationClusters (namespace , Sets .newHashSet ("r1" ));
180
+
181
+ final String topicName = "persistent://" + namespace + "/topic" ;
182
+
183
+ @ Cleanup
184
+ PulsarClient client1 = PulsarClient .builder ().serviceUrl (url1 .toString ()).statsInterval (0 , TimeUnit .SECONDS )
185
+ .build ();
186
+
187
+ ProducerImpl <byte []> producer1 = (ProducerImpl <byte []>) client1 .newProducer ().topic (topicName )
188
+ .enableBatching (false ).messageRoutingMode (MessageRoutingMode .SinglePartition ).create ();
189
+ producer1 .close ();
190
+
191
+ admin1 .topics ().delete (topicName , true );
192
+
193
+ MockedPulsarServiceBaseTest
194
+ .retryStrategically ((test ) -> !pulsar1 .getBrokerService ().getTopics ().containsKey (topicName ), 50 , 150 );
195
+
196
+ Assert .assertFalse (pulsar1 .getBrokerService ().getTopics ().containsKey (topicName ));
197
+ }
198
+
256
199
@ SuppressWarnings ("unchecked" )
257
200
@ Test (timeOut = 30000 )
258
201
public void testConcurrentReplicator () throws Exception {
@@ -1240,7 +1183,7 @@ public void testReplicatedCluster() throws Exception {
1240
1183
1241
1184
log .info ("--- Starting ReplicatorTest::testReplicatedCluster ---" );
1242
1185
1243
- final String namespace = "pulsar/global/repl" ;
1186
+ final String namespace = BrokerTestUtil . newUniqueName ( "pulsar/global/repl" ) ;
1244
1187
final String topicName = BrokerTestUtil .newUniqueName ("persistent://" + namespace + "/topic1" );
1245
1188
admin1 .namespaces ().createNamespace (namespace );
1246
1189
admin1 .namespaces ().setNamespaceReplicationClusters (namespace , Sets .newHashSet ("r1" , "r2" , "r3" ));
@@ -1647,7 +1590,7 @@ public void testReplicatorWithFailedAck() throws Exception {
1647
1590
1648
1591
log .info ("--- Starting ReplicatorTest::testReplication ---" );
1649
1592
1650
- String namespace = "pulsar/global/ns2" ;
1593
+ String namespace = BrokerTestUtil . newUniqueName ( "pulsar/global/ns" ) ;
1651
1594
admin1 .namespaces ().createNamespace (namespace , Sets .newHashSet ("r1" ));
1652
1595
final TopicName dest = TopicName
1653
1596
.get (BrokerTestUtil .newUniqueName ("persistent://" + namespace + "/ackFailedTopic" ));
@@ -1685,13 +1628,15 @@ public void testReplicatorWithFailedAck() throws Exception {
1685
1628
1686
1629
MessageIdImpl lastMessageId = (MessageIdImpl ) topic .getLastMessageId ().get ();
1687
1630
Position lastPosition = PositionImpl .get (lastMessageId .getLedgerId (), lastMessageId .getEntryId ());
1688
- ConcurrentOpenHashMap <String , Replicator > replicators = topic .getReplicators ();
1689
- PersistentReplicator replicator = (PersistentReplicator ) replicators .get ("r2" );
1690
1631
1691
1632
Awaitility .await ().pollInterval (1 , TimeUnit .SECONDS ).timeout (30 , TimeUnit .SECONDS )
1692
- .untilAsserted (() -> assertEquals (org .apache .pulsar .broker .service .AbstractReplicator .State .Started ,
1693
- replicator .getState ()));
1694
- assertEquals (replicator .getState (), org .apache .pulsar .broker .service .AbstractReplicator .State .Started );
1633
+ .ignoreExceptions ()
1634
+ .untilAsserted (() -> {
1635
+ ConcurrentOpenHashMap <String , Replicator > replicators = topic .getReplicators ();
1636
+ PersistentReplicator replicator = (PersistentReplicator ) replicators .get ("r2" );
1637
+ assertEquals (org .apache .pulsar .broker .service .AbstractReplicator .State .Started ,
1638
+ replicator .getState ());
1639
+ });
1695
1640
1696
1641
// Make sure all the data has replicated to the remote cluster before close the cursor.
1697
1642
Awaitility .await ().untilAsserted (() -> assertEquals (cursor .getMarkDeletedPosition (), lastPosition ));
@@ -1717,7 +1662,7 @@ public void testReplicatorWithFailedAck() throws Exception {
1717
1662
@ Test
1718
1663
public void testWhenUpdateReplicationCluster () throws Exception {
1719
1664
log .info ("--- testWhenUpdateReplicationCluster ---" );
1720
- String namespace = "pulsar/ns2" ;
1665
+ String namespace = BrokerTestUtil . newUniqueName ( "pulsar/ns" ); ;
1721
1666
admin1 .namespaces ().createNamespace (namespace );
1722
1667
admin1 .namespaces ().setNamespaceReplicationClusters (namespace , Sets .newHashSet ("r1" , "r2" ));
1723
1668
final TopicName dest = TopicName .get (
@@ -1746,12 +1691,12 @@ public void testWhenUpdateReplicationCluster() throws Exception {
1746
1691
@ Test
1747
1692
public void testReplicatorProducerNotExceed () throws Exception {
1748
1693
log .info ("--- testReplicatorProducerNotExceed ---" );
1749
- String namespace1 = "pulsar/ns11" ;
1694
+ String namespace1 = BrokerTestUtil . newUniqueName ( "pulsar/ns1" ) ;
1750
1695
admin1 .namespaces ().createNamespace (namespace1 );
1751
1696
admin1 .namespaces ().setNamespaceReplicationClusters (namespace1 , Sets .newHashSet ("r1" , "r2" ));
1752
1697
final TopicName dest1 = TopicName .get (
1753
1698
BrokerTestUtil .newUniqueName ("persistent://" + namespace1 + "/testReplicatorProducerNotExceed1" ));
1754
- String namespace2 = "pulsar/ns22" ;
1699
+ String namespace2 = BrokerTestUtil . newUniqueName ( "pulsar/ns2" ) ;
1755
1700
admin2 .namespaces ().createNamespace (namespace2 );
1756
1701
admin2 .namespaces ().setNamespaceReplicationClusters (namespace2 , Sets .newHashSet ("r1" , "r2" ));
1757
1702
final TopicName dest2 = TopicName .get (
0 commit comments