Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CEA5A18B4F for ; Thu, 28 Jan 2016 07:37:08 +0000 (UTC) Received: (qmail 49510 invoked by uid 500); 28 Jan 2016 07:37:02 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 49336 invoked by uid 500); 28 Jan 2016 07:37:02 -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 48710 invoked by uid 99); 28 Jan 2016 07:37:01 -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; Thu, 28 Jan 2016 07:37:01 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D73C7E0C09; Thu, 28 Jan 2016 07:37:01 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vozerov@apache.org To: commits@ignite.apache.org Date: Thu, 28 Jan 2016 07:37:33 -0000 Message-Id: In-Reply-To: <3db10955b08343e38993d286e8de72c1@git.apache.org> References: <3db10955b08343e38993d286e8de72c1@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [33/50] ignite git commit: # Added failing test case (IGNITE-2434) # Added failing test case (IGNITE-2434) Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/0d8e6a8e Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/0d8e6a8e Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/0d8e6a8e Branch: refs/heads/ignite-2324 Commit: 0d8e6a8e359a84218e3f160c473bffbfa3a9caf3 Parents: 243a857 Author: Alexey Goncharuk Authored: Fri Jan 22 16:26:41 2016 +0300 Committer: Alexey Goncharuk Committed: Fri Jan 22 16:27:25 2016 +0300 ---------------------------------------------------------------------- .../IgniteCacheWriteBehindNoUpdateSelfTest.java | 178 +++++++++++++++++++ 1 file changed, 178 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/0d8e6a8e/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/IgniteCacheWriteBehindNoUpdateSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/IgniteCacheWriteBehindNoUpdateSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/IgniteCacheWriteBehindNoUpdateSelfTest.java new file mode 100644 index 0000000..4b95fc9 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/IgniteCacheWriteBehindNoUpdateSelfTest.java @@ -0,0 +1,178 @@ +/* + * 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.store; + +import java.io.Serializable; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import javax.cache.Cache; +import javax.cache.configuration.FactoryBuilder; +import javax.cache.expiry.CreatedExpiryPolicy; +import javax.cache.expiry.Duration; +import javax.cache.integration.CacheLoaderException; +import javax.cache.integration.CacheWriterException; +import javax.cache.processor.EntryProcessor; +import javax.cache.processor.EntryProcessorException; +import javax.cache.processor.MutableEntry; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.store.CacheStoreAdapter; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class IgniteCacheWriteBehindNoUpdateSelfTest extends GridCommonAbstractTest { + /** */ + private static final String THROTTLES_CACHE_NAME = "test"; + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + startGrids(1); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + stopAllGrids(); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg = new CacheConfiguration<>(); + + ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); + ccfg.setCacheMode(CacheMode.PARTITIONED); + ccfg.setBackups(1); + ccfg.setReadFromBackup(true); + ccfg.setCopyOnRead(false); + ccfg.setName(THROTTLES_CACHE_NAME); + + Duration expiryDuration = new Duration(TimeUnit.MINUTES, 1); + + ccfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(expiryDuration)); + ccfg.setReadThrough(false); + ccfg.setWriteThrough(true); + + ccfg.setCacheStoreFactory(new FactoryBuilder.SingletonFactory<>(new TestCacheStore())); + + cfg.setCacheConfiguration(ccfg); + + return cfg; + } + + /** + * @throws Exception If failed. + */ + public void testEntryProcessorNoUpdate() throws Exception { + IgniteCache cache = ignite(0).cache(THROTTLES_CACHE_NAME); + + IgniteCache skipStore = cache.withSkipStore(); + + int entryCnt = 500; + + Set keys = new HashSet<>(); + + for (int i = 0; i < entryCnt; i++) { + skipStore.put(String.valueOf(i), i); + + keys.add(String.valueOf(i)); + } + + TestCacheStore testStore = (TestCacheStore)grid(0).context().cache().cache(THROTTLES_CACHE_NAME).context() + .store().configuredStore(); + + assertEquals(0, testStore.writeCnt.get()); + + cache.invokeAll(keys, new NoOpEntryProcessor()); + + assertEquals(0, testStore.writeCnt.get()); + + cache.invokeAll(keys, new OpEntryProcessor()); + + assertEquals(1, testStore.writeCnt.get()); + } + + /** + * + */ + private static class TestCacheStore extends CacheStoreAdapter implements Serializable { + /** */ + private AtomicInteger writeCnt = new AtomicInteger(); + + /** + * + */ + public void resetWrites() { + writeCnt.set(0); + } + + /** {@inheritDoc} */ + @Override public Long load(String key) throws CacheLoaderException { + return null; + } + + /** {@inheritDoc} */ + @Override public void writeAll(Collection> entries) { + writeCnt.incrementAndGet(); + } + + /** {@inheritDoc} */ + @Override public void write(Cache.Entry entry) throws CacheWriterException { + assert false; + } + + /** {@inheritDoc} */ + @Override public void delete(Object key) throws CacheWriterException { + + } + } + + /** + * + */ + private static class NoOpEntryProcessor implements EntryProcessor { + /** {@inheritDoc} */ + @Override public Object process(MutableEntry entry, Object... arguments) throws EntryProcessorException { + entry.getValue(); + + return null; + } + } + + /** + * + */ + private static class OpEntryProcessor implements EntryProcessor { + /** {@inheritDoc} */ + @Override public Object process(MutableEntry entry, Object... arguments) throws EntryProcessorException { + entry.setValue(1L); + + return null; + } + } +}