cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ko...@apache.org
Subject [1/6] git commit: updated refs/heads/master to c72f65d
Date Sat, 26 Oct 2013 16:30:02 GMT
Updated Branches:
  refs/heads/master 790231528 -> c72f65dc1


InputStream use fix in PorpoertiesStorage

- Properties object polulation using PropertiesUtil.loadFromFile
- test added
- the separate FileNotFoundException handling block was removed as the next IOException block
is catching it and it is only logging

Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/5e1ea1a3
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/5e1ea1a3
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/5e1ea1a3

Branch: refs/heads/master
Commit: 5e1ea1a3e4411bf2c891406e189f9015c7327aec
Parents: 7902315
Author: Laszlo Hornyak <laszlo.hornyak@gmail.com>
Authored: Thu Oct 24 21:20:56 2013 +0200
Committer: Laszlo Hornyak <laszlo.hornyak@gmail.com>
Committed: Sat Oct 26 17:47:33 2013 +0200

----------------------------------------------------------------------
 .../cloud/agent/dao/impl/PropertiesStorage.java | 14 ++----
 .../agent/dao/impl/PropertiesStorageTest.java   | 51 ++++++++++++++++++++
 2 files changed, 54 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5e1ea1a3/agent/src/com/cloud/agent/dao/impl/PropertiesStorage.java
----------------------------------------------------------------------
diff --git a/agent/src/com/cloud/agent/dao/impl/PropertiesStorage.java b/agent/src/com/cloud/agent/dao/impl/PropertiesStorage.java
index 2bf26f4..411d946 100755
--- a/agent/src/com/cloud/agent/dao/impl/PropertiesStorage.java
+++ b/agent/src/com/cloud/agent/dao/impl/PropertiesStorage.java
@@ -17,7 +17,6 @@
 package com.cloud.agent.dao.impl;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -26,6 +25,7 @@ import java.util.Properties;
 
 import javax.ejb.Local;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.dao.StorageComponent;
@@ -59,18 +59,10 @@ public class PropertiesStorage implements StorageComponent {
             _properties.store(output, _name);
             output.flush();
             output.close();
-        } catch (FileNotFoundException e) {
-            s_logger.error("Who deleted the file? ", e);
         } catch (IOException e) {
             s_logger.error("Uh-oh: ", e);
         } finally {
-            if (output != null) {
-                try {
-                    output.close();
-                } catch (IOException e) {
-                    // ignore.
-                }
-            }
+            IOUtils.closeQuietly(output);
         }
     }
 
@@ -99,7 +91,7 @@ public class PropertiesStorage implements StorageComponent {
         }
 
         try {
-            _properties.load(new FileInputStream(file));
+            PropertiesUtil.loadFromFile(_properties, file);
             _file = file;
         } catch (FileNotFoundException e) {
             s_logger.error("How did we get here? ", e);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5e1ea1a3/agent/test/com/cloud/agent/dao/impl/PropertiesStorageTest.java
----------------------------------------------------------------------
diff --git a/agent/test/com/cloud/agent/dao/impl/PropertiesStorageTest.java b/agent/test/com/cloud/agent/dao/impl/PropertiesStorageTest.java
new file mode 100644
index 0000000..4075892
--- /dev/null
+++ b/agent/test/com/cloud/agent/dao/impl/PropertiesStorageTest.java
@@ -0,0 +1,51 @@
+package com.cloud.agent.dao.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+
+import junit.framework.Assert;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.Test;
+
+public class PropertiesStorageTest {
+    @Test
+    public void configureWithNotExistingFile() {
+        String fileName = "target/notyetexistingfile"
+                + System.currentTimeMillis();
+        File file = new File(fileName);
+
+        PropertiesStorage storage = new PropertiesStorage();
+        HashMap<String, Object> params = new HashMap<String, Object>();
+        params.put("path", fileName);
+        Assert.assertTrue(storage.configure("test", params));
+        Assert.assertTrue(file.exists());
+        storage.persist("foo", "bar");
+        Assert.assertEquals("bar", storage.get("foo"));
+
+        storage.stop();
+        file.delete();
+    }
+
+    @Test
+    public void configureWithExistingFile() throws IOException {
+        String fileName = "target/existingfile"
+                + System.currentTimeMillis();
+        File file = new File(fileName);
+
+        FileUtils.writeStringToFile(file, "a=b\n\n");
+
+        PropertiesStorage storage = new PropertiesStorage();
+        HashMap<String, Object> params = new HashMap<String, Object>();
+        params.put("path", fileName);
+        Assert.assertTrue(storage.configure("test", params));
+        Assert.assertEquals("b", storage.get("a"));
+        Assert.assertTrue(file.exists());
+        storage.persist("foo", "bar");
+        Assert.assertEquals("bar", storage.get("foo"));
+
+        storage.stop();
+        file.delete();
+    }
+}


Mime
View raw message