Search in sources :

Example 31 with DataStore

use of com.yahoo.elide.core.datastore.DataStore in project elide by yahoo.

the class LifeCycleTest method testElideGetInvalidKey.

@Test
public void testElideGetInvalidKey() throws Exception {
    DataStore store = mock(DataStore.class);
    Elide elide = getElide(store, dictionary, MOCK_AUDIT_LOGGER);
    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    queryParams.putSingle("fields[testModel]", "field");
    // Key starts with '?'
    queryParams.putSingle("?filter", "field");
    // Valid Key is sort
    queryParams.putSingle("Sort", "field");
    // Valid Key is include
    queryParams.putSingle("INCLUDE", "field");
    // fields is not followed by [
    queryParams.putSingle("fields.testModel", "field");
    // page is not followed by [
    queryParams.putSingle("page.size", "10");
    ElideResponse response = elide.get(baseUrl, "/testModel/1", queryParams, null, NO_VERSION);
    assertEquals(HttpStatus.SC_BAD_REQUEST, response.getResponseCode());
    assertEquals("{\"errors\":[{\"detail\":\"Found undefined keys in request: fields.testModel, ?filter, Sort, page.size, INCLUDE\"}]}", response.getBody());
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ElideResponse(com.yahoo.elide.ElideResponse) DataStore(com.yahoo.elide.core.datastore.DataStore) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Elide(com.yahoo.elide.Elide) Test(org.junit.jupiter.api.Test)

Example 32 with DataStore

use of com.yahoo.elide.core.datastore.DataStore in project elide by yahoo.

the class MultiplexTransaction method getProperty.

@Override
public <T> T getProperty(String propertyName) {
    DataStore matchingStore = multiplexManager.dataStores.stream().filter(store -> propertyName.startsWith(store.getClass().getPackage().getName())).findFirst().orElse(null);
    // Data store transaction properties must be prefixed with their package name.
    if (matchingStore == null) {
        return null;
    }
    if (!transactions.containsKey(matchingStore)) {
        DataStoreTransaction tx = beginTransaction(matchingStore);
        transactions.put(matchingStore, tx);
    }
    return transactions.get(matchingStore).getProperty(propertyName);
}
Also used : DataStore(com.yahoo.elide.core.datastore.DataStore) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction)

Example 33 with DataStore

use of com.yahoo.elide.core.datastore.DataStore in project elide by yahoo.

the class MultiplexTransaction method getTransaction.

protected DataStoreTransaction getTransaction(Type<?> cls) {
    DataStore lookupDataStore = this.multiplexManager.getSubManager(cls);
    DataStoreTransaction transaction = transactions.get(lookupDataStore);
    if (transaction == null) {
        for (DataStore dataStore : multiplexManager.dataStores) {
            if (dataStore.equals(lookupDataStore)) {
                transaction = beginTransaction(dataStore);
                transactions.put(dataStore, transaction);
                break;
            }
        }
        if (transaction == null) {
            throw new InvalidCollectionException(cls.getName());
        }
    }
    return transaction;
}
Also used : DataStore(com.yahoo.elide.core.datastore.DataStore) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) InvalidCollectionException(com.yahoo.elide.core.exceptions.InvalidCollectionException)

Example 34 with DataStore

use of com.yahoo.elide.core.datastore.DataStore in project elide by yahoo.

the class MultiplexWriteTransaction method commit.

@Override
public void commit(RequestScope scope) {
    // flush all before commits
    flush(scope);
    ArrayList<DataStore> commitList = new ArrayList<>();
    for (Entry<DataStore, DataStoreTransaction> entry : transactions.entrySet()) {
        try {
            entry.getValue().commit(scope);
            commitList.add(entry.getKey());
        } catch (HttpStatusException | WebApplicationException e) {
            reverseTransactions(commitList, e, scope);
            throw e;
        } catch (Error | RuntimeException e) {
            TransactionException transactionException = new TransactionException(e);
            reverseTransactions(commitList, transactionException, scope);
            throw transactionException;
        }
    }
}
Also used : TransactionException(com.yahoo.elide.core.exceptions.TransactionException) WebApplicationException(javax.ws.rs.WebApplicationException) DataStore(com.yahoo.elide.core.datastore.DataStore) ArrayList(java.util.ArrayList) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) HttpStatusException(com.yahoo.elide.core.exceptions.HttpStatusException)

Example 35 with DataStore

use of com.yahoo.elide.core.datastore.DataStore in project elide by yahoo.

the class MultiplexTransactionTest method testPrecommit.

@Test
public void testPrecommit() throws Exception {
    DataStore store1 = mock(DataStore.class);
    DataStore store2 = mock(DataStore.class);
    DataStoreTransaction tx1 = mock(DataStoreTransaction.class);
    DataStoreTransaction tx2 = mock(DataStoreTransaction.class);
    RequestScope scope = mock(RequestScope.class);
    when(store1.beginReadTransaction()).thenReturn(tx1);
    when(store2.beginReadTransaction()).thenReturn(tx2);
    MultiplexManager store = new MultiplexManager(store1, store2);
    DataStoreTransaction multiplexTx = store.beginReadTransaction();
    multiplexTx.preCommit(scope);
    // Since transactions are lazy initialized,
    // preCommit will not be called on individual transactions.
    verify(tx1, Mockito.times(0)).preCommit(any());
    verify(tx2, Mockito.times(0)).preCommit(any());
    MultiplexReadTransaction multiplexReadTx = (MultiplexReadTransaction) multiplexTx;
    long countInitializedTransaction = multiplexReadTx.transactions.values().stream().filter(dataStoreTransaction -> dataStoreTransaction != null).count();
    assertEquals(0, countInitializedTransaction);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) HashMapStoreTransaction(com.yahoo.elide.core.datastore.inmemory.HashMapStoreTransaction) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) DataStore(com.yahoo.elide.core.datastore.DataStore) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Mockito.mock(org.mockito.Mockito.mock) RequestScope(com.yahoo.elide.core.RequestScope) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) DataStore(com.yahoo.elide.core.datastore.DataStore) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Aggregations

DataStore (com.yahoo.elide.core.datastore.DataStore)38 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)31 Test (org.junit.jupiter.api.Test)27 Elide (com.yahoo.elide.Elide)25 ElideResponse (com.yahoo.elide.ElideResponse)21 RequestScope (com.yahoo.elide.core.RequestScope)19 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 EntityProjection (com.yahoo.elide.core.request.EntityProjection)10 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)5 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)5 HashMapDataStore (com.yahoo.elide.core.datastore.inmemory.HashMapDataStore)3 FieldTestModel (com.yahoo.elide.core.lifecycle.FieldTestModel)3 AggregationDataStore (com.yahoo.elide.datastores.aggregation.AggregationDataStore)3 MetaDataStore (com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore)3 JpaDataStore (com.yahoo.elide.datastores.jpa.JpaDataStore)3 NonJtaTransaction (com.yahoo.elide.datastores.jpa.transaction.NonJtaTransaction)3 MultiplexManager (com.yahoo.elide.datastores.multiplex.MultiplexManager)3 NoopBean (com.yahoo.elide.beans.NoopBean)2 TemplateConfigValidator (com.yahoo.elide.datastores.aggregation.validator.TemplateConfigValidator)2 ConfigDataStore (com.yahoo.elide.modelconfig.store.ConfigDataStore)2