Source:
public void testEudeDiskSpaceUsage () throws IOException, IllegalAccessException, ClassNotFoundException, InstantiationException, SQLException { LOGGER.info("Creating entity"); generator.generateDummyEntities(ENTITIES, FIELDS, LOOKUPS, true); EntityDto entityDto = entityService.getEntityByClassName (Constants.Packages.ENTITY.concat(".").concat(generator.getEntityPrefix()).concat("0")); LOGGER.info("Creating instances for entity", INSTANCES); generator.generateDummyInstances(entityDto.getId(), INSTANCES); WebApplicationContext context = ServiceRetriever.getWebAppContext(bundleContext, MDS_BUNDLE_SYMBOLIC_NAME); LocalPersistenceManagerFactoryBean dataPersistenceManagerFactoryBean = (LocalPersistenceManagerFactoryBean) context.getBean("&dataPersistenceManagerFactoryBean"); LocalPersistenceManagerFactoryBean schemaPersistenceManagerFactoryBean = (LocalPersistenceManagerFactoryBean) context.getBean("&persistenceManagerFactoryBean"); PersistenceManagerFactory dataPersistenceManagerFactory = dataPersistenceManagerFactoryBean.getObject(); PersistenceManagerFactory schemaPersistenceManagerFactory = schemaPersistenceManagerFactoryBean.getObject(); JDOConnection dataCon = dataPersistenceManagerFactory.getPersistenceManager().getDataStoreConnection(); JDOConnection schemaCon = schemaPersistenceManagerFactory.getPersistenceManager().getDataStoreConnection(); Connection dataNativeCon = (Connection) dataCon.getNativeConnection(); Connection schemaNativeCon = (Connection) schemaCon.getNativeConnection(); Statement dataStmt = dataNativeCon.createStatement(); Statement schemaStmt = schemaNativeCon.createStatement(); ResultSet dataResultSet = dataStmt.executeQuery(String.format(SQLQUERY, "motechdata")); dataResultSet.absolute(1); double spaceUsage = dataResultSet.getDouble("MB"); ResultSet schemaResultSet = schemaStmt.executeQuery(String.format(SQLQUERY, "motechschema")); schemaResultSet.absolute(1); spaceUsage += schemaResultSet.getDouble("MB"); LOGGER.info("Disk space usage of Motech Data Services database after creating instances is MB", INSTANCES, spaceUsage); logToFile((long) spaceUsage); Bundle entitiesBundle = OsgiBundleUtils.findBundleBySymbolicName(bundleContext, MDS_ENTITIES_SYMBOLIC_NAME); MotechDataService service = generator.getService(entitiesBundle.getBundleContext(), entityDto.getClassName()); service.deleteAll(); }

Target:
public void testEudeDiskSpaceUsage () throws IOException, IllegalAccessException, ClassNotFoundException, InstantiationException, SQLException { LOGGER.info("Creating entity"); generator.generateDummyEntities(ENTITIES, FIELDS, LOOKUPS, true); EntityDto entityDto = entityService.getEntityByClassName (Constants.Packages.ENTITY.concat(".").concat(generator.getEntityPrefix()).concat("0")); LOGGER.info("Creating instances for entity", INSTANCES); generator.generateDummyInstances(entityDto.getId(), INSTANCES); WebApplicationContext context = ServiceRetriever.getWebAppContext(bundleContext, MDS_BUNDLE_SYMBOLIC_NAME); LocalPersistenceManagerFactoryBean dataPersistenceManagerFactoryBean = (LocalPersistenceManagerFactoryBean) context.getBean(BeanFactory.FACTORY_BEAN_PREFIX + "dataPersistenceManagerFactoryBean"); LocalPersistenceManagerFactoryBean schemaPersistenceManagerFactoryBean = (LocalPersistenceManagerFactoryBean) context.getBean(BeanFactory.FACTORY_BEAN_PREFIX + "persistenceManagerFactoryBean"); PersistenceManagerFactory dataPersistenceManagerFactory = dataPersistenceManagerFactoryBean.getObject(); PersistenceManagerFactory schemaPersistenceManagerFactory = schemaPersistenceManagerFactoryBean.getObject(); JDOConnection dataCon = dataPersistenceManagerFactory.getPersistenceManager().getDataStoreConnection(); JDOConnection schemaCon = schemaPersistenceManagerFactory.getPersistenceManager().getDataStoreConnection(); Connection dataNativeCon = (Connection) dataCon.getNativeConnection(); Connection schemaNativeCon = (Connection) schemaCon.getNativeConnection(); Statement dataStmt = dataNativeCon.createStatement(); Statement schemaStmt = schemaNativeCon.createStatement(); ResultSet dataResultSet = dataStmt.executeQuery(String.format(SQLQUERY, "motechdata")); dataResultSet.absolute(1); double spaceUsage = dataResultSet.getDouble("MB"); ResultSet schemaResultSet = schemaStmt.executeQuery(String.format(SQLQUERY, "motechschema")); schemaResultSet.absolute(1); spaceUsage += schemaResultSet.getDouble("MB"); LOGGER.info("Disk space usage of Motech Data Services database after creating instances is MB", INSTANCES, spaceUsage); logToFile(spaceUsage); Bundle entitiesBundle = OsgiBundleUtils.findBundleBySymbolicName(bundleContext, MDS_ENTITIES_SYMBOLIC_NAME); MotechDataService service = generator.getService(entitiesBundle.getBundleContext(), entityDto.getClassName()); service.deleteAll(); }