You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by lh...@apache.org on 2024/06/19 11:15:03 UTC
(pulsar) 03/04: [fix][test] Fix TableViewBuilderImplTest NPE and infinite loop (#22924)
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch branch-3.3
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 5cfb0ebf8eac1a37d1948ef8a26fb37ad4c66a6f
Author: Lari Hotari <lh...@users.noreply.github.com>
AuthorDate: Mon Jun 17 21:13:10 2024 +0300
[fix][test] Fix TableViewBuilderImplTest NPE and infinite loop (#22924)
(cherry picked from commit 2dc0d96fa0da696949414d86fb11a62beca7cb3f)
---
.../client/impl/TableViewBuilderImplTest.java | 33 ++++++++++++++--------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/TableViewBuilderImplTest.java b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/TableViewBuilderImplTest.java
index eee8ba4e8f4..01353e47cd0 100644
--- a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/TableViewBuilderImplTest.java
+++ b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/TableViewBuilderImplTest.java
@@ -18,6 +18,14 @@
*/
package org.apache.pulsar.client.impl;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertNotNull;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
import org.apache.pulsar.client.api.ConsumerCryptoFailureAction;
import org.apache.pulsar.client.api.CryptoKeyReader;
import org.apache.pulsar.client.api.PulsarClientException;
@@ -25,32 +33,25 @@ import org.apache.pulsar.client.api.Reader;
import org.apache.pulsar.client.api.Schema;
import org.apache.pulsar.client.api.TableView;
import org.apache.pulsar.client.impl.conf.ReaderConfigurationData;
+import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.TimeUnit;
-
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.testng.Assert.assertNotNull;
-
/**
- * Unit tests of {@link TablewViewBuilderImpl}.
+ * Unit tests of {@link TableViewBuilderImpl}.
*/
public class TableViewBuilderImplTest {
private static final String TOPIC_NAME = "testTopicName";
private PulsarClientImpl client;
private TableViewBuilderImpl tableViewBuilderImpl;
+ private CompletableFuture readNextFuture;
@BeforeClass(alwaysRun = true)
public void setup() {
Reader reader = mock(Reader.class);
- when(reader.readNextAsync()).thenReturn(CompletableFuture.allOf());
+ readNextFuture = new CompletableFuture();
+ when(reader.readNextAsync()).thenReturn(readNextFuture);
client = mock(PulsarClientImpl.class);
ConnectionPool connectionPool = mock(ConnectionPool.class);
when(client.getCnxPool()).thenReturn(connectionPool);
@@ -61,6 +62,14 @@ public class TableViewBuilderImplTest {
tableViewBuilderImpl = new TableViewBuilderImpl(client, Schema.BYTES);
}
+ @AfterClass(alwaysRun = true)
+ public void cleanup() {
+ if (readNextFuture != null) {
+ readNextFuture.completeExceptionally(new PulsarClientException.AlreadyClosedException("Closing test case"));
+ readNextFuture = null;
+ }
+ }
+
@Test
public void testTableViewBuilderImpl() throws PulsarClientException {
TableView tableView = tableViewBuilderImpl.topic(TOPIC_NAME)