mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)
64703: Fix ACE-987: NPE in NodeEntity during post-commit write through to shared cache - Query selecting specific root nodes was not fully populating the stored entity - The failure itself mainly occurs when a check is made to prevent duplication of cache transfers (the cached value is the same); once the cache has an entry, the error would not have occurred again. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@66181 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,12 +18,15 @@
|
||||
*/
|
||||
package org.alfresco.repo.domain.node;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.cache.SimpleCache;
|
||||
import org.alfresco.repo.domain.node.NodeDAO.NodeRefQueryCallback;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
@@ -34,6 +37,7 @@ import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.junit.Assert;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
@@ -53,7 +57,9 @@ public class NodeDAOTest extends TestCase
|
||||
private TransactionService transactionService;
|
||||
private RetryingTransactionHelper txnHelper;
|
||||
private NodeDAO nodeDAO;
|
||||
private SimpleCache<Serializable, Node> rootNodesCache;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void setUp()
|
||||
{
|
||||
@@ -65,6 +71,7 @@ public class NodeDAOTest extends TestCase
|
||||
txnHelper.setMaxRetryWaitMs(50);
|
||||
|
||||
nodeDAO = (NodeDAO) ctx.getBean("nodeDAO");
|
||||
rootNodesCache = (SimpleCache<Serializable, Node>) ctx.getBean("node.rootNodesSharedCache");
|
||||
}
|
||||
|
||||
public void testTransaction() throws Throwable
|
||||
@@ -141,4 +148,35 @@ public class NodeDAOTest extends TestCase
|
||||
assertEquals("Store pair did not match. ", storePair, checkStorePair);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the {@link NodeEntity} values cached as root nodes are valid instances.
|
||||
* <p/>
|
||||
* ACE-987: NPE in NodeEntity during post-commit write through to shared cache
|
||||
*/
|
||||
public void testRootNodeCacheEntries() throws Throwable
|
||||
{
|
||||
// Get the stores
|
||||
List<Pair<Long, StoreRef>> storeRefPairs = nodeDAO.getStores();
|
||||
assertTrue("No stores in the system.", storeRefPairs.size() > 0);
|
||||
// Drop all cache entries and reload them one by one
|
||||
for (Pair<Long, StoreRef> storeRefPair : storeRefPairs)
|
||||
{
|
||||
StoreRef storeRef = storeRefPair.getSecond();
|
||||
nodeDAO.getRootNode(storeRef);
|
||||
}
|
||||
// The cache should be populated again
|
||||
Collection<Serializable> keys = rootNodesCache.getKeys();
|
||||
assertTrue("Cache entries were not populated. ", keys.size() > 0);
|
||||
// Check each root node
|
||||
for (Serializable key : keys)
|
||||
{
|
||||
NodeEntity node = (NodeEntity) rootNodesCache.get(key);
|
||||
// Create a good value
|
||||
NodeEntity clonedNode = (NodeEntity) node.clone();
|
||||
// Run equals and hashcode
|
||||
node.hashCode();
|
||||
Assert.assertEquals(node, clonedNode); // Does NPE check implicitly
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user