public void testTxnCacheGet() throws Exception {
Long txnId = new Long(123456);
int baseFragmentId = 1111;
int partitionId = 1;
long baseValue = 9900;
ParameterSet params = new ParameterSet("Squirrels", 1981);
Map<Integer, Long> expectedValues = new HashMap<Integer, Long>();
for (int i = 0; i < 5; i++) {
int fragmentId = baseFragmentId + i;
long expected = baseValue + i;
VoltTable result = new VoltTable(TARGET_RESULT);
result.addRow(expected);
expectedValues.put(fragmentId, expected);
// First store it in the cache
this.cache.addResult(txnId, fragmentId, partitionId, params, result);
} // FOR
// System.err.println(StringUtil.formatMaps(expectedValues));
// System.err.println("---------------");
// System.err.println(this.cache.toString());
// Then ask for them back in a shuffled order
List<Integer> fragmentIds = new ArrayList<Integer>(expectedValues.keySet());
Collections.shuffle(fragmentIds);
for (Integer fragmentId : fragmentIds) {
long expected = expectedValues.get(fragmentId);
VoltTable cacheResult = this.cache.getResult(txnId, fragmentId, partitionId, params);
assertNotNull(fragmentId.toString(), cacheResult);
assertEquals(1, cacheResult.getRowCount());
assertEquals(expected, cacheResult.asScalarLong());
} // FOR
// If we change the params, we should never get back our results
params = new ParameterSet("WuTang!", 1981);
for (Integer fragmentId : fragmentIds) {
VoltTable cacheResult = this.cache.getResult(txnId, fragmentId, partitionId, params);
assertNull(fragmentId.toString(), cacheResult);
} // FOR
// Now create a new ParameteSet with the same values and make
// sure get back the same results.
params = new ParameterSet("Squi" + "rrels", 1981);
for (Integer fragmentId : fragmentIds) {
long expected = expectedValues.get(fragmentId);
VoltTable cacheResult = this.cache.getResult(txnId, fragmentId, partitionId, params);
assertNotNull(fragmentId.toString(), cacheResult);
assertEquals(1, cacheResult.getRowCount());