Repository: incubator-ignite Updated Branches: refs/heads/ignite-901 8cafff66f -> 38c783780
IGNITE-901 Added tests. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/38c78378 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/38c78378 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/38c78378 Branch: refs/heads/ignite-901 Commit: 38c7837807357ac5a831d8ab7278c892fd009041 Parents: 8cafff6 Author: nikolay_tikhonov <ntikho...@gridgain.com> Authored: Fri Jul 3 18:01:29 2015 +0300 Committer: nikolay_tikhonov <ntikho...@gridgain.com> Committed: Fri Jul 3 18:01:29 2015 +0300 ---------------------------------------------------------------------- .../IgniteClientReconnectComputeTest.java | 146 ++++++++++++++++++- 1 file changed, 144 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/38c78378/modules/core/src/test/java/org/apache/ignite/internal/IgniteClientReconnectComputeTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteClientReconnectComputeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteClientReconnectComputeTest.java index 01eb2ca..186459e 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/IgniteClientReconnectComputeTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteClientReconnectComputeTest.java @@ -17,6 +17,13 @@ package org.apache.ignite.internal; +import org.apache.ignite.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.testframework.*; + +import java.util.*; +import java.util.concurrent.*; + /** * */ @@ -26,10 +33,145 @@ public class IgniteClientReconnectComputeTest extends IgniteClientReconnectAbstr return 1; } + /** {@inheritDoc} */ + @Override protected int clientCount() { + return 1; + } + /** * @throws Exception If failed. */ - public void testReconnectOperationInProgress() throws Exception { - // TODO IGNITE-901. + public void testReconnectAffCallInProgress() throws Exception { + final Ignite client = grid(serverCount()); + + assertTrue(client.cluster().localNode().isClient()); + + Ignite srv = clientRouter(client); + + IgniteCache<Integer, Integer> cache = client.getOrCreateCache("test-cache"); + + for (int i = 0; i < 100; i++) + cache.put(i, i); + + BlockTpcCommunicationSpi commSpi = commSpi(srv); + + commSpi.blockMsg(GridJobExecuteResponse.class); + + final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() { + @Override public Object call() throws Exception { + return client.compute().affinityCall("test-cache", 40, new IgniteCallable<Object>() { + @Override public Integer call() throws Exception { + return 42; + } + }); + } + }); + + // Check that client waiting operation. + GridTestUtils.assertThrows(log, new Callable<Object>() { + @Override public Object call() throws Exception { + return fut.get(200); + } + }, IgniteFutureTimeoutCheckedException.class, null); + + assertNotDone(fut); + + commSpi.unblockMsg(); + + reconnectClientNode(client, srv, new Runnable() { + @Override public void run() { + // Check that future failed. + assertNotNull(fut.error()); + assertEquals(IgniteClientDisconnectedException.class, fut.error().getClass()); + } + }); + } + + /** + * @throws Exception If failed. + */ + public void testReconnectBroadcastInProgress() throws Exception { + final Ignite client = grid(serverCount()); + + assertTrue(client.cluster().localNode().isClient()); + + Ignite srv = clientRouter(client); + + BlockTpcCommunicationSpi commSpi = commSpi(srv); + + commSpi.blockMsg(GridJobExecuteResponse.class); + + final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() { + @Override public Object call() throws Exception { + return client.compute().broadcast(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return 42; + } + }); + } + }); + + // Check that client waiting operation. + GridTestUtils.assertThrows(log, new Callable<Object>() { + @Override public Object call() throws Exception { + return fut.get(200); + } + }, IgniteFutureTimeoutCheckedException.class, null); + + assertNotDone(fut); + + commSpi.unblockMsg(); + + reconnectClientNode(client, srv, new Runnable() { + @Override public void run() { + // Check that future failed. + assertNotNull(fut.error()); + assertEquals(IgniteClientDisconnectedException.class, fut.error().getClass()); + } + }); + } + + /** + * @throws Exception If failed. + */ + public void testReconnectApplyInProgress() throws Exception { + final Ignite client = grid(serverCount()); + + assertTrue(client.cluster().localNode().isClient()); + + Ignite srv = clientRouter(client); + + BlockTpcCommunicationSpi commSpi = commSpi(srv); + + commSpi.blockMsg(GridJobExecuteResponse.class); + + final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() { + @Override public Object call() throws Exception { + return client.compute().apply(new IgniteClosure<Integer, Integer>() { + @Override public Integer apply(Integer o) { + return o + 1; + } + }, Arrays.asList(1, 2, 3)); + } + }); + + // Check that client waiting operation. + GridTestUtils.assertThrows(log, new Callable<Object>() { + @Override public Object call() throws Exception { + return fut.get(200); + } + }, IgniteFutureTimeoutCheckedException.class, null); + + assertNotDone(fut); + + commSpi.unblockMsg(); + + reconnectClientNode(client, srv, new Runnable() { + @Override public void run() { + // Check that future failed. + assertNotNull(fut.error()); + assertEquals(IgniteClientDisconnectedException.class, fut.error().getClass()); + } + }); } }