Fix reflection usage in V1_ProducerConsumerTest#testActiveAndInActiveConsumerEntryCacheBehavior
use org.powermock.reflect.Whitebox.getInternalState/setInternalState instead
similar change was made in
@@ -26,13 +26,9 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
-
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
-
import java.io.IOException;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
@@ -50,7 +46,6 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
-
import lombok.Cleanup;
import org.apache.bookkeeper.mledger.impl.EntryCacheImpl;
import org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl;
@@ -72,10 +67,11 @@ import org.apache.pulsar.client.api.TypedMessageBuilder;
import org.apache.pulsar.client.impl.ConsumerImpl;
import org.apache.pulsar.client.impl.MessageIdImpl;
import org.apache.pulsar.client.impl.TypedMessageBuilderImpl;
-import org.apache.pulsar.common.protocol.Commands;
import org.apache.pulsar.common.naming.TopicName;
+import org.apache.pulsar.common.protocol.Commands;
import org.apache.pulsar.common.util.FutureUtil;
import org.awaitility.Awaitility;
+import org.powermock.reflect.Whitebox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
@@ -651,13 +647,9 @@ public class V1_ProducerConsumerTest extends V1_ProducerConsumerBase {
PersistentTopic topicRef = (PersistentTopic) pulsar.getBrokerService().getTopicReference(topic).get();
ManagedLedgerImpl ledger = (ManagedLedgerImpl) topicRef.getManagedLedger();
- Field cacheField = ManagedLedgerImpl.class.getDeclaredField("entryCache");
- cacheField.setAccessible(true);
- Field modifiersField = Field.class.getDeclaredField("modifiers");
- modifiersField.setAccessible(true);
- modifiersField.setInt(cacheField, cacheField.getModifiers() & ~Modifier.FINAL);
- EntryCacheImpl entryCache = spy((EntryCacheImpl) cacheField.get(ledger));
- cacheField.set(ledger, entryCache);
+
+ EntryCacheImpl entryCache = spy((EntryCacheImpl) Whitebox.getInternalState(ledger, "entryCache"));
+ Whitebox.setInternalState(ledger, "entryCache", entryCache);
Message<byte[]>msg = null;
// 2. Produce messages
