Search in sources :

Example 1 with AsyncQuery

use of com.yahoo.elide.async.models.AsyncQuery in project elide by yahoo.

the class AsyncExecutorServiceTest method testExecuteQueryComplete.

// Test for executor hook execution
@Test
public void testExecuteQueryComplete() {
    AsyncQuery queryObj = mock(AsyncQuery.class);
    String query = "/group?sort=commonName&fields%5Bgroup%5D=commonName,description";
    String id = "edc4a871-dff2-4054-804e-d80075cf827d";
    when(queryObj.getQuery()).thenReturn(query);
    when(queryObj.getId()).thenReturn(id);
    when(queryObj.getRequestId()).thenReturn(id);
    when(queryObj.getQueryType()).thenReturn(QueryType.JSONAPI_V1_0);
    when(queryObj.getAsyncAfterSeconds()).thenReturn(10);
    when(scope.getApiVersion()).thenReturn(NO_VERSION);
    when(scope.getUser()).thenReturn(testUser);
    JSONAPIAsyncQueryOperation jsonOperation = new JSONAPIAsyncQueryOperation(service, queryObj, scope);
    service.executeQuery(queryObj, jsonOperation);
    verify(queryObj, times(1)).setStatus(QueryStatus.PROCESSING);
    verify(queryObj, times(1)).setStatus(QueryStatus.COMPLETE);
}
Also used : AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) JSONAPIAsyncQueryOperation(com.yahoo.elide.async.operation.JSONAPIAsyncQueryOperation) Test(org.junit.jupiter.api.Test)

Example 2 with AsyncQuery

use of com.yahoo.elide.async.models.AsyncQuery in project elide by yahoo.

the class AsyncExecutorServiceTest method testExecuteQueryFail.

// Test for executor hook execution
@Test
public void testExecuteQueryFail() throws Exception {
    AsyncQuery queryObj = mock(AsyncQuery.class);
    when(queryObj.getAsyncAfterSeconds()).thenReturn(10);
    Callable<AsyncAPIResult> mockCallable = mock(Callable.class);
    when(mockCallable.call()).thenThrow(new NoHttpResponseException(""));
    service.executeQuery(queryObj, mockCallable);
    verify(queryObj, times(1)).setStatus(QueryStatus.PROCESSING);
    verify(queryObj, times(1)).setStatus(QueryStatus.FAILURE);
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) AsyncAPIResult(com.yahoo.elide.async.models.AsyncAPIResult) Test(org.junit.jupiter.api.Test)

Example 3 with AsyncQuery

use of com.yahoo.elide.async.models.AsyncQuery in project elide by yahoo.

the class DefaultAsyncAPIDAOTest method setupMocks.

@BeforeEach
public void setupMocks() {
    dataStore = mock(DataStore.class);
    asyncQuery = mock(AsyncQuery.class);
    asyncQueryResult = mock(AsyncQueryResult.class);
    filter = mock(FilterExpression.class);
    tx = mock(DataStoreTransaction.class);
    Map<String, Class<? extends Check>> checkMappings = new HashMap<>();
    EntityDictionary dictionary = EntityDictionary.builder().checks(checkMappings).build();
    dictionary.bindEntity(AsyncQuery.class);
    dictionary.bindEntity(AsyncQueryResult.class);
    ElideSettings elideSettings = new ElideSettingsBuilder(dataStore).withEntityDictionary(dictionary).withJoinFilterDialect(RSQLFilterDialect.builder().dictionary(dictionary).build()).withSubqueryFilterDialect(RSQLFilterDialect.builder().dictionary(dictionary).build()).withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")).build();
    elide = new Elide(elideSettings);
    when(dataStore.beginTransaction()).thenReturn(tx);
    asyncAPIDAO = new DefaultAsyncAPIDAO(elide.getElideSettings(), dataStore);
}
Also used : HashMap(java.util.HashMap) Check(com.yahoo.elide.core.security.checks.Check) AsyncQueryResult(com.yahoo.elide.async.models.AsyncQueryResult) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) DataStore(com.yahoo.elide.core.datastore.DataStore) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) ElideSettings(com.yahoo.elide.ElideSettings) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Elide(com.yahoo.elide.Elide) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with AsyncQuery

use of com.yahoo.elide.async.models.AsyncQuery in project elide by yahoo.

the class AsyncAPICancelRunnableTest method createAsyncQueryTestObject.

public AsyncQuery createAsyncQueryTestObject(String id, Long createdOn, QueryStatus status) {
    AsyncQuery asyncQuery = new AsyncQuery();
    asyncQuery.setId(id);
    asyncQuery.setRequestId(id);
    asyncQuery.setCreatedOn(new Date(createdOn));
    asyncQuery.setStatus(status);
    return asyncQuery;
}
Also used : AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) Date(java.util.Date)

Example 5 with AsyncQuery

use of com.yahoo.elide.async.models.AsyncQuery in project elide by yahoo.

the class GraphQLAsyncQueryOperationTest method testProcessQueryGraphQlRunnerException.

@Test
public void testProcessQueryGraphQlRunnerException() {
    AsyncQuery queryObj = new AsyncQuery();
    String query = "{\"query\":\"{ group { edges { node { name commonName description } } } }\",\"variables\":null}";
    String id = "edc4a871-dff2-4054-804e-d80075cf827d";
    queryObj.setId(id);
    queryObj.setQuery(query);
    queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
    when(runner.run(any(), any(), any(), any())).thenThrow(RuntimeException.class);
    GraphQLAsyncQueryOperation graphQLOperation = new GraphQLAsyncQueryOperation(asyncExecutorService, queryObj, requestScope);
    assertThrows(RuntimeException.class, () -> graphQLOperation.call());
}
Also used : AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) 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