Search in sources :

Example 26 with SnapshotRegistry

use of org.apache.kafka.timeline.SnapshotRegistry in project kafka by apache.

the class ClusterControlManagerTest method testReplay.

@Test
public void testReplay() {
    MockTime time = new MockTime(0, 0, 0);
    SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
    ClusterControlManager clusterControl = new ClusterControlManager(new LogContext(), Uuid.randomUuid().toString(), time, snapshotRegistry, 1000, new StripedReplicaPlacer(new Random()), new MockControllerMetrics());
    clusterControl.activate();
    assertFalse(clusterControl.unfenced(0));
    RegisterBrokerRecord brokerRecord = new RegisterBrokerRecord().setBrokerEpoch(100).setBrokerId(1);
    brokerRecord.endPoints().add(new BrokerEndpoint().setSecurityProtocol(SecurityProtocol.PLAINTEXT.id).setPort((short) 9092).setName("PLAINTEXT").setHost("example.com"));
    clusterControl.replay(brokerRecord);
    clusterControl.checkBrokerEpoch(1, 100);
    assertThrows(StaleBrokerEpochException.class, () -> clusterControl.checkBrokerEpoch(1, 101));
    assertThrows(StaleBrokerEpochException.class, () -> clusterControl.checkBrokerEpoch(2, 100));
    assertFalse(clusterControl.unfenced(0));
    assertFalse(clusterControl.unfenced(1));
    UnfenceBrokerRecord unfenceBrokerRecord = new UnfenceBrokerRecord().setId(1).setEpoch(100);
    clusterControl.replay(unfenceBrokerRecord);
    assertFalse(clusterControl.unfenced(0));
    assertTrue(clusterControl.unfenced(1));
}
Also used : SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) Random(java.util.Random) RegisterBrokerRecord(org.apache.kafka.common.metadata.RegisterBrokerRecord) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) LogContext(org.apache.kafka.common.utils.LogContext) UnfenceBrokerRecord(org.apache.kafka.common.metadata.UnfenceBrokerRecord) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with SnapshotRegistry

use of org.apache.kafka.timeline.SnapshotRegistry in project kafka by apache.

the class ClusterControlManagerTest method testRegistrationWithIncorrectClusterId.

@Test
public void testRegistrationWithIncorrectClusterId() throws Exception {
    SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
    ClusterControlManager clusterControl = new ClusterControlManager(new LogContext(), "fPZv1VBsRFmnlRvmGcOW9w", new MockTime(0, 0, 0), snapshotRegistry, 1000, new StripedReplicaPlacer(new Random()), new MockControllerMetrics());
    clusterControl.activate();
    assertThrows(InconsistentClusterIdException.class, () -> clusterControl.registerBroker(new BrokerRegistrationRequestData().setClusterId("WIjw3grwRZmR2uOpdpVXbg").setBrokerId(0).setRack(null).setIncarnationId(Uuid.fromString("0H4fUu1xQEKXFYwB1aBjhg")), 123L, new FeatureMapAndEpoch(new FeatureMap(Collections.emptyMap()), 456L)));
}
Also used : FeatureMap(org.apache.kafka.metadata.FeatureMap) SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) Random(java.util.Random) BrokerRegistrationRequestData(org.apache.kafka.common.message.BrokerRegistrationRequestData) LogContext(org.apache.kafka.common.utils.LogContext) FeatureMapAndEpoch(org.apache.kafka.metadata.FeatureMapAndEpoch) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with SnapshotRegistry

use of org.apache.kafka.timeline.SnapshotRegistry in project kafka by apache.

the class ClusterControlManagerTest method testUnregister.

@Test
public void testUnregister() throws Exception {
    RegisterBrokerRecord brokerRecord = new RegisterBrokerRecord().setBrokerId(1).setBrokerEpoch(100).setIncarnationId(Uuid.fromString("fPZv1VBsRFmnlRvmGcOW9w")).setRack("arack");
    brokerRecord.endPoints().add(new BrokerEndpoint().setSecurityProtocol(SecurityProtocol.PLAINTEXT.id).setPort((short) 9092).setName("PLAINTEXT").setHost("example.com"));
    SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
    ClusterControlManager clusterControl = new ClusterControlManager(new LogContext(), Uuid.randomUuid().toString(), new MockTime(0, 0, 0), snapshotRegistry, 1000, new StripedReplicaPlacer(new Random()), new MockControllerMetrics());
    clusterControl.activate();
    clusterControl.replay(brokerRecord);
    assertEquals(new BrokerRegistration(1, 100, Uuid.fromString("fPZv1VBsRFmnlRvmGcOW9w"), Collections.singletonMap("PLAINTEXT", new Endpoint("PLAINTEXT", SecurityProtocol.PLAINTEXT, "example.com", 9092)), Collections.emptyMap(), Optional.of("arack"), true), clusterControl.brokerRegistrations().get(1));
    UnregisterBrokerRecord unregisterRecord = new UnregisterBrokerRecord().setBrokerId(1).setBrokerEpoch(100);
    clusterControl.replay(unregisterRecord);
    assertFalse(clusterControl.brokerRegistrations().containsKey(1));
}
Also used : SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) Random(java.util.Random) Endpoint(org.apache.kafka.common.Endpoint) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) RegisterBrokerRecord(org.apache.kafka.common.metadata.RegisterBrokerRecord) UnregisterBrokerRecord(org.apache.kafka.common.metadata.UnregisterBrokerRecord) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) LogContext(org.apache.kafka.common.utils.LogContext) BrokerRegistration(org.apache.kafka.metadata.BrokerRegistration) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

LogContext (org.apache.kafka.common.utils.LogContext)28 SnapshotRegistry (org.apache.kafka.timeline.SnapshotRegistry)28 Test (org.junit.jupiter.api.Test)24 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)12 HashMap (java.util.HashMap)6 MockTime (org.apache.kafka.common.utils.MockTime)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 Random (java.util.Random)5 RegisterBrokerRecord (org.apache.kafka.common.metadata.RegisterBrokerRecord)5 FeatureMap (org.apache.kafka.metadata.FeatureMap)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Endpoint (org.apache.kafka.common.Endpoint)4 ConfigRecord (org.apache.kafka.common.metadata.ConfigRecord)4 FeatureLevelRecord (org.apache.kafka.common.metadata.FeatureLevelRecord)4 BrokerEndpoint (org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint)4 ClientQuotaEntity (org.apache.kafka.common.quota.ClientQuotaEntity)4 ApiError (org.apache.kafka.common.requests.ApiError)4 HashSet (java.util.HashSet)3 List (java.util.List)3