You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2014/09/01 18:55:38 UTC

[07/11] git commit: Fix BrooklynLauncherRebindTestToFiles

Fix BrooklynLauncherRebindTestToFiles


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/01a013bc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/01a013bc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/01a013bc

Branch: refs/heads/master
Commit: 01a013bc9d7d0a1e981e92adb4d8b0c6aef45d81
Parents: e345ba0
Author: Aled Sage <al...@gmail.com>
Authored: Thu Aug 21 15:36:45 2014 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Thu Aug 21 15:46:43 2014 +0100

----------------------------------------------------------------------
 .../rebind/persister/FileBasedObjectStore.java    | 18 ++++++++++++++++--
 .../BrooklynLauncherRebindTestToFiles.java        | 15 ++++++++++-----
 2 files changed, 26 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/01a013bc/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedObjectStore.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedObjectStore.java b/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedObjectStore.java
index 691f43c..2e6f15d 100644
--- a/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedObjectStore.java
+++ b/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedObjectStore.java
@@ -18,6 +18,7 @@
  */
 package brooklyn.entity.rebind.persister;
 
+import static com.google.common.base.Preconditions.checkNotNull;
 import static java.lang.String.format;
 
 import java.io.File;
@@ -77,7 +78,7 @@ public class FileBasedObjectStore implements PersistenceObjectStore {
      * @param basedir
      */
     public FileBasedObjectStore(File basedir) {
-        this.basedir = basedir;
+        this.basedir = checkPersistenceDirPlausible(basedir);
         this.executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
         log.debug("File-based objectStore will use directory {}", basedir);
         // don't check accessible yet, we do that when we prepare
@@ -281,6 +282,16 @@ public class FileBasedObjectStore implements PersistenceObjectStore {
         prepared = true;        
     }
 
+    protected File checkPersistenceDirPlausible(File dir) {
+        checkNotNull(dir, "directory");
+        if (!dir.exists()) return dir;
+        if (dir.isFile()) throw new FatalConfigurationRuntimeException("Invalid persistence directory" + dir + ": must not be a file");
+        if (!(dir.canRead() && dir.canWrite())) throw new FatalConfigurationRuntimeException("Invalid persistence directory" + dir + ": " +
+                (!dir.canRead() ? "not readable" :
+                        (!dir.canWrite() ? "not writable" : "unknown reason")));
+        return dir;
+    }
+
     protected void checkPersistenceDirAccessible(File dir) {
         if (!(dir.exists() && dir.isDirectory() && dir.canRead() && dir.canWrite())) {
             FatalConfigurationRuntimeException problem = new FatalConfigurationRuntimeException("Invalid persistence directory " + dir + ": " +
@@ -385,7 +396,10 @@ public class FileBasedObjectStore implements PersistenceObjectStore {
     
     static boolean isMementoDirExistButEmpty(File dir) {
         if (!dir.exists()) return false;
-        for (File sub : dir.listFiles()) {
+        File[] contents = dir.listFiles();
+        if (contents == null) return false;
+        
+        for (File sub : contents) {
             if (sub.isFile()) return false;
             if (sub.isDirectory() && sub.listFiles().length > 0) return false;
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/01a013bc/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindTestToFiles.java
----------------------------------------------------------------------
diff --git a/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindTestToFiles.java b/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindTestToFiles.java
index e212c71..20809fc 100644
--- a/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindTestToFiles.java
+++ b/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindTestToFiles.java
@@ -24,12 +24,15 @@ import java.io.File;
 
 import org.testng.annotations.Test;
 
+import brooklyn.config.BrooklynProperties;
 import brooklyn.config.BrooklynServerConfig;
+import brooklyn.config.StringConfigMap;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.entity.rebind.persister.BrooklynMementoPersisterToObjectStore;
 import brooklyn.entity.rebind.persister.FileBasedObjectStore;
 import brooklyn.entity.rebind.persister.PersistMode;
 import brooklyn.management.ManagementContext;
+import brooklyn.mementos.BrooklynMemento;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.util.javalang.JavaClassNames;
 import brooklyn.util.os.Os;
@@ -50,7 +53,8 @@ public class BrooklynLauncherRebindTestToFiles extends BrooklynLauncherRebindTes
     }
     
     protected void checkPersistenceContainerNameIs(String expected) {
-        assertEquals(getPersistenceDir(lastMgmt()).getAbsolutePath(), expected);
+        String expectedFqp = new File(Os.tidyPath(expected)).getAbsolutePath();
+        assertEquals(getPersistenceDir(lastMgmt()).getAbsolutePath(), expectedFqp);
     }
 
     static File getPersistenceDir(ManagementContext managementContext) {
@@ -60,7 +64,8 @@ public class BrooklynLauncherRebindTestToFiles extends BrooklynLauncherRebindTes
     }
 
     protected void checkPersistenceContainerNameIsDefault() {
-        checkPersistenceContainerNameIs(BrooklynServerConfig.DEFAULT_PERSISTENCE_DIR_FOR_FILESYSTEM);
+        String expected = BrooklynServerConfig.resolvePersistencePath(null, BrooklynProperties.Factory.newEmpty(), null);
+        checkPersistenceContainerNameIs(expected);
     }
 
     @Test
@@ -70,9 +75,9 @@ public class BrooklynLauncherRebindTestToFiles extends BrooklynLauncherRebindTes
         String tempFileName = tempF.getAbsolutePath();
         
         try {
-            runRebindFails(PersistMode.AUTO, tempFileName, "not a directory");
-            runRebindFails(PersistMode.REBIND, tempFileName, "not a directory");
-            runRebindFails(PersistMode.CLEAN, tempFileName, "not a directory");
+            runRebindFails(PersistMode.AUTO, tempFileName, "must not be a file");
+            runRebindFails(PersistMode.REBIND, tempFileName, "must not be a file");
+            runRebindFails(PersistMode.CLEAN, tempFileName, "must not be a file");
         } finally {
             new File(tempFileName).delete();
         }