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 2dc0d96fa0d [fix][test] Fix TableViewBuilderImplTest NPE and infinite
loop (#22924)
2dc0d96fa0d is described below
commit 2dc0d96fa0da696949414d86fb11a62beca7cb3f
Author: Lari Hotari <[email protected]>
AuthorDate: Mon Jun 17 21:13:10 2024 +0300
[fix][test] Fix TableViewBuilderImplTest NPE and infinite loop (#22924)
---
.../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)