Repository: ignite Updated Branches: refs/heads/ignite-1272 bc13beb27 -> 696e183c8
ignite-1272: added new deployment related tests Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/696e183c Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/696e183c Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/696e183c Branch: refs/heads/ignite-1272 Commit: 696e183c8b0d9849e1267ea7ddd71dfd8387c62f Parents: bc13beb Author: Denis Magda <[email protected]> Authored: Thu Oct 8 16:05:07 2015 +0300 Committer: Denis Magda <[email protected]> Committed: Thu Oct 8 16:05:07 2015 +0300 ---------------------------------------------------------------------- .../GridCacheConditionalDeploymentSelfTest.java | 115 +++++++++++++++++-- .../testsuites/IgniteCacheTestSuite3.java | 4 +- 2 files changed, 109 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/696e183c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConditionalDeploymentSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConditionalDeploymentSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConditionalDeploymentSelfTest.java index 6489e9b..5f82a67 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConditionalDeploymentSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConditionalDeploymentSelfTest.java @@ -21,14 +21,21 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.Ignition; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.GridDirectCollection; import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.managers.communication.GridIoMessageFactory; +import org.apache.ignite.internal.portable.api.PortableMarshaller; +import org.apache.ignite.internal.util.IgniteUtils; +import org.apache.ignite.internal.util.typedef.CO; +import org.apache.ignite.plugin.extensions.communication.Message; import org.apache.ignite.plugin.extensions.communication.MessageCollectionItemType; import org.apache.ignite.plugin.extensions.communication.MessageReader; import org.apache.ignite.plugin.extensions.communication.MessageWriter; +import org.apache.ignite.spi.communication.GridTestMessage; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; @@ -46,6 +53,17 @@ public class GridCacheConditionalDeploymentSelfTest extends GridCommonAbstractTe /** IP finder. */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + /** + * + */ + static { + GridIoMessageFactory.registerCustom(TestMessage.DIRECT_TYPE, new CO<Message>() { + @Override public Message apply() { + return new TestMessage(); + } + }); + } + /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); @@ -78,7 +96,16 @@ public class GridCacheConditionalDeploymentSelfTest extends GridCommonAbstractTe } /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { + @Override protected void beforeTestsStarted() throws Exception { + Ignite ignite0 = startGrid(0); + + startGrid(1); + + ignite0.cache(null).put(1, new TestValue()); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { Ignition.stopAll(true); } @@ -86,28 +113,93 @@ public class GridCacheConditionalDeploymentSelfTest extends GridCommonAbstractTe * @throws Exception In case of error. */ public void testNoDeploymentInfo() throws Exception { - Ignite ignite0 = startGrid(0); - Ignite ignite1 = startGrid(1); + GridCacheIoManager ioMgr = cacheIoManager(); + + TestMessage msg = new TestMessage(); + + assertNull(msg.deployInfo()); - GridCacheContext ctx = ((IgniteCacheProxy)ignite0.cache(null)).context(); + msg.depEnabled = false; - GridCacheIoManager ioMgr = ((IgniteKernal)ignite0).context().cache().context().io(); + IgniteUtils.invoke(GridCacheIoManager.class, ioMgr, "onSend", msg, grid(1).cluster().localNode().id()); + + assertNull(msg.deployInfo()); + } + + /** + * @throws Exception In case of error. + */ + public void testAddedDeploymentInfo() throws Exception { + GridCacheIoManager ioMgr = cacheIoManager(); TestMessage msg = new TestMessage(); - assertNull(msg.depEnabled); + assertNull(msg.deployInfo()); msg.depEnabled = true; - ioMgr.send(ignite1.cluster().localNode().id(), msg, ctx.ioPolicy()); + IgniteUtils.invoke(GridCacheIoManager.class, ioMgr, "onSend", msg, grid(1).cluster().localNode().id()); + + assertNotNull(msg.deployInfo()); + } + + /** + * @throws Exception In case of error. + */ + public void testAddedDeploymentInfo2() throws Exception { + GridCacheContext ctx = cacheContext(); + + assertTrue(ctx.deploymentEnabled()); + + GridCacheIoManager ioMgr = cacheIoManager(); + + TestMessage msg = new TestMessage(); + + assertNull(msg.deployInfo()); + + msg.cacheId(ctx.cacheId()); + + IgniteUtils.invoke(GridCacheIoManager.class, ioMgr, "onSend", msg, grid(1).cluster().localNode().id()); + + assertNotNull(msg.deployInfo()); + } + + /** + * @throws Exception In case of error. + */ + public void testDeploymentInfoException() throws Exception { + GridCacheIoManager ioMgr = cacheIoManager(); + + TestMessage msg = new TestMessage(); + + assertNull(msg.deployInfo()); + + try { + IgniteUtils.invoke(GridCacheIoManager.class, ioMgr, "onSend", msg, grid(1).cluster().localNode().id()); + } + catch (IgniteCheckedException e) { + assert e.getCause().getCause().getMessage().contains("Deployment related info is missing in message"); + + return; + } + + assert false; + } + + protected GridCacheContext cacheContext() { + return ((IgniteCacheProxy)grid(0).cache(null)).context(); + } + + protected GridCacheIoManager cacheIoManager() { + return grid(0).context().cache().context().io(); } /** * Test message class. */ - private static class TestMessage extends GridCacheMessage { + public static class TestMessage extends GridCacheMessage implements GridCacheDeployable { /** */ - public static final byte DIRECT_TYPE = (byte)202; + public static final byte DIRECT_TYPE = (byte)302; @Override public byte directType() { return DIRECT_TYPE; @@ -117,4 +209,9 @@ public class GridCacheConditionalDeploymentSelfTest extends GridCommonAbstractTe return 3; } } + + /** */ + private static class TestValue { + + } } http://git-wip-us.apache.org/repos/asf/ignite/blob/696e183c/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite3.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite3.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite3.java index 02a7f7f..08c0c75 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite3.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite3.java @@ -18,6 +18,7 @@ package org.apache.ignite.testsuites; import junit.framework.TestSuite; +import org.apache.ignite.internal.processors.cache.GridCacheConditionalDeploymentSelfTest; import org.apache.ignite.internal.processors.cache.GridCacheDeploymentOffHeapSelfTest; import org.apache.ignite.internal.processors.cache.GridCacheDeploymentSelfTest; import org.apache.ignite.internal.processors.cache.GridCacheEntryVersionSelfTest; @@ -116,6 +117,7 @@ public class IgniteCacheTestSuite3 extends TestSuite { suite.addTestSuite(GridCacheDeploymentSelfTest.class); suite.addTestSuite(GridCacheDeploymentOffHeapSelfTest.class); + suite.addTestSuite(GridCacheConditionalDeploymentSelfTest.class); suite.addTestSuite(GridCachePutArrayValueSelfTest.class); suite.addTestSuite(GridCacheReplicatedUnswapAdvancedSelfTest.class); @@ -183,4 +185,4 @@ public class IgniteCacheTestSuite3 extends TestSuite { return suite; } -} \ No newline at end of file +}
