@ -72,6 +72,7 @@ import org.apache.kafka.common.utils.LogContext;
@@ -72,6 +72,7 @@ import org.apache.kafka.common.utils.LogContext;
import org.apache.kafka.common.utils.MockTime ;
import org.apache.kafka.common.utils.Utils ;
import org.apache.kafka.common.utils.annotation.ApiKeyVersionsSource ;
import org.apache.kafka.controller.BrokerHeartbeatManager.BrokerHeartbeatState ;
import org.apache.kafka.controller.ReplicationControlManager.KRaftClusterDescriber ;
import org.apache.kafka.metadata.BrokerHeartbeatReply ;
import org.apache.kafka.metadata.BrokerRegistration ;
@ -154,9 +155,36 @@ public class ReplicationControlManagerTest {
@@ -154,9 +155,36 @@ public class ReplicationControlManagerTest {
private final static int BROKER_SESSION_TIMEOUT_MS = 1000 ;
private static class ReplicationControlTestContext {
private static class Builder {
private Optional < CreateTopicPolicy > createTopicPolicy = Optional . empty ( ) ;
private MetadataVersion metadataVersion = MetadataVersion . latest ( ) ;
private MockTime mockTime = new MockTime ( ) ;
Builder setCreateTopicPolicy ( CreateTopicPolicy createTopicPolicy ) {
this . createTopicPolicy = Optional . of ( createTopicPolicy ) ;
return this ;
}
Builder setMetadataVersion ( MetadataVersion metadataVersion ) {
this . metadataVersion = metadataVersion ;
return this ;
}
Builder setMockTime ( MockTime mockTime ) {
this . mockTime = mockTime ;
return this ;
}
ReplicationControlTestContext build ( ) {
return new ReplicationControlTestContext ( metadataVersion ,
createTopicPolicy ,
mockTime ) ;
}
}
final SnapshotRegistry snapshotRegistry = new SnapshotRegistry ( new LogContext ( ) ) ;
final LogContext logContext = new LogContext ( ) ;
final MockTime time = new MockTime ( ) ;
final MockTime time ;
final MockRandom random = new MockRandom ( ) ;
final FeatureControlManager featureControl ;
final ClusterControlManager clusterControl ;
@ -171,19 +199,12 @@ public class ReplicationControlManagerTest {
@@ -171,19 +199,12 @@ public class ReplicationControlManagerTest {
RecordTestUtils . replayAll ( replicationControl , records ) ;
}
ReplicationControlTestContext ( ) {
this ( Optional . empty ( ) ) ;
}
ReplicationControlTestContext ( MetadataVersion metadataVersion ) {
this ( metadataVersion , Optional . empty ( ) ) ;
}
ReplicationControlTestContext ( Optional < CreateTopicPolicy > createTopicPolicy ) {
this ( MetadataVersion . latest ( ) , createTopicPolicy ) ;
}
ReplicationControlTestContext ( MetadataVersion metadataVersion , Optional < CreateTopicPolicy > createTopicPolicy ) {
private ReplicationControlTestContext (
MetadataVersion metadataVersion ,
Optional < CreateTopicPolicy > createTopicPolicy ,
MockTime time
) {
this . time = time ;
this . featureControl = new FeatureControlManager . Builder ( ) .
setSnapshotRegistry ( snapshotRegistry ) .
setQuorumFeatures ( new QuorumFeatures ( 0 , new ApiVersions ( ) ,
@ -469,7 +490,7 @@ public class ReplicationControlManagerTest {
@@ -469,7 +490,7 @@ public class ReplicationControlManagerTest {
@Test
public void testCreateTopics ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replicationControl = ctx . replicationControl ;
CreateTopicsRequestData request = new CreateTopicsRequestData ( ) ;
request . topics ( ) . add ( new CreatableTopic ( ) . setName ( "foo" ) .
@ -525,7 +546,7 @@ public class ReplicationControlManagerTest {
@@ -525,7 +546,7 @@ public class ReplicationControlManagerTest {
@Test
public void testCreateTopicsWithMutationQuotaExceeded ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replicationControl = ctx . replicationControl ;
CreateTopicsRequestData request = new CreateTopicsRequestData ( ) ;
request . topics ( ) . add ( new CreatableTopic ( ) . setName ( "foo" ) .
@ -545,7 +566,7 @@ public class ReplicationControlManagerTest {
@@ -545,7 +566,7 @@ public class ReplicationControlManagerTest {
@Test
public void testCreateTopicsISRInvariants ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replicationControl = ctx . replicationControl ;
CreateTopicsRequestData request = new CreateTopicsRequestData ( ) ;
@ -586,7 +607,7 @@ public class ReplicationControlManagerTest {
@@ -586,7 +607,7 @@ public class ReplicationControlManagerTest {
@Test
public void testCreateTopicsWithConfigs ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replicationControl = ctx . replicationControl ;
ctx . registerBrokers ( 0 , 1 , 2 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 ) ;
@ -692,7 +713,7 @@ public class ReplicationControlManagerTest {
@@ -692,7 +713,7 @@ public class ReplicationControlManagerTest {
@ParameterizedTest ( name = "testCreateTopicsWithValidateOnlyFlag with mutationQuotaExceeded: {0}" )
@ValueSource ( booleans = { true , false } )
public void testCreateTopicsWithValidateOnlyFlag ( boolean mutationQuotaExceeded ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ctx . registerBrokers ( 0 , 1 , 2 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 ) ;
CreateTopicsRequestData request = new CreateTopicsRequestData ( ) . setValidateOnly ( true ) ;
@ -714,7 +735,7 @@ public class ReplicationControlManagerTest {
@@ -714,7 +735,7 @@ public class ReplicationControlManagerTest {
@Test
public void testInvalidCreateTopicsWithValidateOnlyFlag ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ctx . registerBrokers ( 0 , 1 , 2 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 ) ;
CreateTopicsRequestData request = new CreateTopicsRequestData ( ) . setValidateOnly ( true ) ;
@ -745,8 +766,9 @@ public class ReplicationControlManagerTest {
@@ -745,8 +766,9 @@ public class ReplicationControlManagerTest {
Collections . singletonMap ( SEGMENT_BYTES_CONFIG , "12300000" ) ) ,
new CreateTopicPolicy . RequestMetadata ( "quux" , null , null ,
Collections . singletonMap ( 0 , asList ( 2 , 1 , 0 ) ) , Collections . emptyMap ( ) ) ) ) ;
ReplicationControlTestContext ctx =
new ReplicationControlTestContext ( Optional . of ( createTopicPolicy ) ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) .
setCreateTopicPolicy ( createTopicPolicy ) .
build ( ) ;
ctx . registerBrokers ( 0 , 1 , 2 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 ) ;
ctx . createTestTopic ( "foo" , 2 , ( short ) 2 , NONE . code ( ) ) ;
@ -758,7 +780,7 @@ public class ReplicationControlManagerTest {
@@ -758,7 +780,7 @@ public class ReplicationControlManagerTest {
@Test
public void testCreateTopicWithCollisionChars ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( Optional . empty ( ) ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ctx . registerBrokers ( 0 , 1 , 2 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 ) ;
@ -808,7 +830,7 @@ public class ReplicationControlManagerTest {
@@ -808,7 +830,7 @@ public class ReplicationControlManagerTest {
@Test
public void testRemoveLeaderships ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replicationControl = ctx . replicationControl ;
ctx . registerBrokers ( 0 , 1 , 2 , 3 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 , 3 ) ;
@ -833,7 +855,7 @@ public class ReplicationControlManagerTest {
@@ -833,7 +855,7 @@ public class ReplicationControlManagerTest {
@Test
public void testShrinkAndExpandIsr ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replicationControl = ctx . replicationControl ;
ctx . registerBrokers ( 0 , 1 , 2 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 ) ;
@ -863,7 +885,7 @@ public class ReplicationControlManagerTest {
@@ -863,7 +885,7 @@ public class ReplicationControlManagerTest {
@ParameterizedTest
@ApiKeyVersionsSource ( apiKey = ApiKeys . ALTER_PARTITION )
public void testAlterPartitionHandleUnknownTopicIdOrName ( short version ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replicationControl = ctx . replicationControl ;
ctx . registerBrokers ( 0 , 1 , 2 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 ) ;
@ -900,7 +922,7 @@ public class ReplicationControlManagerTest {
@@ -900,7 +922,7 @@ public class ReplicationControlManagerTest {
@Test
public void testInvalidAlterPartitionRequests ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replicationControl = ctx . replicationControl ;
ctx . registerBrokers ( 0 , 1 , 2 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 ) ;
@ -1073,7 +1095,7 @@ public class ReplicationControlManagerTest {
@@ -1073,7 +1095,7 @@ public class ReplicationControlManagerTest {
@Test
public void testDeleteTopics ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replicationControl = ctx . replicationControl ;
CreateTopicsRequestData request = new CreateTopicsRequestData ( ) ;
CreateTopicsRequestData . CreateableTopicConfigCollection requestConfigs =
@ -1148,7 +1170,7 @@ public class ReplicationControlManagerTest {
@@ -1148,7 +1170,7 @@ public class ReplicationControlManagerTest {
@Test
public void testDeleteTopicsWithMutationQuotaExceeded ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replicationControl = ctx . replicationControl ;
CreateTopicsRequestData request = new CreateTopicsRequestData ( ) ;
request . topics ( ) . add ( new CreatableTopic ( ) . setName ( "foo" ) .
@ -1175,7 +1197,7 @@ public class ReplicationControlManagerTest {
@@ -1175,7 +1197,7 @@ public class ReplicationControlManagerTest {
@Test
public void testCreatePartitions ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replicationControl = ctx . replicationControl ;
CreateTopicsRequestData request = new CreateTopicsRequestData ( ) ;
request . topics ( ) . add ( new CreatableTopic ( ) . setName ( "foo" ) .
@ -1261,7 +1283,7 @@ public class ReplicationControlManagerTest {
@@ -1261,7 +1283,7 @@ public class ReplicationControlManagerTest {
@Test
public void testCreatePartitionsWithMutationQuotaExceeded ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replicationControl = ctx . replicationControl ;
CreateTopicsRequestData request = new CreateTopicsRequestData ( ) ;
request . topics ( ) . add ( new CreatableTopic ( ) . setName ( "foo" ) .
@ -1300,7 +1322,7 @@ public class ReplicationControlManagerTest {
@@ -1300,7 +1322,7 @@ public class ReplicationControlManagerTest {
@Test
public void testCreatePartitionsFailsWhenAllBrokersAreFencedOrInControlledShutdown ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replicationControl = ctx . replicationControl ;
CreateTopicsRequestData request = new CreateTopicsRequestData ( ) ;
request . topics ( ) . add ( new CreatableTopic ( ) . setName ( "foo" ) .
@ -1336,7 +1358,7 @@ public class ReplicationControlManagerTest {
@@ -1336,7 +1358,7 @@ public class ReplicationControlManagerTest {
@Test
public void testCreatePartitionsISRInvariants ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replicationControl = ctx . replicationControl ;
CreateTopicsRequestData request = new CreateTopicsRequestData ( ) ;
@ -1376,7 +1398,7 @@ public class ReplicationControlManagerTest {
@@ -1376,7 +1398,7 @@ public class ReplicationControlManagerTest {
@Test
public void testValidateGoodManualPartitionAssignments ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ctx . registerBrokers ( 1 , 2 , 3 ) ;
ctx . replicationControl . validateManualPartitionAssignment ( new PartitionAssignment ( asList ( 1 ) ) ,
OptionalInt . of ( 1 ) ) ;
@ -1390,7 +1412,7 @@ public class ReplicationControlManagerTest {
@@ -1390,7 +1412,7 @@ public class ReplicationControlManagerTest {
@Test
public void testValidateBadManualPartitionAssignments ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ctx . registerBrokers ( 1 , 2 ) ;
assertEquals ( "The manual partition assignment includes an empty replica list." ,
assertThrows ( InvalidReplicaAssignmentException . class , ( ) - >
@ -1417,7 +1439,7 @@ public class ReplicationControlManagerTest {
@@ -1417,7 +1439,7 @@ public class ReplicationControlManagerTest {
@ParameterizedTest
@ApiKeyVersionsSource ( apiKey = ApiKeys . ALTER_PARTITION )
public void testReassignPartitions ( short version ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replication = ctx . replicationControl ;
ctx . registerBrokers ( 0 , 1 , 2 , 3 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 , 3 ) ;
@ -1534,7 +1556,7 @@ public class ReplicationControlManagerTest {
@@ -1534,7 +1556,7 @@ public class ReplicationControlManagerTest {
@ParameterizedTest
@ApiKeyVersionsSource ( apiKey = ApiKeys . ALTER_PARTITION )
public void testAlterPartitionShouldRejectFencedBrokers ( short version ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replication = ctx . replicationControl ;
ctx . registerBrokers ( 0 , 1 , 2 , 3 , 4 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 , 3 , 4 ) ;
@ -1612,7 +1634,7 @@ public class ReplicationControlManagerTest {
@@ -1612,7 +1634,7 @@ public class ReplicationControlManagerTest {
@ParameterizedTest
@ApiKeyVersionsSource ( apiKey = ApiKeys . ALTER_PARTITION )
public void testAlterPartitionShouldRejectBrokersWithStaleEpoch ( short version ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replication = ctx . replicationControl ;
ctx . registerBrokers ( 0 , 1 , 2 , 3 , 4 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 , 3 , 4 ) ;
@ -1681,7 +1703,7 @@ public class ReplicationControlManagerTest {
@@ -1681,7 +1703,7 @@ public class ReplicationControlManagerTest {
@ParameterizedTest
@ApiKeyVersionsSource ( apiKey = ApiKeys . ALTER_PARTITION )
public void testAlterPartitionShouldRejectShuttingDownBrokers ( short version ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replication = ctx . replicationControl ;
ctx . registerBrokers ( 0 , 1 , 2 , 3 , 4 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 , 3 , 4 ) ;
@ -1736,7 +1758,7 @@ public class ReplicationControlManagerTest {
@@ -1736,7 +1758,7 @@ public class ReplicationControlManagerTest {
@Test
public void testCancelReassignPartitions ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replication = ctx . replicationControl ;
ctx . registerBrokers ( 0 , 1 , 2 , 3 , 4 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 , 3 , 4 ) ;
@ -1855,7 +1877,7 @@ public class ReplicationControlManagerTest {
@@ -1855,7 +1877,7 @@ public class ReplicationControlManagerTest {
@Test
public void testManualPartitionAssignmentOnAllFencedBrokers ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ctx . registerBrokers ( 0 , 1 , 2 , 3 ) ;
ctx . createTestTopic ( "foo" , new int [ ] [ ] { new int [ ] { 0 , 1 , 2 } } ,
INVALID_REPLICA_ASSIGNMENT . code ( ) ) ;
@ -1863,7 +1885,7 @@ public class ReplicationControlManagerTest {
@@ -1863,7 +1885,7 @@ public class ReplicationControlManagerTest {
@Test
public void testCreatePartitionsFailsWithManualAssignmentWithAllFenced ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ctx . registerBrokers ( 0 , 1 , 2 , 3 , 4 , 5 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 ) ;
Uuid fooId = ctx . createTestTopic ( "foo" , new int [ ] [ ] { new int [ ] { 0 , 1 , 2 } } ) . topicId ( ) ;
@ -1892,7 +1914,7 @@ public class ReplicationControlManagerTest {
@@ -1892,7 +1914,7 @@ public class ReplicationControlManagerTest {
@ParameterizedTest
@ValueSource ( booleans = { true , false } )
public void testElectUncleanLeaders ( boolean electAllPartitions ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replication = ctx . replicationControl ;
ctx . registerBrokers ( 0 , 1 , 2 , 3 , 4 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 , 3 , 4 ) ;
@ -1978,7 +2000,7 @@ public class ReplicationControlManagerTest {
@@ -1978,7 +2000,7 @@ public class ReplicationControlManagerTest {
@Test
public void testPreferredElectionDoesNotTriggerUncleanElection ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replication = ctx . replicationControl ;
ctx . registerBrokers ( 1 , 2 , 3 , 4 ) ;
ctx . unfenceBrokers ( 1 , 2 , 3 , 4 ) ;
@ -2031,7 +2053,7 @@ public class ReplicationControlManagerTest {
@@ -2031,7 +2053,7 @@ public class ReplicationControlManagerTest {
@Test
public void testFenceMultipleBrokers ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replication = ctx . replicationControl ;
ctx . registerBrokers ( 0 , 1 , 2 , 3 , 4 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 , 3 , 4 ) ;
@ -2061,7 +2083,7 @@ public class ReplicationControlManagerTest {
@@ -2061,7 +2083,7 @@ public class ReplicationControlManagerTest {
@Test
public void testElectPreferredLeaders ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replication = ctx . replicationControl ;
ctx . registerBrokers ( 0 , 1 , 2 , 3 , 4 ) ;
ctx . unfenceBrokers ( 1 , 2 , 3 , 4 ) ;
@ -2181,7 +2203,7 @@ public class ReplicationControlManagerTest {
@@ -2181,7 +2203,7 @@ public class ReplicationControlManagerTest {
@Test
public void testBalancePartitionLeaders ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replication = ctx . replicationControl ;
ctx . registerBrokers ( 0 , 1 , 2 , 3 , 4 ) ;
ctx . unfenceBrokers ( 2 , 3 , 4 ) ;
@ -2307,7 +2329,7 @@ public class ReplicationControlManagerTest {
@@ -2307,7 +2329,7 @@ public class ReplicationControlManagerTest {
@Test
public void testKRaftClusterDescriber ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replication = ctx . replicationControl ;
ctx . registerBrokers ( 0 , 1 , 2 , 3 , 4 ) ;
ctx . unfenceBrokers ( 2 , 3 , 4 ) ;
@ -2329,7 +2351,9 @@ public class ReplicationControlManagerTest {
@@ -2329,7 +2351,9 @@ public class ReplicationControlManagerTest {
@ParameterizedTest
@EnumSource ( value = MetadataVersion . class , names = { "IBP_3_3_IV2" , "IBP_3_3_IV3" } )
public void testProcessBrokerHeartbeatInControlledShutdown ( MetadataVersion metadataVersion ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( metadataVersion ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) .
setMetadataVersion ( metadataVersion ) .
build ( ) ;
ctx . registerBrokers ( 0 , 1 , 2 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 ) ;
@ -2367,9 +2391,34 @@ public class ReplicationControlManagerTest {
@@ -2367,9 +2391,34 @@ public class ReplicationControlManagerTest {
assertEquals ( expectedRecords , result . records ( ) ) ;
}
@Test
public void testProcessExpiredBrokerHeartbeat ( ) throws Exception {
MockTime mockTime = new MockTime ( 0 , 0 , 0 ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) .
setMockTime ( mockTime ) .
build ( ) ;
ctx . registerBrokers ( 0 , 1 , 2 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 ) ;
BrokerHeartbeatRequestData heartbeatRequest = new BrokerHeartbeatRequestData ( ) .
setBrokerId ( 0 ) .
setBrokerEpoch ( 100 ) .
setCurrentMetadataOffset ( 123 ) .
setWantShutDown ( false ) ;
mockTime . sleep ( 100 ) ;
ctx . replicationControl . processExpiredBrokerHeartbeat ( heartbeatRequest ) ;
Optional < BrokerHeartbeatState > state =
ctx . clusterControl . heartbeatManager ( ) . brokers ( ) . stream ( ) .
filter ( broker - > broker . id ( ) = = 0 ) . findFirst ( ) ;
assertTrue ( state . isPresent ( ) ) ;
assertEquals ( 0 , state . get ( ) . id ( ) ) ;
assertEquals ( 100000000L , state . get ( ) . lastContactNs ) ;
assertEquals ( 123 , state . get ( ) . metadataOffset ) ;
}
@Test
public void testReassignPartitionsHandlesNewReassignmentThatRemovesPreviouslyAddingReplicas ( ) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext ( ) ;
ReplicationControlTestContext ctx = new ReplicationControlTestContext . Builder ( ) . build ( ) ;
ReplicationControlManager replication = ctx . replicationControl ;
ctx . registerBrokers ( 0 , 1 , 2 , 3 , 4 , 5 ) ;
ctx . unfenceBrokers ( 0 , 1 , 2 , 3 , 4 , 5 ) ;