Search in sources :

Example 1 with CacheKey

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()))));
}
Also used : DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) CacheKey(org.pentaho.di.trans.dataservice.optimization.cache.CachedService.CacheKey) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 SQL (org.pentaho.di.core.sql.SQL)1 DataServiceExecutor (org.pentaho.di.trans.dataservice.DataServiceExecutor)1 CacheKey (org.pentaho.di.trans.dataservice.optimization.cache.CachedService.CacheKey)1