use of org.pentaho.di.trans.dataservice.optimization.cache.CachedService.CacheKey in project pdi-dataservice-server-plugin by pentaho.
the class CachedServiceTest method testCreateCacheKey.
@Test
public void testCreateCacheKey() throws Exception {
CacheKey unbounded, withCondition, withConditionOrdered, withLimit, otherVersion;
unbounded = cacheKey(BASE_QUERY);
withCondition = cacheKey(BASE_QUERY + " WHERE A = 42");
withConditionOrdered = cacheKey(BASE_QUERY + " WHERE A=42 ORDER BY B");
withLimit = cacheKey(BASE_QUERY + " LIMIT 20");
when(transMeta.getCacheVersion()).thenReturn(2);
otherVersion = cacheKey(BASE_QUERY);
// Verifies order from most specific to general
assertThat(withConditionOrdered.all(), contains(withConditionOrdered, withCondition, unbounded));
assertThat(withLimit, equalTo(unbounded));
for (CacheKey cacheKey : ImmutableList.of(withCondition, withConditionOrdered, otherVersion)) {
assertThat(cacheKey, not(equalTo(unbounded)));
}
assertThat(withCondition.withoutCondition(), equalTo(unbounded));
assertThat(withConditionOrdered.withoutOrder(), equalTo(withCondition));
// Verify that execution parameters will change the key
SQL sql = new SQL(BASE_QUERY);
sql.parse(rowMeta);
assertThat(CacheKey.create(new DataServiceExecutor.Builder(sql, dataServiceMeta, context).prepareExecution(false).parameters(ImmutableMap.of("foo", "bar")).serviceTrans(serviceTrans).build()), not(equalTo(CacheKey.create(new DataServiceExecutor.Builder(sql, dataServiceMeta, context).prepareExecution(false).serviceTrans(serviceTrans).build()))));
}
Aggregations