/** * @throws Exception If failed. */ @Test public void testLoadCacheTx() throws Exception { startTestGrid(false, false, false, true, 512); checkCacheLoad(); }
/** * @throws Exception If failed. */ @Test public void testLoadCacheWithSqlTx() throws Exception { startTestGrid(false, false, false, true, 512); checkCacheLoadWithSql(); }
/** * @throws Exception If failed. */ @Test public void testLoadCacheWithStatement() throws Exception { startTestGrid(false, false, false, false, 512); checkCacheLoadWithStatement(); }
/** * @throws Exception If failed. */ @Test public void testPutRemoveTxBuiltIn() throws Exception { startTestGrid(true, false, false, true, 512); checkPutRemove(); }
boolean binaryMarshaller = marshaller() instanceof BinaryMarshaller || marshaller() == null; IgniteCache<Object, Person> c1 = grid().cache(CACHE_NAME); Connection conn = getConnection(); try { PreparedStatement stmt = conn.prepareStatement("SELECT ID, ORG_ID, BIRTHDAY, NAME, GENDER FROM PERSON WHERE ID = ?"); assertFalse("Unexpected non empty result set", rs.next()); assertTrue("Unexpected empty result set", rs.next()); assertEquals(-1, rs.getInt(1)); assertEquals(-2, rs.getInt(2)); assertEquals(testDate, rs.getDate(3)); assertEquals("Person-to-test-put-insert", rs.getString(4)); assertEquals(testGender.toString(), binaryMarshaller ? Gender.values()[rs.getInt(5)].toString(): rs.getString(5)); assertFalse("Unexpected more data in result set", rs.next()); assertTrue("Unexpected empty result set", rs.next()); assertEquals(-1, rs.getInt(1)); assertEquals(-3, rs.getInt(2)); assertEquals(testDate, rs.getDate(3)); assertEquals("Person-to-test-put-update", rs.getString(4));
/** * @return Cache configuration for test. * @throws Exception In case when failed to create cache configuration. */ protected CacheConfiguration cacheConfiguration() throws Exception { CacheConfiguration cc = defaultCacheConfiguration(); cc.setName(CACHE_NAME); cc.setCacheMode(PARTITIONED); cc.setAtomicityMode(transactional ? TRANSACTIONAL : ATOMIC); cc.setWriteBehindEnabled(false); cc.setStoreKeepBinary(storeKeepBinary()); CacheJdbcPojoStoreFactory<Object, Object> storeFactory = new CacheJdbcPojoStoreFactory<>(); storeFactory.setDialect(new H2Dialect()); storeFactory.setTypes(storeTypes()); storeFactory.setDataSourceFactory(new H2DataSourceFactory()); // H2 DataSource factory. storeFactory.setSqlEscapeAll(sqlEscapeAll()); storeFactory.setParallelLoadCacheMinimumThreshold(parallelLoadThreshold); cc.setCacheStoreFactory(storeFactory); cc.setReadThrough(true); cc.setWriteThrough(true); cc.setLoadPreviousValue(true); return cc; }
/** * @throws Exception If failed. */ @Test public void testLoadNotRegisteredType() throws Exception { startTestGrid(false, false, false, false, 512); IgniteCache<Object, Object> c1 = grid().cache(CACHE_NAME); try { c1.loadCache(null, "PersonKeyWrong", "SELECT * FROM Person"); } catch (CacheLoaderException e) { String msg = e.getMessage(); assertTrue("Unexpected exception: " + msg, ("Provided key type is not found in store or cache configuration " + "[cache=" + CACHE_NAME + ", key=PersonKeyWrong]").equals(msg)); } } }
/** * Checks that data was loaded correctly with prepared statement. */ protected void checkCacheLoadWithStatement() throws SQLException { Connection conn = null; PreparedStatement stmt = null; try { conn = getConnection(); conn.setAutoCommit(true); String qry = "select id, org_id, name, birthday, gender from Person"; stmt = conn.prepareStatement(qry); IgniteCache<Object, Object> c1 = grid().cache(CACHE_NAME); c1.loadCache(null, "org.apache.ignite.cache.store.jdbc.model.PersonKey", stmt); assertEquals(PERSON_CNT, c1.size()); } finally { U.closeQuiet(stmt); U.closeQuiet(conn); } }
/** * Check that data was loaded correctly. */ protected void checkCacheLoadWithSql() { IgniteCache<Object, Object> c1 = grid().cache(CACHE_NAME); c1.loadCache(null, "org.apache.ignite.cache.store.jdbc.model.PersonKey", "select id, org_id, name, birthday, gender from Person"); assertEquals(PERSON_CNT, c1.size()); }
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { Connection conn = getConnection(); Statement stmt = conn.createStatement(); stmt.executeUpdate("DROP TABLE IF EXISTS Organization"); stmt.executeUpdate("DROP TABLE IF EXISTS Person"); stmt.executeUpdate("CREATE TABLE Organization (" + " id INTEGER PRIMARY KEY," + " name VARCHAR(50)," + " city VARCHAR(50))"); stmt.executeUpdate("CREATE TABLE Person (" + " id INTEGER PRIMARY KEY," + " org_id INTEGER," + " birthday DATE," + " name VARCHAR(50)," + " gender VARCHAR(50))"); conn.commit(); U.closeQuiet(stmt); fillSampleDatabase(conn); U.closeQuiet(conn); }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_STORE); IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); cfg.setCacheConfiguration(cacheConfiguration()); cfg.setMarshaller(marshaller()); ConnectorConfiguration connCfg = new ConnectorConfiguration(); cfg.setConnectorConfiguration(connCfg); return cfg; }
/** * @throws Exception If failed. */ @Test public void testPutRemoveTx() throws Exception { startTestGrid(false, false, false, true, 512); checkPutRemove(); }
/** * Check that data was loaded correctly. */ protected void checkCacheLoad() { IgniteCache<Object, Object> c1 = grid().cache(CACHE_NAME); c1.loadCache(null); assertEquals(ORGANIZATION_CNT + PERSON_CNT, c1.size()); }
/** * @throws Exception If failed. */ @Test public void testLoadCachePrimitiveKeysTx() throws Exception { startTestGrid(true, false, false, true, 512); checkCacheLoad(); }
/** * @throws Exception If failed. */ @Test public void testPutRemoveBuiltIn() throws Exception { startTestGrid(true, false, false, false, 512); checkPutRemove(); }
/** * @throws Exception If failed. */ @Test public void testLoadCacheWithSql() throws Exception { startTestGrid(false, false, false, false, 512); checkCacheLoadWithSql(); }
/** * @throws Exception If failed. */ @Test public void testLoadCacheWithStatementTx() throws Exception { startTestGrid(false, false, false, true, 512); checkCacheLoadWithStatement(); }
/** * @throws Exception If failed. */ @Test public void testLoadCache() throws Exception { startTestGrid(false, false, false, false, 512); checkCacheLoad(); }
/** * @throws Exception If failed. */ @Test public void testPutRemove() throws Exception { startTestGrid(false, false, false, false, 512); checkPutRemove(); }
/** * @throws Exception If failed. */ @Test public void testLoadCacheAll() throws Exception { startTestGrid(false, false, false, false, ORGANIZATION_CNT + PERSON_CNT + 1); checkCacheLoad(); }