# ignite-662
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/5caa1078 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/5caa1078 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/5caa1078 Branch: refs/heads/ignite-471 Commit: 5caa107806fde27487a15b6c8f6ca3769dbb959b Parents: 35d05e9 Author: sboikov <sboi...@gridgain.com> Authored: Wed Apr 1 13:49:48 2015 +0300 Committer: sboikov <sboi...@gridgain.com> Committed: Wed Apr 1 15:33:57 2015 +0300 ---------------------------------------------------------------------- .../processors/cache/CacheObjectContext.java | 14 +- .../processors/cache/CacheObjectImpl.java | 10 +- .../processors/cache/GridCacheMapEntry.java | 2 +- .../cache/query/GridCacheQueryManager.java | 16 +- .../IgniteCacheObjectProcessorImpl.java | 14 +- .../IgniteCacheAtomicLocalStoreValueTest.java | 49 ++++ ...iteCacheAtomicNearEnabledStoreValueTest.java | 30 ++ ...maryWriteOrderNearEnabledStoreValueTest.java | 31 +++ ...heAtomicPrimaryWriteOrderStoreValueTest.java | 32 +++ .../cache/IgniteCacheAtomicStoreValueTest.java | 55 ++++ .../IgniteCacheStoreValueAbstractTest.java | 277 +++++++++++++++++++ .../cache/IgniteCacheTxLocalStoreValueTest.java | 49 ++++ .../IgniteCacheTxNearEnabledStoreValueTest.java | 30 ++ .../cache/IgniteCacheTxStoreValueTest.java | 49 ++++ .../ignite/testsuites/IgniteCacheTestSuite.java | 9 + 15 files changed, 651 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5caa1078/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java index 5c1b5ae..e85a04a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java @@ -40,7 +40,7 @@ public class CacheObjectContext { private boolean cpyOnGet; /** */ - private boolean unmarshalVals; + private boolean storeVal; /** */ private boolean p2pEnabled; @@ -49,17 +49,17 @@ public class CacheObjectContext { * @param kernalCtx Kernal context. * @param dfltAffMapper Default affinity mapper. * @param cpyOnGet Copy on get flag. - * @param unmarshalVals Unmarshal values flag. + * @param storeVal {@code True} if should store unmarshalled value in cache. */ public CacheObjectContext(GridKernalContext kernalCtx, AffinityKeyMapper dfltAffMapper, boolean cpyOnGet, - boolean unmarshalVals) { + boolean storeVal) { this.kernalCtx = kernalCtx; this.p2pEnabled = kernalCtx.config().isPeerClassLoadingEnabled(); this.dfltAffMapper = dfltAffMapper; this.cpyOnGet = cpyOnGet; - this.unmarshalVals = unmarshalVals; + this.storeVal = storeVal; proc = kernalCtx.cacheObjects(); } @@ -79,10 +79,10 @@ public class CacheObjectContext { } /** - * @return Unmarshal values flag. + * @return {@code True} if should store unmarshalled value in cache. */ - public boolean unmarshalValues() { - return unmarshalVals; + public boolean storeValue() { + return storeVal; } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5caa1078/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java index b131535..33a747d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java @@ -67,13 +67,17 @@ public class CacheObjectImpl extends CacheObjectAdapter { assert valBytes != null; - val = ctx.processor().unmarshal(ctx, valBytes, ctx.kernalContext().config().getClassLoader()); + Object val = ctx.processor().unmarshal(ctx, valBytes, ctx.kernalContext().config().getClassLoader()); + + if (ctx.storeValue()) + this.val = val; + + return (T)val; } catch (IgniteCheckedException e) { throw new IgniteException("Failed to unmarshal object.", e); } - return (T)val; } /** {@inheritDoc} */ @@ -96,7 +100,7 @@ public class CacheObjectImpl extends CacheObjectAdapter { @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException { assert val != null || valBytes != null; - if (val == null && ctx.unmarshalValues()) + if (val == null && ctx.storeValue()) val = ctx.processor().unmarshal(ctx, valBytes, ldr); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5caa1078/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java index 58ff57f..d7fbde9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java @@ -3674,7 +3674,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx { try { GridCacheQueryManager qryMgr = cctx.queries(); - if (qryMgr != null) { + if (qryMgr != null && qryMgr.enabled()) { qryMgr.store(key.value(cctx.cacheObjectContext(), false), null, CU.value(val, cctx, false), http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5caa1078/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java index 145fb9c..6c8cf9a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java @@ -91,6 +91,9 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte /** Event listener. */ private GridLocalEventListener lsnr; + /** */ + private boolean enabled; + /** {@inheritDoc} */ @Override public void start0() throws IgniteCheckedException { qryProc = cctx.kernalContext().query(); @@ -135,6 +138,15 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte }; cctx.events().addListener(lsnr, EVT_NODE_LEFT, EVT_NODE_FAILED); + + enabled = GridQueryProcessor.isEnabled(cctx.config()); + } + + /** + * @return {@code True} if indexing is enabled for cache. + */ + public boolean enabled() { + return enabled; } /** {@inheritDoc} */ @@ -334,8 +346,9 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte throws IgniteCheckedException { assert key != null; assert val != null || valBytes != null; + assert enabled(); - if (!GridQueryProcessor.isEnabled(cctx.config()) && !(key instanceof GridCacheInternal)) + if (key instanceof GridCacheInternal) return; // No-op. if (!enterBusy()) @@ -356,6 +369,7 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte /** * @param key Key. + * @param val Value. * @throws IgniteCheckedException Thrown in case of any errors. */ @SuppressWarnings("SimplifiableIfStatement") http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5caa1078/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java index c0be7c9..a9b7c00 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java @@ -233,10 +233,14 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme if (ccfg != null) { CacheMemoryMode memMode = ccfg.getMemoryMode(); + boolean storeVal = ctx.config().isPeerClassLoadingEnabled() || + GridQueryProcessor.isEnabled(ccfg) || + !ccfg.isCopyOnRead(); + return new CacheObjectContext(ctx, new GridCacheDefaultAffinityKeyMapper(), ccfg.isCopyOnRead() && memMode == ONHEAP_TIERED, - ctx.config().isPeerClassLoadingEnabled() || GridQueryProcessor.isEnabled(ccfg)); + storeVal); } else return new CacheObjectContext( @@ -323,7 +327,8 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme } /** - * + * @param val Value. + * @param valBytes Value bytes. */ public IgniteCacheObjectImpl(Object val, byte[] valBytes) { super(val, valBytes); @@ -341,7 +346,7 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme if (valBytes == null) valBytes = ctx.processor().marshal(ctx, val); - if (ctx.unmarshalValues()) { + if (ctx.storeValue()) { ClassLoader ldr = ctx.p2pEnabled() ? IgniteUtils.detectClass(this.val).getClassLoader() : val.getClass().getClassLoader(); @@ -355,7 +360,8 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme catch (IgniteCheckedException e) { throw new IgniteException("Failed to marshal object: " + val, e); } - } else + } + else return new CacheObjectImpl(val, valBytes); } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5caa1078/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalStoreValueTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalStoreValueTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalStoreValueTest.java new file mode 100644 index 0000000..c547ae0 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalStoreValueTest.java @@ -0,0 +1,49 @@ +/* + * 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.*; + +import static org.apache.ignite.cache.CacheAtomicityMode.*; +import static org.apache.ignite.cache.CacheMode.*; + +/** + * + */ +public class IgniteCacheAtomicLocalStoreValueTest extends IgniteCacheStoreValueAbstractTest { + /** {@inheritDoc} */ + @Override protected int gridCount() { + return 1; + } + + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return LOCAL; + } + + /** {@inheritDoc} */ + @Override protected CacheAtomicityMode atomicityMode() { + return ATOMIC; + } + + /** {@inheritDoc} */ + @Override protected NearCacheConfiguration nearConfiguration() { + return null; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5caa1078/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicNearEnabledStoreValueTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicNearEnabledStoreValueTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicNearEnabledStoreValueTest.java new file mode 100644 index 0000000..a86c50c --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicNearEnabledStoreValueTest.java @@ -0,0 +1,30 @@ +/* + * 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.configuration.*; + +/** + * + */ +public class IgniteCacheAtomicNearEnabledStoreValueTest extends IgniteCacheAtomicStoreValueTest { + /** {@inheritDoc} */ + @Override protected NearCacheConfiguration nearConfiguration() { + return new NearCacheConfiguration(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5caa1078/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPrimaryWriteOrderNearEnabledStoreValueTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPrimaryWriteOrderNearEnabledStoreValueTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPrimaryWriteOrderNearEnabledStoreValueTest.java new file mode 100644 index 0000000..a759ea3 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPrimaryWriteOrderNearEnabledStoreValueTest.java @@ -0,0 +1,31 @@ +/* + * 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.configuration.*; + +/** + * + */ +public class IgniteCacheAtomicPrimaryWriteOrderNearEnabledStoreValueTest + extends IgniteCacheAtomicPrimaryWriteOrderStoreValueTest { + /** {@inheritDoc} */ + @Override protected NearCacheConfiguration nearConfiguration() { + return new NearCacheConfiguration(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5caa1078/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPrimaryWriteOrderStoreValueTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPrimaryWriteOrderStoreValueTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPrimaryWriteOrderStoreValueTest.java new file mode 100644 index 0000000..17ae2bd --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPrimaryWriteOrderStoreValueTest.java @@ -0,0 +1,32 @@ +/* + * 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 static org.apache.ignite.cache.CacheAtomicWriteOrderMode.*; + +/** + * + */ +public class IgniteCacheAtomicPrimaryWriteOrderStoreValueTest extends IgniteCacheAtomicStoreValueTest { + /** {@inheritDoc} */ + @Override protected CacheAtomicWriteOrderMode atomicWriteOrderMode() { + return PRIMARY; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5caa1078/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicStoreValueTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicStoreValueTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicStoreValueTest.java new file mode 100644 index 0000000..9b8f0b1 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicStoreValueTest.java @@ -0,0 +1,55 @@ +/* + * 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.*; + +import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.*; +import static org.apache.ignite.cache.CacheAtomicityMode.*; +import static org.apache.ignite.cache.CacheMode.*; + +/** + * + */ +public class IgniteCacheAtomicStoreValueTest extends IgniteCacheStoreValueAbstractTest { + /** {@inheritDoc} */ + @Override protected int gridCount() { + return 4; + } + + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return PARTITIONED; + } + + /** {@inheritDoc} */ + @Override protected CacheAtomicityMode atomicityMode() { + return ATOMIC; + } + + /** {@inheritDoc} */ + @Override protected CacheAtomicWriteOrderMode atomicWriteOrderMode() { + return CLOCK; + } + + /** {@inheritDoc} */ + @Override protected NearCacheConfiguration nearConfiguration() { + return null; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5caa1078/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java new file mode 100644 index 0000000..9fa24cc --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java @@ -0,0 +1,277 @@ +/* + * 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.*; +import org.apache.ignite.cache.affinity.*; +import org.apache.ignite.cache.store.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.processors.cache.distributed.near.*; +import org.apache.ignite.internal.util.lang.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.testframework.*; + +import javax.cache.*; +import javax.cache.integration.*; +import javax.cache.processor.*; +import java.io.*; +import java.lang.ref.*; +import java.util.*; + +import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*; + +/** + * + */ +public abstract class IgniteCacheStoreValueAbstractTest extends IgniteCacheAbstractTest { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setPeerClassLoadingEnabled(false); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception { + CacheConfiguration ccfg = super.cacheConfiguration(gridName); + + if (ccfg.getCacheMode() != CacheMode.LOCAL) + assertEquals(1, ccfg.getBackups()); + + assertTrue(ccfg.isCopyOnRead()); + + assertEquals(FULL_SYNC, ccfg.getWriteSynchronizationMode()); + + ccfg.setCacheStoreFactory(singletonFactory(new CacheStoreAdapter() { + @Override public void loadCache(IgniteBiInClosure clo, Object... args) { + clo.apply(new TestKey(1), new TestValue()); + } + + @Override public Object load(Object key) throws CacheLoaderException { + return null; + } + + @Override public void write(Cache.Entry entry) throws CacheWriterException { + // No-op. + } + + @Override public void delete(Object key) throws CacheWriterException { + // No-op. + } + })); + + ccfg.setInterceptor(new TestInterceptor()); + + return ccfg; + } + + /** {@inheritDoc} */ + @Override protected boolean swapEnabled() { + return true; + } + + /** + * @throws Exception If failed. + */ + public void testValueNotStored() throws Exception { + IgniteCache<TestKey, TestValue> cache = grid(0).cache(null); + + Affinity<Object> aff = grid(0).affinity(null); + + final List<WeakReference<Object>> refs = new ArrayList<>(); + + for (int i = 0; i < 1000; i++) { + TestKey key = new TestKey(i); + TestValue val = new TestValue(); + + refs.add(new WeakReference<Object>(val)); + + cache.put(key, val); + + checkNoValue(aff, key); + + for (int g = 0; g < gridCount(); g++) + assertNotNull(grid(g).cache(null).get(key)); + + checkNoValue(aff, key); + + cache.invoke(key, new CacheEntryProcessor<TestKey, TestValue, Object>() { + @Override public Object process(MutableEntry<TestKey, TestValue> entry, Object... args) { + assertNotNull(entry.getValue()); + + entry.setValue(new TestValue()); + + return new TestValue(); + } + }); + + checkNoValue(aff, key); + + for (int g = 0; g < gridCount(); g++) + assertNotNull(grid(g).cache(null).get(key)); + + checkNoValue(aff, key); + + cache.remove(key); + + for (int g = 0; g < gridCount(); g++) + assertNull(grid(g).cache(null).get(key)); + + try (IgniteDataStreamer streamer = grid(0).dataStreamer(null)) { + streamer.addData(key, val); + } + + checkNoValue(aff, key); + + if (aff.isPrimaryOrBackup(grid(0).localNode(), key)) { + cache.localEvict(Collections.singleton(key)); + + assertNull(cache.localPeek(key, CachePeekMode.ONHEAP)); + + cache.localPromote(Collections.singleton(key)); + + assertNotNull(cache.localPeek(key, CachePeekMode.ONHEAP)); + + checkNoValue(aff, key); + } + } + + cache.loadCache(null); // Should load TestKey(1). + + TestKey key = new TestKey(1); + + checkNoValue(aff, key); + + for (int g = 0; g < gridCount(); g++) + assertNotNull(grid(g).cache(null).get(key)); + + checkNoValue(aff, key); + +// boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() { +// @Override public boolean apply() { +// System.gc(); +// +// boolean pass = true; +// +// for (Iterator<WeakReference<Object>> it = refs.iterator(); it.hasNext();) { +// WeakReference<Object> ref = it.next(); +// +// if (ref.get() == null) +// it.remove(); +// else +// pass = false; +// } +// +// return pass; +// } +// }, 10_000); +// +// assertTrue("Failed to wait for when values are collected", wait); + } + + /** + * @param aff Affinity. + * @param key Key. + */ + private void checkNoValue(Affinity<Object> aff, Object key) { + for (int g = 0; g < gridCount(); g++) { + GridCacheAdapter cache0 = internalCache(grid(g), null); + + GridCacheEntryEx e = cache0.peekEx(key); + + if (e == null && cache0.isNear()) + e = ((GridNearCacheAdapter)cache0).dht().peekEx(key); + + if (e != null) { + CacheObject obj = e.rawGet(); + + if (obj != null) { + assertNotNull(obj); + assertEquals(CacheObjectImpl.class, obj.getClass()); + + assertNull("Unexpected value, node: " + g, + GridTestUtils.getFieldValue(obj, CacheObjectAdapter.class, "val")); + + assertNotNull(obj.value(cache0.context().cacheObjectContext(), true)); + + assertNull("Unexpected value after value() requested1: " + g, + GridTestUtils.getFieldValue(obj, CacheObjectAdapter.class, "val")); + + assertNotNull(obj.value(cache0.context().cacheObjectContext(), false)); + + assertNull("Unexpected value after value() requested2: " + g, + GridTestUtils.getFieldValue(obj, CacheObjectAdapter.class, "val")); + } + else + assertFalse(aff.isPrimaryOrBackup(grid(g).localNode(), key)); + } + else + assertFalse("Entry not found, node: " + g, aff.isPrimaryOrBackup(grid(g).localNode(), key)); + } + } + + /** + * + */ + static class TestKey implements Serializable { + /** */ + private int key; + + /** + * @param key Key. + */ + public TestKey(int key) { + this.key = key; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + TestKey that = (TestKey)o; + + return key == that.key; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return key; + } + } + + /** + * + */ + static class TestValue implements Serializable { + // No-op. + } + + /** + * + */ + static class TestInterceptor extends CacheInterceptorAdapter { + // No-op. + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5caa1078/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalStoreValueTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalStoreValueTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalStoreValueTest.java new file mode 100644 index 0000000..c9a0cdd --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalStoreValueTest.java @@ -0,0 +1,49 @@ +/* + * 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.*; + +import static org.apache.ignite.cache.CacheAtomicityMode.*; +import static org.apache.ignite.cache.CacheMode.*; + +/** + * + */ +public class IgniteCacheTxLocalStoreValueTest extends IgniteCacheStoreValueAbstractTest { + /** {@inheritDoc} */ + @Override protected int gridCount() { + return 1; + } + + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return LOCAL; + } + + /** {@inheritDoc} */ + @Override protected CacheAtomicityMode atomicityMode() { + return TRANSACTIONAL; + } + + /** {@inheritDoc} */ + @Override protected NearCacheConfiguration nearConfiguration() { + return null; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5caa1078/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxNearEnabledStoreValueTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxNearEnabledStoreValueTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxNearEnabledStoreValueTest.java new file mode 100644 index 0000000..29b8307 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxNearEnabledStoreValueTest.java @@ -0,0 +1,30 @@ +/* + * 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.configuration.*; + +/** + * + */ +public class IgniteCacheTxNearEnabledStoreValueTest extends IgniteCacheTxStoreValueTest { + /** {@inheritDoc} */ + @Override protected NearCacheConfiguration nearConfiguration() { + return new NearCacheConfiguration(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5caa1078/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxStoreValueTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxStoreValueTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxStoreValueTest.java new file mode 100644 index 0000000..390224f --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxStoreValueTest.java @@ -0,0 +1,49 @@ +/* + * 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.*; + +import static org.apache.ignite.cache.CacheAtomicityMode.*; +import static org.apache.ignite.cache.CacheMode.*; + +/** + * + */ +public class IgniteCacheTxStoreValueTest extends IgniteCacheStoreValueAbstractTest { + /** {@inheritDoc} */ + @Override protected int gridCount() { + return 4; + } + + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return PARTITIONED; + } + + /** {@inheritDoc} */ + @Override protected CacheAtomicityMode atomicityMode() { + return TRANSACTIONAL; + } + + /** {@inheritDoc} */ + @Override protected NearCacheConfiguration nearConfiguration() { + return null; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5caa1078/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java index e3fefc8..9e50565 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java @@ -415,6 +415,15 @@ public class IgniteCacheTestSuite extends TestSuite { suite.addTestSuite(GridCacheMarshallingNodeJoinSelfTest.class); + suite.addTestSuite(IgniteCacheAtomicLocalStoreValueTest.class); + suite.addTestSuite(IgniteCacheAtomicStoreValueTest.class); + suite.addTestSuite(IgniteCacheAtomicNearEnabledStoreValueTest.class); + suite.addTestSuite(IgniteCacheAtomicPrimaryWriteOrderStoreValueTest.class); + suite.addTestSuite(IgniteCacheAtomicPrimaryWriteOrderNearEnabledStoreValueTest.class); + suite.addTestSuite(IgniteCacheTxLocalStoreValueTest.class); + suite.addTestSuite(IgniteCacheTxStoreValueTest.class); + suite.addTestSuite(IgniteCacheTxNearEnabledStoreValueTest.class); + return suite; } }