This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new de99c2c [Tests] Fix flakiness issue when spying ServerCnx (#13608)
de99c2c is described below
commit de99c2c9c3c54b31096e6d734de8132e96d50c79
Author: Lari Hotari <[email protected]>
AuthorDate: Tue Jan 4 19:32:09 2022 +0200
[Tests] Fix flakiness issue when spying ServerCnx (#13608)
Fixes #13570
---
.../service/PersistentDispatcherFailoverConsumerTest.java | 10 ++++++++--
.../broker/service/PersistentTopicConcurrentTest.java | 6 +++++-
.../apache/pulsar/broker/service/PersistentTopicTest.java | 14 +++++++++++---
3 files changed, 24 insertions(+), 6 deletions(-)
diff --git
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentDispatcherFailoverConsumerTest.java
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentDispatcherFailoverConsumerTest.java
index c858ed3..2ced6d4 100644
---
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentDispatcherFailoverConsumerTest.java
+++
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentDispatcherFailoverConsumerTest.java
@@ -21,6 +21,7 @@ package org.apache.pulsar.broker.service;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.matches;
import static org.mockito.ArgumentMatchers.same;
+import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -28,6 +29,7 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.withSettings;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
import static org.testng.AssertJUnit.assertEquals;
@@ -157,7 +159,9 @@ public class PersistentDispatcherFailoverConsumerTest {
return null;
}).when(channelCtx).writeAndFlush(any(), any());
- serverCnx = spy(new ServerCnx(pulsar));
+ serverCnx = mock(ServerCnx.class, withSettings()
+ .useConstructor(pulsar)
+ .defaultAnswer(CALLS_REAL_METHODS));
doReturn(true).when(serverCnx).isActive();
doReturn(true).when(serverCnx).isWritable();
doReturn(new InetSocketAddress("localhost",
1234)).when(serverCnx).clientAddress();
@@ -166,7 +170,9 @@ public class PersistentDispatcherFailoverConsumerTest {
doReturn(new PulsarCommandSenderImpl(null, serverCnx))
.when(serverCnx).getCommandSender();
- serverCnxWithOldVersion = spy(new ServerCnx(pulsar));
+ serverCnxWithOldVersion = mock(ServerCnx.class, withSettings()
+ .useConstructor(pulsar)
+ .defaultAnswer(CALLS_REAL_METHODS));
doReturn(true).when(serverCnxWithOldVersion).isActive();
doReturn(true).when(serverCnxWithOldVersion).isWritable();
doReturn(new InetSocketAddress("localhost", 1234))
diff --git
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicConcurrentTest.java
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicConcurrentTest.java
index 15f3cdc..02acdfa 100644
---
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicConcurrentTest.java
+++
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicConcurrentTest.java
@@ -18,10 +18,12 @@
*/
package org.apache.pulsar.broker.service;
+import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.withSettings;
import static org.testng.Assert.assertFalse;
import java.lang.reflect.Method;
@@ -99,7 +101,9 @@ public class PersistentTopicConcurrentTest extends
MockedBookKeeperTestCase {
brokerService = spy(new BrokerService(pulsar, eventLoopGroup));
doReturn(brokerService).when(pulsar).getBrokerService();
- serverCnx = spy(new ServerCnx(pulsar));
+ serverCnx = mock(ServerCnx.class, withSettings()
+ .useConstructor(pulsar)
+ .defaultAnswer(CALLS_REAL_METHODS));
doReturn(true).when(serverCnx).isActive();
NamespaceService nsSvc = mock(NamespaceService.class);
diff --git
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicTest.java
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicTest.java
index d085dcb..7c9400d 100644
---
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicTest.java
+++
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicTest.java
@@ -22,6 +22,7 @@ import static
org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.createMo
import static
org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.createMockZooKeeper;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doAnswer;
@@ -34,6 +35,7 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.withSettings;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
@@ -206,7 +208,9 @@ public class PersistentTopicTest extends
MockedBookKeeperTestCase {
brokerService = spy(new BrokerService(pulsar, eventLoopGroup));
doReturn(brokerService).when(pulsar).getBrokerService();
- serverCnx = spy(new ServerCnx(pulsar));
+ serverCnx = mock(ServerCnx.class, withSettings()
+ .useConstructor(pulsar)
+ .defaultAnswer(CALLS_REAL_METHODS));
doReturn(true).when(serverCnx).isActive();
doReturn(true).when(serverCnx).isWritable();
doReturn(new InetSocketAddress("localhost",
1234)).when(serverCnx).clientAddress();
@@ -587,7 +591,9 @@ public class PersistentTopicTest extends
MockedBookKeeperTestCase {
final String producerNameBase = "producer";
final String role = "appid1";
- ServerCnx cnx = spy(new ServerCnx(pulsar));
+ ServerCnx cnx = mock(ServerCnx.class, withSettings()
+ .useConstructor(pulsar)
+ .defaultAnswer(CALLS_REAL_METHODS));
doReturn(true).when(cnx).isActive();
doReturn(true).when(cnx).isWritable();
doReturn(new InetSocketAddress(address,
1234)).when(cnx).clientAddress();
@@ -1042,7 +1048,9 @@ public class PersistentTopicTest extends
MockedBookKeeperTestCase {
final String consumerNameBase = "consumer";
final String role = "appid1";
- ServerCnx cnx = spy(new ServerCnx(pulsar));
+ ServerCnx cnx = mock(ServerCnx.class, withSettings()
+ .useConstructor(pulsar)
+ .defaultAnswer(CALLS_REAL_METHODS));
doReturn(true).when(cnx).isActive();
doReturn(true).when(cnx).isWritable();
doReturn(new InetSocketAddress(address,
1234)).when(cnx).clientAddress();