Skip to content

Commit a6fb9e2

Browse files
authored
[ISSUE #10410] Fix RocksDBOptionsFactoryTest compile failure (#10411)
1 parent 78b0546 commit a6fb9e2

3 files changed

Lines changed: 16 additions & 21 deletions

File tree

broker/src/test/java/org/apache/rocketmq/broker/BrokerOuterAPITest.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.apache.rocketmq.common.MixAll;
4545
import org.apache.rocketmq.common.message.MessageDecoder;
4646
import org.apache.rocketmq.common.message.MessageExt;
47+
import org.apache.rocketmq.remoting.InvokeCallback;
4748
import org.apache.rocketmq.remoting.common.SemaphoreReleaseOnlyOnce;
4849
import org.apache.rocketmq.remoting.exception.RemotingTimeoutException;
4950
import org.apache.rocketmq.remoting.netty.NettyClientConfig;
@@ -334,12 +335,7 @@ public void testPullMessageFromSpecificBrokerAsync_timeout() throws Exception {
334335

335336
@Test
336337
public void testPullMessageFromSpecificBrokerAsync_brokerReturn_pullStatusCode() throws Exception {
337-
Channel channel = Mockito.mock(Channel.class);
338-
when(channel.isActive()).thenReturn(true);
339-
NettyRemotingClient mockClient = PowerMockito.spy(new NettyRemotingClient(new NettyClientConfig()));
340-
DefaultChannelPromise promise = PowerMockito.spy(new DefaultChannelPromise(PowerMockito.mock(Channel.class), new DefaultEventExecutor()));
341-
PowerMockito.when(mockClient, "getAndCreateChannelAsync", any()).thenReturn(promise);
342-
when(promise.channel()).thenReturn(channel);
338+
NettyRemotingClient mockClient = Mockito.mock(NettyRemotingClient.class);
343339
BrokerOuterAPI api = new BrokerOuterAPI(new NettyClientConfig(), new AuthConfig());
344340
Field field = BrokerOuterAPI.class.getDeclaredField("remotingClient");
345341
field.setAccessible(true);
@@ -348,14 +344,12 @@ public void testPullMessageFromSpecificBrokerAsync_brokerReturn_pullStatusCode()
348344
int[] respCodes = new int[] {ResponseCode.SUCCESS, ResponseCode.PULL_NOT_FOUND, ResponseCode.PULL_RETRY_IMMEDIATELY, ResponseCode.PULL_OFFSET_MOVED};
349345
PullStatus[] respStatus = new PullStatus[] {PullStatus.FOUND, PullStatus.NO_NEW_MSG, PullStatus.NO_MATCHED_MSG, PullStatus.OFFSET_ILLEGAL};
350346
for (int i = 0; i < respCodes.length; i++) {
351-
CompletableFuture<ResponseFuture> future = new CompletableFuture<>();
352-
doReturn(future).when(mockClient).invokeImpl(any(Channel.class), any(RemotingCommand.class), anyLong());
353347
RemotingCommand response = mockPullMessageResponse(respCodes[i]);
354-
ResponseFuture responseFuture = new ResponseFuture(channel, 0, null, 1000,
355-
resp -> { }, new SemaphoreReleaseOnlyOnce(new Semaphore(1)));
356-
responseFuture.setResponseCommand(response);
357-
promise.trySuccess(null);
358-
future.complete(responseFuture);
348+
Mockito.doAnswer(invocation -> {
349+
InvokeCallback callback = invocation.getArgument(3);
350+
callback.operationSucceed(response);
351+
return null;
352+
}).when(mockClient).invokeAsync(anyString(), any(RemotingCommand.class), anyLong(), any(InvokeCallback.class));
359353

360354
Triple<PullResult, String, Boolean> rst = api.pullMessageFromSpecificBrokerAsync("", "", "", "", 1, 1, 1, 3000L).join();
361355
Assert.assertEquals(respStatus[i], rst.getLeft().getPullStatus());

client/src/test/java/org/apache/rocketmq/client/consumer/DefaultLitePullConsumerTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
import static org.mockito.ArgumentMatchers.anyLong;
7676
import static org.mockito.ArgumentMatchers.anyString;
7777
import static org.mockito.ArgumentMatchers.nullable;
78-
import static org.mockito.Mockito.doAnswer;
7978
import static org.mockito.Mockito.doNothing;
8079
import static org.mockito.Mockito.doReturn;
8180
import static org.mockito.Mockito.spy;
@@ -727,7 +726,7 @@ private void initDefaultLitePullConsumer(DefaultLitePullConsumer litePullConsume
727726
field.setAccessible(true);
728727
field.set(litePullConsumerImpl, offsetStore);
729728

730-
when(mQClientFactory.getMQClientAPIImpl().pullMessage(anyString(), any(PullMessageRequestHeader.class),
729+
when(mQClientAPIImpl.pullMessage(anyString(), any(PullMessageRequestHeader.class),
731730
anyLong(), any(CommunicationMode.class), nullable(PullCallback.class)))
732731
.thenAnswer(new Answer<PullResult>() {
733732
@Override
@@ -746,9 +745,11 @@ public PullResult answer(InvocationOnMock mock) throws Throwable {
746745
}
747746
});
748747

749-
doAnswer(x -> new FindBrokerResult("127.0.0.1:10911", false)).when(mQClientFactory).findBrokerAddressInSubscribe(anyString(), anyLong(), anyBoolean());
748+
doReturn(new FindBrokerResult("127.0.0.1:10911", false))
749+
.when(mQClientFactory).findBrokerAddressInSubscribe(anyString(), anyLong(), anyBoolean());
750750

751-
doReturn(Collections.singletonList(mQClientFactory.getClientId())).when(mQClientFactory).findConsumerIdList(anyString(), anyString());
751+
String clientId = mQClientFactory.getClientId();
752+
doReturn(Collections.singletonList(clientId)).when(mQClientFactory).findConsumerIdList(anyString(), anyString());
752753

753754
doReturn(123L).when(offsetStore).readOffset(any(MessageQueue.class), any(ReadOffsetType.class));
754755
}
@@ -787,7 +788,7 @@ private void initDefaultLitePullConsumerWithTag(DefaultLitePullConsumer litePull
787788
field.setAccessible(true);
788789
field.set(litePullConsumerImpl, offsetStore);
789790

790-
when(mQClientFactory.getMQClientAPIImpl().pullMessage(anyString(), any(PullMessageRequestHeader.class),
791+
when(mQClientAPIImpl.pullMessage(anyString(), any(PullMessageRequestHeader.class),
791792
anyLong(), any(CommunicationMode.class), nullable(PullCallback.class)))
792793
.thenAnswer(new Answer<PullResult>() {
793794
@Override
@@ -807,7 +808,8 @@ public PullResult answer(InvocationOnMock mock) throws Throwable {
807808
}
808809
});
809810

810-
when(mQClientFactory.findBrokerAddressInSubscribe(anyString(), anyLong(), anyBoolean())).thenReturn(new FindBrokerResult("127.0.0.1:10911", false));
811+
doReturn(new FindBrokerResult("127.0.0.1:10911", false))
812+
.when(mQClientFactory).findBrokerAddressInSubscribe(anyString(), anyLong(), anyBoolean());
811813

812814
doReturn(123L).when(offsetStore).readOffset(any(MessageQueue.class), any(ReadOffsetType.class));
813815
}

store/src/test/java/org/apache/rocketmq/store/rocksdb/RocksDBOptionsFactoryTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ public void testConsumeQueueUniversalCompactionMaxSizeAmplificationPercent() {
5252
MessageStore messageStore = mock(MessageStore.class);
5353
when(messageStore.getMessageStoreConfig()).thenReturn(config);
5454

55-
ConsumeQueueCompactionFilterFactory compactionFilterFactory = new ConsumeQueueCompactionFilterFactory(() -> 0);
56-
try (ColumnFamilyOptions options = RocksDBOptionsFactory.createCQCFOptions(messageStore, compactionFilterFactory);
55+
try (ColumnFamilyOptions options = RocksDBOptionsFactory.createCQCFOptions(messageStore);
5756
CompactionOptionsUniversal compactionOptions = options.compactionOptionsUniversal()) {
5857
Assert.assertEquals(50, compactionOptions.maxSizeAmplificationPercent());
5958
}

0 commit comments

Comments
 (0)