Search in sources :

Example 6 with AsyncQuery

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());
}
Also used : ElideResponse(com.yahoo.elide.ElideResponse) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) AsyncQueryResult(com.yahoo.elide.async.models.AsyncQueryResult) Test(org.junit.jupiter.api.Test)

Example 7 with AsyncQuery

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());
}
Also used : ElideResponse(com.yahoo.elide.ElideResponse) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) AsyncQueryResult(com.yahoo.elide.async.models.AsyncQueryResult) Test(org.junit.jupiter.api.Test)

Example 8 with AsyncQuery

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());
}
Also used : AsyncAPI(com.yahoo.elide.async.models.AsyncAPI) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) ArrayList(java.util.ArrayList) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) QueryStatus(com.yahoo.elide.async.models.QueryStatus) Test(org.junit.jupiter.api.Test)

Example 9 with AsyncQuery

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());
}
Also used : AsyncAPI(com.yahoo.elide.async.models.AsyncAPI) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) ArrayList(java.util.ArrayList) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) QueryStatus(com.yahoo.elide.async.models.QueryStatus) Test(org.junit.jupiter.api.Test)

Example 10 with AsyncQuery

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());
}
Also used : AsyncAPI(com.yahoo.elide.async.models.AsyncAPI) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) ArrayList(java.util.ArrayList) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Aggregations

AsyncQuery (com.yahoo.elide.async.models.AsyncQuery)13 Test (org.junit.jupiter.api.Test)11 AsyncQueryResult (com.yahoo.elide.async.models.AsyncQueryResult)5 ElideResponse (com.yahoo.elide.ElideResponse)4 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)4 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)4 AsyncAPI (com.yahoo.elide.async.models.AsyncAPI)3 ArrayList (java.util.ArrayList)3 QueryStatus (com.yahoo.elide.async.models.QueryStatus)2 Elide (com.yahoo.elide.Elide)1 ElideSettings (com.yahoo.elide.ElideSettings)1 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)1 AsyncAPIResult (com.yahoo.elide.async.models.AsyncAPIResult)1 JSONAPIAsyncQueryOperation (com.yahoo.elide.async.operation.JSONAPIAsyncQueryOperation)1 DataStore (com.yahoo.elide.core.datastore.DataStore)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 Check (com.yahoo.elide.core.security.checks.Check)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 NoHttpResponseException (org.apache.http.NoHttpResponseException)1