Search in sources :

Example 11 with QueryResult

use of com.yahoo.elide.datastores.aggregation.query.QueryResult in project elide by yahoo.

the class AggregationDataStoreTransactionTest method loadObjectsUsesCache.

@Test
public void loadObjectsUsesCache() {
    Mockito.reset(queryLogger);
    String cacheKey = "foo;" + queryKey;
    QueryResult queryResult = QueryResult.builder().data(DATA).build();
    NativeQuery myQuery = NativeQuery.builder().fromClause(playerStatsTable.getName()).projectionClause(" ").build();
    when(cache.get(cacheKey)).thenReturn(queryResult);
    when(queryEngine.getTableVersion(playerStatsTable, qeTransaction)).thenReturn("foo");
    when(queryEngine.explain(query)).thenReturn(Arrays.asList(myQuery.toString()));
    AggregationDataStoreTransaction transaction = new MyAggregationDataStoreTransaction(queryEngine, cache, queryLogger);
    EntityProjection entityProjection = EntityProjection.builder().type(PlayerStats.class).build();
    assertEquals(DATA, Lists.newArrayList(transaction.loadObjects(entityProjection, scope)));
    Mockito.verify(queryEngine, never()).executeQuery(any(), any());
    Mockito.verify(cache).get(cacheKey);
    Mockito.verifyNoMoreInteractions(cache);
    Mockito.verify(queryLogger, times(1)).acceptQuery(Mockito.eq(scope.getRequestId()), any(), any(), any(), any(), any());
    Mockito.verify(queryLogger, times(1)).processQuery(Mockito.eq(scope.getRequestId()), any(), any(), Mockito.eq(true));
    Mockito.verify(queryLogger, times(1)).completeQuery(Mockito.eq(scope.getRequestId()), any());
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) QueryResult(com.yahoo.elide.datastores.aggregation.query.QueryResult) NativeQuery(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.NativeQuery) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PlayerStats(example.PlayerStats) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 12 with QueryResult

use of com.yahoo.elide.datastores.aggregation.query.QueryResult in project elide by yahoo.

the class RedisCacheTest method testGetResultsMulti.

@Test
public void testGetResultsMulti() {
    String key = "example_PlayerStats;{highScore;{}}{}{};;;;";
    Iterable<Object> data = Collections.singletonList("xyzzy");
    QueryResult queryResult = QueryResult.builder().data(data).build();
    cache.put(key, queryResult);
    // retrive results and verify they match original.
    assertEquals(queryResult, cache.get(key));
    // retrive results again and verify they match original.
    assertEquals(queryResult, cache.get(key));
    String key1 = "example_PlayerStats1;{highScore;{}}{}{};;;;";
    Iterable<Object> data1 = Collections.singletonList("xyzz");
    QueryResult queryResult1 = QueryResult.builder().data(data).build();
    cache.put(key1, queryResult1);
    // retrive results and verify they match original.
    assertEquals(queryResult1, cache.get(key1));
}
Also used : QueryResult(com.yahoo.elide.datastores.aggregation.query.QueryResult) Test(org.junit.jupiter.api.Test)

Aggregations

QueryResult (com.yahoo.elide.datastores.aggregation.query.QueryResult)12 Test (org.junit.jupiter.api.Test)10 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)7 EntityProjection (com.yahoo.elide.core.request.EntityProjection)6 NativeQuery (com.yahoo.elide.datastores.aggregation.queryengines.sql.query.NativeQuery)6 PlayerStats (example.PlayerStats)6 Query (com.yahoo.elide.datastores.aggregation.query.Query)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Pagination (com.yahoo.elide.core.request.Pagination)2 ImmutablePagination (com.yahoo.elide.datastores.aggregation.query.ImmutablePagination)2 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 RequestScope (com.yahoo.elide.core.RequestScope)1 DataStoreIterable (com.yahoo.elide.core.datastore.DataStoreIterable)1 DataStoreIterableBuilder (com.yahoo.elide.core.datastore.DataStoreIterableBuilder)1 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 BadRequestException (com.yahoo.elide.core.exceptions.BadRequestException)1 HttpStatus (com.yahoo.elide.core.exceptions.HttpStatus)1 HttpStatusException (com.yahoo.elide.core.exceptions.HttpStatusException)1