rdhabalia closed pull request #1945:  Fix: managedledger factory shutdown stuck 
when any of ledger future-result is not completed
URL: https://github.com/apache/incubator-pulsar/pull/1945
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerFactoryImpl.java
 
b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerFactoryImpl.java
index cb4d2f99e4..2d9072545a 100644
--- 
a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerFactoryImpl.java
+++ 
b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerFactoryImpl.java
@@ -272,6 +272,7 @@ public void shutdown() throws InterruptedException, 
ManagedLedgerException {
         for (CompletableFuture<ManagedLedgerImpl> ledgerFuture : 
ledgers.values()) {
             ManagedLedgerImpl ledger = ledgerFuture.getNow(null);
             if (ledger == null) {
+                latch.countDown();
                 continue;
             }
 
diff --git 
a/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarSinkE2ETest.java 
b/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarSinkE2ETest.java
index 328d6b23c2..531f8adbb5 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarSinkE2ETest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarSinkE2ETest.java
@@ -26,7 +26,6 @@
 import java.lang.reflect.Method;
 import java.net.InetAddress;
 import java.net.MalformedURLException;
-import java.net.URI;
 import java.net.URL;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -103,8 +102,6 @@
     final String tenant = "external-repl-prop";
     String pulsarFunctionsNamespace = tenant + "/use/pulsar-function-admin";
     String primaryHost;
-    ExecutorService executor;
-    ExecutorService workerExecutor;
 
     private final int ZOOKEEPER_PORT = PortManager.nextFreePort();
     private final int brokerWebServicePort = PortManager.nextFreePort();
@@ -125,9 +122,6 @@ void setup(Method method) throws Exception {
 
         log.info("--- Setting up method {} ---", method.getName());
 
-        executor = new ThreadPoolExecutor(5, 20, 30, TimeUnit.SECONDS, new 
LinkedBlockingQueue<Runnable>());
-        workerExecutor = Executors.newScheduledThreadPool(1, new 
DefaultThreadFactory("pulsar-worker-test"));
-
         // Start local bookkeeper ensemble
         bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, 
PortManager.nextFreePort());
         bkEnsemble.start();
@@ -158,10 +152,7 @@ void setup(Method method) throws Exception {
 
         functionsWorkerService = createPulsarFunctionWorker(config);
         urlTls = new URL(brokerServiceUrl);
-        boolean isFunctionWebServerRequired = method.getName()
-                .equals("testExternalReplicatorRedirectionToWorkerService");
-        Optional<WorkerService> functionWorkerService = 
isFunctionWebServerRequired ? Optional.ofNullable(null)
-                : Optional.of(functionsWorkerService);
+        Optional<WorkerService> functionWorkerService = 
Optional.of(functionsWorkerService);
         pulsar = new PulsarService(config, functionWorkerService);
         pulsar.start();
 
@@ -197,29 +188,17 @@ void setup(Method method) throws Exception {
         TenantInfo propAdmin = new TenantInfo();
         
propAdmin.setAllowedClusters(Sets.newHashSet(Lists.newArrayList("use")));
         admin.tenants().updateTenant(tenant, propAdmin);
-
-        if (isFunctionWebServerRequired) {
-            URI dlogURI = 
Utils.initializeDlogNamespace(config.getZookeeperServers(), "/ledgers");
-            functionsWorkerService.start(dlogURI);
-            functionsWorkerServer = new WorkerServer(functionsWorkerService);
-            workerExecutor.submit(functionsWorkerServer);
-        }
+       
         Thread.sleep(100);
     }
 
     @AfterMethod
     void shutdown() throws Exception {
         log.info("--- Shutting down ---");
-        if (executor != null) {
-            executor.shutdown();
-        }
-        if (workerExecutor != null) {
-            workerExecutor.shutdown();
-        }
         pulsarClient.close();
         admin.close();
-        pulsar.close();
         functionsWorkerService.stop();
+        pulsar.close();
         bkEnsemble.stop();
     }
 
@@ -260,7 +239,7 @@ private WorkerService 
createPulsarFunctionWorker(ServiceConfiguration config) {
      * 
      * @throws Exception
      */
-    @Test
+    @Test(timeOut = 20000)
     public void testE2EPulsarSink() throws Exception {
 
         final String namespacePortion = "myReplNs";
@@ -289,7 +268,8 @@ public void testE2EPulsarSink() throws Exception {
         // validate pulsar sink consumer has started on the topic
         
Assert.assertEquals(admin.topics().getStats(sourceTopic).subscriptions.size(), 
1);
 
-        for (int i = 0; i < 5; i++) {
+        int totalMsgs = 5;
+        for (int i = 0; i < totalMsgs; i++) {
             String message = "my-message-" + i;
             producer.send(message.getBytes());
         }
@@ -304,8 +284,8 @@ public void testE2EPulsarSink() throws Exception {
         }, 5, 150);
         // validate pulsar-sink consumer has consumed all messages and 
delivered to Pulsar sink but unacked messages
         // due to publish failure
-        Assert.assertEquals(
-                
admin.topics().getStats(sourceTopic).subscriptions.values().iterator().next().unackedMessages,
 0);
+        Assert.assertNotEquals(
+                
admin.topics().getStats(sourceTopic).subscriptions.values().iterator().next().unackedMessages,
 totalMsgs);
 
     }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to