use of com.yahoo.elide.example.other.OtherBean 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");
}
}
Aggregations