flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hshreedha...@apache.org
Subject git commit: FLUME-1854: Application class can deadlock if stopped immediately after start
Date Thu, 24 Jan 2013 21:29:13 GMT
Updated Branches:
  refs/heads/flume-1.4 90322322b -> 244709b71


FLUME-1854: Application class can deadlock if stopped immediately after start

(Brock Noland via Hari Shreedharan)


Project: http://git-wip-us.apache.org/repos/asf/flume/repo
Commit: http://git-wip-us.apache.org/repos/asf/flume/commit/244709b7
Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/244709b7
Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/244709b7

Branch: refs/heads/flume-1.4
Commit: 244709b7187b67af1ec91eb3eb0f0173145cbf4b
Parents: 9032232
Author: Hari Shreedharan <harishreedharan@gmail.com>
Authored: Thu Jan 24 13:27:31 2013 -0800
Committer: Hari Shreedharan <harishreedharan@gmail.com>
Committed: Thu Jan 24 13:28:57 2013 -0800

----------------------------------------------------------------------
 .../java/org/apache/flume/node/Application.java    |    4 +-
 .../org/apache/flume/node/TestApplication.java     |   35 ++++++++++++++-
 2 files changed, 36 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flume/blob/244709b7/flume-ng-node/src/main/java/org/apache/flume/node/Application.java
----------------------------------------------------------------------
diff --git a/flume-ng-node/src/main/java/org/apache/flume/node/Application.java b/flume-ng-node/src/main/java/org/apache/flume/node/Application.java
index c066a1a..f501bd7 100644
--- a/flume-ng-node/src/main/java/org/apache/flume/node/Application.java
+++ b/flume-ng-node/src/main/java/org/apache/flume/node/Application.java
@@ -74,7 +74,7 @@ public class Application  {
     supervisor = new LifecycleSupervisor();
   }
 
-  public void start() {
+  public synchronized void start() {
     for(LifecycleAware component : components) {
       supervisor.supervise(component,
           new SupervisorPolicy.AlwaysRestartPolicy(), LifecycleState.START);
@@ -88,7 +88,7 @@ public class Application  {
     startAllComponents(conf);
   }
 
-  public void stop() {
+  public synchronized void stop() {
     supervisor.stop();
     if(monitorServer != null) {
       monitorServer.stop();

http://git-wip-us.apache.org/repos/asf/flume/blob/244709b7/flume-ng-node/src/test/java/org/apache/flume/node/TestApplication.java
----------------------------------------------------------------------
diff --git a/flume-ng-node/src/test/java/org/apache/flume/node/TestApplication.java b/flume-ng-node/src/test/java/org/apache/flume/node/TestApplication.java
index d326312..930f2a2 100644
--- a/flume-ng-node/src/test/java/org/apache/flume/node/TestApplication.java
+++ b/flume-ng-node/src/test/java/org/apache/flume/node/TestApplication.java
@@ -21,26 +21,39 @@ package org.apache.flume.node;
 
 import static org.mockito.Mockito.*;
 
+import java.io.File;
+import java.util.List;
+import java.util.Random;
 import java.util.concurrent.atomic.AtomicReference;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.flume.Channel;
 import org.apache.flume.SinkRunner;
 import org.apache.flume.SourceRunner;
 import org.apache.flume.lifecycle.LifecycleAware;
 import org.apache.flume.lifecycle.LifecycleState;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
+import com.google.common.collect.Lists;
 import com.google.common.eventbus.EventBus;
+import com.google.common.io.Files;
 
 public class TestApplication {
 
 
+  private File baseDir;
+
   @Before
   public void setup() throws Exception {
-
+    baseDir = Files.createTempDir();
+  }
+  @After
+  public void tearDown() throws Exception {
+    FileUtils.deleteDirectory(baseDir);
   }
 
   private <T extends LifecycleAware> T mockLifeCycle(Class<T> klass) {
@@ -118,6 +131,26 @@ public class TestApplication {
     verify(sourceRunner).stop();
     verify(sinkRunner).stop();
     verify(channel).stop();
+  }
 
+  @Test
+  public void testFLUME1854() throws Exception {
+    File configFile = new File(baseDir, "flume-conf.properties");
+    Files.copy(new File(getClass().getClassLoader()
+        .getResource("flume-conf.properties").getFile()), configFile);
+    Random random = new Random();
+    for (int i = 0; i < 3; i++) {
+      EventBus eventBus = new EventBus("test-event-bus");
+      PollingPropertiesFileConfigurationProvider configurationProvider =
+          new PollingPropertiesFileConfigurationProvider("host1",
+              configFile, eventBus, 1);
+      List<LifecycleAware> components = Lists.newArrayList();
+      components.add(configurationProvider);
+      Application application = new Application(components);
+      eventBus.register(application);
+      application.start();
+      Thread.sleep(random.nextInt(10000));
+      application.stop();
+    }
   }
 }


Mime
View raw message