blob: c0fe40a9efbb5bc0bf8acd270b1a36f9e6012def [file] [log] [blame]
/*
* 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;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteClientDisconnectedException;
import org.apache.ignite.lang.IgniteCallable;
import org.apache.ignite.lang.IgniteClosure;
import org.apache.ignite.testframework.GridTestUtils;
import org.junit.Test;
/**
*
*/
public class IgniteClientReconnectComputeTest extends IgniteClientReconnectAbstractTest {
/** {@inheritDoc} */
@Override protected int serverCount() {
return 1;
}
/** {@inheritDoc} */
@Override protected int clientCount() {
return 1;
}
/**
* @throws Exception If failed.
*/
@Test
public void testReconnectAffinityCallInProgress() throws Exception {
final Ignite client = grid(serverCount());
assertTrue(client.cluster().localNode().isClient());
Ignite srv = ignite(0);
IgniteCache<Integer, Integer> cache = client.getOrCreateCache("test-cache");
for (int i = 0; i < 100; i++)
cache.put(i, i);
BlockTcpCommunicationSpi commSpi = commSpi(srv);
commSpi.blockMessage(GridJobExecuteResponse.class);
final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {
@Override public Object call() throws Exception {
try {
client.compute().affinityCall("test-cache", 40, new IgniteCallable<Object>() {
@Override public Integer call() throws Exception {
return 42;
}
});
}
catch (IgniteClientDisconnectedException e) {
checkAndWait(e);
return true;
}
return false;
}
});
// 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.unblockMessage();
reconnectClientNode(client, srv, null);
assertTrue((Boolean)fut.get(2, TimeUnit.SECONDS));
}
/**
* @throws Exception If failed.
*/
@Test
public void testReconnectBroadcastInProgress() throws Exception {
final Ignite client = grid(serverCount());
assertTrue(client.cluster().localNode().isClient());
Ignite srv = ignite(0);
BlockTcpCommunicationSpi commSpi = commSpi(srv);
commSpi.blockMessage(GridJobExecuteResponse.class);
final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {
@Override public Object call() throws Exception {
try {
client.compute().broadcast(new IgniteCallable<Object>() {
@Override public Object call() throws Exception {
return 42;
}
});
}
catch (IgniteClientDisconnectedException e) {
checkAndWait(e);
return true;
}
return false;
}
});
// 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.unblockMessage();
reconnectClientNode(client, srv, null);
assertTrue((Boolean)fut.get(2, TimeUnit.SECONDS));
}
/**
* @throws Exception If failed.
*/
@Test
public void testReconnectApplyInProgress() throws Exception {
final Ignite client = grid(serverCount());
assertTrue(client.cluster().localNode().isClient());
Ignite srv = ignite(0);
BlockTcpCommunicationSpi commSpi = commSpi(srv);
commSpi.blockMessage(GridJobExecuteResponse.class);
final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {
@Override public Object call() throws Exception {
try {
client.compute().apply(new IgniteClosure<Integer, Integer>() {
@Override public Integer apply(Integer o) {
return o + 1;
}
}, Arrays.asList(1, 2, 3));
}
catch (IgniteClientDisconnectedException e) {
checkAndWait(e);
return true;
}
return false;
}
});
// 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.unblockMessage();
reconnectClientNode(client, srv, null);
assertTrue((Boolean)fut.get(2, TimeUnit.SECONDS));
}
}