use of com.yahoo.elide.datastores.aggregation.query.QueryResult in project elide by yahoo.
the class AggregationDataStoreTransactionTest method loadObjectsBypassCache.
@Test
public void loadObjectsBypassCache() {
Mockito.reset(queryLogger);
query = Query.builder().source(playerStatsTable).bypassingCache(true).build();
NativeQuery myQuery = NativeQuery.builder().fromClause(playerStatsTable.getName()).projectionClause(" ").build();
QueryResult queryResult = QueryResult.builder().data(DATA).build();
when(queryEngine.executeQuery(query, qeTransaction)).thenReturn(queryResult);
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()).getTableVersion(any(), any());
Mockito.verifyNoInteractions(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(false));
Mockito.verify(queryLogger, times(1)).completeQuery(Mockito.eq(scope.getRequestId()), any());
}
use of com.yahoo.elide.datastores.aggregation.query.QueryResult in project elide by yahoo.
the class AggregationDataStoreTransactionTest method loadObjectsNoTableVersion.
@Test
public void loadObjectsNoTableVersion() {
Mockito.reset(queryLogger);
NativeQuery myQuery = NativeQuery.builder().fromClause(playerStatsTable.getName()).projectionClause(" ").build();
QueryResult queryResult = QueryResult.builder().data(DATA).build();
when(queryEngine.executeQuery(query, qeTransaction)).thenReturn(queryResult);
when(queryEngine.explain(query)).thenReturn(Arrays.asList(myQuery.toString()));
AggregationDataStoreTransaction transaction = new MyAggregationDataStoreTransaction(queryEngine, cache, queryLogger);
EntityProjection entityProjection = EntityProjection.builder().type(PlayerStats.class).build();
transaction.loadObjects(entityProjection, scope);
String cacheKey = ";" + queryKey;
Mockito.verify(cache).get(cacheKey);
Mockito.verify(cache).put(cacheKey, queryResult);
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(false));
Mockito.verify(queryLogger, times(1)).completeQuery(Mockito.eq(scope.getRequestId()), any());
}
use of com.yahoo.elide.datastores.aggregation.query.QueryResult in project elide by yahoo.
the class RedisCacheTest method testPutResults.
@Test
public void testPutResults() {
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));
assertEquals("xyzzy", cache.get(key).getData().iterator().next());
}
use of com.yahoo.elide.datastores.aggregation.query.QueryResult in project elide by yahoo.
the class RedisCacheTest method testPutResultsFail.
// Redis server does not exist.
@Test
public void testPutResultsFail() throws IOException {
destroy();
String key = "example_PlayerStats;{highScore;{}}{}{};;;;";
Iterable<Object> data = Collections.singletonList("xyzzy");
QueryResult queryResult = QueryResult.builder().data(data).build();
assertThrows(JedisConnectionException.class, () -> cache.put(key, queryResult));
}
use of com.yahoo.elide.datastores.aggregation.query.QueryResult in project elide by yahoo.
the class QueryEngineTest method testPagination.
/**
* Test pagination.
*
* @throws Exception exception
*/
@Test
public void testPagination() throws Exception {
Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("lowScore")).dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate")).pagination(new ImmutablePagination(0, 1, false, true)).build();
QueryResult result = engine.executeQuery(query, transaction);
List<Object> data = toList(result.getData());
// Jon Doe,1234,72,Good,840,2019-07-12 00:00:00
PlayerStats stats1 = new PlayerStats();
stats1.setId("0");
stats1.setLowScore(35);
stats1.setOverallRating("Good");
stats1.setRecordedDate(new Day(Date.valueOf("2019-07-12")));
assertEquals(ImmutableList.of(stats1), data, "Returned record does not match");
assertEquals(3, result.getPageTotals(), "Page totals does not match");
}
Aggregations