[ https://issues.apache.org/jira/browse/GEODE-8202?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17241960#comment-17241960 ]
ASF GitHub Bot commented on GEODE-8202: --------------------------------------- DonalEvans commented on a change in pull request #5600: URL: https://github.com/apache/geode/pull/5600#discussion_r533812068 ########## File path: geode-wan/src/test/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcherJUnitTest.java ########## @@ -77,4 +132,160 @@ public void getConnectionShouldCreateNewConnectionWhenServerIsNull() { verify(dispatcher, times(1)).initializeConnection(); verify(dispatcher, times(2)).getConnectionLifeCycleLock(); } + + @Test + public void enforceThreadsConnectSameReceiver_initializeParallelSenderConnection_retriesAreNotUsed() { + when(senderMock.isParallel()).thenReturn(true); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(0)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).setServerLocation(any()); + verify(poolMock, times(1)).acquireConnection(); + verify(dispatcherSpy, times(0)).retryInitializeConnection(connectionMock); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToFalse_retriesAreNotUsed() { Review comment: This test name might be better as "intializeConnectionWithSerialSenderAndEnforceThreadsConnectSameRecieverFalseDoesNotRetryInitializeConnection". ########## File path: geode-wan/src/test/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcherJUnitTest.java ########## @@ -77,4 +132,160 @@ public void getConnectionShouldCreateNewConnectionWhenServerIsNull() { verify(dispatcher, times(1)).initializeConnection(); verify(dispatcher, times(2)).getConnectionLifeCycleLock(); } + + @Test + public void enforceThreadsConnectSameReceiver_initializeParallelSenderConnection_retriesAreNotUsed() { + when(senderMock.isParallel()).thenReturn(true); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(0)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).setServerLocation(any()); + verify(poolMock, times(1)).acquireConnection(); + verify(dispatcherSpy, times(0)).retryInitializeConnection(connectionMock); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToFalse_retriesAreNotUsed() { + when(senderMock.getEnforceThreadsConnectSameReceiver()).thenReturn(false); + + when(connectionMock.getEndpoint()).thenReturn(endpointMock); + when(endpointMock.getMemberId()).thenReturn(memberIdMock); + when(memberIdMock.getUniqueId()).thenReturn("receiverId"); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(1)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).getEnforceThreadsConnectSameReceiver(); + verify(poolMock, times(1)).acquireConnection(); + verify(dispatcherSpy, times(0)).retryInitializeConnection(connectionMock); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToTrue_firstThreadObtainsTheReceiverId() { Review comment: This test might be better named "initializeConnectionWithSerialSenderAndEnforceThreadsConnectSameReceiverTrueAndNoExpectedReceiverSetsReceiverIdAndDoesNotReacquireConnection". ########## File path: geode-wan/src/test/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcherJUnitTest.java ########## @@ -77,4 +132,160 @@ public void getConnectionShouldCreateNewConnectionWhenServerIsNull() { verify(dispatcher, times(1)).initializeConnection(); verify(dispatcher, times(2)).getConnectionLifeCycleLock(); } + + @Test + public void enforceThreadsConnectSameReceiver_initializeParallelSenderConnection_retriesAreNotUsed() { + when(senderMock.isParallel()).thenReturn(true); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(0)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).setServerLocation(any()); + verify(poolMock, times(1)).acquireConnection(); + verify(dispatcherSpy, times(0)).retryInitializeConnection(connectionMock); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToFalse_retriesAreNotUsed() { + when(senderMock.getEnforceThreadsConnectSameReceiver()).thenReturn(false); + + when(connectionMock.getEndpoint()).thenReturn(endpointMock); + when(endpointMock.getMemberId()).thenReturn(memberIdMock); + when(memberIdMock.getUniqueId()).thenReturn("receiverId"); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(1)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).getEnforceThreadsConnectSameReceiver(); + verify(poolMock, times(1)).acquireConnection(); + verify(dispatcherSpy, times(0)).retryInitializeConnection(connectionMock); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToTrue_firstThreadObtainsTheReceiverId() { + + when(senderMock.getEnforceThreadsConnectSameReceiver()).thenReturn(true); + + when(connectionMock.getEndpoint()).thenReturn(endpointMock); + when(endpointMock.getMemberId()).thenReturn(memberIdMock); + when(memberIdMock.getUniqueId()).thenReturn("receiverId"); + when(eventProcessorMock.getExpectedReceiverUniqueId()).thenReturn(""); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(1)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).getEnforceThreadsConnectSameReceiver(); + verify(dispatcherSpy, times(1)).retryInitializeConnection(connectionMock); + verify(poolMock, times(1)).acquireConnection(); + verify(eventProcessorMock, times(1)).setExpectedReceiverUniqueId("receiverId"); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToTrue_threadConnectsToExpectedReceiverWithNoRetry() { Review comment: This test might be better named "initializeConnectionWithSerialSenderAndEnforceThreadsConnectSameReceiverTrueAndConnectedToExpectedReceiverDoesNotReacquireConnection". ########## File path: geode-wan/src/test/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcherJUnitTest.java ########## @@ -77,4 +132,160 @@ public void getConnectionShouldCreateNewConnectionWhenServerIsNull() { verify(dispatcher, times(1)).initializeConnection(); verify(dispatcher, times(2)).getConnectionLifeCycleLock(); } + + @Test + public void enforceThreadsConnectSameReceiver_initializeParallelSenderConnection_retriesAreNotUsed() { Review comment: These test names are still rather confusing in terms of what the test is doing and expecting to see. As per [the blog post on good test naming](https://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html) I linked previously, a test name should ideally be of the form: (what work the test is doing)\_(what the conditions are)\_(what the expected result is), so for this test, a good name might be "initializeConnectionWithParalellSenderDoesNotRetryInitializeConnection". ########## File path: geode-wan/src/test/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcherJUnitTest.java ########## @@ -77,4 +132,160 @@ public void getConnectionShouldCreateNewConnectionWhenServerIsNull() { verify(dispatcher, times(1)).initializeConnection(); verify(dispatcher, times(2)).getConnectionLifeCycleLock(); } + + @Test + public void enforceThreadsConnectSameReceiver_initializeParallelSenderConnection_retriesAreNotUsed() { + when(senderMock.isParallel()).thenReturn(true); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(0)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).setServerLocation(any()); + verify(poolMock, times(1)).acquireConnection(); + verify(dispatcherSpy, times(0)).retryInitializeConnection(connectionMock); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToFalse_retriesAreNotUsed() { + when(senderMock.getEnforceThreadsConnectSameReceiver()).thenReturn(false); + + when(connectionMock.getEndpoint()).thenReturn(endpointMock); + when(endpointMock.getMemberId()).thenReturn(memberIdMock); + when(memberIdMock.getUniqueId()).thenReturn("receiverId"); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(1)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).getEnforceThreadsConnectSameReceiver(); + verify(poolMock, times(1)).acquireConnection(); + verify(dispatcherSpy, times(0)).retryInitializeConnection(connectionMock); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToTrue_firstThreadObtainsTheReceiverId() { + + when(senderMock.getEnforceThreadsConnectSameReceiver()).thenReturn(true); + + when(connectionMock.getEndpoint()).thenReturn(endpointMock); + when(endpointMock.getMemberId()).thenReturn(memberIdMock); + when(memberIdMock.getUniqueId()).thenReturn("receiverId"); + when(eventProcessorMock.getExpectedReceiverUniqueId()).thenReturn(""); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(1)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).getEnforceThreadsConnectSameReceiver(); + verify(dispatcherSpy, times(1)).retryInitializeConnection(connectionMock); + verify(poolMock, times(1)).acquireConnection(); + verify(eventProcessorMock, times(1)).setExpectedReceiverUniqueId("receiverId"); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToTrue_threadConnectsToExpectedReceiverWithNoRetry() { + + when(senderMock.getEnforceThreadsConnectSameReceiver()).thenReturn(true); + + when(connectionMock.getEndpoint()).thenReturn(endpointMock); + when(endpointMock.getMemberId()).thenReturn(memberIdMock); + when(memberIdMock.getUniqueId()).thenReturn("expectedId"); + when(eventProcessorMock.getExpectedReceiverUniqueId()).thenReturn("expectedId"); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(1)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).getEnforceThreadsConnectSameReceiver(); + verify(dispatcherSpy, times(1)).retryInitializeConnection(connectionMock); + verify(poolMock, times(1)).acquireConnection(); + verify(eventProcessorMock, times(0)).setExpectedReceiverUniqueId(any()); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToTrue_threadConnectsToExpectedReceiverWithRetry() { Review comment: This test might be better named "initializeConnectionWithSerialSenderAndEnforceThreadsConnectSameReceiverTrueAndConnectedToExpectedReceiverOnDecondTryReacquiresConnectionOnce". ########## File path: geode-wan/src/test/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcherJUnitTest.java ########## @@ -77,4 +132,160 @@ public void getConnectionShouldCreateNewConnectionWhenServerIsNull() { verify(dispatcher, times(1)).initializeConnection(); verify(dispatcher, times(2)).getConnectionLifeCycleLock(); } + + @Test + public void enforceThreadsConnectSameReceiver_initializeParallelSenderConnection_retriesAreNotUsed() { + when(senderMock.isParallel()).thenReturn(true); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(0)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).setServerLocation(any()); + verify(poolMock, times(1)).acquireConnection(); + verify(dispatcherSpy, times(0)).retryInitializeConnection(connectionMock); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToFalse_retriesAreNotUsed() { + when(senderMock.getEnforceThreadsConnectSameReceiver()).thenReturn(false); + + when(connectionMock.getEndpoint()).thenReturn(endpointMock); + when(endpointMock.getMemberId()).thenReturn(memberIdMock); + when(memberIdMock.getUniqueId()).thenReturn("receiverId"); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(1)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).getEnforceThreadsConnectSameReceiver(); + verify(poolMock, times(1)).acquireConnection(); + verify(dispatcherSpy, times(0)).retryInitializeConnection(connectionMock); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToTrue_firstThreadObtainsTheReceiverId() { + + when(senderMock.getEnforceThreadsConnectSameReceiver()).thenReturn(true); + + when(connectionMock.getEndpoint()).thenReturn(endpointMock); + when(endpointMock.getMemberId()).thenReturn(memberIdMock); + when(memberIdMock.getUniqueId()).thenReturn("receiverId"); + when(eventProcessorMock.getExpectedReceiverUniqueId()).thenReturn(""); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(1)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).getEnforceThreadsConnectSameReceiver(); + verify(dispatcherSpy, times(1)).retryInitializeConnection(connectionMock); + verify(poolMock, times(1)).acquireConnection(); + verify(eventProcessorMock, times(1)).setExpectedReceiverUniqueId("receiverId"); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToTrue_threadConnectsToExpectedReceiverWithNoRetry() { + + when(senderMock.getEnforceThreadsConnectSameReceiver()).thenReturn(true); + + when(connectionMock.getEndpoint()).thenReturn(endpointMock); + when(endpointMock.getMemberId()).thenReturn(memberIdMock); + when(memberIdMock.getUniqueId()).thenReturn("expectedId"); + when(eventProcessorMock.getExpectedReceiverUniqueId()).thenReturn("expectedId"); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(1)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).getEnforceThreadsConnectSameReceiver(); + verify(dispatcherSpy, times(1)).retryInitializeConnection(connectionMock); + verify(poolMock, times(1)).acquireConnection(); + verify(eventProcessorMock, times(0)).setExpectedReceiverUniqueId(any()); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToTrue_threadConnectsToExpectedReceiverWithRetry() { + + when(senderMock.getEnforceThreadsConnectSameReceiver()).thenReturn(true); + + when(connectionMock.getEndpoint()).thenReturn(endpointMock); + when(endpointMock.getMemberId()).thenReturn(memberIdMock); + when(memberIdMock.getUniqueId()).thenReturn("notExpectedId").thenReturn("expectedId"); + when(eventProcessorMock.getExpectedReceiverUniqueId()).thenReturn("expectedId"); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(1)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).getEnforceThreadsConnectSameReceiver(); + verify(dispatcherSpy, times(1)).retryInitializeConnection(connectionMock); + verify(poolMock, times(2)).acquireConnection(); + verify(eventProcessorMock, times(0)).setExpectedReceiverUniqueId(any()); + + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToTrue_exceptionThrownWhenMaxRetriesReachedAndNoServersAvailable() { + + when(senderMock.getEnforceThreadsConnectSameReceiver()).thenReturn(true); + + when(connectionMock.getEndpoint()).thenReturn(endpointMock); + when(endpointMock.getMemberId()).thenReturn(memberIdMock); + when(memberIdMock.getUniqueId()).thenReturn("notExpectedId"); + when(eventProcessorMock.getExpectedReceiverUniqueId()).thenReturn("expectedId"); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + + String expectedExceptionMessage = + "There are no active servers. " + + GatewaySenderEventRemoteDispatcher.maxAttemptsReachedConnectingServerIdExceptionMessage + + " [expectedId] (5 attempts)"; + assertThatThrownBy(() -> { + dispatcherSpy.initializeConnection(); + }).isInstanceOf(GatewaySenderException.class).hasMessageContaining(expectedExceptionMessage); + + verify(senderMock, times(1)).getLockForConcurrentDispatcher(); + verify(senderMock, times(2)).getEnforceThreadsConnectSameReceiver(); + verify(dispatcherSpy, times(1)).retryInitializeConnection(connectionMock); + verify(poolMock, times(5)).acquireConnection(); + verify(eventProcessorMock, times(0)).setExpectedReceiverUniqueId(any()); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToTrue_exceptionThrownWhenMaxRetriesReachedButServersAreAvailable() { Review comment: This test might be better named "initializeConnectionWithSerialSenderAndEnforceThreadsConnectSameReceiverTrueAndMaxRetriesExceededAndServersAvailableThrowsException". ########## File path: geode-wan/src/test/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcherJUnitTest.java ########## @@ -77,4 +132,160 @@ public void getConnectionShouldCreateNewConnectionWhenServerIsNull() { verify(dispatcher, times(1)).initializeConnection(); verify(dispatcher, times(2)).getConnectionLifeCycleLock(); } + + @Test + public void enforceThreadsConnectSameReceiver_initializeParallelSenderConnection_retriesAreNotUsed() { + when(senderMock.isParallel()).thenReturn(true); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(0)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).setServerLocation(any()); + verify(poolMock, times(1)).acquireConnection(); + verify(dispatcherSpy, times(0)).retryInitializeConnection(connectionMock); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToFalse_retriesAreNotUsed() { + when(senderMock.getEnforceThreadsConnectSameReceiver()).thenReturn(false); + + when(connectionMock.getEndpoint()).thenReturn(endpointMock); + when(endpointMock.getMemberId()).thenReturn(memberIdMock); + when(memberIdMock.getUniqueId()).thenReturn("receiverId"); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(1)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).getEnforceThreadsConnectSameReceiver(); + verify(poolMock, times(1)).acquireConnection(); + verify(dispatcherSpy, times(0)).retryInitializeConnection(connectionMock); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToTrue_firstThreadObtainsTheReceiverId() { + + when(senderMock.getEnforceThreadsConnectSameReceiver()).thenReturn(true); + + when(connectionMock.getEndpoint()).thenReturn(endpointMock); + when(endpointMock.getMemberId()).thenReturn(memberIdMock); + when(memberIdMock.getUniqueId()).thenReturn("receiverId"); + when(eventProcessorMock.getExpectedReceiverUniqueId()).thenReturn(""); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(1)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).getEnforceThreadsConnectSameReceiver(); + verify(dispatcherSpy, times(1)).retryInitializeConnection(connectionMock); + verify(poolMock, times(1)).acquireConnection(); + verify(eventProcessorMock, times(1)).setExpectedReceiverUniqueId("receiverId"); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToTrue_threadConnectsToExpectedReceiverWithNoRetry() { + + when(senderMock.getEnforceThreadsConnectSameReceiver()).thenReturn(true); + + when(connectionMock.getEndpoint()).thenReturn(endpointMock); + when(endpointMock.getMemberId()).thenReturn(memberIdMock); + when(memberIdMock.getUniqueId()).thenReturn("expectedId"); + when(eventProcessorMock.getExpectedReceiverUniqueId()).thenReturn("expectedId"); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(1)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).getEnforceThreadsConnectSameReceiver(); + verify(dispatcherSpy, times(1)).retryInitializeConnection(connectionMock); + verify(poolMock, times(1)).acquireConnection(); + verify(eventProcessorMock, times(0)).setExpectedReceiverUniqueId(any()); + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToTrue_threadConnectsToExpectedReceiverWithRetry() { + + when(senderMock.getEnforceThreadsConnectSameReceiver()).thenReturn(true); + + when(connectionMock.getEndpoint()).thenReturn(endpointMock); + when(endpointMock.getMemberId()).thenReturn(memberIdMock); + when(memberIdMock.getUniqueId()).thenReturn("notExpectedId").thenReturn("expectedId"); + when(eventProcessorMock.getExpectedReceiverUniqueId()).thenReturn("expectedId"); + + eventDispatcher = new GatewaySenderEventRemoteDispatcher(eventProcessorMock, null); + GatewaySenderEventRemoteDispatcher dispatcherSpy = spy(eventDispatcher); + dispatcherSpy.initializeConnection(); + + verify(senderMock, times(1)).getLockForConcurrentDispatcher(); + verify(senderMock, times(1)).getEnforceThreadsConnectSameReceiver(); + verify(dispatcherSpy, times(1)).retryInitializeConnection(connectionMock); + verify(poolMock, times(2)).acquireConnection(); + verify(eventProcessorMock, times(0)).setExpectedReceiverUniqueId(any()); + + } + + @Test + public void enforceThreadsConnectSameReceiver_initializingConnectionOfSerialSenderWithOptionSetToTrue_exceptionThrownWhenMaxRetriesReachedAndNoServersAvailable() { Review comment: This test might be better named "initializeConnectionWithSerialSenderAndEnforceThreadsConnectSameReceiverTrueAndMaxRetriesExceededAndNoServersAvailableThrowsException". ---------------------------------------------------------------- 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: us...@infra.apache.org > New option for serial gw sender threads start when receivers share ip and port > ------------------------------------------------------------------------------ > > Key: GEODE-8202 > URL: https://issues.apache.org/jira/browse/GEODE-8202 > Project: Geode > Issue Type: Improvement > Reporter: Alberto Bustamante Reyes > Assignee: Alberto Bustamante Reyes > Priority: Major > Labels: pull-request-available > > RFC: > [https://cwiki.apache.org/confluence/display/GEODE/New+option+for+serial+gw+sender+dispatcher+threads+start|https://cwiki.apache.org/confluence/display/GEODE/New+option+for+serial+gw+sender+dispatcher+threads+start] -- This message was sent by Atlassian Jira (v8.3.4#803005)