Minors.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/7fd543c3 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/7fd543c3 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/7fd543c3 Branch: refs/heads/ignite-2693 Commit: 7fd543c340bcfc495a108dc4b11278644767070f Parents: b915b85 Author: vozerov-gridgain <[email protected]> Authored: Tue May 24 14:12:13 2016 +0300 Committer: vozerov-gridgain <[email protected]> Committed: Tue May 24 14:12:13 2016 +0300 ---------------------------------------------------------------------- .../cache/CacheWithKeepBinarySelfTest.java | 105 +++++++++++++++++++ .../junits/CacheWithKeepBinarySelfTest.java | 77 -------------- .../ignite/testsuites/IgniteCacheTestSuite.java | 3 + 3 files changed, 108 insertions(+), 77 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/7fd543c3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheWithKeepBinarySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheWithKeepBinarySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheWithKeepBinarySelfTest.java new file mode 100644 index 0000000..b29ec9d --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheWithKeepBinarySelfTest.java @@ -0,0 +1,105 @@ +/* + * 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.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteException; +import org.apache.ignite.binary.BinaryObject; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.binary.BinaryMarshaller; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.marshaller.optimized.OptimizedMarshaller; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +import java.util.concurrent.Callable; +import org.apache.ignite.testframework.GridTestUtils; + +/** + * Tests for "keepBinary" method. + */ +@SuppressWarnings("unchecked") +public class CacheWithKeepBinarySelfTest extends GridCommonAbstractTest { + /** Whether to use binary marshaller. */ + private boolean binary; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + if (binary) + cfg.setMarshaller(new BinaryMarshaller()); + else + cfg.setMarshaller(new OptimizedMarshaller()); + + cfg.setCacheConfiguration(new CacheConfiguration()); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + } + + /** + * Test for binary marshaller. + * + * @throws Exception If failed. + */ + @SuppressWarnings("UnnecessaryBoxing") + public void testBinaryMarshaller() throws Exception { + binary = true; + + Ignite ignite = startGrid(); + + IgniteCache<Integer, BinaryObject> cache = ignite.cache(null).withKeepBinary(); + + BinaryObject obj = ignite.binary().builder(CacheWithKeepBinarySelfTest.class.getSimpleName()) + .setField("intField", 1).build(); + + cache.put(1, obj); + + BinaryObject otherObj = cache.get(1); + + assert otherObj != null; + assert F.eq(obj.type().typeName(), otherObj.type().typeName()); + assert F.eq(otherObj.field("intField"), Integer.valueOf(1)); + } + + /** + * Test for non-binary marshaller. + * + * @throws Exception If failed. + */ + @SuppressWarnings("ThrowableResultOfMethodCallIgnored") + public void testNonBinaryMarshaller() throws Exception { + binary = false; + + final Ignite ignite = startGrid(); + + GridTestUtils.assertThrows(log, new Callable<Object>() { + @Override public IgniteCache<String,String> call() throws Exception { + ignite.cache(null).withKeepBinary(); + + return null; + } + }, IgniteException.class, null); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/7fd543c3/modules/core/src/test/java/org/apache/ignite/testframework/junits/CacheWithKeepBinarySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/CacheWithKeepBinarySelfTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/CacheWithKeepBinarySelfTest.java deleted file mode 100644 index 6d6c3a5..0000000 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/CacheWithKeepBinarySelfTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.apache.ignite.testframework.junits; - -/** - * Created by ognen_000 on 3/5/2016. - */ -import org.apache.ignite.Ignite; -import org.apache.ignite.IgniteCache; -import org.apache.ignite.IgniteException; -import org.apache.ignite.binary.BinaryObject; -import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; -import static org.apache.ignite.cache.CacheMode.LOCAL; -import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; -import org.apache.ignite.marshaller.jdk.JdkMarshaller; - -import java.util.concurrent.Callable; -import org.apache.ignite.testframework.GridTestUtils; -import org.apache.ignite.testframework.GridStringLogger; - -/** - * Created by oddo on 3/4/2016. - */ -@SuppressWarnings("unchecked") -public class CacheWithKeepBinarySelfTest extends GridCommonAbstractTest { - - private boolean binaryCache; - - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - CacheConfiguration cacheCfg = defaultCacheConfiguration(); - - cacheCfg.setName(gridName); - cacheCfg.setCacheMode(LOCAL); - cacheCfg.setAtomicityMode(ATOMIC); - if (!binaryCache) { - cacheCfg.setStoreKeepBinary(false); - cfg.setMarshaller(new JdkMarshaller()); - } else { - // by default we use BinaryMarshaller - cacheCfg.setStoreKeepBinary(true); - } - - cfg.setCacheConfiguration(cacheCfg); - - return cfg; - } - - public void testWithKeepBinary() throws Exception { - - /* test with a non-binary marshaller - should induce an exception */ - binaryCache = false; - final Ignite ignite = startGrid("binary_tests"); - - GridTestUtils.assertThrows( - new GridStringLogger(false), - new Callable<IgniteCache<String,String>>() { - @Override public IgniteCache<String,String> call() throws Exception { - IgniteCache<String, String> cacheNonBin = ignite.cache(null).withKeepBinary(); - return null; - } - }, - IgniteException.class, - "error: withKeepBinary() cannot be invoked on a cache that has no binary marshaller" - ); - - /* now test with a binary marshaller - should return a valid cache */ - binaryCache = true; - IgniteCache<String, String> cacheNormal = ignite.cache("binary"); - cacheNormal.put("1","1"); - IgniteCache<String, BinaryObject> cacheBin = cacheNormal.withKeepBinary(); - BinaryObject binOb = cacheBin.get("1"); - - stopGrid(); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/7fd543c3/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 3238786..ce8ce62 100755 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java @@ -45,6 +45,7 @@ import org.apache.ignite.internal.processors.cache.CacheNamesSelfTest; import org.apache.ignite.internal.processors.cache.CacheNamesWithSpecialCharactersTest; import org.apache.ignite.internal.processors.cache.CachePutEventListenerErrorSelfTest; import org.apache.ignite.internal.processors.cache.CacheTxFastFinishTest; +import org.apache.ignite.internal.processors.cache.CacheWithKeepBinarySelfTest; import org.apache.ignite.internal.processors.cache.GridCacheAffinityApiSelfTest; import org.apache.ignite.internal.processors.cache.GridCacheAffinityMapperSelfTest; import org.apache.ignite.internal.processors.cache.GridCacheAffinityRoutingSelfTest; @@ -305,6 +306,8 @@ public class IgniteCacheTestSuite extends TestSuite { suite.addTestSuite(CacheTxFastFinishTest.class); + suite.addTestSuite(CacheWithKeepBinarySelfTest.class); + return suite; } }
