protected ConnectionFactory getConnection() { JdbcStringBasedStore store = (JdbcStringBasedStore) cacheStore; return store.getConnectionFactory(); }
private void assertRowCount(int rowCount) { ConnectionFactory connectionFactory = store.getConnectionFactory(); TableName tableName = store.getTableManager().getTableName(); int value = UnitTestDatabaseManager.rowCount(connectionFactory, tableName); assert value == rowCount : "Expected " + rowCount + " rows, actual value is " + value; }
@Override public void call() { Cache<String, String> first = cm.getCache("first"); Cache<String, String> second = cm.getCache("second"); StoreConfiguration firstCacheLoaderConfig = first.getCacheConfiguration().persistence().stores().get(0); assertNotNull(firstCacheLoaderConfig); assertTrue(firstCacheLoaderConfig instanceof JdbcStringBasedStoreConfiguration); StoreConfiguration secondCacheLoaderConfig = second.getCacheConfiguration().persistence().stores().get(0); assertNotNull(secondCacheLoaderConfig); assertTrue(secondCacheLoaderConfig instanceof JdbcStringBasedStoreConfiguration); JdbcStringBasedStore loader = (JdbcStringBasedStore) TestingUtil.getFirstLoader(first); assertTrue(loader.getConnectionFactory() instanceof ManagedConnectionFactory); } });
public void testForJdbcStringBasedCacheStore() throws Exception { CacheContainer cm = null; try { cm = TestCacheManagerFactory.fromXml("configs/string-based.xml"); Cache<String, String> first = cm.getCache("first"); Cache<String, String> second = cm.getCache("second"); StoreConfiguration firstCacheLoaderConfig = first.getCacheConfiguration().persistence().stores().get(0); StoreConfiguration secondCacheLoaderConfig = second.getCacheConfiguration().persistence().stores().get(0); assertEquals(JdbcStringBasedStoreConfiguration.class, firstCacheLoaderConfig.getClass()); assertEquals(JdbcStringBasedStoreConfiguration.class, secondCacheLoaderConfig.getClass()); JdbcStringBasedStore firstCs = (JdbcStringBasedStore) TestingUtil.getFirstLoader(first); JdbcStringBasedStore secondCs = (JdbcStringBasedStore) TestingUtil.getFirstLoader(second); assertTableExistence(firstCs.getConnectionFactory().getConnection(), firstCs.getTableManager().getIdentifierQuoteString(), "second", "first", "ISPN_STRING_TABLE"); assertNoOverlapingState(first, second, firstCs, secondCs); } finally { TestingUtil.killCacheManagers(cm); } }
public void testNotCreateConnectionFactory() throws Exception { ConfigurationBuilder builder = TestCacheManagerFactory .getDefaultCacheConfiguration(false); JdbcStringBasedStoreConfigurationBuilder storeBuilder = builder .persistence() .addStore(JdbcStringBasedStoreConfigurationBuilder.class) .manageConnectionFactory(false) .dialect(DatabaseType.H2) .dbMajorVersion(1) .dbMinorVersion(4); storeBuilder.table().createOnStart(false); JdbcStringBasedStore stringBasedCacheStore = new JdbcStringBasedStore(); stringBasedCacheStore.init(createContext(builder.build())); stringBasedCacheStore.start(); assertNull(stringBasedCacheStore.getConnectionFactory()); // this will make sure that if a method like stop is called on the connection then it will barf an exception ConnectionFactory connectionFactory = mock(ConnectionFactory.class); TableManager tableManager = mock(TableManager.class); tableManager.start(); tableManager.setCacheName("otherName"); stringBasedCacheStore.initializeConnectionFactory(connectionFactory); //stop should be called even if this is an external reset(tableManager, connectionFactory); tableManager.stop(); stringBasedCacheStore.stop(); }