Created
January 8, 2012 16:31
-
-
Save maniksurtani/1578904 to your computer and use it in GitHub Desktop.
Unit test for ISPN-1649
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<infinispan | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="urn:infinispan:config:5.1 http://www.infinispan.org/schemas/infinispan-config-5.1.xsd" | |
xmlns="urn:infinispan:config:5.1"> | |
<default> | |
<clustering mode="LOCAL" /> | |
<loaders> | |
<loader | |
class="org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore" | |
fetchPersistentState="true" | |
purgeOnStartup="false"> | |
<properties> | |
<property name="stringsTableNamePrefix" value="ISPN_STRING_TABLE"/> | |
<property name="idColumnName" value="ID_COLUMN"/> | |
<property name="dataColumnName" value="DATA_COLUMN"/> | |
<property name="timestampColumnName" value="TIMESTAMP_COLUMN"/> | |
<property name="timestampColumnType" value="BIGINT"/> | |
<property name="connectionFactoryClass" | |
value="org.infinispan.loaders.jdbc.connectionfactory.PooledConnectionFactory"/> | |
<property name="connectionUrl" value="jdbc:h2:file:/tmp/testStore;DB_CLOSE_DELAY=-1"/> | |
<property name="userName" value="sa"/> | |
<property name="driverClass" value="org.h2.Driver"/> | |
<property name="idColumnType" value="VARCHAR(255)"/> | |
<property name="dataColumnType" value="BINARY"/> | |
<property name="dropTableOnExit" value="true"/> | |
<property name="createTableOnStart" value="true"/> | |
</properties> | |
</loader> | |
</loaders> | |
</default> | |
</infinispan> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.infinispan.config; | |
import org.infinispan.loaders.CacheLoaderException; | |
import org.infinispan.loaders.jdbc.connectionfactory.PooledConnectionFactory; | |
import org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore; | |
import org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStoreConfig; | |
import org.infinispan.manager.DefaultCacheManager; | |
import org.infinispan.manager.EmbeddedCacheManager; | |
import org.infinispan.test.SingleCacheManagerTest; | |
import org.infinispan.test.TestingUtil; | |
import org.testng.annotations.Test; | |
import java.sql.Connection; | |
import java.sql.ResultSet; | |
import java.sql.SQLException; | |
@Test(groups = "functional", testName = "config.DropTablesOnShutdownFunctionalTest") | |
public class DropTablesOnShutdownXmlFunctionalTest extends SingleCacheManagerTest { | |
@Override | |
protected EmbeddedCacheManager createCacheManager() throws Exception { | |
return new DefaultCacheManager(getClass().getClassLoader().getResourceAsStream("org/infinispan/config/drop_tables_config.xml")); | |
} | |
public void testShutdown() throws CacheLoaderException, SQLException { | |
System.out.println("Doing PUT"); | |
cache.put("Key", "Value"); | |
JdbcStringBasedCacheStore store = (JdbcStringBasedCacheStore) TestingUtil.getCacheLoader(cache); | |
PooledConnectionFactory cf = (PooledConnectionFactory) store.getConnectionFactory(); | |
JdbcStringBasedCacheStoreConfig cfg = (JdbcStringBasedCacheStoreConfig) store.getCacheStoreConfig(); | |
Connection c = cf.getConnection(); | |
ResultSet rs = c.prepareCall("SHOW TABLES").executeQuery(); | |
int count = 0; | |
while (rs.next()) count ++; | |
assert count != 0; | |
cache.stop(); | |
PooledConnectionFactory pcf = new PooledConnectionFactory(); | |
pcf.start(cfg.getConnectionFactoryConfig(), cfg.getClassLoader()); | |
c = pcf.getConnection(); | |
rs = c.prepareCall("SHOW TABLES").executeQuery(); | |
count = 0; | |
while (rs.next()) count ++; | |
assert count == 0 : "Expected 0 tables to exist; instead saw " + count + " tables!"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment