From f332a9446b798dc57a98af202edfd585334aff20 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Thu, 5 Mar 2020 10:03:09 -0500 Subject: [PATCH] GH-3199: Test for fail back with Long.MAX_VALUE Resolves https://github.com/spring-projects/spring-integration/issues/3199 --- .../FailoverClientConnectionFactoryTests.java | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/FailoverClientConnectionFactoryTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/FailoverClientConnectionFactoryTests.java index 5cda502698..3dab3cd438 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/FailoverClientConnectionFactoryTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/FailoverClientConnectionFactoryTests.java @@ -18,6 +18,7 @@ package org.springframework.integration.ip.tcp.connection; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; @@ -40,7 +41,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -import org.junit.Rule; import org.junit.Test; import org.mockito.InOrder; import org.mockito.Mockito; @@ -56,7 +56,6 @@ import org.springframework.integration.ip.IpHeaders; import org.springframework.integration.ip.tcp.TcpInboundGateway; import org.springframework.integration.ip.tcp.TcpOutboundGateway; import org.springframework.integration.ip.util.TestingUtilities; -import org.springframework.integration.test.rule.Log4j2LevelAdjuster; import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.util.SimplePool; import org.springframework.messaging.Message; @@ -86,12 +85,6 @@ public class FailoverClientConnectionFactoryTests { }; - @Rule - public Log4j2LevelAdjuster adjuster = - Log4j2LevelAdjuster.trace() - .classes(SimplePool.class) - .categories("org.springframework.integration.ip.tcp"); - @Test public void testFailoverGood() throws Exception { AbstractClientConnectionFactory factory1 = mock(AbstractClientConnectionFactory.class); @@ -117,15 +110,20 @@ public class FailoverClientConnectionFactoryTests { @Test public void testRefreshShared() throws Exception { - testRefreshShared(false); + testRefreshShared(false, 10_000); } @Test public void testRefreshSharedCloseOnRefresh() throws Exception { - testRefreshShared(true); + testRefreshShared(true, 10_000); } - private void testRefreshShared(boolean closeOnRefresh) throws Exception { + @Test + public void testRefreshSharedInfinite() throws Exception { + testRefreshShared(false, Long.MAX_VALUE); + } + + private void testRefreshShared(boolean closeOnRefresh, long interval) throws Exception { AbstractClientConnectionFactory factory1 = mock(AbstractClientConnectionFactory.class); AbstractClientConnectionFactory factory2 = mock(AbstractClientConnectionFactory.class); List factories = new ArrayList(); @@ -150,21 +148,29 @@ public class FailoverClientConnectionFactoryTests { failoverFactory.start(); TcpConnectionSupport connection = failoverFactory.getConnection(); assertThat(TestUtils.getPropertyValue(failoverFactory, "theConnection")).isNotNull(); - failoverFactory.setRefreshSharedInterval(10_000); - assertThat(failoverFactory.getConnection()).isSameAs(connection); - failoverFactory.setRefreshSharedInterval(-1); - assertThat(failoverFactory.getConnection()).isNotSameAs(connection); - InOrder inOrder = inOrder(factory1, factory2, conn1); + failoverFactory.setRefreshSharedInterval(interval); + InOrder inOrder = inOrder(factory1, factory2, conn1, conn2); inOrder.verify(factory1).getConnection(); inOrder.verify(factory2).getConnection(); + inOrder.verify(conn1).registerListener(any()); + inOrder.verify(conn1).isOpen(); + assertThat(failoverFactory.getConnection()).isSameAs(connection); + inOrder.verifyNoMoreInteractions(); + failoverFactory.setRefreshSharedInterval(-1); + assertThat(failoverFactory.getConnection()).isNotSameAs(connection); inOrder.verify(factory1).getConnection(); inOrder.verify(factory2).getConnection(); if (closeOnRefresh) { + inOrder.verify(conn2).registerListener(any()); + inOrder.verify(conn2).isOpen(); inOrder.verify(conn1).close(); } else { + inOrder.verify(conn1).registerListener(any()); + inOrder.verify(conn1).isOpen(); inOrder.verify(conn1, never()).close(); } + inOrder.verifyNoMoreInteractions(); } @Test(expected = UncheckedIOException.class)