Search in sources :

Example 1 with FeatureMap

use of org.apache.kafka.metadata.FeatureMap in project kafka by apache.

the class FeatureControlManagerTest method testReplay.

@Test
public void testReplay() {
    FeatureLevelRecord record = new FeatureLevelRecord().setName("foo").setMinFeatureLevel((short) 1).setMaxFeatureLevel((short) 2);
    SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
    snapshotRegistry.getOrCreateSnapshot(-1);
    FeatureControlManager manager = new FeatureControlManager(rangeMap("foo", 1, 2), snapshotRegistry);
    manager.replay(record);
    snapshotRegistry.getOrCreateSnapshot(123);
    assertEquals(new FeatureMapAndEpoch(new FeatureMap(rangeMap("foo", 1, 2)), 123), manager.finalizedFeatures(123));
}
Also used : FeatureMap(org.apache.kafka.metadata.FeatureMap) SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) LogContext(org.apache.kafka.common.utils.LogContext) FeatureMapAndEpoch(org.apache.kafka.metadata.FeatureMapAndEpoch) FeatureLevelRecord(org.apache.kafka.common.metadata.FeatureLevelRecord) Test(org.junit.jupiter.api.Test)

Example 2 with FeatureMap

use of org.apache.kafka.metadata.FeatureMap in project kafka by apache.

the class FeatureControlManagerTest method testUpdateFeatures.

@Test
public void testUpdateFeatures() {
    SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
    snapshotRegistry.getOrCreateSnapshot(-1);
    FeatureControlManager manager = new FeatureControlManager(rangeMap("foo", 1, 2), snapshotRegistry);
    assertEquals(new FeatureMapAndEpoch(new FeatureMap(Collections.emptyMap()), -1), manager.finalizedFeatures(-1));
    assertEquals(ControllerResult.atomicOf(Collections.emptyList(), Collections.singletonMap("foo", new ApiError(Errors.INVALID_UPDATE_VERSION, "The controller does not support the given feature range."))), manager.updateFeatures(rangeMap("foo", 1, 3), Collections.singleton("foo"), Collections.emptyMap()));
    ControllerResult<Map<String, ApiError>> result = manager.updateFeatures(rangeMap("foo", 1, 2, "bar", 1, 1), Collections.emptySet(), Collections.emptyMap());
    Map<String, ApiError> expectedMap = new HashMap<>();
    expectedMap.put("foo", ApiError.NONE);
    expectedMap.put("bar", new ApiError(Errors.INVALID_UPDATE_VERSION, "The controller does not support the given feature range."));
    assertEquals(expectedMap, result.response());
    List<ApiMessageAndVersion> expectedMessages = new ArrayList<>();
    expectedMessages.add(new ApiMessageAndVersion(new FeatureLevelRecord().setName("foo").setMinFeatureLevel((short) 1).setMaxFeatureLevel((short) 2), (short) 0));
    assertEquals(expectedMessages, result.records());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LogContext(org.apache.kafka.common.utils.LogContext) FeatureMapAndEpoch(org.apache.kafka.metadata.FeatureMapAndEpoch) FeatureLevelRecord(org.apache.kafka.common.metadata.FeatureLevelRecord) FeatureMap(org.apache.kafka.metadata.FeatureMap) SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ApiError(org.apache.kafka.common.requests.ApiError) HashMap(java.util.HashMap) FeatureMap(org.apache.kafka.metadata.FeatureMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 3 with FeatureMap

use of org.apache.kafka.metadata.FeatureMap 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)

Aggregations

LogContext (org.apache.kafka.common.utils.LogContext)3 FeatureMap (org.apache.kafka.metadata.FeatureMap)3 FeatureMapAndEpoch (org.apache.kafka.metadata.FeatureMapAndEpoch)3 SnapshotRegistry (org.apache.kafka.timeline.SnapshotRegistry)3 Test (org.junit.jupiter.api.Test)3 FeatureLevelRecord (org.apache.kafka.common.metadata.FeatureLevelRecord)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 BrokerRegistrationRequestData (org.apache.kafka.common.message.BrokerRegistrationRequestData)1 ApiError (org.apache.kafka.common.requests.ApiError)1 MockTime (org.apache.kafka.common.utils.MockTime)1 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1