summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew MacBean <macbean@apache.org>2014-09-17 10:35:33 +0000
committerAndrew MacBean <macbean@apache.org>2014-09-17 10:35:33 +0000
commit5186e947711bb39c32546a5748df16d4e467ec7f (patch)
tree730c1a4a09e8e4eaca0f5b9d31fa34fa055aa451
parent8ed450c3d3db77b5822f293e6683d11dabc8e05a (diff)
downloadqpid-python-5186e947711bb39c32546a5748df16d4e467ec7f.tar.gz
QPID-6095: [Java Broker] Deletion of an ERRORED JSON VHN with an invalid store path causes an exception
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1625505 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java24
-rw-r--r--java/broker-core/src/test/java/org/apache/qpid/server/store/JsonFileConfigStoreTest.java9
2 files changed, 26 insertions, 7 deletions
diff --git a/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java b/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java
index b00428064d..edcad2f51a 100644
--- a/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java
+++ b/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java
@@ -91,6 +91,7 @@ public class JsonFileConfigStore implements DurableConfigurationStore
private String _name;
private FileLock _fileLock;
private String _configFileName;
+ private String _backupFileName;
private String _lockFileName;
private static final Module _module;
@@ -170,12 +171,14 @@ public class JsonFileConfigStore implements DurableConfigurationStore
{
_directoryName = fileFromSettings.getParent();
_configFileName = fileFromSettings.getName();
+ _backupFileName = fileFromSettings.getName() + ".bak";
_lockFileName = fileFromSettings.getName() + ".lck";
}
else
{
_directoryName = configurationStoreSettings.getStorePath();
_configFileName = _name + ".json";
+ _backupFileName = _name + ".bak";
_lockFileName = _name + ".lck";
}
@@ -185,14 +188,21 @@ public class JsonFileConfigStore implements DurableConfigurationStore
if(!fileExists(_configFileName))
{
- File newFile = new File(_directoryName, _configFileName);
- try
+ if(!fileExists(_backupFileName))
{
- _objectMapper.writeValue(newFile, Collections.emptyMap());
+ File newFile = new File(_directoryName, _configFileName);
+ try
+ {
+ _objectMapper.writeValue(newFile, Collections.emptyMap());
+ }
+ catch (IOException e)
+ {
+ throw new StoreException("Could not write configuration file " + newFile, e);
+ }
}
- catch (IOException e)
+ else
{
- throw new StoreException("Could not write configuration file " + newFile, e);
+ renameFile(_backupFileName, _configFileName);
}
}
}
@@ -390,8 +400,11 @@ public class JsonFileConfigStore implements DurableConfigurationStore
File tmpFile = File.createTempFile("cfg","tmp", new File(_directoryName));
tmpFile.deleteOnExit();
_objectMapper.writeValue(tmpFile, data);
+ renameFile(_configFileName, _backupFileName);
renameFile(tmpFile.getName(),_configFileName);
tmpFile.delete();
+ File backupFile = new File(_directoryName, _backupFileName);
+ backupFile.delete();
}
catch (IOException e)
{
@@ -619,5 +632,4 @@ public class JsonFileConfigStore implements DurableConfigurationStore
}
return map;
}
-
}
diff --git a/java/broker-core/src/test/java/org/apache/qpid/server/store/JsonFileConfigStoreTest.java b/java/broker-core/src/test/java/org/apache/qpid/server/store/JsonFileConfigStoreTest.java
index d76ba0bc76..2e0a7c5bdb 100644
--- a/java/broker-core/src/test/java/org/apache/qpid/server/store/JsonFileConfigStoreTest.java
+++ b/java/broker-core/src/test/java/org/apache/qpid/server/store/JsonFileConfigStoreTest.java
@@ -352,18 +352,25 @@ public class JsonFileConfigStoreTest extends QpidTestCase
public void testStoreFileLifecycle()
{
File expectedJsonFile = new File(_storeLocation, _parent.getName() + ".json");
+ File expectedJsonFileBak = new File(_storeLocation, _parent.getName() + ".bak");
+ File expectedJsonFileLck = new File(_storeLocation, _parent.getName() + ".lck");
assertFalse("JSON store should not exist", expectedJsonFile.exists());
+ assertFalse("JSON backup should not exist", expectedJsonFileBak.exists());
+ assertFalse("JSON lock should not exist", expectedJsonFileLck.exists());
_store.openConfigurationStore(_parent, false);
assertTrue("JSON store should exist after open", expectedJsonFile.exists());
+ assertFalse("JSON backup should not exist after open", expectedJsonFileBak.exists());
+ assertTrue("JSON lock should exist", expectedJsonFileLck.exists());
_store.closeConfigurationStore();
assertTrue("JSON store should exist after close", expectedJsonFile.exists());
_store.onDelete(_parent);
assertFalse("JSON store should not exist after delete", expectedJsonFile.exists());
-
+ assertFalse("JSON backup should not exist after delete", expectedJsonFileBak.exists());
+ assertFalse("JSON lock should not exist after delete", expectedJsonFileLck.exists());
}
public void testCreatedNestedObjects() throws Exception