anton-vinogradov commented on a change in pull request #8881:
URL: https://github.com/apache/ignite/pull/8881#discussion_r643000714
##########
File path:
modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
##########
@@ -8220,14 +8248,19 @@ public void sock(Socket sock) {
/** */
private int failedNodes;
- /** */
- private final long failTimeNanos;
+ /** Maximal time point for any recovery operation. Nanos. */
+ private final long absoluteTimeout;
+
+ /** Time of the failure in nanos. */
+ private final long failTime;
Review comment:
never used
##########
File path:
modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
##########
@@ -412,6 +416,58 @@ public void testFailureDetectionOnNodePing2() throws
Exception {
}
}
+ /**
+ * Checks that node leaves the cluster after lose of outgoing connections.
+ *
+ * @throws Exception If any error occurs.
+ */
+ @Test
+ public void testOutgoingConnectionsFailure() throws Exception {
+ try {
+ final int gridCnt = 4;
+
+ failureDetectionTimeout = 2000;
+
+ startGrids(gridCnt - 1);
+
+ nodeSpi.set(new FailureSimulatingTcpDiscoverySpi());
+
+ startGrid(gridCnt - 1);
+
+ UUID failingNodeId = grid(gridCnt - 1).localNode().id();
+
+ CountDownLatch testWaiter = new CountDownLatch(gridCnt - 1);
+
+ for (int i = 0; i < gridCnt - 1; ++i) {
Review comment:
++i in a loop is a new cool trend or this make some sense? %)
Anyway, this can be simplified to allGrids() loop if set before the last
node startup.
##########
File path:
modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
##########
@@ -1642,24 +1642,29 @@ Socket createSocket() throws IOException {
Socket sock = null;
try {
- if (isSslEnabled())
- sock = sslSockFactory.createSocket();
- else
- sock = new Socket();
+ sock = createSocket0();
sock.bind(new InetSocketAddress(locHost, 0));
configureSocketOptions(sock);
return sock;
- } catch (IOException e) {
+ }
+ catch (IOException e) {
if (sock != null)
U.closeQuiet(sock);
throw e;
}
}
+ /**
+ * Creates proper socket.
+ */
+ protected Socket createSocket0() throws IOException {
Review comment:
any reason to enlarge file size with single used single line method?
##########
File path:
modules/core/src/test/java/org/apache/ignite/util/FailureSimulatingTcpDiscoverySpi.java
##########
@@ -0,0 +1,404 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import java.net.SocketTimeoutException;
+import java.nio.channels.SocketChannel;
+import org.apache.ignite.internal.util.lang.IgnitePair;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * The TcpDiscovery able to simulate network failure.
+ */
+public class FailureSimulatingTcpDiscoverySpi extends TcpDiscoverySpi {
Review comment:
NetworkFailure*?
##########
File path:
modules/core/src/test/java/org/apache/ignite/util/FailureSimulatingTcpDiscoverySpi.java
##########
@@ -0,0 +1,404 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import java.net.SocketTimeoutException;
+import java.nio.channels.SocketChannel;
+import org.apache.ignite.internal.util.lang.IgnitePair;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * The TcpDiscovery able to simulate network failure.
+ */
+public class FailureSimulatingTcpDiscoverySpi extends TcpDiscoverySpi {
+ /**
+ * If not {@code null}, enables network timeout simulation. First value
switches traffic droppage: negative for all
+ * incoming, positive for all outgoing, 0 for both.
+ */
+ protected volatile IgnitePair<Integer> simulatedTimeout;
+
+ /** {@inheritDoc} */
+ @Override protected Socket createSocket0() throws IOException {
+ return new SocketWrap(super.createSocket0());
+ }
+
+ /**
+ * Enables simulation of network timeout.
+ *
+ * @param direction If negative, enables timeout simulation for incomming
traffic. If positive, enables timeout
+ * simulation for outgoing traffic. Set 0 to simlate
failure for both traffics.
+ * @param delay Milliseconds of awaiting before raising {@code
SocketTimeoutException}.
+ * @see SocketWrap#simulateTimeout(Socket, int)
+ */
+ public void enableNetworkTimeoutSimulation(int direction, int delay) {
+ simulatedTimeout = new IgnitePair<>(direction, delay);
+ }
+
+ /**
+ * Simulates network timeout if enabled, raises {@code
SocketTimeoutException}.
+ *
+ * @param sock The socket to simulate failure at.
+ * @param forceTimeout If positive of 0, overrides the delay preset in
{@link #enableNetworkTimeoutSimulation(int,
+ * int)}.
+ * @see #enableNetworkTimeoutSimulation(int, int)
+ */
+ private void simulateTimeout(Socket sock, int forceTimeout) throws
SocketTimeoutException {
Review comment:
forceTimeout always -1
add usages or remove the param
##########
File path:
modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
##########
@@ -412,6 +416,58 @@ public void testFailureDetectionOnNodePing2() throws
Exception {
}
}
+ /**
+ * Checks that node leaves the cluster after lose of outgoing connections.
+ *
+ * @throws Exception If any error occurs.
+ */
+ @Test
+ public void testOutgoingConnectionsFailure() throws Exception {
+ try {
+ final int gridCnt = 4;
+
+ failureDetectionTimeout = 2000;
+
+ startGrids(gridCnt - 1);
+
+ nodeSpi.set(new FailureSimulatingTcpDiscoverySpi());
+
+ startGrid(gridCnt - 1);
+
+ UUID failingNodeId = grid(gridCnt - 1).localNode().id();
+
+ CountDownLatch testWaiter = new CountDownLatch(gridCnt - 1);
+
+ for (int i = 0; i < gridCnt - 1; ++i) {
+ grid(0).events().localListen(new IgnitePredicate<Event>() {
+ @Override public boolean apply(Event evt) {
+ if (evt.type() == EventType.EVT_NODE_FAILED
+ &&
failingNodeId.equals(((DiscoveryEvent)evt).eventNode().id()))
+ testWaiter.countDown();
+
+ return false;
+ }
+ }, EVT_NODE_FAILED);
+ }
+
+ FailureSimulatingTcpDiscoverySpi failSpi =
((FailureSimulatingTcpDiscoverySpi)grid(gridCnt - 1)
Review comment:
We should now wait for some time.
We should do this as a real system when write happens but data filtered by
rules.
##########
File path:
modules/core/src/test/java/org/apache/ignite/util/FailureSimulatingTcpDiscoverySpi.java
##########
@@ -0,0 +1,404 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import java.net.SocketTimeoutException;
+import java.nio.channels.SocketChannel;
+import org.apache.ignite.internal.util.lang.IgnitePair;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * The TcpDiscovery able to simulate network failure.
+ */
+public class FailureSimulatingTcpDiscoverySpi extends TcpDiscoverySpi {
+ /**
+ * If not {@code null}, enables network timeout simulation. First value
switches traffic droppage: negative for all
+ * incoming, positive for all outgoing, 0 for both.
+ */
+ protected volatile IgnitePair<Integer> simulatedTimeout;
+
+ /** {@inheritDoc} */
+ @Override protected Socket createSocket0() throws IOException {
+ return new SocketWrap(super.createSocket0());
+ }
+
+ /**
+ * Enables simulation of network timeout.
+ *
+ * @param direction If negative, enables timeout simulation for incomming
traffic. If positive, enables timeout
+ * simulation for outgoing traffic. Set 0 to simlate
failure for both traffics.
+ * @param delay Milliseconds of awaiting before raising {@code
SocketTimeoutException}.
+ * @see SocketWrap#simulateTimeout(Socket, int)
+ */
+ public void enableNetworkTimeoutSimulation(int direction, int delay) {
Review comment:
this method is a setter.
let's call it setNetworkTimeout(..)
##########
File path:
modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
##########
@@ -412,6 +416,58 @@ public void testFailureDetectionOnNodePing2() throws
Exception {
}
}
+ /**
+ * Checks that node leaves the cluster after lose of outgoing connections.
+ *
+ * @throws Exception If any error occurs.
+ */
+ @Test
+ public void testOutgoingConnectionsFailure() throws Exception {
+ try {
+ final int gridCnt = 4;
+
+ failureDetectionTimeout = 2000;
+
+ startGrids(gridCnt - 1);
+
+ nodeSpi.set(new FailureSimulatingTcpDiscoverySpi());
+
+ startGrid(gridCnt - 1);
+
+ UUID failingNodeId = grid(gridCnt - 1).localNode().id();
+
+ CountDownLatch testWaiter = new CountDownLatch(gridCnt - 1);
+
+ for (int i = 0; i < gridCnt - 1; ++i) {
+ grid(0).events().localListen(new IgnitePredicate<Event>() {
+ @Override public boolean apply(Event evt) {
+ if (evt.type() == EventType.EVT_NODE_FAILED
Review comment:
you're listening for this event type only
##########
File path:
modules/core/src/test/java/org/apache/ignite/util/FailureSimulatingTcpDiscoverySpi.java
##########
@@ -0,0 +1,404 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import java.net.SocketTimeoutException;
+import java.nio.channels.SocketChannel;
+import org.apache.ignite.internal.util.lang.IgnitePair;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * The TcpDiscovery able to simulate network failure.
+ */
+public class FailureSimulatingTcpDiscoverySpi extends TcpDiscoverySpi {
+ /**
+ * If not {@code null}, enables network timeout simulation. First value
switches traffic droppage: negative for all
+ * incoming, positive for all outgoing, 0 for both.
+ */
+ protected volatile IgnitePair<Integer> simulatedTimeout;
+
+ /** {@inheritDoc} */
+ @Override protected Socket createSocket0() throws IOException {
+ return new SocketWrap(super.createSocket0());
+ }
+
+ /**
+ * Enables simulation of network timeout.
+ *
+ * @param direction If negative, enables timeout simulation for incomming
traffic. If positive, enables timeout
+ * simulation for outgoing traffic. Set 0 to simlate
failure for both traffics.
+ * @param delay Milliseconds of awaiting before raising {@code
SocketTimeoutException}.
+ * @see SocketWrap#simulateTimeout(Socket, int)
+ */
+ public void enableNetworkTimeoutSimulation(int direction, int delay) {
+ simulatedTimeout = new IgnitePair<>(direction, delay);
+ }
+
+ /**
+ * Simulates network timeout if enabled, raises {@code
SocketTimeoutException}.
+ *
+ * @param sock The socket to simulate failure at.
+ * @param forceTimeout If positive of 0, overrides the delay preset in
{@link #enableNetworkTimeoutSimulation(int,
+ * int)}.
+ * @see #enableNetworkTimeoutSimulation(int, int)
+ */
+ private void simulateTimeout(Socket sock, int forceTimeout) throws
SocketTimeoutException {
+ IgnitePair<Integer> simulatedTimeout = this.simulatedTimeout;
+
+ if (simulatedTimeout == null)
+ return;
+
+ boolean isClientSock = sock.getLocalPort() < locPort ||
sock.getLocalPort() > locPort + locPortRange;
+
+ if (isClientSock && simulatedTimeout.get1() < 0 || !isClientSock &&
simulatedTimeout.get1() > 0)
+ return;
+
+ int timeout = forceTimeout >= 0 ? forceTimeout :
simulatedTimeout.get2();
+
+ try {
+ Thread.sleep(timeout);
+ }
+ catch (InterruptedException ignored) {
+ // No-op.
+ }
+
+ throw new SocketTimeoutException("Simulated failure after delay: " +
timeout + "ms.");
+ }
+
+ /**
+ * @see #simulateTimeout(Socket, int)
+ */
+ private void simulateTimeout(Socket sock) throws SocketTimeoutException {
+ simulateTimeout(sock, -1);
+ }
+
+ /**
+ * Network failure simulator.
+ */
+ private class SocketWrap extends Socket {
+ /** The real socket to simulate failure of. */
+ private final Socket delegate;
+
+ /**
+ * Constructor.
+ *
+ * @param sock The real socket to simulate failure of.
+ */
+ private SocketWrap(Socket sock) {
+ delegate = sock;
+ }
+
+ /** {@inheritDoc} */
+ @Override public OutputStream getOutputStream() throws IOException {
+ OutputStream src = delegate.getOutputStream();
+
+ return new OutputStream() {
+ /** {@inheritDoc} */
+ @Override public void write(@NotNull byte[] b) throws
IOException {
+ simulateTimeout(delegate);
+
+ src.write(b);
Review comment:
Such a simulation looks incorrect to me.
We should just avoid writing (emulating iptables filtering) and exception
should be generated by real TcpDiscoverySPI
##########
File path:
modules/core/src/test/java/org/apache/ignite/util/FailureSimulatingTcpDiscoverySpi.java
##########
@@ -0,0 +1,404 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import java.net.SocketTimeoutException;
+import java.nio.channels.SocketChannel;
+import org.apache.ignite.internal.util.lang.IgnitePair;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * The TcpDiscovery able to simulate network failure.
+ */
+public class FailureSimulatingTcpDiscoverySpi extends TcpDiscoverySpi {
+ /**
+ * If not {@code null}, enables network timeout simulation. First value
switches traffic droppage: negative for all
+ * incoming, positive for all outgoing, 0 for both.
+ */
+ protected volatile IgnitePair<Integer> simulatedTimeout;
+
+ /** {@inheritDoc} */
+ @Override protected Socket createSocket0() throws IOException {
+ return new SocketWrap(super.createSocket0());
+ }
+
+ /**
+ * Enables simulation of network timeout.
+ *
+ * @param direction If negative, enables timeout simulation for incomming
traffic. If positive, enables timeout
+ * simulation for outgoing traffic. Set 0 to simlate
failure for both traffics.
+ * @param delay Milliseconds of awaiting before raising {@code
SocketTimeoutException}.
+ * @see SocketWrap#simulateTimeout(Socket, int)
+ */
+ public void enableNetworkTimeoutSimulation(int direction, int delay) {
+ simulatedTimeout = new IgnitePair<>(direction, delay);
+ }
+
+ /**
+ * Simulates network timeout if enabled, raises {@code
SocketTimeoutException}.
+ *
+ * @param sock The socket to simulate failure at.
+ * @param forceTimeout If positive of 0, overrides the delay preset in
{@link #enableNetworkTimeoutSimulation(int,
+ * int)}.
+ * @see #enableNetworkTimeoutSimulation(int, int)
+ */
+ private void simulateTimeout(Socket sock, int forceTimeout) throws
SocketTimeoutException {
+ IgnitePair<Integer> simulatedTimeout = this.simulatedTimeout;
+
+ if (simulatedTimeout == null)
+ return;
+
+ boolean isClientSock = sock.getLocalPort() < locPort ||
sock.getLocalPort() > locPort + locPortRange;
+
+ if (isClientSock && simulatedTimeout.get1() < 0 || !isClientSock &&
simulatedTimeout.get1() > 0)
+ return;
Review comment:
this newer happens at the tests.
how can we be sure this code works?
##########
File path:
modules/core/src/test/java/org/apache/ignite/util/FailureSimulatingTcpDiscoverySpi.java
##########
@@ -0,0 +1,404 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import java.net.SocketTimeoutException;
+import java.nio.channels.SocketChannel;
+import org.apache.ignite.internal.util.lang.IgnitePair;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * The TcpDiscovery able to simulate network failure.
+ */
+public class FailureSimulatingTcpDiscoverySpi extends TcpDiscoverySpi {
+ /**
+ * If not {@code null}, enables network timeout simulation. First value
switches traffic droppage: negative for all
+ * incoming, positive for all outgoing, 0 for both.
+ */
+ protected volatile IgnitePair<Integer> simulatedTimeout;
+
+ /** {@inheritDoc} */
+ @Override protected Socket createSocket0() throws IOException {
+ return new SocketWrap(super.createSocket0());
+ }
+
+ /**
+ * Enables simulation of network timeout.
+ *
+ * @param direction If negative, enables timeout simulation for incomming
traffic. If positive, enables timeout
+ * simulation for outgoing traffic. Set 0 to simlate
failure for both traffics.
+ * @param delay Milliseconds of awaiting before raising {@code
SocketTimeoutException}.
+ * @see SocketWrap#simulateTimeout(Socket, int)
+ */
+ public void enableNetworkTimeoutSimulation(int direction, int delay) {
+ simulatedTimeout = new IgnitePair<>(direction, delay);
+ }
+
+ /**
+ * Simulates network timeout if enabled, raises {@code
SocketTimeoutException}.
+ *
+ * @param sock The socket to simulate failure at.
+ * @param forceTimeout If positive of 0, overrides the delay preset in
{@link #enableNetworkTimeoutSimulation(int,
+ * int)}.
+ * @see #enableNetworkTimeoutSimulation(int, int)
+ */
+ private void simulateTimeout(Socket sock, int forceTimeout) throws
SocketTimeoutException {
+ IgnitePair<Integer> simulatedTimeout = this.simulatedTimeout;
+
+ if (simulatedTimeout == null)
+ return;
+
+ boolean isClientSock = sock.getLocalPort() < locPort ||
sock.getLocalPort() > locPort + locPortRange;
+
+ if (isClientSock && simulatedTimeout.get1() < 0 || !isClientSock &&
simulatedTimeout.get1() > 0)
+ return;
+
+ int timeout = forceTimeout >= 0 ? forceTimeout :
simulatedTimeout.get2();
+
+ try {
+ Thread.sleep(timeout);
+ }
+ catch (InterruptedException ignored) {
+ // No-op.
+ }
+
+ throw new SocketTimeoutException("Simulated failure after delay: " +
timeout + "ms.");
+ }
+
+ /**
+ * @see #simulateTimeout(Socket, int)
+ */
+ private void simulateTimeout(Socket sock) throws SocketTimeoutException {
+ simulateTimeout(sock, -1);
+ }
+
+ /**
+ * Network failure simulator.
+ */
+ private class SocketWrap extends Socket {
+ /** The real socket to simulate failure of. */
+ private final Socket delegate;
+
+ /**
+ * Constructor.
+ *
+ * @param sock The real socket to simulate failure of.
+ */
+ private SocketWrap(Socket sock) {
+ delegate = sock;
+ }
+
+ /** {@inheritDoc} */
+ @Override public OutputStream getOutputStream() throws IOException {
+ OutputStream src = delegate.getOutputStream();
+
+ return new OutputStream() {
+ /** {@inheritDoc} */
+ @Override public void write(@NotNull byte[] b) throws
IOException {
+ simulateTimeout(delegate);
+
+ src.write(b);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void write(@NotNull byte[] b, int off, int
len) throws IOException {
+ simulateTimeout(delegate);
+
+ src.write(b, off, len);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void write(int b) throws IOException {
+ simulateTimeout(delegate);
+
+ src.write(b);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void flush() throws IOException {
+ simulateTimeout(delegate);
+
+ src.flush();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void close() throws IOException {
+ src.close();
+ }
+ };
+ }
+
+ /** {@inheritDoc} */
+ @Override public InputStream getInputStream() throws IOException {
Review comment:
Looks like we never simulate filtered reads.
Even unable to imagine how to simulate this %)
Filtered reads just mean writes were filtered
##########
File path:
modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
##########
@@ -412,6 +416,58 @@ public void testFailureDetectionOnNodePing2() throws
Exception {
}
}
+ /**
+ * Checks that node leaves the cluster after lose of outgoing connections.
+ *
+ * @throws Exception If any error occurs.
+ */
+ @Test
+ public void testOutgoingConnectionsFailure() throws Exception {
+ try {
+ final int gridCnt = 4;
+
+ failureDetectionTimeout = 2000;
+
+ startGrids(gridCnt - 1);
+
+ nodeSpi.set(new FailureSimulatingTcpDiscoverySpi());
+
+ startGrid(gridCnt - 1);
+
+ UUID failingNodeId = grid(gridCnt - 1).localNode().id();
+
+ CountDownLatch testWaiter = new CountDownLatch(gridCnt - 1);
+
+ for (int i = 0; i < gridCnt - 1; ++i) {
+ grid(0).events().localListen(new IgnitePredicate<Event>() {
+ @Override public boolean apply(Event evt) {
+ if (evt.type() == EventType.EVT_NODE_FAILED
+ &&
failingNodeId.equals(((DiscoveryEvent)evt).eventNode().id()))
+ testWaiter.countDown();
+
+ return false;
+ }
+ }, EVT_NODE_FAILED);
+ }
+
+ FailureSimulatingTcpDiscoverySpi failSpi =
((FailureSimulatingTcpDiscoverySpi)grid(gridCnt - 1)
+ .configuration().getDiscoverySpi());
+
+ long simulatedNetDelay = ((TcpDiscoverySpi)grid(gridCnt -
1).configuration()
+ .getDiscoverySpi()).getEffectiveConnectionRecoveryTimeout() /
gridCnt;
+
+ failSpi.enableNetworkTimeoutSimulation(1, (int)simulatedNetDelay);
+
+ testWaiter.await(failureDetectionTimeout * 3, MILLISECONDS);
+
+ for (int i = 0; i < gridCnt - 1; ++i)
+ assert grid(i).cluster().nodes().size() == gridCnt - 1;
Review comment:
we should wait for a condition instead.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]