Search in sources :

Example 1 with Cancelable

use of com.apollographql.apollo.internal.util.Cancelable in project aws-mobile-appsync-sdk-android by awslabs.

the class QueryInstrumentationTest method testBaseSyncQuery.

@Test
public void testBaseSyncQuery() {
    AWSAppSyncClient awsAppSyncClient = AWSAppSyncClients.withIAMFromAWSConfiguration();
    // Perform a base query and await success.
    LatchedGraphQLCallback<Operation.Data> baseQueryCallback = LatchedGraphQLCallback.instance();
    Cancelable syncCancelable = awsAppSyncClient.sync(AllPostsQuery.builder().build(), baseQueryCallback, 0);
    assertFalse(syncCancelable.isCanceled());
    baseQueryCallback.awaitResponse();
    // Cancel the query. TODO: it just completed with success, so this probably does nothing.
    syncCancelable.cancel();
    assertTrue(syncCancelable.isCanceled());
    // Canceling twice should land things in the same place.
    syncCancelable.cancel();
    assertTrue(syncCancelable.isCanceled());
}
Also used : AWSAppSyncClient(com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient) Cancelable(com.apollographql.apollo.internal.util.Cancelable) Test(org.junit.Test)

Example 2 with Cancelable

use of com.apollographql.apollo.internal.util.Cancelable in project aws-mobile-appsync-sdk-android by awslabs.

the class QueryInstrumentationTest method testBaseAndDeltaSyncQuery.

@Test
public void testBaseAndDeltaSyncQuery() {
    AWSAppSyncClient awsAppSyncClient = AWSAppSyncClients.withIAMFromAWSConfiguration();
    AllPostsQuery baseQuery = AllPostsQuery.builder().build();
    LatchedGraphQLCallback<Operation.Data> baseQueryCallback = LatchedGraphQLCallback.instance();
    AllPostsQuery deltaQuery = AllPostsQuery.builder().build();
    LatchedGraphQLCallback<Operation.Data> deltaQueryCallback = LatchedGraphQLCallback.instance();
    // First, a base sync happens
    Cancelable cancelable = awsAppSyncClient.sync(baseQuery, baseQueryCallback, deltaQuery, deltaQueryCallback, TimeUnit.HOURS.toSeconds(1));
    assertFalse(cancelable.isCanceled());
    baseQueryCallback.awaitSuccessfulResponse();
    // Next, a delta sync, since the refresh interval isn't over.
    // deltaQueryCallback.awaitResponse(); This does not appear to be working.
    cancelable.cancel();
    assertTrue(cancelable.isCanceled());
    // This should be a No op. Test to make sure that there are no unintended side effects
    cancelable.cancel();
    assertTrue(cancelable.isCanceled());
}
Also used : AWSAppSyncClient(com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient) AllPostsQuery(com.amazonaws.mobileconnectors.appsync.demo.AllPostsQuery) Cancelable(com.apollographql.apollo.internal.util.Cancelable) Test(org.junit.Test)

Example 3 with Cancelable

use of com.apollographql.apollo.internal.util.Cancelable in project aws-mobile-appsync-sdk-android by awslabs.

the class MultiClientInstrumentationTest method testSyncOnlyBaseQuery.

@Test
public void testSyncOnlyBaseQuery() {
    List<AWSAppSyncClient> clients = Arrays.asList(AWSAppSyncClients.withAPIKEYFromAWSConfiguration(), AWSAppSyncClients.withIAMFromAWSConfiguration(), AWSAppSyncClients.withUserPoolsFromAWSConfiguration());
    for (AWSAppSyncClient client : clients) {
        Query<AllPostsQuery.Data, AllPostsQuery.Data, Variables> baseQuery = AllPostsQuery.builder().build();
        LatchedGraphQLCallback<Query.Data> baseQueryCallback = LatchedGraphQLCallback.instance();
        Cancelable handle = client.sync(baseQuery, baseQueryCallback, 0);
        assertFalse(handle.isCanceled());
        baseQueryCallback.awaitSuccessfulResponse();
        handle.cancel();
        assertTrue(handle.isCanceled());
        // This should be a No-op. Test to make sure.
        handle.cancel();
        assertTrue(handle.isCanceled());
    }
}
Also used : Variables(com.apollographql.apollo.api.Operation.Variables) AWSAppSyncClient(com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient) Cancelable(com.apollographql.apollo.internal.util.Cancelable) Test(org.junit.Test)

Aggregations

AWSAppSyncClient (com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient)3 Cancelable (com.apollographql.apollo.internal.util.Cancelable)3 Test (org.junit.Test)3 AllPostsQuery (com.amazonaws.mobileconnectors.appsync.demo.AllPostsQuery)1 Variables (com.apollographql.apollo.api.Operation.Variables)1