You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by eo...@apache.org on 2022/04/22 16:30:49 UTC
[pulsar] branch master updated: Fix reflection usage in V1_ProducerConsumerTest#testActiveAndInActiveConsumerEntryCacheBehavior (#15275)
This is an automated email from the ASF dual-hosted git repository.
eolivelli 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 5582e5cd964 Fix reflection usage in V1_ProducerConsumerTest#testActiveAndInActiveConsumerEntryCacheBehavior (#15275)
5582e5cd964 is described below
commit 5582e5cd96438d3a8e4dd79410f7bcbee24a014d
Author: Lari Hotari <lh...@users.noreply.github.com>
AuthorDate: Fri Apr 22 19:30:42 2022 +0300
Fix reflection usage in V1_ProducerConsumerTest#testActiveAndInActiveConsumerEntryCacheBehavior (#15275)
- use org.powermock.reflect.Whitebox.getInternalState/setInternalState instead
- similar change was made in #14128
---
.../pulsar/client/api/v1/V1_ProducerConsumerTest.java | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/v1/V1_ProducerConsumerTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/v1/V1_ProducerConsumerTest.java
index 55c120592e1..a36dd359e59 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/v1/V1_ProducerConsumerTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/v1/V1_ProducerConsumerTest.java
@@ -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