Author: bdekruijff at gmail.com
Date: Thu Jan 13 16:04:40 2011
New Revision: 622
Log:
AMDATU-207 synchronization and some more tests
Modified:
trunk/amdatu-libraries/fsstorage/src/main/java/org/amdatu/libraries/fsstorage/FSStorageBase.java
trunk/amdatu-libraries/fsstorage/src/test/java/org/amdatu/libraries/fsstorage/FSStorageTest.java
Modified:
trunk/amdatu-libraries/fsstorage/src/main/java/org/amdatu/libraries/fsstorage/FSStorageBase.java
==============================================================================
---
trunk/amdatu-libraries/fsstorage/src/main/java/org/amdatu/libraries/fsstorage/FSStorageBase.java
(original)
+++
trunk/amdatu-libraries/fsstorage/src/main/java/org/amdatu/libraries/fsstorage/FSStorageBase.java
Thu Jan 13 16:04:40 2011
@@ -67,7 +67,7 @@
return m_storeFilepostfix;
}
- public final void addEntity(E entity) throws IOException {
+ public final synchronized void addEntity(E entity) throws IOException {
S store = getFSStore(entity.getId());
E storedEntity = store.addEntity(entity);
if (storedEntity == null) {
@@ -76,7 +76,7 @@
store.save();
}
- public final E removeEntity(String entityId) throws IOException {
+ public final synchronized E removeEntity(String entityId) throws
IOException {
S store = getFSStore(entityId);
E storedEntity = store.removeEntity(entityId);
if (storedEntity != null) {
@@ -86,12 +86,12 @@
return storedEntity;
}
- public final E getEntity(String entityId) throws IOException {
+ public final synchronized E getEntity(String entityId) throws IOException {
S store = getFSStore(entityId);
return store.getEntity(entityId);
}
- public final List<E> getAll() throws IOException {
+ public final synchronized List<E> getAll() throws IOException {
List<String> entityIdList = m_entityList.getAll();
final List<E> entityList = new LinkedList<E>();
for (String entityId : entityIdList) {
Modified:
trunk/amdatu-libraries/fsstorage/src/test/java/org/amdatu/libraries/fsstorage/FSStorageTest.java
==============================================================================
---
trunk/amdatu-libraries/fsstorage/src/test/java/org/amdatu/libraries/fsstorage/FSStorageTest.java
(original)
+++
trunk/amdatu-libraries/fsstorage/src/test/java/org/amdatu/libraries/fsstorage/FSStorageTest.java
Thu Jan 13 16:04:40 2011
@@ -18,7 +18,9 @@
import java.io.File;
import java.io.IOException;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Random;
import org.amdatu.libraries.fsstorage.test.FSTestEntity;
@@ -107,4 +109,47 @@
eList = m_testStorage.getAll();
Assert.assertEquals(2, eList.size());
}
+
+ @Test
+ public void testTheTestStoreWithProperties() throws IOException {
+
+ Map<String, String> props = new HashMap<String, String>();
+ props.put("key1", "value1");
+ props.put("key2", "value2");
+
+ FSTestEntity e1 = new FSTestEntity("123", props);
+ m_testStorage.addEntity(e1);
+
+ e1 = m_testStorage.getEntity(e1.getId());
+
+ props = e1.getProperties();
+ Assert.assertNotNull(props);
+ Assert.assertEquals(2, props.size());
+ Assert.assertEquals("value1", props.get("key1"));
+ Assert.assertEquals("value2", props.get("key2"));
+ }
+
+ /**
+ * Testing behavior on tenantEntities with same hashcode() for the id.
This is based on knowledge of the
+ * implementation but as it is a likely pitfall let's test it anyway to
catch future mistakes.
+ *
+ * @throws TenantStorageException
+ */
+ @Test
+ public void testWithEqualHashcodes() throws IOException {
+
+ // Assert the reason for this test
+ Assert.assertEquals("BB".hashCode(), "Aa".hashCode());
+
+ FSTestEntity e1 = new FSTestEntity("BB", null);
+ m_testStorage.addEntity(e1);
+ Assert.assertEquals(e1, m_testStorage.getEntity(e1.getId()));
+
+ FSTestEntity e3 = new FSTestEntity("Aa", null);
+ m_testStorage.addEntity(e3);
+ Assert.assertEquals(e3, m_testStorage.getEntity(e3.getId()));
+
+ List<FSTestEntity> eList = m_testStorage.getAll();
+ Assert.assertEquals(2, eList.size());
+ }
}