Skip to content

Commit

Permalink
[fix][test] Fix TableViewBuilderImplTest NPE and infinite loop (apach…
Browse files Browse the repository at this point in the history
…e#22924)

(cherry picked from commit 2dc0d96)
  • Loading branch information
lhotari committed Jun 19, 2024
1 parent 20de952 commit 9baf4b0
Showing 1 changed file with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,40 @@
*/
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;
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);
Expand All @@ -61,6 +62,14 @@ public void setup() {
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)
Expand Down

0 comments on commit 9baf4b0

Please sign in to comment.