-
Couldn't load subscription status.
- Fork 14.7k
KAFKA-19345: Use ShareFetchUtils mock for DelayedShareFetchTest tests #20765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
| assertNull(shareGroupMetrics.topicPartitionsFetchRatio(groupId)); | ||
|
|
||
| delayedShareFetch.lock().unlock(); | ||
| Mockito.verify(exceptionHandler, never()).accept(any(), any()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exceptionHandler shouldn't be triggered in this test case.
The reason it throw error simply due to incorrect test mock up,
| when(replicaManager.getPartitionOrException(tp0.topicPartition())).thenReturn(p0); |
replicaManager.getPartitionOrException(tp0.topicPartition()) defined in | mockTopicIdPartitionFetchBytes(replicaManager, tp0, hwmOffsetMetadata); |
| exceptionHandler.accept( |
| assertTrue(delayedShareFetch.lock().tryLock()); | ||
| delayedShareFetch.lock().unlock(); | ||
| Mockito.verify(exceptionHandler, times(1)).accept(any(), any()); | ||
| Mockito.verify(exceptionHandler, never()).accept(any(), any()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
|
UserQuotaTest#testThrottledRequest(String) with groupProtocol=classic is a known flaky test (KAFKA-8459). It’s unrelated to this PR and passes locally. |
|
Gentle ping , @AndrewJSchofield, @apoorvmittal10, @adixitconfluent — sorry for the late implementation 🙏 |
|
@adixitconfluent Can you please review the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @brandboat . I've left some comments.
|
|
||
| // We are testing the case when the share partition is getting fetched for the first time, so for the first time | ||
| // the fetchOffsetMetadata will return empty. Post the readFromLog call, the fetchOffsetMetadata will be | ||
| // the fetchOffsetMetadata will return empty. Post the isMinBytesSatisfied call, the fetchOffsetMetadata will be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the comment that makes more sense is Post the first readFromLog call...
| doAnswer(invocation -> buildLogReadResult(List.of(tp0))).when(replicaManager).readFromLog(any(), any(), any(ReplicaQuota.class), anyBoolean()); | ||
| BiConsumer<SharePartitionKey, Throwable> exceptionHandler = mockExceptionHandler(); | ||
|
|
||
| PartitionMaxBytesStrategy partitionMaxBytesStrategy = mockPartitionMaxBytes(Set.of(tp0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why this piece of code has been moved below - basically a cut and paste?
| private void mockTopicIdPartitionFetchBytes(ReplicaManager replicaManager, TopicIdPartition topicIdPartition, LogOffsetMetadata hwmOffsetMetadata) { | ||
| LogOffsetSnapshot endOffsetSnapshot = new LogOffsetSnapshot(1, mock(LogOffsetMetadata.class), | ||
| hwmOffsetMetadata, mock(LogOffsetMetadata.class)); | ||
| Partition partition = mock(Partition.class); | ||
| when(partition.fetchOffsetSnapshot(any(), anyBoolean())).thenReturn(endOffsetSnapshot); | ||
| when(replicaManager.getPartitionOrException(topicIdPartition.topicPartition())).thenReturn(partition); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removal of this function doesn't make sense to me. I agree that the line when(replicaManager.getPartitionOrException(topicIdPartition.topicPartition())).thenReturn(partition); is problematic. We can pass the mock Partition object into this function. Example -
caller function -
Partition p0 = mock(Partition.class);
mockTopicIdPartitionFetchBytes(replicaManager, tp0, hwmOffsetMetadata, p0);
when(p0.isLeader()).thenReturn(true);
when(replicaManager.getPartitionOrException(tp0.topicPartition())).thenReturn(p0);
function mockTopicIdPartitionFetchBytes -
private void mockTopicIdPartitionFetchBytes(LogOffsetMetadata hwmOffsetMetadata, Partition partition) {
LogOffsetSnapshot endOffsetSnapshot = new LogOffsetSnapshot(1, mock(LogOffsetMetadata.class),
hwmOffsetMetadata, mock(LogOffsetMetadata.class));
when(partition.fetchOffsetSnapshot(any(), anyBoolean())).thenReturn(endOffsetSnapshot);
}
|
|
||
| assertFalse(delayedShareFetch.isCompleted()); | ||
| try (MockedStatic<ShareFetchUtils> mockedShareFetchUtils = Mockito.mockStatic(ShareFetchUtils.class, Mockito.CALLS_REAL_METHODS)) { | ||
| mockedShareFetchUtils.when(() -> ShareFetchUtils.processFetchResponse(any(), any(), any(), any(), any())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need mocking of processFetchResponse since it is not being called in this test
| when(replicaManager.getPartitionOrException(tp0.topicPartition())).thenReturn(p0); | ||
| when(replicaManager.getPartitionOrException(tp1.topicPartition())).thenReturn(p1); | ||
|
|
||
| BiConsumer<SharePartitionKey, Throwable> exceptionHandler = mockExceptionHandler(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For safety, should we be mocking ShareFetchUtils.processFetchResponse for the test testRemoteStorageFetchRequestCompletionOnFutureCompletionFailure
This patch wraps ShareFetchUtils static method
processFetchResponsewith MockedStatic to improve test isolation and also fixes some
incorrect test results.