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());
}
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);
}
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;
}
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;
}
}
}
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);
}
Aggregations