@@ -21,7 +21,7 @@ import com.yammer.metrics.core.Metric
21
21
import kafka .log .LogManager
22
22
import kafka .server ._
23
23
import kafka .utils ._
24
- import org .apache .kafka .common .errors .{ApiException , FencedLeaderEpochException , InconsistentTopicIdException , InvalidTxnStateException , NotLeaderOrFollowerException , OffsetNotAvailableException , OffsetOutOfRangeException , UnknownLeaderEpochException }
24
+ import org .apache .kafka .common .errors .{ApiException , FencedLeaderEpochException , InconsistentTopicIdException , InvalidTxnStateException , NotLeaderOrFollowerException , OffsetNotAvailableException , OffsetOutOfRangeException , PolicyViolationException , UnknownLeaderEpochException }
25
25
import org .apache .kafka .common .message .{AlterPartitionResponseData , FetchResponseData }
26
26
import org .apache .kafka .common .protocol .{ApiKeys , Errors }
27
27
import org .apache .kafka .common .record .FileRecords .TimestampAndOffset
@@ -61,7 +61,7 @@ import org.apache.kafka.server.storage.log.{FetchIsolation, FetchParams, Unexpec
61
61
import org .apache .kafka .server .util .{KafkaScheduler , MockTime }
62
62
import org .apache .kafka .storage .internals .checkpoint .OffsetCheckpoints
63
63
import org .apache .kafka .storage .internals .epoch .LeaderEpochFileCache
64
- import org .apache .kafka .storage .internals .log .{AppendOrigin , CleanerConfig , EpochEntry , LocalLog , LogAppendInfo , LogDirFailureChannel , LogLoader , LogOffsetMetadata , LogOffsetsListener , LogReadInfo , LogSegments , LogStartOffsetIncrementReason , ProducerStateManager , ProducerStateManagerConfig , UnifiedLog , VerificationGuard }
64
+ import org .apache .kafka .storage .internals .log .{AppendOrigin , CleanerConfig , EpochEntry , LocalLog , LogAppendInfo , LogConfig , LogDirFailureChannel , LogLoader , LogOffsetMetadata , LogOffsetsListener , LogReadInfo , LogSegments , LogStartOffsetIncrementReason , ProducerStateManager , ProducerStateManagerConfig , UnifiedLog , VerificationGuard }
65
65
import org .apache .kafka .storage .log .metrics .BrokerTopicStats
66
66
import org .junit .jupiter .params .ParameterizedTest
67
67
import org .junit .jupiter .params .provider .ValueSource
@@ -4030,4 +4030,46 @@ class PartitionTest extends AbstractPartitionTest {
4030
4030
alterPartitionManager)
4031
4031
partition.tryCompleteDelayedRequests()
4032
4032
}
4033
+
4034
+ @ Test
4035
+ def testDeleteRecordsOnLeaderWithEmptyPolicy (): Unit = {
4036
+ val leaderEpoch = 5
4037
+ val partition = setupPartitionWithMocks(leaderEpoch, isLeader = true )
4038
+
4039
+ val emptyPolicyConfig = new LogConfig (util.Map .of(
4040
+ TopicConfig .CLEANUP_POLICY_CONFIG , " "
4041
+ ))
4042
+
4043
+ val mockLog = mock(classOf [UnifiedLog ])
4044
+ when(mockLog.config).thenReturn(emptyPolicyConfig)
4045
+ when(mockLog.logEndOffset).thenReturn(2L )
4046
+ when(mockLog.logStartOffset).thenReturn(0L )
4047
+ when(mockLog.highWatermark).thenReturn(2L )
4048
+ when(mockLog.maybeIncrementLogStartOffset(any(), any())).thenReturn(true )
4049
+
4050
+ partition.setLog(mockLog, false )
4051
+
4052
+ val result = partition.deleteRecordsOnLeader(1L )
4053
+ assertEquals(1L , result.requestedOffset)
4054
+ }
4055
+
4056
+ @ Test
4057
+ def testDeleteRecordsOnLeaderWithCompactPolicy (): Unit = {
4058
+ val leaderEpoch = 5
4059
+ val partition = setupPartitionWithMocks(leaderEpoch, isLeader = true )
4060
+
4061
+ val emptyPolicyConfig = new LogConfig (util.Map .of(
4062
+ TopicConfig .CLEANUP_POLICY_CONFIG , " compact"
4063
+ ))
4064
+
4065
+ val mockLog = mock(classOf [UnifiedLog ])
4066
+ when(mockLog.config).thenReturn(emptyPolicyConfig)
4067
+ when(mockLog.logEndOffset).thenReturn(2L )
4068
+ when(mockLog.logStartOffset).thenReturn(0L )
4069
+ when(mockLog.highWatermark).thenReturn(2L )
4070
+ when(mockLog.maybeIncrementLogStartOffset(any(), any())).thenReturn(true )
4071
+
4072
+ partition.setLog(mockLog, false )
4073
+ assertThrows(classOf [PolicyViolationException ], () => partition.deleteRecordsOnLeader(1L ))
4074
+ }
4033
4075
}
0 commit comments