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

93938: Merged BRANCHES/DEV/mward/post50_hbf_fixes to BRANCHES/DEV/HEAD-BUG-FIX:
      93561: Cache stats: Fixed concurrency issue with 'get' count. Added method to retrieve stats snapshot.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@95014 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2015-01-31 15:26:15 +00:00
parent b6e2f3309f
commit 151537105d
5 changed files with 207 additions and 32 deletions

View File

@@ -2,6 +2,8 @@ package org.alfresco.repo.cache;
import static org.junit.Assert.*;
import java.util.Map;
import org.alfresco.repo.cache.TransactionStats.OpType;
import org.junit.Before;
import org.junit.Test;
@@ -60,6 +62,24 @@ public class InMemoryCacheStatisticsTest
{
// Good.
}
try
{
cacheStats.numGets("cache1");
fail("NoStatsForCache should have been thrown.");
}
catch(NoStatsForCache e)
{
// Good.
}
try
{
cacheStats.allStats("cache1");
fail("NoStatsForCache should have been thrown.");
}
catch(NoStatsForCache e)
{
// Good.
}
}
@Test
@@ -141,5 +161,47 @@ public class InMemoryCacheStatisticsTest
assertEquals(5, cacheStats.count("cache1", OpType.GET_HIT));
assertEquals(1, cacheStats.count("cache1", OpType.GET_MISS));
assertEquals(0.83, cacheStats.hitMissRatio("cache1"), 0.01d);
// Check hit+miss count
assertEquals(6, cacheStats.numGets("cache1"));
// Stats snapshot map
Map<OpType, OperationStats> snapshot = cacheStats.allStats("cache1");
assertEquals(5, snapshot.get(OpType.GET_HIT).getCount());
assertEquals(1, snapshot.get(OpType.GET_MISS).getCount());
}
@Test
public void canRetrieveSnapshotOfAllStats()
{
TransactionStats txStats = new TransactionStats();
txStats.record(0, 1000, OpType.GET_HIT);
// Add first statistical datapoint.
cacheStats.add("cache1", txStats);
// Cache stats should be visible
Map<OpType, OperationStats> snapshot1 = cacheStats.allStats("cache1");
assertEquals(1, snapshot1.get(OpType.GET_HIT).getCount());
assertEquals(1000, snapshot1.get(OpType.GET_HIT).getTotalTime(), 0.0d);
// Map is fully populated
assertEquals(0, snapshot1.get(OpType.CLEAR).getCount());
assertEquals(0, snapshot1.get(OpType.PUT).getCount());
assertEquals(0, snapshot1.get(OpType.REMOVE).getCount());
assertEquals(0, snapshot1.get(OpType.GET_MISS).getCount());
// Record further data
txStats = new TransactionStats();
txStats.record(0, 2000, OpType.GET_HIT);
cacheStats.add("cache1", txStats);
// Check new snapshot reflects update
Map<OpType, OperationStats> snapshot2 = cacheStats.allStats("cache1");
assertEquals(2, snapshot2.get(OpType.GET_HIT).getCount());
assertEquals(3000, snapshot2.get(OpType.GET_HIT).getTotalTime(), 0.0d);
// Check old snapshot is not affected
assertEquals(1, snapshot1.get(OpType.GET_HIT).getCount());
assertEquals(1000, snapshot1.get(OpType.GET_HIT).getTotalTime(), 0.0d);
}
}