Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)

103438: Working towards a fix for ACE-3948: BM-0004: Factor out select on alf_content_url table during file creation
    - Complement the 'getOrCreate' EntityCache calls with 'createOrGet'
    - Cleanup of ContentDataDAOImpl code before further changes: tabs, @Override, unused code, etc


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@103622 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2015-05-02 07:44:01 +00:00
parent 93ba7015d1
commit 2758df8308
3 changed files with 143 additions and 54 deletions

View File

@@ -18,6 +18,7 @@
*/
package org.alfresco.repo.cache.lookup;
import java.sql.Savepoint;
import java.util.Map;
import java.util.TreeMap;
@@ -27,8 +28,11 @@ import junit.framework.TestCase;
import org.alfresco.repo.cache.MemoryCache;
import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.cache.lookup.EntityLookupCache.EntityLookupCallbackDAO;
import org.alfresco.repo.domain.control.ControlDAO;
import org.alfresco.util.EqualsHelper;
import org.alfresco.util.Pair;
import org.mockito.Mockito;
import org.springframework.dao.DuplicateKeyException;
/**
* A cache for two-way lookups of database entities. These are characterized by having a unique
@@ -46,6 +50,7 @@ public class EntityLookupCacheTest extends TestCase implements EntityLookupCallb
private EntityLookupCache<Long, Object, String> entityLookupCacheA;
private EntityLookupCache<Long, Object, String> entityLookupCacheB;
private TreeMap<Long, String> database;
private ControlDAO controlDAO;
@Override
protected void setUp() throws Exception
@@ -54,6 +59,9 @@ public class EntityLookupCacheTest extends TestCase implements EntityLookupCallb
entityLookupCacheA = new EntityLookupCache<Long, Object, String>(cache, "A", this);
entityLookupCacheB = new EntityLookupCache<Long, Object, String>(cache, "B", this);
database = new TreeMap<Long, String>();
controlDAO = Mockito.mock(ControlDAO.class);
Mockito.when(controlDAO.createSavepoint(Mockito.anyString())).thenReturn(Mockito.mock(Savepoint.class));
}
public void testLookupsUsingIncorrectValue() throws Exception
@@ -159,6 +167,34 @@ public class EntityLookupCacheTest extends TestCase implements EntityLookupCallb
assertEquals(entityPairNull, entityPairCheck);
}
public void testGetOrCreate() throws Exception
{
TestValue valueOne = new TestValue(getName() + "-ONE");
Pair<Long, Object> entityPairOne = entityLookupCacheA.getOrCreateByValue(valueOne);
assertNotNull(entityPairOne);
Long id = entityPairOne.getFirst();
assertEquals(valueOne.val, database.get(id));
assertEquals(2, cache.getKeys().size());
Pair<Long, Object> entityPairOneCheck = entityLookupCacheA.getOrCreateByValue(valueOne);
assertNotNull(entityPairOneCheck);
assertEquals(id, entityPairOneCheck.getFirst());
}
public void testCreateOrGet() throws Exception
{
TestValue valueOne = new TestValue(getName() + "-ONE");
Pair<Long, Object> entityPairOne = entityLookupCacheA.createOrGetByValue(valueOne, controlDAO);
assertNotNull(entityPairOne);
Long id = entityPairOne.getFirst();
assertEquals(valueOne.val, database.get(id));
assertEquals(1, cache.getKeys().size());
Pair<Long, Object> entityPairOneCheck = entityLookupCacheA.createOrGetByValue(valueOne, controlDAO);
assertNotNull(entityPairOneCheck);
assertEquals(id, entityPairOneCheck.getFirst());
}
public void testUpdate() throws Exception
{
TestValue valueOne = new TestValue(getName() + "-ONE");
@@ -295,6 +331,12 @@ public class EntityLookupCacheTest extends TestCase implements EntityLookupCallb
assertTrue(value == null || value instanceof TestValue);
String dbValue = (value == null) ? null : ((TestValue)value).val;
// Kick out any duplicate values
if (database.containsValue(dbValue))
{
throw new DuplicateKeyException("Value is duplicated: " + value);
}
// Get the last key
Long lastKey = database.isEmpty() ? null : database.lastKey();
Long newKey = null;