Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 639B0200D3B for ; Fri, 10 Nov 2017 11:07:38 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 622A7160BF2; Fri, 10 Nov 2017 10:07:38 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 627F5160BEE for ; Fri, 10 Nov 2017 11:07:36 +0100 (CET) Received: (qmail 99129 invoked by uid 500); 10 Nov 2017 10:07:35 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 99120 invoked by uid 99); 10 Nov 2017 10:07:35 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Nov 2017 10:07:35 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BC471DFCDF; Fri, 10 Nov 2017 10:07:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ntikhonov@apache.org To: commits@ignite.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: ignite git commit: IGNITE-6669: Renamed test by code style. Date: Fri, 10 Nov 2017 10:07:34 +0000 (UTC) archived-at: Fri, 10 Nov 2017 10:07:38 -0000 Repository: ignite Updated Branches: refs/heads/master 291b166f2 -> c11fc4117 IGNITE-6669: Renamed test by code style. Signed-off-by: nikolay_tikhonov Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c11fc411 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c11fc411 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c11fc411 Branch: refs/heads/master Commit: c11fc41176d7fb5c731ddc55f5f544ded4b26d02 Parents: 291b166 Author: Slava Koptilin Authored: Fri Nov 10 13:07:26 2017 +0300 Committer: nikolay_tikhonov Committed: Fri Nov 10 13:07:26 2017 +0300 ---------------------------------------------------------------------- ...oreListenerRWThroughDisabledAtomicCache.java | 33 -- ...istenerRWThroughDisabledAtomicCacheTest.java | 33 ++ ...enerRWThroughDisabledTransactionalCache.java | 138 --------- ...RWThroughDisabledTransactionalCacheTest.java | 138 +++++++++ ...SessionListenerReadWriteThroughDisabled.java | 291 ------------------ ...ionListenerReadWriteThroughDisabledTest.java | 291 ++++++++++++++++++ ...eStoreSessionListenerWriteBehindEnabled.java | 304 ------------------- ...reSessionListenerWriteBehindEnabledTest.java | 304 +++++++++++++++++++ .../testsuites/IgniteCacheTestSuite4.java | 12 +- 9 files changed, 772 insertions(+), 772 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/c11fc411/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledAtomicCache.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledAtomicCache.java b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledAtomicCache.java deleted file mode 100644 index 9b59940..0000000 --- a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledAtomicCache.java +++ /dev/null @@ -1,33 +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.cache.store; - -import org.apache.ignite.cache.CacheAtomicityMode; - -import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; - -/** - * This class tests that redundant calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * and {@link CacheStoreSessionListener#onSessionEnd(CacheStoreSession, boolean)} are not executed. - */ -public class CacheStoreListenerRWThroughDisabledAtomicCache extends CacheStoreSessionListenerReadWriteThroughDisabled { - /** {@inheritDoc} */ - @Override protected CacheAtomicityMode atomicityMode() { - return ATOMIC; - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/c11fc411/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledAtomicCacheTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledAtomicCacheTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledAtomicCacheTest.java new file mode 100644 index 0000000..6e28a52 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledAtomicCacheTest.java @@ -0,0 +1,33 @@ +/* + * 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; + +import org.apache.ignite.cache.CacheAtomicityMode; + +import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; + +/** + * This class tests that redundant calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * and {@link CacheStoreSessionListener#onSessionEnd(CacheStoreSession, boolean)} are not executed. + */ +public class CacheStoreListenerRWThroughDisabledAtomicCacheTest extends CacheStoreSessionListenerReadWriteThroughDisabledTest { + /** {@inheritDoc} */ + @Override protected CacheAtomicityMode atomicityMode() { + return ATOMIC; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/c11fc411/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledTransactionalCache.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledTransactionalCache.java b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledTransactionalCache.java deleted file mode 100644 index 6502c97..0000000 --- a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledTransactionalCache.java +++ /dev/null @@ -1,138 +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.cache.store; - -import java.util.Random; -import org.apache.ignite.IgniteCache; -import org.apache.ignite.cache.CacheAtomicityMode; -import org.apache.ignite.transactions.Transaction; -import org.apache.ignite.transactions.TransactionConcurrency; -import org.apache.ignite.transactions.TransactionIsolation; - -import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; -import static org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC; -import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; -import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED; -import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ; -import static org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE; - -/** - * This class tests that redundant calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * and {@link CacheStoreSessionListener#onSessionEnd(CacheStoreSession, boolean)} are not executed. - */ -public class CacheStoreListenerRWThroughDisabledTransactionalCache extends CacheStoreSessionListenerReadWriteThroughDisabled { - /** {@inheritDoc} */ - @Override protected CacheAtomicityMode atomicityMode() { - return TRANSACTIONAL; - } - - /** - * Tests {@link IgniteCache#get(Object)} with disabled read-through and write-through modes. - */ - public void testTransactionalLookup() { - testTransactionalLookup(OPTIMISTIC, READ_COMMITTED); - testTransactionalLookup(OPTIMISTIC, REPEATABLE_READ); - testTransactionalLookup(OPTIMISTIC, SERIALIZABLE); - - testTransactionalLookup(PESSIMISTIC, READ_COMMITTED); - testTransactionalLookup(PESSIMISTIC, REPEATABLE_READ); - testTransactionalLookup(PESSIMISTIC, SERIALIZABLE); - } - - /** - * @param concurrency Transaction concurrency level. - * @param isolation Transaction isolation level. - */ - private void testTransactionalLookup(TransactionConcurrency concurrency, TransactionIsolation isolation) { - IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - Random r = new Random(); - - try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) { - for (int i = 0; i < CNT; ++i) - cache.get(r.nextInt()); - - tx.commit(); - } - } - - /** - * Tests {@link IgniteCache#put(Object, Object)} with disabled read-through and write-through modes. - */ - public void testTransactionalUpdate() { - testTransactionalUpdate(OPTIMISTIC, READ_COMMITTED); - testTransactionalUpdate(OPTIMISTIC, REPEATABLE_READ); - testTransactionalUpdate(OPTIMISTIC, SERIALIZABLE); - - testTransactionalUpdate(PESSIMISTIC, READ_COMMITTED); - testTransactionalUpdate(PESSIMISTIC, REPEATABLE_READ); - testTransactionalUpdate(PESSIMISTIC, SERIALIZABLE); - } - - /** - * @param concurrency Transaction concurrency level. - * @param isolation Transaction isolation level. - */ - private void testTransactionalUpdate(TransactionConcurrency concurrency, TransactionIsolation isolation) { - IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - Random r = new Random(); - - try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) { - for (int i = 0; i < CNT; ++i) - cache.put(r.nextInt(), "test-value"); - - tx.commit(); - } - } - - /** - * Tests {@link IgniteCache#remove(Object)} with disabled read-through and write-through modes. - */ - public void testTransactionalRemove() { - testTransactionalRemove(OPTIMISTIC, READ_COMMITTED); - testTransactionalRemove(OPTIMISTIC, REPEATABLE_READ); - testTransactionalRemove(OPTIMISTIC, SERIALIZABLE); - - testTransactionalRemove(PESSIMISTIC, READ_COMMITTED); - testTransactionalRemove(PESSIMISTIC, REPEATABLE_READ); - testTransactionalRemove(PESSIMISTIC, SERIALIZABLE); - } - - /** - * @param concurrency Transaction concurrency level. - * @param isolation Transaction isolation level. - */ - private void testTransactionalRemove(TransactionConcurrency concurrency, TransactionIsolation isolation) { - IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - Random r = new Random(); - - try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) { - for (int i = 0; i < CNT; ++i) { - int key = r.nextInt(); - - cache.put(key, "test-value"); - - cache.remove(key, "test-value"); - } - - tx.commit(); - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/c11fc411/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledTransactionalCacheTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledTransactionalCacheTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledTransactionalCacheTest.java new file mode 100644 index 0000000..fd784a3 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledTransactionalCacheTest.java @@ -0,0 +1,138 @@ +/* + * 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; + +import java.util.Random; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.transactions.Transaction; +import org.apache.ignite.transactions.TransactionConcurrency; +import org.apache.ignite.transactions.TransactionIsolation; + +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; +import static org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC; +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED; +import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ; +import static org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE; + +/** + * This class tests that redundant calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * and {@link CacheStoreSessionListener#onSessionEnd(CacheStoreSession, boolean)} are not executed. + */ +public class CacheStoreListenerRWThroughDisabledTransactionalCacheTest extends CacheStoreSessionListenerReadWriteThroughDisabledTest { + /** {@inheritDoc} */ + @Override protected CacheAtomicityMode atomicityMode() { + return TRANSACTIONAL; + } + + /** + * Tests {@link IgniteCache#get(Object)} with disabled read-through and write-through modes. + */ + public void testTransactionalLookup() { + testTransactionalLookup(OPTIMISTIC, READ_COMMITTED); + testTransactionalLookup(OPTIMISTIC, REPEATABLE_READ); + testTransactionalLookup(OPTIMISTIC, SERIALIZABLE); + + testTransactionalLookup(PESSIMISTIC, READ_COMMITTED); + testTransactionalLookup(PESSIMISTIC, REPEATABLE_READ); + testTransactionalLookup(PESSIMISTIC, SERIALIZABLE); + } + + /** + * @param concurrency Transaction concurrency level. + * @param isolation Transaction isolation level. + */ + private void testTransactionalLookup(TransactionConcurrency concurrency, TransactionIsolation isolation) { + IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + Random r = new Random(); + + try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) { + for (int i = 0; i < CNT; ++i) + cache.get(r.nextInt()); + + tx.commit(); + } + } + + /** + * Tests {@link IgniteCache#put(Object, Object)} with disabled read-through and write-through modes. + */ + public void testTransactionalUpdate() { + testTransactionalUpdate(OPTIMISTIC, READ_COMMITTED); + testTransactionalUpdate(OPTIMISTIC, REPEATABLE_READ); + testTransactionalUpdate(OPTIMISTIC, SERIALIZABLE); + + testTransactionalUpdate(PESSIMISTIC, READ_COMMITTED); + testTransactionalUpdate(PESSIMISTIC, REPEATABLE_READ); + testTransactionalUpdate(PESSIMISTIC, SERIALIZABLE); + } + + /** + * @param concurrency Transaction concurrency level. + * @param isolation Transaction isolation level. + */ + private void testTransactionalUpdate(TransactionConcurrency concurrency, TransactionIsolation isolation) { + IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + Random r = new Random(); + + try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) { + for (int i = 0; i < CNT; ++i) + cache.put(r.nextInt(), "test-value"); + + tx.commit(); + } + } + + /** + * Tests {@link IgniteCache#remove(Object)} with disabled read-through and write-through modes. + */ + public void testTransactionalRemove() { + testTransactionalRemove(OPTIMISTIC, READ_COMMITTED); + testTransactionalRemove(OPTIMISTIC, REPEATABLE_READ); + testTransactionalRemove(OPTIMISTIC, SERIALIZABLE); + + testTransactionalRemove(PESSIMISTIC, READ_COMMITTED); + testTransactionalRemove(PESSIMISTIC, REPEATABLE_READ); + testTransactionalRemove(PESSIMISTIC, SERIALIZABLE); + } + + /** + * @param concurrency Transaction concurrency level. + * @param isolation Transaction isolation level. + */ + private void testTransactionalRemove(TransactionConcurrency concurrency, TransactionIsolation isolation) { + IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + Random r = new Random(); + + try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) { + for (int i = 0; i < CNT; ++i) { + int key = r.nextInt(); + + cache.put(key, "test-value"); + + cache.remove(key, "test-value"); + } + + tx.commit(); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/c11fc411/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerReadWriteThroughDisabled.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerReadWriteThroughDisabled.java b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerReadWriteThroughDisabled.java deleted file mode 100644 index 1f6e97d..0000000 --- a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerReadWriteThroughDisabled.java +++ /dev/null @@ -1,291 +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.cache.store; - -import java.io.PrintWriter; -import java.io.Serializable; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.util.HashSet; -import java.util.Map; -import java.util.Random; -import java.util.Set; -import java.util.TreeMap; -import java.util.logging.Logger; -import javax.cache.Cache; -import javax.cache.configuration.Factory; -import javax.cache.configuration.FactoryBuilder; -import javax.cache.integration.CacheLoaderException; -import javax.cache.integration.CacheWriterException; -import javax.sql.DataSource; -import org.apache.ignite.IgniteCache; -import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener; -import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.NearCacheConfiguration; -import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest; - -/** - * This class tests that redundant calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * and {@link CacheStoreSessionListener#onSessionEnd(CacheStoreSession, boolean)} are not executed. - */ -public abstract class CacheStoreSessionListenerReadWriteThroughDisabled extends GridCacheAbstractSelfTest { - /** {@inheritDoc} */ - protected int gridCount() { - return 2; - } - - /** */ - protected final int CNT = 100; - - /** {@inheritDoc} */ - protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception { - CacheConfiguration cacheCfg = super.cacheConfiguration(igniteInstanceName); - - cacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(EmptyCacheStore.class)); - - cacheCfg.setCacheStoreSessionListenerFactories(new CacheStoreSessionFactory()); - - cacheCfg.setReadThrough(false); - cacheCfg.setWriteThrough(false); - - cacheCfg.setBackups(0); - - return cacheCfg; - } - - /** {@inheritDoc} */ - protected NearCacheConfiguration nearConfiguration() { - return null; - } - - /** - * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and - * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * while {@link IgniteCache#get(Object)} performed. - * - * @throws Exception If failed. - */ - public void testLookup() throws Exception { - IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - Random r = new Random(); - - for (int i = 0; i < CNT; ++i) - cache.get(r.nextInt()); - } - - /** - * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and - * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * while {@link IgniteCache#getAll(Set)} performed. - * - * @throws Exception If failed. - */ - public void testBatchLookup() throws Exception { - IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - Random r = new Random(); - - Set values = new HashSet<>(); - - for (int i = 0; i < CNT; ++i) - values.add(r.nextInt()); - - cache.getAll(values); - } - - /** - * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and - * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * while {@link IgniteCache#put(Object, Object)} performed. - * - * @throws Exception If failed. - */ - public void testUpdate() throws Exception { - IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - Random r = new Random(); - - for (int i = 0; i < CNT; ++i) - cache.put(r.nextInt(), "test-value"); - } - - /** - * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and - * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * while {@link IgniteCache#putAll(Map)} performed. - * - * @throws Exception If failed. - */ - public void testBatchUpdate() throws Exception { - IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - Random r = new Random(); - - Map values = new TreeMap<>(); - - for (int i = 0; i < CNT; ++i) - values.put(r.nextInt(), "test-value"); - - cache.putAll(values); - } - - /** - * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and - * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * while {@link IgniteCache#remove(Object)} performed. - * - * @throws Exception If failed. - */ - public void testRemove() throws Exception { - IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - Random r = new Random(); - - for (int i = 0; i < CNT; ++i) { - int key = r.nextInt(); - - cache.put(key, "test-value"); - - cache.remove(key); - } - } - - /** - * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and - * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * while {@link IgniteCache#removeAll(Set)} performed. - * - * @throws Exception If failed. - */ - public void testBatchRemove() throws Exception { - IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - Random r = new Random(); - - Set values = new HashSet<>(); - - for (int i = 0; i < CNT; ++i) { - int key = r.nextInt(); - - cache.put(key, "test-value"); - - values.add(key); - } - - cache.removeAll(values); - } - - /** - * Cache store session factory. - */ - public static class CacheStoreSessionFactory implements Factory { - /** {@inheritDoc} */ - @Override public TestCacheStoreSessionListener create() { - TestCacheStoreSessionListener lsnr = new TestCacheStoreSessionListener(); - lsnr.setDataSource(new DataSourceStub()); - return lsnr; - } - } - - /** - * Test cache store session listener. - */ - public static class TestCacheStoreSessionListener extends CacheJdbcStoreSessionListener { - /** {@inheritDoc} */ - @Override public void onSessionStart(CacheStoreSession ses) { - fail("TestCacheStoreSessionListener.onSessionStart(CacheStoreSession) should not be called."); - } - - /** {@inheritDoc} */ - @Override public void onSessionEnd(CacheStoreSession ses, boolean commit) { - fail("TestCacheStoreSessionListener.onSessionEnd(CacheStoreSession, boolean) should not be called."); - } - } - - /** Empty cache store implementation. All overridden methods should not be called while the test is running. */ - public static class EmptyCacheStore extends CacheStoreAdapter { - /** {@inheritDoc} */ - @Override public Object load(Object key) throws CacheLoaderException { - fail("EmptyCacheStore.load(Object) should not be called."); - - return null; - } - - /** {@inheritDoc} */ - @Override public void write(Cache.Entry entry) throws CacheWriterException { - fail("EmptyCacheStore.write(Cache.Entry) should not be called."); - } - - /** {@inheritDoc} */ - @Override public void delete(Object key) throws CacheWriterException { - fail("EmptyCacheStore.delete(Object) should not be called."); - } - } - - /** - * Data source stub which should not be called. - */ - public static class DataSourceStub implements DataSource, Serializable { - /** {@inheritDoc} */ - @Override public Connection getConnection() throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public Connection getConnection(String username, String password) throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public T unwrap(Class iface) throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public boolean isWrapperFor(Class iface) throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public PrintWriter getLogWriter() throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public void setLogWriter(PrintWriter out) throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public void setLoginTimeout(int seconds) throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public int getLoginTimeout() throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public Logger getParentLogger() throws SQLFeatureNotSupportedException { - throw new UnsupportedOperationException(); - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/c11fc411/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerReadWriteThroughDisabledTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerReadWriteThroughDisabledTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerReadWriteThroughDisabledTest.java new file mode 100644 index 0000000..150e157 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerReadWriteThroughDisabledTest.java @@ -0,0 +1,291 @@ +/* + * 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; + +import java.io.PrintWriter; +import java.io.Serializable; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.util.HashSet; +import java.util.Map; +import java.util.Random; +import java.util.Set; +import java.util.TreeMap; +import java.util.logging.Logger; +import javax.cache.Cache; +import javax.cache.configuration.Factory; +import javax.cache.configuration.FactoryBuilder; +import javax.cache.integration.CacheLoaderException; +import javax.cache.integration.CacheWriterException; +import javax.sql.DataSource; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.NearCacheConfiguration; +import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest; + +/** + * This class tests that redundant calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * and {@link CacheStoreSessionListener#onSessionEnd(CacheStoreSession, boolean)} are not executed. + */ +public abstract class CacheStoreSessionListenerReadWriteThroughDisabledTest extends GridCacheAbstractSelfTest { + /** {@inheritDoc} */ + protected int gridCount() { + return 2; + } + + /** */ + protected final int CNT = 100; + + /** {@inheritDoc} */ + protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception { + CacheConfiguration cacheCfg = super.cacheConfiguration(igniteInstanceName); + + cacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(EmptyCacheStore.class)); + + cacheCfg.setCacheStoreSessionListenerFactories(new CacheStoreSessionFactory()); + + cacheCfg.setReadThrough(false); + cacheCfg.setWriteThrough(false); + + cacheCfg.setBackups(0); + + return cacheCfg; + } + + /** {@inheritDoc} */ + protected NearCacheConfiguration nearConfiguration() { + return null; + } + + /** + * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and + * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * while {@link IgniteCache#get(Object)} performed. + * + * @throws Exception If failed. + */ + public void testLookup() throws Exception { + IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + Random r = new Random(); + + for (int i = 0; i < CNT; ++i) + cache.get(r.nextInt()); + } + + /** + * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and + * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * while {@link IgniteCache#getAll(Set)} performed. + * + * @throws Exception If failed. + */ + public void testBatchLookup() throws Exception { + IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + Random r = new Random(); + + Set values = new HashSet<>(); + + for (int i = 0; i < CNT; ++i) + values.add(r.nextInt()); + + cache.getAll(values); + } + + /** + * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and + * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * while {@link IgniteCache#put(Object, Object)} performed. + * + * @throws Exception If failed. + */ + public void testUpdate() throws Exception { + IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + Random r = new Random(); + + for (int i = 0; i < CNT; ++i) + cache.put(r.nextInt(), "test-value"); + } + + /** + * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and + * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * while {@link IgniteCache#putAll(Map)} performed. + * + * @throws Exception If failed. + */ + public void testBatchUpdate() throws Exception { + IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + Random r = new Random(); + + Map values = new TreeMap<>(); + + for (int i = 0; i < CNT; ++i) + values.put(r.nextInt(), "test-value"); + + cache.putAll(values); + } + + /** + * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and + * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * while {@link IgniteCache#remove(Object)} performed. + * + * @throws Exception If failed. + */ + public void testRemove() throws Exception { + IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + Random r = new Random(); + + for (int i = 0; i < CNT; ++i) { + int key = r.nextInt(); + + cache.put(key, "test-value"); + + cache.remove(key); + } + } + + /** + * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and + * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * while {@link IgniteCache#removeAll(Set)} performed. + * + * @throws Exception If failed. + */ + public void testBatchRemove() throws Exception { + IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + Random r = new Random(); + + Set values = new HashSet<>(); + + for (int i = 0; i < CNT; ++i) { + int key = r.nextInt(); + + cache.put(key, "test-value"); + + values.add(key); + } + + cache.removeAll(values); + } + + /** + * Cache store session factory. + */ + public static class CacheStoreSessionFactory implements Factory { + /** {@inheritDoc} */ + @Override public TestCacheStoreSessionListener create() { + TestCacheStoreSessionListener lsnr = new TestCacheStoreSessionListener(); + lsnr.setDataSource(new DataSourceStub()); + return lsnr; + } + } + + /** + * Test cache store session listener. + */ + public static class TestCacheStoreSessionListener extends CacheJdbcStoreSessionListener { + /** {@inheritDoc} */ + @Override public void onSessionStart(CacheStoreSession ses) { + fail("TestCacheStoreSessionListener.onSessionStart(CacheStoreSession) should not be called."); + } + + /** {@inheritDoc} */ + @Override public void onSessionEnd(CacheStoreSession ses, boolean commit) { + fail("TestCacheStoreSessionListener.onSessionEnd(CacheStoreSession, boolean) should not be called."); + } + } + + /** Empty cache store implementation. All overridden methods should not be called while the test is running. */ + public static class EmptyCacheStore extends CacheStoreAdapter { + /** {@inheritDoc} */ + @Override public Object load(Object key) throws CacheLoaderException { + fail("EmptyCacheStore.load(Object) should not be called."); + + return null; + } + + /** {@inheritDoc} */ + @Override public void write(Cache.Entry entry) throws CacheWriterException { + fail("EmptyCacheStore.write(Cache.Entry) should not be called."); + } + + /** {@inheritDoc} */ + @Override public void delete(Object key) throws CacheWriterException { + fail("EmptyCacheStore.delete(Object) should not be called."); + } + } + + /** + * Data source stub which should not be called. + */ + public static class DataSourceStub implements DataSource, Serializable { + /** {@inheritDoc} */ + @Override public Connection getConnection() throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public Connection getConnection(String username, String password) throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public T unwrap(Class iface) throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public boolean isWrapperFor(Class iface) throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public PrintWriter getLogWriter() throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public void setLogWriter(PrintWriter out) throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public void setLoginTimeout(int seconds) throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public int getLoginTimeout() throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public Logger getParentLogger() throws SQLFeatureNotSupportedException { + throw new UnsupportedOperationException(); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/c11fc411/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerWriteBehindEnabled.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerWriteBehindEnabled.java b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerWriteBehindEnabled.java deleted file mode 100644 index fbb881e..0000000 --- a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerWriteBehindEnabled.java +++ /dev/null @@ -1,304 +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.cache.store; - -import java.io.PrintWriter; -import java.io.Serializable; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Logger; -import javax.cache.Cache; -import javax.cache.configuration.Factory; -import javax.cache.configuration.FactoryBuilder; -import javax.cache.integration.CacheLoaderException; -import javax.cache.integration.CacheWriterException; -import javax.sql.DataSource; -import org.apache.ignite.Ignite; -import org.apache.ignite.IgniteCache; -import org.apache.ignite.IgniteException; -import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener; -import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest; -import org.apache.ignite.internal.processors.cache.store.GridCacheWriteBehindStore; -import org.apache.ignite.resources.IgniteInstanceResource; - -/** - * This class tests that calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * and {@link CacheStoreSessionListener#onSessionEnd(CacheStoreSession, boolean)} are executed from - * {@link GridCacheWriteBehindStore} only. - */ -public class CacheStoreSessionListenerWriteBehindEnabled extends GridCacheAbstractSelfTest { - /** */ - protected final static int CNT = 100; - - /** */ - private final static int WRITE_BEHIND_FLUSH_FREQUENCY = 1000; - - /** */ - private static final List operations = Collections.synchronizedList(new ArrayList()); - - /** */ - private static final AtomicInteger entryCnt = new AtomicInteger(); - - /** {@inheritDoc} */ - @Override protected int gridCount() { - return 1; - } - - /** {@inheritDoc} */ - @Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception { - CacheConfiguration cacheCfg = super.cacheConfiguration(igniteInstanceName); - - cacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(EmptyCacheStore.class)); - - cacheCfg.setCacheStoreSessionListenerFactories(new CacheStoreSessionFactory()); - - cacheCfg.setReadThrough(true); - cacheCfg.setWriteThrough(true); - - cacheCfg.setWriteBehindEnabled(true); - cacheCfg.setWriteBehindBatchSize(CNT * 2); - cacheCfg.setWriteBehindFlushFrequency(WRITE_BEHIND_FLUSH_FREQUENCY); - - cacheCfg.setBackups(0); - - return cacheCfg; - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - super.beforeTest(); - - operations.clear(); - - entryCnt.set(0); - } - - /** - * Tests that there are no redundant calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * while {@link IgniteCache#get(Object)} performed. - */ - public void testLookup() { - IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - for (int i = 0; i < CNT; ++i) - cache.get(i); - - checkSessionCounters(CNT); - } - - /** - * Tests that there are no redundant calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * while {@link IgniteCache#put(Object, Object)} performed. - */ - public void testUpdate() { - IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - for (int i = 0; i < CNT; ++i) - cache.put(i, i); - - checkSessionCounters(1); - } - - /** - * Tests that there are no redundant calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * while {@link IgniteCache#remove(Object)} performed. - */ - public void testRemove() { - IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - for (int i = 0; i < CNT; ++i) { - cache.remove(i); - } - - checkSessionCounters(1); - } - - /** - * @param startedSessions Number of expected sessions. - */ - private void checkSessionCounters(int startedSessions) { - try { - // Wait for GridCacheWriteBehindStore - Thread.sleep(WRITE_BEHIND_FLUSH_FREQUENCY * 4); - - assertEquals(CNT, entryCnt.get()); - - checkOpCount(operations, OperationType.SESSION_START, startedSessions); - - checkOpCount(operations, OperationType.SESSION_END, startedSessions); - } - catch (InterruptedException e) { - throw new IgniteException("Failed to wait for the GridCacheWriteBehindStore due to interruption.", e); - } - } - - /** - * @param operations List of {@link OperationType}. - * @param op Operation. - * @param expected Expected number of operations for the given {@code op}. - */ - private void checkOpCount(List operations, OperationType op, int expected) { - int n = 0; - - for (OperationType o : operations) { - if (op.equals(o)) - ++n; - } - - assertEquals("Operation=" + op.name(), expected, n); - } - - /** - * Operation type. - */ - public enum OperationType { - /** - * Cache store session started. - */ - SESSION_START, - - /** - * Cache store session ended. - */ - SESSION_END, - } - - /** - * Cache store session factory. - */ - public static class CacheStoreSessionFactory implements Factory { - /** {@inheritDoc} */ - @Override public TestCacheStoreSessionListener create() { - TestCacheStoreSessionListener lsnr = new TestCacheStoreSessionListener(); - lsnr.setDataSource(new DataSourceStub()); - return lsnr; - } - } - - /** - * Test cache store session listener. - */ - public static class TestCacheStoreSessionListener extends CacheJdbcStoreSessionListener { - /** */ - @IgniteInstanceResource - private Ignite ignite; - - /** {@inheritDoc} */ - @Override public void onSessionStart(CacheStoreSession ses) { - operations.add(OperationType.SESSION_START); - } - - /** {@inheritDoc} */ - @Override public void onSessionEnd(CacheStoreSession ses, boolean commit) { - operations.add(OperationType.SESSION_END); - } - } - - /** - * Test cache store. - * - * {@link EmptyCacheStore#writeAll(Collection)} and {@link EmptyCacheStore#deleteAll(Collection)} should be called - * by {@link GridCacheWriteBehindStore}. - */ - public static class EmptyCacheStore extends CacheStoreAdapter { - /** */ - @IgniteInstanceResource - private Ignite ignite; - - /** {@inheritDoc} */ - @Override public Object load(Object key) throws CacheLoaderException { - entryCnt.getAndIncrement(); - return null; - } - - /** {@inheritDoc} */ - @Override public void writeAll(Collection> entries) { - entryCnt.addAndGet(entries.size()); - } - - /** {@inheritDoc} */ - @Override public void write(Cache.Entry entry) throws CacheWriterException { - } - - /** {@inheritDoc} */ - @Override public void deleteAll(Collection keys) { - entryCnt.addAndGet(keys.size()); - } - - /** {@inheritDoc} */ - @Override public void delete(Object key) throws CacheWriterException { - } - } - - /** - * Data source stub which should not be called. - */ - public static class DataSourceStub implements DataSource, Serializable { - /** {@inheritDoc} */ - @Override public Connection getConnection() throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public Connection getConnection(String username, String password) throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public T unwrap(Class iface) throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public boolean isWrapperFor(Class iface) throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public PrintWriter getLogWriter() throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public void setLogWriter(PrintWriter out) throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public void setLoginTimeout(int seconds) throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public int getLoginTimeout() throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public Logger getParentLogger() throws SQLFeatureNotSupportedException { - throw new UnsupportedOperationException(); - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/c11fc411/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerWriteBehindEnabledTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerWriteBehindEnabledTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerWriteBehindEnabledTest.java new file mode 100644 index 0000000..b9095d0 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerWriteBehindEnabledTest.java @@ -0,0 +1,304 @@ +/* + * 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; + +import java.io.PrintWriter; +import java.io.Serializable; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Logger; +import javax.cache.Cache; +import javax.cache.configuration.Factory; +import javax.cache.configuration.FactoryBuilder; +import javax.cache.integration.CacheLoaderException; +import javax.cache.integration.CacheWriterException; +import javax.sql.DataSource; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteException; +import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest; +import org.apache.ignite.internal.processors.cache.store.GridCacheWriteBehindStore; +import org.apache.ignite.resources.IgniteInstanceResource; + +/** + * This class tests that calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * and {@link CacheStoreSessionListener#onSessionEnd(CacheStoreSession, boolean)} are executed from + * {@link GridCacheWriteBehindStore} only. + */ +public class CacheStoreSessionListenerWriteBehindEnabledTest extends GridCacheAbstractSelfTest { + /** */ + protected final static int CNT = 100; + + /** */ + private final static int WRITE_BEHIND_FLUSH_FREQUENCY = 1000; + + /** */ + private static final List operations = Collections.synchronizedList(new ArrayList()); + + /** */ + private static final AtomicInteger entryCnt = new AtomicInteger(); + + /** {@inheritDoc} */ + @Override protected int gridCount() { + return 1; + } + + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception { + CacheConfiguration cacheCfg = super.cacheConfiguration(igniteInstanceName); + + cacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(EmptyCacheStore.class)); + + cacheCfg.setCacheStoreSessionListenerFactories(new CacheStoreSessionFactory()); + + cacheCfg.setReadThrough(true); + cacheCfg.setWriteThrough(true); + + cacheCfg.setWriteBehindEnabled(true); + cacheCfg.setWriteBehindBatchSize(CNT * 2); + cacheCfg.setWriteBehindFlushFrequency(WRITE_BEHIND_FLUSH_FREQUENCY); + + cacheCfg.setBackups(0); + + return cacheCfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + operations.clear(); + + entryCnt.set(0); + } + + /** + * Tests that there are no redundant calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * while {@link IgniteCache#get(Object)} performed. + */ + public void testLookup() { + IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + for (int i = 0; i < CNT; ++i) + cache.get(i); + + checkSessionCounters(CNT); + } + + /** + * Tests that there are no redundant calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * while {@link IgniteCache#put(Object, Object)} performed. + */ + public void testUpdate() { + IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + for (int i = 0; i < CNT; ++i) + cache.put(i, i); + + checkSessionCounters(1); + } + + /** + * Tests that there are no redundant calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * while {@link IgniteCache#remove(Object)} performed. + */ + public void testRemove() { + IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + for (int i = 0; i < CNT; ++i) { + cache.remove(i); + } + + checkSessionCounters(1); + } + + /** + * @param startedSessions Number of expected sessions. + */ + private void checkSessionCounters(int startedSessions) { + try { + // Wait for GridCacheWriteBehindStore + Thread.sleep(WRITE_BEHIND_FLUSH_FREQUENCY * 4); + + assertEquals(CNT, entryCnt.get()); + + checkOpCount(operations, OperationType.SESSION_START, startedSessions); + + checkOpCount(operations, OperationType.SESSION_END, startedSessions); + } + catch (InterruptedException e) { + throw new IgniteException("Failed to wait for the GridCacheWriteBehindStore due to interruption.", e); + } + } + + /** + * @param operations List of {@link OperationType}. + * @param op Operation. + * @param expected Expected number of operations for the given {@code op}. + */ + private void checkOpCount(List operations, OperationType op, int expected) { + int n = 0; + + for (OperationType o : operations) { + if (op.equals(o)) + ++n; + } + + assertEquals("Operation=" + op.name(), expected, n); + } + + /** + * Operation type. + */ + public enum OperationType { + /** + * Cache store session started. + */ + SESSION_START, + + /** + * Cache store session ended. + */ + SESSION_END, + } + + /** + * Cache store session factory. + */ + public static class CacheStoreSessionFactory implements Factory { + /** {@inheritDoc} */ + @Override public TestCacheStoreSessionListener create() { + TestCacheStoreSessionListener lsnr = new TestCacheStoreSessionListener(); + lsnr.setDataSource(new DataSourceStub()); + return lsnr; + } + } + + /** + * Test cache store session listener. + */ + public static class TestCacheStoreSessionListener extends CacheJdbcStoreSessionListener { + /** */ + @IgniteInstanceResource + private Ignite ignite; + + /** {@inheritDoc} */ + @Override public void onSessionStart(CacheStoreSession ses) { + operations.add(OperationType.SESSION_START); + } + + /** {@inheritDoc} */ + @Override public void onSessionEnd(CacheStoreSession ses, boolean commit) { + operations.add(OperationType.SESSION_END); + } + } + + /** + * Test cache store. + * + * {@link EmptyCacheStore#writeAll(Collection)} and {@link EmptyCacheStore#deleteAll(Collection)} should be called + * by {@link GridCacheWriteBehindStore}. + */ + public static class EmptyCacheStore extends CacheStoreAdapter { + /** */ + @IgniteInstanceResource + private Ignite ignite; + + /** {@inheritDoc} */ + @Override public Object load(Object key) throws CacheLoaderException { + entryCnt.getAndIncrement(); + return null; + } + + /** {@inheritDoc} */ + @Override public void writeAll(Collection> entries) { + entryCnt.addAndGet(entries.size()); + } + + /** {@inheritDoc} */ + @Override public void write(Cache.Entry entry) throws CacheWriterException { + } + + /** {@inheritDoc} */ + @Override public void deleteAll(Collection keys) { + entryCnt.addAndGet(keys.size()); + } + + /** {@inheritDoc} */ + @Override public void delete(Object key) throws CacheWriterException { + } + } + + /** + * Data source stub which should not be called. + */ + public static class DataSourceStub implements DataSource, Serializable { + /** {@inheritDoc} */ + @Override public Connection getConnection() throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public Connection getConnection(String username, String password) throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public T unwrap(Class iface) throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public boolean isWrapperFor(Class iface) throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public PrintWriter getLogWriter() throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public void setLogWriter(PrintWriter out) throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public void setLoginTimeout(int seconds) throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public int getLoginTimeout() throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public Logger getParentLogger() throws SQLFeatureNotSupportedException { + throw new UnsupportedOperationException(); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/c11fc411/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java index e4930e0..ba7aa1b 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java @@ -18,9 +18,9 @@ package org.apache.ignite.testsuites; import junit.framework.TestSuite; -import org.apache.ignite.cache.store.CacheStoreListenerRWThroughDisabledAtomicCache; -import org.apache.ignite.cache.store.CacheStoreListenerRWThroughDisabledTransactionalCache; -import org.apache.ignite.cache.store.CacheStoreSessionListenerWriteBehindEnabled; +import org.apache.ignite.cache.store.CacheStoreListenerRWThroughDisabledAtomicCacheTest; +import org.apache.ignite.cache.store.CacheStoreListenerRWThroughDisabledTransactionalCacheTest; +import org.apache.ignite.cache.store.CacheStoreSessionListenerWriteBehindEnabledTest; import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListenerSelfTest; import org.apache.ignite.internal.processors.GridCacheTxLoadFromStoreOnLockSelfTest; import org.apache.ignite.internal.processors.cache.CacheClientStoreSelfTest; @@ -279,9 +279,9 @@ public class IgniteCacheTestSuite4 extends TestSuite { suite.addTestSuite(CacheOffheapMapEntrySelfTest.class); suite.addTestSuite(CacheJdbcStoreSessionListenerSelfTest.class); - suite.addTestSuite(CacheStoreListenerRWThroughDisabledAtomicCache.class); - suite.addTestSuite(CacheStoreListenerRWThroughDisabledTransactionalCache.class); - suite.addTestSuite(CacheStoreSessionListenerWriteBehindEnabled.class); + suite.addTestSuite(CacheStoreListenerRWThroughDisabledAtomicCacheTest.class); + suite.addTestSuite(CacheStoreListenerRWThroughDisabledTransactionalCacheTest.class); + suite.addTestSuite(CacheStoreSessionListenerWriteBehindEnabledTest.class); suite.addTestSuite(CacheClientStoreSelfTest.class); suite.addTestSuite(CacheStoreUsageMultinodeStaticStartAtomicTest.class);