/**
* Verifies the data cache metrics are available through simple instrumentation.
*/
public void testDataCacheInstrument() {
OpenJPAEntityManagerFactorySPI oemf = createEMF(
"openjpa.Instrumentation", DC_PROVIDER,
"openjpa.DataCache", "true(EnableStatistics=true)",
"openjpa.RemoteCommitProvider", "sjvm",
"openjpa.jdbc.SynchronizeMappings", "buildSchema",
CacheableEntity.class);
// Verify an EMF was created with the supplied instrumentation
assertNotNull(oemf);
// Verify the instrumentation value was stored in the config
String instrValue = oemf.getConfiguration().getInstrumentation();
assertEquals(DC_PROVIDER, instrValue);
// Verify an instrumentation manager is available
InstrumentationManager mgr = oemf.getConfiguration().getInstrumentationManagerInstance();
assertNotNull(mgr);
// Get the data cache instrument
Set<InstrumentationProvider> providers = mgr.getProviders();
assertNotNull(providers);
assertEquals(1, providers.size());
InstrumentationProvider provider = providers.iterator().next();
assertEquals(provider.getClass(), SimpleProvider.class);
Instrument inst = provider.getInstrumentByName(DCInstrument.NAME);
assertNotNull(inst);
assertTrue(inst instanceof DataCacheInstrument);
DataCacheInstrument dci = (DataCacheInstrument)inst;
assertEquals(dci.getCacheName(), "default");
OpenJPAEntityManagerSPI oem = oemf.createEntityManager();
CacheableEntity ce = new CacheableEntity();
int id = new Random().nextInt();
ce.setId(id);
oem.getTransaction().begin();
oem.persist(ce);
oem.getTransaction().commit();
oem.clear();
assertTrue(oemf.getCache().contains(CacheableEntity.class, id));
ce = oem.find(CacheableEntity.class, id);
assertTrue(dci.getHitCount() > 0);
assertTrue(dci.getReadCount() > 0);
assertTrue(dci.getWriteCount() > 0);