use of org.apache.cayenne.configuration.DefaultRuntimeProperties in project cayenne by apache.
the class DataContextFactoryTest method testCreateDataContextWithDedicatedCache.
@Test
public void testCreateDataContextWithDedicatedCache() throws Exception {
final EventManager eventManager = new MockEventManager();
final DataDomain domain = new DataDomain("d1");
domain.setSharedCacheEnabled(false);
Module testModule = binder -> {
binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class);
binder.bind(DataDomain.class).toInstance(domain);
binder.bind(EventManager.class).toInstance(eventManager);
binder.bind(QueryCache.class).toInstance(new MapQueryCache(5));
binder.bind(RuntimeProperties.class).toInstance(new DefaultRuntimeProperties(Collections.<String, String>emptyMap()));
binder.bind(ObjectMapRetainStrategy.class).to(DefaultObjectMapRetainStrategy.class);
binder.bind(ObjectStoreFactory.class).to(DefaultObjectStoreFactory.class);
binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
binder.bind(EventBridge.class).toProvider(NoopEventBridgeProvider.class);
binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
};
Injector injector = DIBootstrap.createInjector(testModule);
DataContextFactory factory = new DataContextFactory();
injector.injectMembers(factory);
DataContext c3 = (DataContext) factory.createContext();
assertNotNull(c3.getObjectStore().getDataRowCache());
assertNull(domain.getSharedSnapshotCache());
assertNotSame(c3.getObjectStore().getDataRowCache(), domain.getSharedSnapshotCache());
}
use of org.apache.cayenne.configuration.DefaultRuntimeProperties in project cayenne by apache.
the class DataContextSerializationIT method testSerializeWithLocalCache.
@Test
public void testSerializeWithLocalCache() throws Exception {
createSingleArtistDataSet();
// manually assemble a DataContext with local cache....
DataDomain domain = context.getParentDataDomain();
DataRowStore snapshotCache = new DataRowStore(domain.getName(), new DefaultRuntimeProperties(domain.getProperties()), domain.getEventManager());
Map<Object, Persistent> map = new HashMap<>();
DataContext localCacheContext = new DataContext(domain, new ObjectStore(snapshotCache, map));
localCacheContext.setValidatingObjectsOnCommit(domain.isValidatingObjectsOnCommit());
localCacheContext.setUsingSharedSnapshotCache(false);
assertNotSame(domain.getSharedSnapshotCache(), localCacheContext.getObjectStore().getDataRowCache());
DataContext deserializedContext = Util.cloneViaSerialization(localCacheContext);
assertNotSame(localCacheContext, deserializedContext);
assertNotSame(localCacheContext.getObjectStore(), deserializedContext.getObjectStore());
assertSame(localCacheContext.getParentDataDomain(), deserializedContext.getParentDataDomain());
assertNotSame(localCacheContext.getObjectStore().getDataRowCache(), deserializedContext.getObjectStore().getDataRowCache());
assertNotSame(deserializedContext.getParentDataDomain().getSharedSnapshotCache(), deserializedContext.getObjectStore().getDataRowCache());
Artist a = Cayenne.objectForPK(deserializedContext, Artist.class, 33001);
assertNotNull(a);
a.setArtistName(a.getArtistName() + "___");
// this blows per CAY-796
deserializedContext.commitChanges();
}
use of org.apache.cayenne.configuration.DefaultRuntimeProperties in project cayenne by apache.
the class DataRowStoreIT method testMaxSize.
/**
* Tests LRU cache behavior.
*/
@Test
public void testMaxSize() throws Exception {
Map<String, String> props = new HashMap<>();
props.put(Constants.SNAPSHOT_CACHE_SIZE_PROPERTY, String.valueOf(2));
cache = new DataRowStore("cacheXYZ", new DefaultRuntimeProperties(props), null);
assertEquals(2, cache.maximumSize());
assertEquals(0, cache.size());
ObjectId key1 = new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, 1);
Map<ObjectId, DataRow> diff1 = new HashMap<>();
diff1.put(key1, new DataRow(1));
ObjectId key2 = new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, 2);
Map<ObjectId, DataRow> diff2 = new HashMap<>();
diff2.put(key2, new DataRow(1));
ObjectId key3 = new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, 3);
Map<ObjectId, DataRow> diff3 = new HashMap<>();
diff3.put(key3, new DataRow(1));
cache.processSnapshotChanges(this, diff1, Collections.<ObjectId>emptyList(), Collections.<ObjectId>emptyList(), Collections.<ObjectId>emptyList());
assertEquals(1, cache.size());
cache.processSnapshotChanges(this, diff2, Collections.<ObjectId>emptyList(), Collections.<ObjectId>emptyList(), Collections.<ObjectId>emptyList());
assertEquals(2, cache.size());
// this addition must overflow the cache, and throw out the first item
cache.processSnapshotChanges(this, diff3, Collections.<ObjectId>emptyList(), Collections.<ObjectId>emptyList(), Collections.<ObjectId>emptyList());
assertEquals(2, cache.size());
assertNotNull(cache.getCachedSnapshot(key2));
assertNotNull(cache.getCachedSnapshot(key3));
assertNull(cache.getCachedSnapshot(key1));
}
use of org.apache.cayenne.configuration.DefaultRuntimeProperties in project cayenne by apache.
the class DataContextSharedCacheEmpiricIT method setUp.
@Before
public void setUp() throws Exception {
eventManager = new DefaultEventManager();
DataRowStore cache = new DataRowStore("cacheTest", new DefaultRuntimeProperties(Collections.<String, String>emptyMap()), eventManager);
c1 = new DataContext(runtime.getDataDomain(), objectStoreFactory.createObjectStore(cache));
c2 = new DataContext(runtime.getDataDomain(), objectStoreFactory.createObjectStore(cache));
// prepare a single artist record
TableHelper tArtist = new TableHelper(dbHelper, "ARTIST");
tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
tArtist.insert(1, "version1");
}
use of org.apache.cayenne.configuration.DefaultRuntimeProperties in project cayenne by apache.
the class DataDomainIT method testShutdownCache.
@Test
public void testShutdownCache() {
DataDomain domain = new DataDomain("X");
final boolean[] cacheShutdown = new boolean[1];
DefaultEventManager eventManager = new DefaultEventManager();
try {
DataRowStore cache = new DataRowStore("Y", new DefaultRuntimeProperties(Collections.<String, String>emptyMap()), eventManager) {
@Override
public void shutdown() {
cacheShutdown[0] = true;
}
};
domain.setSharedSnapshotCache(cache);
domain.shutdown();
} finally {
eventManager.shutdown();
}
assertTrue(cacheShutdown[0]);
}
Aggregations