Search in sources :

Example 1 with InMemoryDataStore

use of com.yahoo.elide.core.datastore.inmemory.InMemoryDataStore in project elide by yahoo.

the class ElideCustomSerdeRegistrationTest method testRegisterCustomSerde.

@Test
public void testRegisterCustomSerde() {
    // Create a fake Elide.  Don't actually bind any entities.
    HashMapDataStore wrapped = new HashMapDataStore(DefaultClassScanner.getInstance(), String.class.getPackage());
    InMemoryDataStore store = new InMemoryDataStore(wrapped);
    ElideSettings elideSettings = new ElideSettingsBuilder(store).withEntityDictionary(EntityDictionary.builder().build()).build();
    Elide elide = new Elide(elideSettings);
    elide.doScans();
    assertNotNull(CoerceUtil.lookup(Dummy.class));
    assertNotNull(CoerceUtil.lookup(DummyTwo.class));
    assertNotNull(CoerceUtil.lookup(DummyThree.class));
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) ElideSettings(com.yahoo.elide.ElideSettings) Elide(com.yahoo.elide.Elide) InMemoryDataStore(com.yahoo.elide.core.datastore.inmemory.InMemoryDataStore) Test(org.junit.jupiter.api.Test)

Example 2 with InMemoryDataStore

use of com.yahoo.elide.core.datastore.inmemory.InMemoryDataStore in project elide by yahoo.

the class SubscriptionDataFetcherTest method runSubscription.

/**
 * Run a subscription.
 * @param request The subscription query.
 * @return A discrete list of results returned from the subscription.
 */
protected List<ExecutionResult> runSubscription(String request) {
    InMemoryDataStore inMemoryDataStore = new InMemoryDataStore(dataStore);
    DataStoreTransaction tx = inMemoryDataStore.beginTransaction();
    GraphQLProjectionInfo projectionInfo = new SubscriptionEntityProjectionMaker(settings, new HashMap<>(), NO_VERSION).make(request);
    GraphQLRequestScope requestScope = new GraphQLRequestScope(baseUrl, tx, null, NO_VERSION, settings, projectionInfo, UUID.randomUUID(), null);
    ExecutionInput executionInput = ExecutionInput.newExecutionInput().query(request).localContext(requestScope).build();
    ExecutionResult executionResult = api.execute(executionInput);
    if (!(executionResult.getData() instanceof Publisher)) {
        return List.of(executionResult);
    }
    Publisher<ExecutionResult> resultPublisher = executionResult.getData();
    requestScope.getTransaction().commit(requestScope);
    if (resultPublisher == null) {
        return List.of(executionResult);
    }
    List<ExecutionResult> results = new ArrayList<>();
    AtomicReference<Subscription> subscriptionRef = new AtomicReference<>();
    AtomicReference<Throwable> errorRef = new AtomicReference<>();
    resultPublisher.subscribe(new Subscriber<ExecutionResult>() {

        @Override
        public void onSubscribe(Subscription subscription) {
            subscriptionRef.set(subscription);
            subscription.request(1);
        }

        @Override
        public void onNext(ExecutionResult executionResult) {
            results.add(executionResult);
            subscriptionRef.get().request(1);
        }

        @Override
        public void onError(Throwable t) {
            errorRef.set(t);
        }

        @Override
        public void onComplete() {
        // NOOP
        }
    });
    return results;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GraphQLProjectionInfo(com.yahoo.elide.graphql.parser.GraphQLProjectionInfo) GraphQLRequestScope(com.yahoo.elide.graphql.GraphQLRequestScope) ExecutionResult(graphql.ExecutionResult) AtomicReference(java.util.concurrent.atomic.AtomicReference) Publisher(org.reactivestreams.Publisher) InMemoryDataStore(com.yahoo.elide.core.datastore.inmemory.InMemoryDataStore) SubscriptionEntityProjectionMaker(com.yahoo.elide.graphql.parser.SubscriptionEntityProjectionMaker) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) ExecutionInput(graphql.ExecutionInput) Subscription(org.reactivestreams.Subscription)

Aggregations

InMemoryDataStore (com.yahoo.elide.core.datastore.inmemory.InMemoryDataStore)2 Elide (com.yahoo.elide.Elide)1 ElideSettings (com.yahoo.elide.ElideSettings)1 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)1 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)1 HashMapDataStore (com.yahoo.elide.core.datastore.inmemory.HashMapDataStore)1 GraphQLRequestScope (com.yahoo.elide.graphql.GraphQLRequestScope)1 GraphQLProjectionInfo (com.yahoo.elide.graphql.parser.GraphQLProjectionInfo)1 SubscriptionEntityProjectionMaker (com.yahoo.elide.graphql.parser.SubscriptionEntityProjectionMaker)1 ExecutionInput (graphql.ExecutionInput)1 ExecutionResult (graphql.ExecutionResult)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.junit.jupiter.api.Test)1 Publisher (org.reactivestreams.Publisher)1 Subscription (org.reactivestreams.Subscription)1