Repository: incubator-ignite Updated Branches: refs/heads/ignite-471-2 a989aa09d -> a062467e5
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheConfigurationPrimitiveTypesSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheConfigurationPrimitiveTypesSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheConfigurationPrimitiveTypesSelfTest.java new file mode 100644 index 0000000..e90f10c --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheConfigurationPrimitiveTypesSelfTest.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache; + +import org.apache.ignite.*; +import org.apache.ignite.cache.query.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.apache.ignite.testframework.junits.common.*; + +/** + * + */ +@SuppressWarnings("unchecked") +public class IgniteCacheConfigurationPrimitiveTypesSelfTest extends GridCommonAbstractTest { + /** */ + private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(ipFinder); + + cfg.setDiscoverySpi(disco); + + return cfg; + } + + /** + * @throws Exception If failed. + */ + public void testPrimitiveTypes() throws Exception { + Ignite ignite = startGrid(1); + + CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>("c1"); + + ccfg.setIndexedTypes( + byte.class, byte.class, + short.class, short.class, + int.class, int.class, + long.class, long.class, + float.class, float.class, + double.class, double.class, + boolean.class, boolean.class); + + IgniteCache<Object, Object> cache = ignite.getOrCreateCache(ccfg); + + byte b = 1; + cache.put(b, b); + + short s = 2; + cache.put(s, s); + + int i = 3; + cache.put(i, i); + + long l = 4; + cache.put(l, l); + + float f = 5; + cache.put(f, f); + + double d = 6; + cache.put(d, d); + + boolean bool = true; + cache.put(bool, bool); + + assert cache.query(new ScanQuery<>()).getAll().size() == 7; + + assertEquals(cache.query(new SqlQuery<>(Byte.class, "1 = 1")).getAll().size(), 1); + assertEquals(cache.query(new SqlQuery<>(Short.class, "1 = 1")).getAll().size(), 1); + assertEquals(cache.query(new SqlQuery<>(Integer.class, "1 = 1")).getAll().size(), 1); + assertEquals(cache.query(new SqlQuery<>(Long.class, "1 = 1")).getAll().size(), 1); + assertEquals(cache.query(new SqlQuery<>(Float.class, "1 = 1")).getAll().size(), 1); + assertEquals(cache.query(new SqlQuery<>(Double.class, "1 = 1")).getAll().size(), 1); + assertEquals(cache.query(new SqlQuery<>(Boolean.class, "1 = 1")).getAll().size(), 1); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingQueryErrorTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingQueryErrorTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingQueryErrorTest.java index b2095a8..b171ead 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingQueryErrorTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingQueryErrorTest.java @@ -30,7 +30,8 @@ public class IgniteCacheP2pUnmarshallingQueryErrorTest extends IgniteCacheP2pUnm @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - cfg.getCacheConfiguration()[0].setIndexedTypes(TestKey.class, String.class); + if (cfg.getCacheConfiguration().length > 0) + cfg.getCacheConfiguration()[0].setIndexedTypes(TestKey.class, String.class); return cfg; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedOffHeapTieredSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedOffHeapTieredSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedOffHeapTieredSelfTest.java new file mode 100644 index 0000000..df4c01d --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedOffHeapTieredSelfTest.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache; + +import org.apache.ignite.cache.*; +import org.apache.ignite.configuration.*; + +/** + * Test queries in off-heap tiered mode. + */ +public class IgniteCacheQueryMultiThreadedOffHeapTieredSelfTest extends IgniteCacheQueryMultiThreadedSelfTest { + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration() { + CacheConfiguration ccfg = super.cacheConfiguration(); + + ccfg.setCacheMode(CacheMode.REPLICATED); + ccfg.setMemoryMode(CacheMemoryMode.OFFHEAP_TIERED); + ccfg.setOffHeapMaxMemory(0); + + return ccfg; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedOffHeapTiredSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedOffHeapTiredSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedOffHeapTiredSelfTest.java deleted file mode 100644 index 8b09d0f..0000000 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedOffHeapTiredSelfTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.cache; - -import org.apache.ignite.cache.*; -import org.apache.ignite.configuration.*; - -/** - * Test queries in off-heap tired mode. - */ -public class IgniteCacheQueryMultiThreadedOffHeapTiredSelfTest extends IgniteCacheQueryMultiThreadedSelfTest { - /** {@inheritDoc} */ - @Override protected CacheConfiguration cacheConfiguration() { - CacheConfiguration ccfg = super.cacheConfiguration(); - - ccfg.setCacheMode(CacheMode.REPLICATED); - ccfg.setMemoryMode(CacheMemoryMode.OFFHEAP_TIERED); - ccfg.setOffHeapMaxMemory(0); - - return ccfg; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedSelfTest.java index 4e91a5c..9fcd947 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedSelfTest.java @@ -103,7 +103,16 @@ public class IgniteCacheQueryMultiThreadedSelfTest extends GridCommonAbstractTes cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); cacheCfg.setSwapEnabled(true); cacheCfg.setBackups(1); - cacheCfg.setEvictionPolicy(evictsEnabled() ? new LruEvictionPolicy(100) : null); + + LruEvictionPolicy plc = null; + + if (evictsEnabled()) { + plc = new LruEvictionPolicy(); + plc.setMaxSize(100); + } + + cacheCfg.setEvictionPolicy(plc); + cacheCfg.setSqlOnheapRowCacheSize(128); cacheCfg.setIndexedTypes( Integer.class, Integer.class, http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryNodeRestartSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryNodeRestartSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryNodeRestartSelfTest.java index 5dce126..f86ae9c 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryNodeRestartSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryNodeRestartSelfTest.java @@ -43,6 +43,11 @@ import static org.apache.ignite.cache.CacheMode.*; * Test for distributed queries with node restarts. */ public class IgniteCacheQueryNodeRestartSelfTest extends GridCacheAbstractSelfTest { + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + fail("https://issues.apache.org/jira/browse/IGNITE-484"); + } + /** */ private static final int GRID_CNT = 3; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/ttl/CacheTtlAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/ttl/CacheTtlAbstractSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/ttl/CacheTtlAbstractSelfTest.java index 3833576..4553fec 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/ttl/CacheTtlAbstractSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/ttl/CacheTtlAbstractSelfTest.java @@ -67,7 +67,11 @@ public abstract class CacheTtlAbstractSelfTest extends GridCommonAbstractTest { ccfg.setAtomicityMode(atomicityMode()); ccfg.setMemoryMode(memoryMode()); ccfg.setOffHeapMaxMemory(0); - ccfg.setEvictionPolicy(new LruEvictionPolicy(MAX_CACHE_SIZE)); + + LruEvictionPolicy plc = new LruEvictionPolicy(); + plc.setMaxSize(MAX_CACHE_SIZE); + + ccfg.setEvictionPolicy(plc); ccfg.setIndexedTypes(Integer.class, Integer.class); ccfg.setBackups(2); ccfg.setWriteSynchronizationMode(FULL_SYNC); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java index 3ec67b2..23d9fda 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java @@ -417,7 +417,9 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract } } - public void _testResultReuse() throws Exception { + public void testResultReuse() throws Exception { + fail("https://issues.apache.org/jira/browse/IGNITE-828"); + final IgniteH2Indexing spi = getIndexing(); multithreaded(new Callable<Object>() { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/BaseH2CompareQueryTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/BaseH2CompareQueryTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/BaseH2CompareQueryTest.java index 99366f0..9da7cf8 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/BaseH2CompareQueryTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/BaseH2CompareQueryTest.java @@ -437,7 +437,9 @@ public class BaseH2CompareQueryTest extends AbstractH2CompareQueryTest { /** * @throws Exception If failed. */ - public void _testCrossCache() throws Exception { + public void testCrossCache() throws Exception { + fail("https://issues.apache.org/jira/browse/IGNITE-829"); + //TODO Investigate (should be 20 results instead of 0). compareQueryRes0("select firstName, lastName" + " from \"part\".Person, \"part\".Purchase" + http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java index f42963a..cfc8f2c 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java @@ -59,13 +59,13 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite { suite.addTestSuite(IgniteCacheLargeResultSelfTest.class); suite.addTestSuite(GridCacheQueryInternalKeysSelfTest.class); suite.addTestSuite(IgniteCacheQueryMultiThreadedSelfTest.class); - suite.addTestSuite(IgniteCacheQueryMultiThreadedOffHeapTiredSelfTest.class); + suite.addTestSuite(IgniteCacheQueryMultiThreadedOffHeapTieredSelfTest.class); suite.addTestSuite(IgniteCacheQueryEvictsMultiThreadedSelfTest.class); suite.addTestSuite(IgniteCacheQueryOffheapMultiThreadedSelfTest.class); - suite.addTestSuite(IgniteCacheQueryOffheapEvictsMultiThreadedSelfTest.class); + // suite.addTestSuite(IgniteCacheQueryOffheapEvictsMultiThreadedSelfTest.class); TODO IGNITE-971. suite.addTestSuite(IgniteCacheSqlQueryMultiThreadedSelfTest.class); suite.addTestSuite(IgniteCacheOffheapTieredMultithreadedSelfTest.class); -// suite.addTestSuite(IgniteCacheQueryNodeRestartSelfTest.class); TODO IGNITE-484 + suite.addTestSuite(IgniteCacheQueryNodeRestartSelfTest.class); suite.addTestSuite(GridCacheReduceQueryMultithreadedSelfTest.class); suite.addTestSuite(GridCacheCrossCacheQuerySelfTest.class); suite.addTestSuite(GridCacheQuerySerializationSelfTest.class); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java index ae45120..67ebda9 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java @@ -47,9 +47,12 @@ public class IgniteCacheWithIndexingTestSuite extends TestSuite { suite.addTestSuite(CacheTtlOnheapAtomicPartitionedSelfTest.class); suite.addTestSuite(GridCacheOffheapIndexGetSelfTest.class); + suite.addTestSuite(GridCacheOffheapIndexEntryEvictTest.class); suite.addTestSuite(CacheConfigurationP2PTest.class); + suite.addTestSuite(IgniteCacheConfigurationPrimitiveTypesSelfTest.class); + return suite; } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/spring/pom.xml ---------------------------------------------------------------------- diff --git a/modules/spring/pom.xml b/modules/spring/pom.xml index e922215..a6e61ac 100644 --- a/modules/spring/pom.xml +++ b/modules/spring/pom.xml @@ -77,6 +77,12 @@ </dependency> <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>${spring.version}</version> + </dependency> + + <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> @@ -103,6 +109,14 @@ <type>test-jar</type> <scope>test</scope> </dependency> + + + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <version>1.3.175</version> + <scope>test</scope> + </dependency> </dependencies> <build> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/spring/src/main/java/org/apache/ignite/cache/store/spring/CacheSpringStoreSessionListener.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/main/java/org/apache/ignite/cache/store/spring/CacheSpringStoreSessionListener.java b/modules/spring/src/main/java/org/apache/ignite/cache/store/spring/CacheSpringStoreSessionListener.java new file mode 100644 index 0000000..0a32816 --- /dev/null +++ b/modules/spring/src/main/java/org/apache/ignite/cache/store/spring/CacheSpringStoreSessionListener.java @@ -0,0 +1,207 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.store.spring; + +import org.apache.ignite.*; +import org.apache.ignite.cache.store.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.lifecycle.*; +import org.apache.ignite.resources.*; +import org.apache.ignite.transactions.*; +import org.springframework.jdbc.core.*; +import org.springframework.jdbc.datasource.*; +import org.springframework.transaction.*; +import org.springframework.transaction.support.*; + +import javax.cache.integration.*; +import javax.sql.*; + +/** + * Cache store session listener based on Spring transaction management. + * <p> + * This listener starts a new DB transaction for each session and commits + * or rolls it back when session ends. If there is no ongoing + * cache transaction, this listener is no-op. + * <p> + * Store implementation can use any Spring APIs like {@link JdbcTemplate} + * and others. The listener will guarantee that if there is an + * ongoing cache transaction, all store operations within this + * transaction will be automatically enlisted in the same database + * transaction. + * <p> + * {@link CacheSpringStoreSessionListener} requires that either + * {@link #setTransactionManager(PlatformTransactionManager) transaction manager} + * or {@link #setDataSource(DataSource) data source} is configured. If non of them is + * provided, exception is thrown. Is both are provided, data source will be + * ignored. + * <p> + * If there is a transaction, a {@link TransactionStatus} object will be saved + * as a store session {@link CacheStoreSession#attachment() attachment}. It + * can be used to acquire current DB transaction status. + */ +public class CacheSpringStoreSessionListener implements CacheStoreSessionListener, LifecycleAware { + /** Transaction manager. */ + private PlatformTransactionManager txMgr; + + /** Data source. */ + private DataSource dataSrc; + + /** Logger. */ + @LoggerResource + private IgniteLogger log; + + /** + * Sets transaction manager. + * <p> + * Either transaction manager or data source is required. + * If none is provided, exception will be thrown on startup. + * + * @param txMgr Transaction manager. + */ + public void setTransactionManager(PlatformTransactionManager txMgr) { + this.txMgr = txMgr; + } + + /** + * Gets transaction manager. + * + * @return Transaction manager. + */ + public PlatformTransactionManager getTransactionManager() { + return txMgr; + } + + /** + * Sets data source. + * <p> + * Either transaction manager or data source is required. + * If none is provided, exception will be thrown on startup. + * + * @param dataSrc Data source. + */ + public void setDataSource(DataSource dataSrc) { + this.dataSrc = dataSrc; + } + + /** + * Gets data source. + * + * @return Data source. + */ + public DataSource getDataSource() { + return dataSrc; + } + + /** {@inheritDoc} */ + @Override public void start() throws IgniteException { + if (txMgr == null && dataSrc == null) + throw new IgniteException("Either transaction manager or data source is required by " + + getClass().getSimpleName() + '.'); + + if (dataSrc != null) { + if (txMgr == null) + txMgr = new DataSourceTransactionManager(dataSrc); + else + U.warn(log, "Data source configured in " + getClass().getSimpleName() + + " will be ignored (transaction manager is already set)."); + } + + assert txMgr != null; + } + + /** {@inheritDoc} */ + @Override public void stop() throws IgniteException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void onSessionStart(CacheStoreSession ses) { + if (ses.isWithinTransaction() && ses.attachment() == null) { + try { + TransactionDefinition def = definition(ses.transaction(), ses.cacheName()); + + ses.attach(txMgr.getTransaction(def)); + } + catch (TransactionException e) { + throw new CacheWriterException("Failed to start store session [tx=" + ses.transaction() + ']', e); + } + } + } + + /** {@inheritDoc} */ + @Override public void onSessionEnd(CacheStoreSession ses, boolean commit) { + if (ses.isWithinTransaction()) { + TransactionStatus tx = ses.attach(null); + + if (tx != null) { + try { + if (commit) + txMgr.commit(tx); + else + txMgr.rollback(tx); + } + catch (TransactionException e) { + throw new CacheWriterException("Failed to end store session [tx=" + ses.transaction() + ']', e); + } + } + } + } + + /** + * Gets DB transaction isolation level based on ongoing cache transaction isolation. + * + * @return DB transaction isolation. + */ + private TransactionDefinition definition(Transaction tx, String cacheName) { + assert tx != null; + + DefaultTransactionDefinition def = new DefaultTransactionDefinition(); + + def.setName("Ignite Tx [cache=" + (cacheName != null ? cacheName : "<default>") + ", id=" + tx.xid() + ']'); + def.setIsolationLevel(isolationLevel(tx.isolation())); + + long timeoutSec = (tx.timeout() + 500) / 1000; + + if (timeoutSec > 0 && timeoutSec < Integer.MAX_VALUE) + def.setTimeout((int)timeoutSec); + + return def; + } + + /** + * Gets DB transaction isolation level based on ongoing cache transaction isolation. + * + * @param isolation Cache transaction isolation. + * @return DB transaction isolation. + */ + private int isolationLevel(TransactionIsolation isolation) { + switch (isolation) { + case READ_COMMITTED: + return TransactionDefinition.ISOLATION_READ_COMMITTED; + + case REPEATABLE_READ: + return TransactionDefinition.ISOLATION_REPEATABLE_READ; + + case SERIALIZABLE: + return TransactionDefinition.ISOLATION_SERIALIZABLE; + + default: + throw new IllegalStateException(); // Will never happen. + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/spring/src/test/java/org/apache/ignite/cache/store/spring/CacheSpringStoreSessionListenerSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/cache/store/spring/CacheSpringStoreSessionListenerSelfTest.java b/modules/spring/src/test/java/org/apache/ignite/cache/store/spring/CacheSpringStoreSessionListenerSelfTest.java new file mode 100644 index 0000000..74f5c69 --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/cache/store/spring/CacheSpringStoreSessionListenerSelfTest.java @@ -0,0 +1,197 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.store.spring; + +import org.apache.ignite.cache.store.*; +import org.apache.ignite.cache.store.jdbc.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.resources.*; +import org.springframework.jdbc.core.*; +import org.springframework.jdbc.datasource.*; +import org.springframework.transaction.*; + +import javax.cache.*; +import javax.cache.configuration.*; +import javax.cache.integration.*; +import javax.sql.*; +import java.sql.*; +import java.util.*; + +/** + * Tests for {@link CacheJdbcStoreSessionListener}. + */ +public class CacheSpringStoreSessionListenerSelfTest extends CacheStoreSessionListenerAbstractSelfTest { + /** */ + private static final DataSource DATA_SRC = new DriverManagerDataSource(URL); + + /** {@inheritDoc} */ + @Override protected Factory<? extends CacheStore<Integer, Integer>> storeFactory() { + return new Factory<CacheStore<Integer, Integer>>() { + @Override public CacheStore<Integer, Integer> create() { + return new Store(new JdbcTemplate(DATA_SRC)); + } + }; + } + + /** {@inheritDoc} */ + @Override protected Factory<CacheStoreSessionListener> sessionListenerFactory() { + return new Factory<CacheStoreSessionListener>() { + @Override public CacheStoreSessionListener create() { + CacheSpringStoreSessionListener lsnr = new CacheSpringStoreSessionListener(); + + lsnr.setDataSource(DATA_SRC); + + return lsnr; + } + }; + } + + /** + */ + private static class Store extends CacheStoreAdapter<Integer, Integer> { + /** */ + private static String SES_CONN_KEY = "ses_conn"; + + /** */ + private final JdbcTemplate jdbc; + + /** */ + @CacheStoreSessionResource + private CacheStoreSession ses; + + /** + * @param jdbc JDBC template. + */ + private Store(JdbcTemplate jdbc) { + this.jdbc = jdbc; + } + + /** {@inheritDoc} */ + @Override public void loadCache(IgniteBiInClosure<Integer, Integer> clo, Object... args) { + loadCacheCnt.incrementAndGet(); + + checkTransaction(); + checkConnection(); + } + + /** {@inheritDoc} */ + @Override public Integer load(Integer key) throws CacheLoaderException { + loadCnt.incrementAndGet(); + + checkTransaction(); + checkConnection(); + + return null; + } + + /** {@inheritDoc} */ + @Override public void write(Cache.Entry<? extends Integer, ? extends Integer> entry) + throws CacheWriterException { + writeCnt.incrementAndGet(); + + checkTransaction(); + checkConnection(); + + if (write.get()) { + String table; + + switch (ses.cacheName()) { + case "cache1": + table = "Table1"; + + break; + + case "cache2": + if (fail.get()) + throw new CacheWriterException("Expected failure."); + + table = "Table2"; + + break; + + default: + throw new CacheWriterException("Wring cache: " + ses.cacheName()); + } + + jdbc.update("INSERT INTO " + table + " (key, value) VALUES (?, ?)", + entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override public void delete(Object key) throws CacheWriterException { + deleteCnt.incrementAndGet(); + + checkTransaction(); + checkConnection(); + } + + /** {@inheritDoc} */ + @Override public void sessionEnd(boolean commit) { + assertNull(ses.attachment()); + } + + /** + */ + private void checkTransaction() { + TransactionStatus tx = ses.attachment(); + + if (ses.isWithinTransaction()) { + assertNotNull(tx); + assertFalse(tx.isCompleted()); + } + else + assertNull(tx); + } + + /** + */ + private void checkConnection() { + Connection conn = DataSourceUtils.getConnection(jdbc.getDataSource()); + + assertNotNull(conn); + + try { + assertFalse(conn.isClosed()); + assertEquals(!ses.isWithinTransaction(), conn.getAutoCommit()); + } + catch (SQLException e) { + throw new RuntimeException(e); + } + + verifySameInstance(conn); + } + + /** + * @param conn Connection. + */ + private void verifySameInstance(Connection conn) { + Map<String, Connection> props = ses.properties(); + + Connection sesConn = props.get(SES_CONN_KEY); + + if (sesConn == null) + props.put(SES_CONN_KEY, conn); + else { + assertSame(conn, sesConn); + + reuseCnt.incrementAndGet(); + } + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java b/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java index 8251c18..12dd494 100644 --- a/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java +++ b/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java @@ -18,6 +18,7 @@ package org.apache.ignite.testsuites; import junit.framework.*; +import org.apache.ignite.cache.store.spring.*; import org.apache.ignite.internal.*; import org.apache.ignite.p2p.*; import org.apache.ignite.spring.*; @@ -47,6 +48,8 @@ public class IgniteSpringTestSuite extends TestSuite { suite.addTest(new TestSuite(IgniteStartFromStreamConfigurationTest.class)); + suite.addTestSuite(CacheSpringStoreSessionListenerSelfTest.class); + return suite; } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheScanCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheScanCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheScanCommand.scala index 4b66720..3aa2a19 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheScanCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheScanCommand.scala @@ -139,7 +139,7 @@ class VisorCacheScanCommand { val firstPage = try executeRandom(groupForDataNode(node, cacheName), - classOf[VisorQueryTask], new VisorQueryArg(cacheName, "SCAN", false, pageSize)) match { + classOf[VisorQueryTask], new VisorQueryArg(cacheName, null, false, pageSize)) match { case x if x.get1() != null => error(x.get1()) http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/web/src/test/java/org/apache/ignite/internal/websession/IgniteWebSessionSelfTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/web/src/test/java/org/apache/ignite/internal/websession/IgniteWebSessionSelfTestSuite.java b/modules/web/src/test/java/org/apache/ignite/internal/websession/IgniteWebSessionSelfTestSuite.java index 8f8b9ee..f7e5a2b 100644 --- a/modules/web/src/test/java/org/apache/ignite/internal/websession/IgniteWebSessionSelfTestSuite.java +++ b/modules/web/src/test/java/org/apache/ignite/internal/websession/IgniteWebSessionSelfTestSuite.java @@ -55,7 +55,7 @@ public class IgniteWebSessionSelfTestSuite extends TestSuite { /** {@inheritDoc} */ @Override public void testRestarts() throws Exception { - // TODO GG-8166, enable when fixed. + // TODO IGNITE-810, enable when fixed. } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/scripts/git-apply-patch.sh ---------------------------------------------------------------------- diff --git a/scripts/git-apply-patch.sh b/scripts/git-apply-patch.sh index c5f686f..757cd26 100755 --- a/scripts/git-apply-patch.sh +++ b/scripts/git-apply-patch.sh @@ -56,18 +56,18 @@ do IGNITE_HOME="$2" shift ;; - + -idb|--ignitedefbranch) IGNITE_DEFAULT_BRANCH="$2" shift ;; - + -ph|--patchhome) PATCHES_HOME="$2" shift ;; *) - + echo "Unknown parameter: ${key}" ;; esac @@ -75,7 +75,7 @@ do done echo "IGNITE_HOME : ${IGNITE_HOME}" -echo "Master branch : ${IGNITE_DEFAULT_BRANCH}" +echo "Default branch : ${IGNITE_DEFAULT_BRANCH}" echo "Ignite task : ${IGNITE_TASK}" echo echo "PATCHES_HOME : ${PATCHES_HOME}" http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/scripts/git-format-patch.sh ---------------------------------------------------------------------- diff --git a/scripts/git-format-patch.sh b/scripts/git-format-patch.sh index 970347f..b11c73d 100755 --- a/scripts/git-format-patch.sh +++ b/scripts/git-format-patch.sh @@ -20,9 +20,13 @@ # Git patch-file maker. # echo 'Usage: scripts/git-format-patch.sh [-ih|--ignitehome <path>] [-idb|--ignitedefbranch <branch-name>] [-ph|--patchhome <path>]' +echo 'It is a script to create patch between Current branch (branch with changes) and Default branche. The script is safe and do not broke or lose your changes.' echo "It should be called from IGNITE_HOME directory." -echo "Patch will be created at PATCHES_HOME between Master branch (IGNITE_DEFAULT_BRANCH) and Current branch." +echo "Patch will be created at PATCHES_HOME (= IGNITE_HOME, by default) between Default branch (IGNITE_DEFAULT_BRANCH) and Current branch." echo "Note: you can use ${IGNITE_HOME}/scripts/git-patch-prop-local.sh to set your own local properties (to rewrite settings at git-patch-prop-local.sh). " +echo 'Examples:' +echo '- Basic (with all defaults and properties from git-patch-prop.sh): ./scripts/git-format-patch.sh' +echo '- Rewrite some defaults (see Usage): ./scripts/git-format-patch.sh -ph /home/user_name/patches' echo # @@ -51,17 +55,17 @@ do IGNITE_HOME="$2" shift ;; - + -idb|--ignitedefbranch) IGNITE_DEFAULT_BRANCH="$2" shift ;; - + -ph|--patchhome) PATCHES_HOME="$2" shift ;; - + *) echo "Unknown parameter: ${key}" ;; @@ -72,7 +76,7 @@ done IGNITE_CURRENT_BRANCH=$( determineCurrentBranch ${IGNITE_HOME} ) echo "IGNITE_HOME : ${IGNITE_HOME}" -echo "Master branch : ${IGNITE_DEFAULT_BRANCH}" +echo "Default branch : ${IGNITE_DEFAULT_BRANCH}" echo "Current branch : ${IGNITE_CURRENT_BRANCH}" echo echo "PATCHES_HOME : ${PATCHES_HOME}" @@ -84,4 +88,4 @@ echo requireCleanWorkTree ${IGNITE_HOME} -formatPatch ${IGNITE_HOME} ${IGNITE_DEFAULT_BRANCH} ${IGNITE_CURRENT_BRANCH} .patch \ No newline at end of file +formatPatch ${IGNITE_HOME} ${IGNITE_DEFAULT_BRANCH} ${IGNITE_CURRENT_BRANCH} .patch http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/scripts/git-patch-functions.sh ---------------------------------------------------------------------- diff --git a/scripts/git-patch-functions.sh b/scripts/git-patch-functions.sh index 796bccd..3cc1bb0 100644 --- a/scripts/git-patch-functions.sh +++ b/scripts/git-patch-functions.sh @@ -39,6 +39,14 @@ formatPatch () { PATCHED_BRANCH=$3 PATCH_SUFFIX=$4 + if [ ${IGNITE_CURRENT_BRANCH} = ${IGNITE_DEFAULT_BRANCH} ] + then + echo $0", ERROR:" + echo "You are on Default branch. Please, checkout branch with changes." + + exit 1 + fi + cd ${GIT_HOME} git checkout ${DEFAULT_BRANCH} @@ -54,15 +62,15 @@ formatPatch () { echo "Patch file created." git checkout ${PATCHED_BRANCH} - + git branch -D tmppatch # Delete tmp branch. - - echo + + echo echo "Patch created: ${PATCH_FILE}" } # -# Determines current branch. +# Determines Current branch. # # Params: # - Git home. @@ -70,11 +78,11 @@ formatPatch () { # determineCurrentBranch () { GIT_HOME=$1 - + cd ${GIT_HOME} - + CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD` - + echo "$CURRENT_BRANCH" } @@ -131,22 +139,22 @@ applyPatch () { PATCH_FILE=$3 cd ${GIT_HOME} - + if [ ! -f ${PATCH_FILE} ] then echo $0", ERROR:" echo "Expected patch file not found: $PATCH_FILE." - + exit 1 fi echo "Patch $PATCH_FILE will be applied to $DEFAULT_BRANCH branch." - + git am ${PATCH_FILE} } # -# Checks that given default branch and current branch are equal. +# Checks that given Default branch and Current branch are equal. # Exit with code 1 in error case. # # Params: @@ -160,12 +168,12 @@ currentAndDefaultBranchesShouldBeEqual () { cd ${GIT_HOME} CURRENT_BRANCH=$( determineCurrentBranch ${GIT_HOME} ) - + if [ "$CURRENT_BRANCH" != "$DEFAULT_BRANCH" ] - then + then echo $0", ERROR:" echo "You are not on an expected branch. Your current branch at $GIT_HOME is $CURRENT_BRANCH, should be $DEFAULT_BRANCH." - + exit 1 fi }