use of org.apache.ignite.internal.processors.resource.DependencyResolver in project ignite by apache.
the class TcpCommunicationHandshakeTimeoutTest method testSocketForcedClosedBecauseSlowReadFromSocket.
/**
* 1. Cluster from three nodes.
* 2. Waiting when communication connection goes idle.
* 4. Configure the delay during the communication connection handshake.
* 5. Force establishing of new connection from node2 to node1 from timeout object processor thread
* (it use compute in this test).
* 6. Expected: The frozen attempt of handshake would be successfully handled and a new connection
* would be established.
*
* @throws Exception If fail.
*/
@Test
public void testSocketForcedClosedBecauseSlowReadFromSocket() throws Exception {
// given: Two ordinary nodes.
startGrid(0);
IgniteEx g1 = startGrid(1);
// and: One more node which communication connection can be delayed by demand.
AtomicBoolean delayHandshakeUntilSocketClosed = new AtomicBoolean();
IgniteEx g2 = startGrid(2, new DependencyResolver() {
@Override
public <T> T resolve(T instance) {
if (instance instanceof TcpHandshakeExecutor) {
TcpHandshakeExecutor gridNioServer = (TcpHandshakeExecutor) instance;
return (T) new DelaydTcpHandshakeExecutor(gridNioServer, delayHandshakeUntilSocketClosed);
}
return instance;
}
});
awaitPartitionMapExchange();
AtomicBoolean result = new AtomicBoolean(false);
// Wait for connections go idle.
doSleep(1000);
// when: Initiate communication connection from timeout object processor thread.
g2.context().timeout().addTimeoutObject(new GridTimeoutObjectAdapter(0) {
@Override
public void onTimeout() {
delayHandshakeUntilSocketClosed.set(true);
g2.compute(g2.cluster().forNodes(Arrays.asList(g1.localNode()))).withNoFailover().call(() -> true);
result.set(true);
}
});
// then: Despite the first attempt of handshake would be frozen the compute should be handled well eventually.
assertTrue("Compute should be successfully handled.", waitForCondition(result::get, 20_000));
}
Aggregations