Skip to content

Commit

Permalink
[test] remove reflection direct usage from SimpleProducerConsumerTest…
Browse files Browse the repository at this point in the history
….testActiveAndInActiveConsumerEntryCacheBehavior (apache#14128)

* [test] remove reflection direct usage from SimpleProducerConsumerTest.testActiveAndInActiveConsumerEntryCacheBehavior

* checkstyle
  • Loading branch information
nicoloboschi authored Feb 7, 2022
1 parent 7a39a36 commit 7671777
Showing 1 changed file with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
import io.netty.buffer.Unpooled;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand Down Expand Up @@ -103,6 +101,7 @@
import org.apache.pulsar.common.schema.SchemaType;
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;
Expand Down Expand Up @@ -978,13 +977,8 @@ public void testActiveAndInActiveConsumerEntryCacheBehavior() throws Exception {

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;
// 2. Produce messages
Expand Down

0 comments on commit 7671777

Please sign in to comment.