use of com.yahoo.elide.core.datastore.inmemory.HashMapDataStore 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));
}
use of com.yahoo.elide.core.datastore.inmemory.HashMapDataStore in project elide by yahoo.
the class MetaDataStore method getMetaData.
/**
* Get all metadata of a specific metadata class.
*
* @param cls metadata class
* @param <T> metadata class
* @return all metadata of given class
*/
public <T> Set<T> getMetaData(Type<T> cls) {
String version = EntityDictionary.getModelVersion(cls);
HashMapDataStore hashMapDataStore = hashMapDataStores.computeIfAbsent(version, SERVER_ERROR);
return hashMapDataStore.get(cls).values().stream().map(obj -> (T) obj).collect(Collectors.toSet());
}
use of com.yahoo.elide.core.datastore.inmemory.HashMapDataStore in project elide by yahoo.
the class MultiplexManagerTest method partialCommitFailure.
@Test
public void partialCommitFailure() throws IOException {
final EntityDictionary entityDictionary = EntityDictionary.builder().build();
final HashMapDataStore ds1 = new HashMapDataStore(DefaultClassScanner.getInstance(), FirstBean.class.getPackage());
final DataStore ds2 = new TestDataStore(OtherBean.class.getPackage());
final MultiplexManager multiplexManager = new MultiplexManager(ds1, ds2);
multiplexManager.populateEntityDictionary(entityDictionary);
assertEquals(ds1, multiplexManager.getSubManager(ClassType.of(FirstBean.class)));
assertEquals(ds2, multiplexManager.getSubManager(ClassType.of(OtherBean.class)));
try (DataStoreTransaction t = ds1.beginTransaction()) {
assertFalse(t.loadObjects(EntityProjection.builder().type(FirstBean.class).build(), null).iterator().hasNext());
FirstBean firstBean = FirstBean.class.newInstance();
firstBean.setName("name");
t.createObject(firstBean, null);
// t.save(firstBean);
assertFalse(t.loadObjects(EntityProjection.builder().type(FirstBean.class).build(), null).iterator().hasNext());
t.commit(null);
} catch (InstantiationException | IllegalAccessException e) {
log.error("", e);
}
try (DataStoreTransaction t = multiplexManager.beginTransaction()) {
FirstBean firstBean = (FirstBean) t.loadObjects(EntityProjection.builder().type(FirstBean.class).build(), null).iterator().next();
firstBean.setName("update");
t.save(firstBean, null);
OtherBean otherBean = OtherBean.class.newInstance();
t.createObject(otherBean, null);
// t.save(firstBean);
assertThrows(TransactionException.class, () -> t.commit(null));
} catch (InstantiationException | IllegalAccessException e) {
log.error("", e);
}
// verify state
try (DataStoreTransaction t = ds1.beginTransaction()) {
Iterable<Object> beans = t.loadObjects(EntityProjection.builder().type(FirstBean.class).build(), null);
assertNotNull(beans);
ArrayList<Object> list = Lists.newArrayList(beans.iterator());
assertEquals(list.size(), 1);
assertEquals(((FirstBean) list.get(0)).getName(), "name");
}
}
use of com.yahoo.elide.core.datastore.inmemory.HashMapDataStore in project elide by yahoo.
the class MultiplexManagerTest method setup.
@BeforeAll
public void setup() {
ClassScanner scanner = DefaultClassScanner.getInstance();
entityDictionary = EntityDictionary.builder().build();
final HashMapDataStore inMemoryDataStore1 = new HashMapDataStore(scanner, FirstBean.class.getPackage());
final HashMapDataStore inMemoryDataStore2 = new HashMapDataStore(scanner, OtherBean.class.getPackage());
multiplexManager = new MultiplexManager(inMemoryDataStore1, inMemoryDataStore2);
multiplexManager.populateEntityDictionary(entityDictionary);
}
use of com.yahoo.elide.core.datastore.inmemory.HashMapDataStore in project elide by yahoo.
the class AsyncAPICancelRunnableTest method setupMocks.
@BeforeEach
public void setupMocks() {
HashMapDataStore inMemoryStore = new HashMapDataStore(DefaultClassScanner.getInstance(), AsyncQuery.class.getPackage());
Map<String, Class<? extends Check>> checkMappings = new HashMap<>();
elide = new Elide(new ElideSettingsBuilder(inMemoryStore).withEntityDictionary(EntityDictionary.builder().checks(checkMappings).build()).withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")).build());
asyncAPIDao = mock(DefaultAsyncAPIDAO.class);
cancelThread = new AsyncAPICancelRunnable(7, elide, asyncAPIDao);
transactionRegistry = elide.getTransactionRegistry();
}
Aggregations