|
35 | 35 | import org.apache.kafka.server.share.SharePartitionKey;
|
36 | 36 | import org.apache.kafka.server.share.fetch.DelayedShareFetchGroupKey;
|
37 | 37 | import org.apache.kafka.server.share.fetch.PartitionMaxBytesStrategy;
|
38 |
| -import org.apache.kafka.server.share.fetch.ShareAcquiredRecords; |
39 | 38 | import org.apache.kafka.server.share.fetch.ShareFetch;
|
40 | 39 | import org.apache.kafka.server.share.metrics.ShareGroupMetrics;
|
41 | 40 | import org.apache.kafka.server.storage.log.FetchIsolation;
|
|
74 | 73 | import static kafka.server.share.SharePartitionManagerTest.PARTITION_MAX_BYTES;
|
75 | 74 | import static kafka.server.share.SharePartitionManagerTest.buildLogReadResult;
|
76 | 75 | import static kafka.server.share.SharePartitionManagerTest.mockReplicaManagerDelayedShareFetch;
|
| 76 | +import static org.apache.kafka.server.share.fetch.ShareFetchTestUtils.createShareAcquiredRecords; |
77 | 77 | import static org.apache.kafka.server.share.fetch.ShareFetchTestUtils.orderedMap;
|
78 | 78 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
79 | 79 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
@@ -186,7 +186,7 @@ public void testTryCompleteWhenMinBytesNotSatisfiedOnFirstFetch() {
|
186 | 186 | when(sp0.canAcquireRecords()).thenReturn(true);
|
187 | 187 | when(sp1.canAcquireRecords()).thenReturn(false);
|
188 | 188 | when(sp0.acquire(any(), anyInt(), anyInt(), anyLong(), any())).thenReturn(
|
189 |
| - ShareAcquiredRecords.fromAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
| 189 | + createShareAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
190 | 190 |
|
191 | 191 | // We are testing the case when the share partition is getting fetched for the first time, so for the first time
|
192 | 192 | // the fetchOffsetMetadata will return empty. Post the readFromLog call, the fetchOffsetMetadata will be
|
@@ -259,7 +259,7 @@ public void testTryCompleteWhenMinBytesNotSatisfiedOnSubsequentFetch() {
|
259 | 259 | when(sp0.canAcquireRecords()).thenReturn(true);
|
260 | 260 | when(sp1.canAcquireRecords()).thenReturn(false);
|
261 | 261 | when(sp0.acquire(any(), anyInt(), anyInt(), anyLong(), any())).thenReturn(
|
262 |
| - ShareAcquiredRecords.fromAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
| 262 | + createShareAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
263 | 263 |
|
264 | 264 | // We are testing the case when the share partition has been fetched before, hence we are mocking positionDiff
|
265 | 265 | // functionality to give the file position difference as 1 byte, so it doesn't satisfy the minBytes(2).
|
@@ -312,7 +312,7 @@ public void testDelayedShareFetchTryCompleteReturnsTrue() {
|
312 | 312 | when(sp0.canAcquireRecords()).thenReturn(true);
|
313 | 313 | when(sp1.canAcquireRecords()).thenReturn(false);
|
314 | 314 | when(sp0.acquire(anyString(), anyInt(), anyInt(), anyLong(), any(FetchPartitionData.class))).thenReturn(
|
315 |
| - ShareAcquiredRecords.fromAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
| 315 | + createShareAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
316 | 316 | doAnswer(invocation -> buildLogReadResult(Collections.singleton(tp0))).when(replicaManager).readFromLog(any(), any(), any(ReplicaQuota.class), anyBoolean());
|
317 | 317 |
|
318 | 318 | when(sp0.fetchOffsetMetadata(anyLong())).thenReturn(Optional.of(new LogOffsetMetadata(0, 1, 0)));
|
@@ -427,7 +427,7 @@ public void testReplicaManagerFetchShouldHappenOnComplete() {
|
427 | 427 | when(sp0.canAcquireRecords()).thenReturn(true);
|
428 | 428 | when(sp1.canAcquireRecords()).thenReturn(false);
|
429 | 429 | when(sp0.acquire(anyString(), anyInt(), anyInt(), anyLong(), any(FetchPartitionData.class))).thenReturn(
|
430 |
| - ShareAcquiredRecords.fromAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
| 430 | + createShareAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
431 | 431 | doAnswer(invocation -> buildLogReadResult(Collections.singleton(tp0))).when(replicaManager).readFromLog(any(), any(), any(ReplicaQuota.class), anyBoolean());
|
432 | 432 |
|
433 | 433 | PartitionMaxBytesStrategy partitionMaxBytesStrategy = mockPartitionMaxBytes(Collections.singleton(tp0));
|
@@ -591,7 +591,7 @@ public void testForceCompleteTriggersDelayedActionsQueue() {
|
591 | 591 | when(sp1.maybeAcquireFetchLock()).thenReturn(true);
|
592 | 592 | when(sp1.canAcquireRecords()).thenReturn(true);
|
593 | 593 | when(sp1.acquire(anyString(), anyInt(), anyInt(), anyLong(), any(FetchPartitionData.class))).thenReturn(
|
594 |
| - ShareAcquiredRecords.fromAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
| 594 | + createShareAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
595 | 595 |
|
596 | 596 | // when forceComplete is called for delayedShareFetch2, since tp1 is common in between delayed share fetch
|
597 | 597 | // requests, it should add a "check and complete" action for request key tp1 on the purgatory.
|
@@ -689,7 +689,7 @@ public void testExceptionInMinBytesCalculation() {
|
689 | 689 |
|
690 | 690 | when(sp0.canAcquireRecords()).thenReturn(true);
|
691 | 691 | when(sp0.acquire(any(), anyInt(), anyInt(), anyLong(), any())).thenReturn(
|
692 |
| - ShareAcquiredRecords.fromAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
| 692 | + createShareAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
693 | 693 | doAnswer(invocation -> buildLogReadResult(Collections.singleton(tp0))).when(replicaManager).readFromLog(any(), any(), any(ReplicaQuota.class), anyBoolean());
|
694 | 694 |
|
695 | 695 | // Mocking partition object to throw an exception during min bytes calculation while calling fetchOffsetSnapshot
|
@@ -897,15 +897,15 @@ public void testPartitionMaxBytesFromUniformStrategyWhenAllPartitionsAreAcquirab
|
897 | 897 | BROKER_TOPIC_STATS);
|
898 | 898 |
|
899 | 899 | when(sp0.acquire(anyString(), anyInt(), anyInt(), anyLong(), any(FetchPartitionData.class))).thenReturn(
|
900 |
| - ShareAcquiredRecords.fromAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
| 900 | + createShareAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
901 | 901 | when(sp1.acquire(anyString(), anyInt(), anyInt(), anyLong(), any(FetchPartitionData.class))).thenReturn(
|
902 |
| - ShareAcquiredRecords.fromAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
| 902 | + createShareAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
903 | 903 | when(sp2.acquire(anyString(), anyInt(), anyInt(), anyLong(), any(FetchPartitionData.class))).thenReturn(
|
904 |
| - ShareAcquiredRecords.fromAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
| 904 | + createShareAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
905 | 905 | when(sp3.acquire(anyString(), anyInt(), anyInt(), anyLong(), any(FetchPartitionData.class))).thenReturn(
|
906 |
| - ShareAcquiredRecords.fromAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
| 906 | + createShareAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
907 | 907 | when(sp4.acquire(anyString(), anyInt(), anyInt(), anyLong(), any(FetchPartitionData.class))).thenReturn(
|
908 |
| - ShareAcquiredRecords.fromAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
| 908 | + createShareAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
909 | 909 |
|
910 | 910 | // All 5 partitions are acquirable.
|
911 | 911 | doAnswer(invocation -> buildLogReadResult(sharePartitions.keySet())).when(replicaManager).readFromLog(any(), any(), any(ReplicaQuota.class), anyBoolean());
|
@@ -995,9 +995,9 @@ public void testPartitionMaxBytesFromUniformStrategyWhenFewPartitionsAreAcquirab
|
995 | 995 | BROKER_TOPIC_STATS);
|
996 | 996 |
|
997 | 997 | when(sp0.acquire(anyString(), anyInt(), anyInt(), anyLong(), any(FetchPartitionData.class))).thenReturn(
|
998 |
| - ShareAcquiredRecords.fromAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
| 998 | + createShareAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
999 | 999 | when(sp1.acquire(anyString(), anyInt(), anyInt(), anyLong(), any(FetchPartitionData.class))).thenReturn(
|
1000 |
| - ShareAcquiredRecords.fromAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
| 1000 | + createShareAcquiredRecords(new ShareFetchResponseData.AcquiredRecords().setFirstOffset(0).setLastOffset(3).setDeliveryCount((short) 1))); |
1001 | 1001 |
|
1002 | 1002 | // Only 2 out of 5 partitions are acquirable.
|
1003 | 1003 | Set<TopicIdPartition> acquirableTopicPartitions = new LinkedHashSet<>();
|
|
0 commit comments