use of com.yahoo.elide.async.models.AsyncQuery in project elide by yahoo.
the class JSONAPIAsyncQueryOperationTest method testProcessQueryNonSuccessResponse.
@Test
public void testProcessQueryNonSuccessResponse() throws URISyntaxException {
AsyncQuery queryObj = new AsyncQuery();
String responseBody = "ResponseBody";
ElideResponse response = new ElideResponse(201, responseBody);
String query = "/group?sort=commonName&fields%5Bgroup%5D=commonName,description";
String id = "edc4a871-dff2-4054-804e-d80075cf827d";
queryObj.setId(id);
queryObj.setQuery(query);
queryObj.setQueryType(QueryType.JSONAPI_V1_0);
when(elide.get(any(), any(), any(), any(), any(), any(), any())).thenReturn(response);
JSONAPIAsyncQueryOperation jsonOperation = new JSONAPIAsyncQueryOperation(asyncExecutorService, queryObj, requestScope);
AsyncQueryResult queryResultObj = (AsyncQueryResult) jsonOperation.call();
assertEquals(responseBody, queryResultObj.getResponseBody());
assertEquals(201, queryResultObj.getHttpStatus());
assertNull(queryResultObj.getRecordCount());
}
use of com.yahoo.elide.async.models.AsyncQuery in project elide by yahoo.
the class JSONAPIAsyncQueryOperationTest method testProcessQueryJsonApi.
@Test
public void testProcessQueryJsonApi() throws URISyntaxException {
AsyncQuery queryObj = new AsyncQuery();
String responseBody = "{\"data\":" + "[{\"type\":\"book\",\"id\":\"3\",\"attributes\":{\"title\":\"For Whom the Bell Tolls\"}}" + ",{\"type\":\"book\",\"id\":\"2\",\"attributes\":{\"title\":\"Song of Ice and Fire\"}}," + "{\"type\":\"book\",\"id\":\"1\",\"attributes\":{\"title\":\"Ender's Game\"}}]}";
ElideResponse response = new ElideResponse(200, responseBody);
String query = "/group?sort=commonName&fields%5Bgroup%5D=commonName,description";
String id = "edc4a871-dff2-4054-804e-d80075cf827d";
queryObj.setId(id);
queryObj.setQuery(query);
queryObj.setQueryType(QueryType.JSONAPI_V1_0);
when(elide.get(any(), any(), any(), any(), any(), any(), any())).thenReturn(response);
JSONAPIAsyncQueryOperation jsonOperation = new JSONAPIAsyncQueryOperation(asyncExecutorService, queryObj, requestScope);
AsyncQueryResult queryResultObj = (AsyncQueryResult) jsonOperation.call();
assertEquals(responseBody, queryResultObj.getResponseBody());
assertEquals(200, queryResultObj.getHttpStatus());
assertEquals(3, queryResultObj.getRecordCount());
}
use of com.yahoo.elide.async.models.AsyncQuery in project elide by yahoo.
the class AsyncAPICancelRunnableTest method testTimeBasedCancellation.
@Test
public void testTimeBasedCancellation() {
DataStoreTransaction dtx = elide.getDataStore().beginTransaction();
transactionRegistry.addRunningTransaction(UUID.fromString("edc4a871-dff2-4054-804e-d80075cf828d"), dtx);
transactionRegistry.addRunningTransaction(UUID.fromString("edc4a871-dff2-4054-804e-d80075cf827d"), dtx);
AsyncQuery asyncQuery1 = createAsyncQueryTestObject("edc4a871-dff2-4054-804e-d80075cf828d", System.currentTimeMillis(), QueryStatus.QUEUED);
AsyncQuery asyncQuery2 = createAsyncQueryTestObject("edc4a871-dff2-4054-804e-d80075cf827d", 1577883600000L, QueryStatus.QUEUED);
AsyncQuery asyncQuery3 = createAsyncQueryTestObject("edc4a871-dff2-4054-804e-d80075cf826d", 1577883600000L, QueryStatus.QUEUED);
Collection<AsyncAPI> asyncCollection = new ArrayList<>();
asyncCollection.add(asyncQuery1);
asyncCollection.add(asyncQuery2);
asyncCollection.add(asyncQuery3);
when(cancelThread.getAsyncAPIDao().loadAsyncAPIByFilter(any(), any())).thenReturn(asyncCollection);
cancelThread.cancelAsyncAPI(AsyncQuery.class);
ArgumentCaptor<FilterExpression> filterCaptor = ArgumentCaptor.forClass(FilterExpression.class);
ArgumentCaptor<QueryStatus> statusCaptor = ArgumentCaptor.forClass(QueryStatus.class);
verify(asyncAPIDao, times(1)).updateStatusAsyncAPIByFilter(filterCaptor.capture(), statusCaptor.capture(), any());
assertEquals("asyncQuery.id IN [[edc4a871-dff2-4054-804e-d80075cf827d]]", filterCaptor.getValue().toString());
assertEquals("CANCEL_COMPLETE", statusCaptor.getValue().toString());
}
use of com.yahoo.elide.async.models.AsyncQuery in project elide by yahoo.
the class AsyncAPICancelRunnableTest method testActiveTransactionCancellation.
@Test
public void testActiveTransactionCancellation() {
DataStoreTransaction dtx = elide.getDataStore().beginTransaction();
transactionRegistry.addRunningTransaction(UUID.fromString("edc4a871-dff2-4054-804e-d80075cf828d"), dtx);
AsyncQuery asyncQuery1 = createAsyncQueryTestObject("edc4a871-dff2-4054-804e-d80075cf828d", 1577883600000L, QueryStatus.QUEUED);
AsyncQuery asyncQuery2 = createAsyncQueryTestObject("edc4a871-dff2-4054-804e-d80075cf827d", 1577883600000L, QueryStatus.QUEUED);
Collection<AsyncAPI> asyncCollection = new ArrayList<>();
asyncCollection.add(asyncQuery1);
asyncCollection.add(asyncQuery2);
when(cancelThread.getAsyncAPIDao().loadAsyncAPIByFilter(any(), any())).thenReturn(asyncCollection);
cancelThread.cancelAsyncAPI(AsyncQuery.class);
ArgumentCaptor<FilterExpression> filterCaptor = ArgumentCaptor.forClass(FilterExpression.class);
ArgumentCaptor<QueryStatus> statusCaptor = ArgumentCaptor.forClass(QueryStatus.class);
verify(asyncAPIDao, times(1)).loadAsyncAPIByFilter(any(), any());
verify(asyncAPIDao, times(1)).updateStatusAsyncAPIByFilter(filterCaptor.capture(), statusCaptor.capture(), any());
assertEquals("asyncQuery.id IN [[edc4a871-dff2-4054-804e-d80075cf828d]]", filterCaptor.getValue().toString());
assertEquals("CANCEL_COMPLETE", statusCaptor.getValue().toString());
}
use of com.yahoo.elide.async.models.AsyncQuery in project elide by yahoo.
the class AsyncAPICancelRunnableTest method testStatusBasedFilter.
@Test
public void testStatusBasedFilter() {
DataStoreTransaction dtx = elide.getDataStore().beginTransaction();
transactionRegistry.addRunningTransaction(UUID.fromString("edc4a871-dff2-4054-804e-d80075cf828d"), dtx);
transactionRegistry.addRunningTransaction(UUID.fromString("edc4a871-dff2-4054-804e-d80075cf827d"), dtx);
transactionRegistry.addRunningTransaction(UUID.fromString("edc4a871-dff2-4054-804e-d80075cf826d"), dtx);
AsyncQuery asyncQuery1 = createAsyncQueryTestObject("edc4a871-dff2-4054-804e-d80075cf828d", 1577883600000L, QueryStatus.CANCEL_COMPLETE);
AsyncQuery asyncQuery2 = createAsyncQueryTestObject("edc4a871-dff2-4054-804e-d80075cf827d", 1577883600000L, QueryStatus.CANCELLED);
AsyncQuery asyncQuery3 = createAsyncQueryTestObject("edc4a871-dff2-4054-804e-d80075cf826d", 1577883600000L, QueryStatus.PROCESSING);
Collection<AsyncAPI> asyncCollection = new ArrayList<>();
asyncCollection.add(asyncQuery1);
asyncCollection.add(asyncQuery2);
asyncCollection.add(asyncQuery3);
when(cancelThread.getAsyncAPIDao().loadAsyncAPIByFilter(any(), any())).thenReturn(asyncCollection);
cancelThread.cancelAsyncAPI(AsyncQuery.class);
ArgumentCaptor<FilterExpression> fltStatusCaptor = ArgumentCaptor.forClass(FilterExpression.class);
verify(asyncAPIDao, times(1)).loadAsyncAPIByFilter(fltStatusCaptor.capture(), any());
assertEquals("asyncQuery.status IN [CANCELLED, PROCESSING, QUEUED]", fltStatusCaptor.getValue().toString());
verify(asyncAPIDao, times(1)).updateStatusAsyncAPIByFilter(any(), any(), any());
}
Aggregations