sashapolo commented on a change in pull request #135: URL: https://github.com/apache/ignite-3/pull/135#discussion_r637086926
########## File path: modules/network/src/integrationTest/java/org/apache/ignite/network/internal/recovery/RecoveryHandshakeTest.java ########## @@ -0,0 +1,327 @@ +/* + * 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.network.internal.recovery; + +import io.netty.channel.Channel; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.network.TestMessage; +import org.apache.ignite.network.TestMessageSerializationFactory; +import org.apache.ignite.network.internal.handshake.HandshakeAction; +import org.apache.ignite.network.internal.netty.ConnectionManager; +import org.apache.ignite.network.internal.netty.NettySender; +import org.apache.ignite.network.internal.netty.NettyUtils; +import org.apache.ignite.network.internal.recovery.message.HandshakeStartMessage; +import org.apache.ignite.network.internal.recovery.message.HandshakeStartMessageSerializationFactory; +import org.apache.ignite.network.internal.recovery.message.HandshakeStartResponseMessage; +import org.apache.ignite.network.internal.recovery.message.HandshakeStartResponseMessageSerializationFactory; +import org.apache.ignite.network.message.MessageSerializationRegistry; +import org.apache.ignite.network.message.NetworkMessage; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail.CLIENT_CONNECTION_OPENED; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail.CLIENT_DOESNT_FAIL; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail.CLIENT_INIT; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail.CLIENT_SERVER_RESPONDED; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail.SERVER_CLIENT_RESPONDED; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail.SERVER_CONNECTION_OPENED; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail.SERVER_DOESNT_FAIL; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail.SERVER_INIT; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * Recovery protocol handshake tests. + */ +public class RecoveryHandshakeTest { + /** Started connection managers. */ + private final List<ConnectionManager> startedManagers = new ArrayList<>(); + + /** */ + @AfterEach + final void tearDown() { + startedManagers.forEach(ConnectionManager::stop); + } + + /** + * Tests handshake scenarios in which some of the parts of handshake protocol are failed. Review comment: ```suggestion * Tests handshake scenarios in which some of the parts of handshake protocol can fail. ``` ########## File path: modules/network/src/integrationTest/java/org/apache/ignite/network/internal/recovery/RecoveryHandshakeTest.java ########## @@ -0,0 +1,327 @@ +/* + * 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.network.internal.recovery; + +import io.netty.channel.Channel; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.network.TestMessage; +import org.apache.ignite.network.TestMessageSerializationFactory; +import org.apache.ignite.network.internal.handshake.HandshakeAction; +import org.apache.ignite.network.internal.netty.ConnectionManager; +import org.apache.ignite.network.internal.netty.NettySender; +import org.apache.ignite.network.internal.netty.NettyUtils; +import org.apache.ignite.network.internal.recovery.message.HandshakeStartMessage; +import org.apache.ignite.network.internal.recovery.message.HandshakeStartMessageSerializationFactory; +import org.apache.ignite.network.internal.recovery.message.HandshakeStartResponseMessage; +import org.apache.ignite.network.internal.recovery.message.HandshakeStartResponseMessageSerializationFactory; +import org.apache.ignite.network.message.MessageSerializationRegistry; +import org.apache.ignite.network.message.NetworkMessage; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail.CLIENT_CONNECTION_OPENED; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail.CLIENT_DOESNT_FAIL; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail.CLIENT_INIT; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail.CLIENT_SERVER_RESPONDED; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail.SERVER_CLIENT_RESPONDED; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail.SERVER_CONNECTION_OPENED; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail.SERVER_DOESNT_FAIL; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail.SERVER_INIT; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * Recovery protocol handshake tests. + */ +public class RecoveryHandshakeTest { + /** Started connection managers. */ + private final List<ConnectionManager> startedManagers = new ArrayList<>(); + + /** */ + @AfterEach + final void tearDown() { + startedManagers.forEach(ConnectionManager::stop); + } + + /** + * Tests handshake scenarios in which some of the parts of handshake protocol are failed. + * + * @param scenario Handshake scenario. + * @throws Exception If failed. + */ + @ParameterizedTest + @MethodSource("handshakeScenarios") + public void testHandshakeScenario(HandshakeScenario scenario) throws Exception { + ConnectionManager manager1 = startManager( + 4000, + scenario.serverFailAt, + CLIENT_DOESNT_FAIL + ); + + ConnectionManager manager2 = startManager( + 4001, + SERVER_DOESNT_FAIL, + scenario.clientFailAt + ); + + NettySender from2to1; + + try { + from2to1 = manager2.channel(manager1.consistentId(), manager1.getLocalAddress()).get(3, TimeUnit.SECONDS); + } + catch (Exception e) { + if (scenario.clientFailAt == CLIENT_DOESNT_FAIL && + scenario.serverFailAt == SERVER_DOESNT_FAIL) + Assertions.fail(e); + + return; + } + + if (scenario.serverFailAt == SERVER_CLIENT_RESPONDED && scenario.clientFailAt == CLIENT_DOESNT_FAIL) { + // Special case: the client assumes a handshake has been finished, but the server fails on client's response. + // The server will then close a connection and the client should get the "connection closed event". + NettyUtils.toCompletableFuture(from2to1.channel().closeFuture()).get(3, TimeUnit.SECONDS); Review comment: no need for NettyUtils here ########## File path: modules/network/src/integrationTest/java/org/apache/ignite/network/internal/recovery/RecoveryHandshakeTest.java ########## @@ -0,0 +1,327 @@ +/* + * 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.network.internal.recovery; + +import io.netty.channel.Channel; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.network.TestMessage; +import org.apache.ignite.network.TestMessageSerializationFactory; +import org.apache.ignite.network.internal.handshake.HandshakeAction; +import org.apache.ignite.network.internal.netty.ConnectionManager; +import org.apache.ignite.network.internal.netty.NettySender; +import org.apache.ignite.network.internal.netty.NettyUtils; +import org.apache.ignite.network.internal.recovery.message.HandshakeStartMessage; +import org.apache.ignite.network.internal.recovery.message.HandshakeStartMessageSerializationFactory; +import org.apache.ignite.network.internal.recovery.message.HandshakeStartResponseMessage; +import org.apache.ignite.network.internal.recovery.message.HandshakeStartResponseMessageSerializationFactory; +import org.apache.ignite.network.message.MessageSerializationRegistry; +import org.apache.ignite.network.message.NetworkMessage; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail.CLIENT_CONNECTION_OPENED; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail.CLIENT_DOESNT_FAIL; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail.CLIENT_INIT; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail.CLIENT_SERVER_RESPONDED; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail.SERVER_CLIENT_RESPONDED; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail.SERVER_CONNECTION_OPENED; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail.SERVER_DOESNT_FAIL; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail.SERVER_INIT; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * Recovery protocol handshake tests. + */ +public class RecoveryHandshakeTest { + /** Started connection managers. */ + private final List<ConnectionManager> startedManagers = new ArrayList<>(); + + /** */ + @AfterEach + final void tearDown() { + startedManagers.forEach(ConnectionManager::stop); + } + + /** + * Tests handshake scenarios in which some of the parts of handshake protocol are failed. + * + * @param scenario Handshake scenario. + * @throws Exception If failed. + */ + @ParameterizedTest + @MethodSource("handshakeScenarios") + public void testHandshakeScenario(HandshakeScenario scenario) throws Exception { + ConnectionManager manager1 = startManager( + 4000, + scenario.serverFailAt, + CLIENT_DOESNT_FAIL + ); + + ConnectionManager manager2 = startManager( + 4001, + SERVER_DOESNT_FAIL, + scenario.clientFailAt + ); + + NettySender from2to1; + + try { + from2to1 = manager2.channel(manager1.consistentId(), manager1.getLocalAddress()).get(3, TimeUnit.SECONDS); + } + catch (Exception e) { + if (scenario.clientFailAt == CLIENT_DOESNT_FAIL && + scenario.serverFailAt == SERVER_DOESNT_FAIL) + Assertions.fail(e); + + return; + } + + if (scenario.serverFailAt == SERVER_CLIENT_RESPONDED && scenario.clientFailAt == CLIENT_DOESNT_FAIL) { + // Special case: the client assumes a handshake has been finished, but the server fails on client's response. + // The server will then close a connection and the client should get the "connection closed event". + NettyUtils.toCompletableFuture(from2to1.channel().closeFuture()).get(3, TimeUnit.SECONDS); + return; + } + + if (scenario.clientFailAt != CLIENT_DOESNT_FAIL || scenario.serverFailAt != SERVER_DOESNT_FAIL) Review comment: I would suggest extracting this condition into a method ########## File path: modules/network/src/integrationTest/java/org/apache/ignite/network/internal/recovery/RecoveryHandshakeTest.java ########## @@ -0,0 +1,327 @@ +/* + * 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.network.internal.recovery; + +import io.netty.channel.Channel; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.network.TestMessage; +import org.apache.ignite.network.TestMessageSerializationFactory; +import org.apache.ignite.network.internal.handshake.HandshakeAction; +import org.apache.ignite.network.internal.netty.ConnectionManager; +import org.apache.ignite.network.internal.netty.NettySender; +import org.apache.ignite.network.internal.netty.NettyUtils; +import org.apache.ignite.network.internal.recovery.message.HandshakeStartMessage; +import org.apache.ignite.network.internal.recovery.message.HandshakeStartMessageSerializationFactory; +import org.apache.ignite.network.internal.recovery.message.HandshakeStartResponseMessage; +import org.apache.ignite.network.internal.recovery.message.HandshakeStartResponseMessageSerializationFactory; +import org.apache.ignite.network.message.MessageSerializationRegistry; +import org.apache.ignite.network.message.NetworkMessage; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail.CLIENT_CONNECTION_OPENED; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail.CLIENT_DOESNT_FAIL; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail.CLIENT_INIT; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryClientHandshakeManager.ClientStageFail.CLIENT_SERVER_RESPONDED; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail.SERVER_CLIENT_RESPONDED; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail.SERVER_CONNECTION_OPENED; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail.SERVER_DOESNT_FAIL; +import static org.apache.ignite.network.internal.recovery.RecoveryHandshakeTest.FailingRecoveryServerHandshakeManager.ServerStageFail.SERVER_INIT; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * Recovery protocol handshake tests. + */ +public class RecoveryHandshakeTest { + /** Started connection managers. */ + private final List<ConnectionManager> startedManagers = new ArrayList<>(); + + /** */ + @AfterEach + final void tearDown() { + startedManagers.forEach(ConnectionManager::stop); + } + + /** + * Tests handshake scenarios in which some of the parts of handshake protocol are failed. + * + * @param scenario Handshake scenario. + * @throws Exception If failed. + */ + @ParameterizedTest + @MethodSource("handshakeScenarios") + public void testHandshakeScenario(HandshakeScenario scenario) throws Exception { + ConnectionManager manager1 = startManager( + 4000, + scenario.serverFailAt, + CLIENT_DOESNT_FAIL Review comment: What does failing some parts actually test? I don't see any particular assertions related to it -- 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]
