You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2015/06/03 15:32:47 UTC

tomee git commit: TOMEE-1596 ensuring we dont deploy twice at startup and dont delete the deployng file in AutoDeployer

Repository: tomee
Updated Branches:
  refs/heads/master fc50761ea -> 3a52b81c5


TOMEE-1596 ensuring we dont deploy twice at startup and dont delete the deployng file in AutoDeployer


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/3a52b81c
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/3a52b81c
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/3a52b81c

Branch: refs/heads/master
Commit: 3a52b81c5f552f89e22ca0e25b76f7d3dc9c70ac
Parents: fc50761
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Wed Jun 3 15:32:28 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Wed Jun 3 15:32:28 2015 +0200

----------------------------------------------------------------------
 .../org/apache/openejb/config/AutoDeployer.java |  6 ++
 .../apache/openejb/config/AutoDeployerTest.java | 63 ++++++++++++++++++++
 2 files changed, 69 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/3a52b81c/container/openejb-core/src/main/java/org/apache/openejb/config/AutoDeployer.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/AutoDeployer.java b/container/openejb-core/src/main/java/org/apache/openejb/config/AutoDeployer.java
index 57fd3ce..9602208 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/AutoDeployer.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/AutoDeployer.java
@@ -133,12 +133,16 @@ public class AutoDeployer {
                         assembler.destroyApplication(app);
 
                         for (final String location : app.paths) {
+                            if (new File(location).equals(file)) {
+                                continue;
+                            }
 
                             final File delete = new File(location.replace("%20", " ").replace("%23", "#"));
 
                             for (int i = 0; i < 3; i++) {
                                 try {
                                     Files.remove(delete);
+                                    break;
                                 } catch (final Exception e) {
                                     if (i < 2) {
                                         //Try again as file IO is not a science
@@ -237,6 +241,7 @@ public class AutoDeployer {
 
             final FileInfo now = newInfo(file);
             now.setChanging(false);
+            now.setNewFile(false);
 
             logger.debug("Auto-Deployer initialization found: " + file.getAbsolutePath());
         }
@@ -291,6 +296,7 @@ public class AutoDeployer {
                     // Used to be changing, now in (hopefully) its final state
                     logger.info("New File: " + newStatus);
                     newStatus.setNewFile(!fileAdded(file));
+                    newStatus.setChanging(false);
                 } else if (oldStatus.isChanging()) {
                     logger.info("Updated Auto-Deployer File: " + newStatus);
                     fileUpdated(file);

http://git-wip-us.apache.org/repos/asf/tomee/blob/3a52b81c/container/openejb-core/src/test/java/org/apache/openejb/config/AutoDeployerTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/config/AutoDeployerTest.java b/container/openejb-core/src/test/java/org/apache/openejb/config/AutoDeployerTest.java
index c4cd3fb..42b9aff 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/config/AutoDeployerTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/config/AutoDeployerTest.java
@@ -105,6 +105,7 @@ public class AutoDeployerTest {
         properties.setProperty("openejb.deployment.unpack.location", "false");
         properties.setProperty("openejb.home", tmpdir.getAbsolutePath());
         properties.setProperty("openejb.base", tmpdir.getAbsolutePath());
+        properties.setProperty("openejb.autodeploy.interval", "2 seconds");
 
         SystemInstance.init(properties);
 
@@ -153,6 +154,65 @@ public class AutoDeployerTest {
     }
 
     @Test
+    public void testOriginalAppScanning() throws Exception {
+        final File tmpdir = Files.tmpdir();
+        final File apps = Files.mkdir(tmpdir, "myapps");
+        final File conf = Files.mkdir(tmpdir, "conf");
+
+        files.add(apps);
+
+        final Properties properties = new Properties();
+        properties.setProperty("openejb.deployments.classpath", "false");
+        properties.setProperty("openejb.deployment.unpack.location", "false");
+        properties.setProperty("openejb.home", tmpdir.getAbsolutePath());
+        properties.setProperty("openejb.base", tmpdir.getAbsolutePath());
+        properties.setProperty("openejb.autodeploy.interval", "2 seconds");
+
+        SystemInstance.init(properties);
+
+        { // Setup the configuration location
+            final File config = new File(conf, "openejb.xml");
+            IO.writeString(config, "<openejb><Deployments autoDeploy=\"true\" dir=\"myapps\"/> </openejb>");
+            SystemInstance.get().setProperty("openejb.configuration", config.getAbsolutePath());
+        }
+
+        final File deployed = Files.path(apps, "colors.ear");
+        final File ear = createEar(tmpdir, Orange.class, State.class);
+        IO.copy(ear, deployed);
+
+        final ConfigurationFactory configurationFactory = new ConfigurationFactory();
+        configurationFactory.init(properties);
+        final OpenEjbConfiguration configuration = configurationFactory.getOpenEjbConfiguration();
+
+        { // Check the ContainerSystemInfo
+
+            final List<String> autoDeploy = configuration.containerSystem.autoDeploy;
+            assertEquals(1, autoDeploy.size());
+            assertEquals("myapps", autoDeploy.get(0));
+        }
+
+        final Assembler assembler = new Assembler();
+        assembler.buildContainerSystem(configuration);
+
+        assertTrue(Orange.deployed);
+        final long start = Orange.start;
+
+        assertFalse(Yellow.deployed);
+        assertTrue(Orange.deployed);
+
+        // wait another to ensure it doesnt redeploy again
+        Thread.sleep(4000);
+        assertEquals(start, Orange.start);
+
+        Files.delete(deployed);
+
+        Orange.state.waitForChange(1, TimeUnit.MINUTES);
+
+        assertFalse(Yellow.deployed);
+        assertFalse(Orange.deployed);
+    }
+
+    @Test
     public void testSpaces() throws Exception {
         final File tmpdir = new File(Files.tmpdir(), "with spaces");
         final File apps = Files.mkdir(tmpdir, "my apps");
@@ -323,8 +383,11 @@ public class AutoDeployerTest {
         public static volatile boolean deployed;
         public static final State state = new State();
 
+        public static long start;
+
         @PostConstruct
         private void startup() {
+            start = System.currentTimeMillis();
             deployed = true;
             state.toggle();
         }