Search in sources :

Example 11 with SnapshotRegistry

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

the class ClusterControlManagerTest method testIterator.

@Test
public void testIterator() throws Exception {
    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));
    for (int i = 0; i < 3; i++) {
        RegisterBrokerRecord brokerRecord = new RegisterBrokerRecord().setBrokerEpoch(100).setBrokerId(i).setRack(null);
        brokerRecord.endPoints().add(new BrokerEndpoint().setSecurityProtocol(SecurityProtocol.PLAINTEXT.id).setPort((short) 9092 + i).setName("PLAINTEXT").setHost("example.com"));
        clusterControl.replay(brokerRecord);
    }
    for (int i = 0; i < 2; i++) {
        UnfenceBrokerRecord unfenceBrokerRecord = new UnfenceBrokerRecord().setId(i).setEpoch(100);
        clusterControl.replay(unfenceBrokerRecord);
    }
    RecordTestUtils.assertBatchIteratorContains(Arrays.asList(Arrays.asList(new ApiMessageAndVersion(new RegisterBrokerRecord().setBrokerEpoch(100).setBrokerId(0).setRack(null).setEndPoints(new BrokerEndpointCollection(Collections.singleton(new BrokerEndpoint().setSecurityProtocol(SecurityProtocol.PLAINTEXT.id).setPort((short) 9092).setName("PLAINTEXT").setHost("example.com")).iterator())).setFenced(false), (short) 0)), Arrays.asList(new ApiMessageAndVersion(new RegisterBrokerRecord().setBrokerEpoch(100).setBrokerId(1).setRack(null).setEndPoints(new BrokerEndpointCollection(Collections.singleton(new BrokerEndpoint().setSecurityProtocol(SecurityProtocol.PLAINTEXT.id).setPort((short) 9093).setName("PLAINTEXT").setHost("example.com")).iterator())).setFenced(false), (short) 0)), Arrays.asList(new ApiMessageAndVersion(new RegisterBrokerRecord().setBrokerEpoch(100).setBrokerId(2).setRack(null).setEndPoints(new BrokerEndpointCollection(Collections.singleton(new BrokerEndpoint().setSecurityProtocol(SecurityProtocol.PLAINTEXT.id).setPort((short) 9094).setName("PLAINTEXT").setHost("example.com")).iterator())).setFenced(true), (short) 0))), clusterControl.iterator(Long.MAX_VALUE));
}
Also used : BrokerEndpointCollection(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpointCollection) LogContext(org.apache.kafka.common.utils.LogContext) Endpoint(org.apache.kafka.common.Endpoint) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) 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) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) 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 12 with SnapshotRegistry

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

the class ClusterControlManagerTest method testPlaceReplicas.

@ParameterizedTest
@ValueSource(ints = { 3, 10 })
public void testPlaceReplicas(int numUsableBrokers) throws Exception {
    MockTime time = new MockTime(0, 0, 0);
    SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
    MockRandom random = new MockRandom();
    ClusterControlManager clusterControl = new ClusterControlManager(new LogContext(), Uuid.randomUuid().toString(), time, snapshotRegistry, 1000, new StripedReplicaPlacer(random), new MockControllerMetrics());
    clusterControl.activate();
    for (int i = 0; i < numUsableBrokers; i++) {
        RegisterBrokerRecord brokerRecord = new RegisterBrokerRecord().setBrokerEpoch(100).setBrokerId(i);
        brokerRecord.endPoints().add(new BrokerEndpoint().setSecurityProtocol(SecurityProtocol.PLAINTEXT.id).setPort((short) 9092).setName("PLAINTEXT").setHost("example.com"));
        clusterControl.replay(brokerRecord);
        UnfenceBrokerRecord unfenceRecord = new UnfenceBrokerRecord().setId(i).setEpoch(100);
        clusterControl.replay(unfenceRecord);
        clusterControl.heartbeatManager().touch(i, false, 0);
    }
    for (int i = 0; i < numUsableBrokers; i++) {
        assertTrue(clusterControl.unfenced(i), String.format("broker %d was not unfenced.", i));
    }
    for (int i = 0; i < 100; i++) {
        List<List<Integer>> results = clusterControl.placeReplicas(0, 1, (short) 3);
        HashSet<Integer> seen = new HashSet<>();
        for (Integer result : results.get(0)) {
            assertTrue(result >= 0);
            assertTrue(result < numUsableBrokers);
            assertTrue(seen.add(result));
        }
    }
}
Also used : LogContext(org.apache.kafka.common.utils.LogContext) Endpoint(org.apache.kafka.common.Endpoint) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) RegisterBrokerRecord(org.apache.kafka.common.metadata.RegisterBrokerRecord) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) List(java.util.List) UnfenceBrokerRecord(org.apache.kafka.common.metadata.UnfenceBrokerRecord) MockTime(org.apache.kafka.common.utils.MockTime) HashSet(java.util.HashSet) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with SnapshotRegistry

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

the class TimelineHashMapBenchmark method testAddEntriesWithSnapshots.

@Benchmark
public Map<Integer, String> testAddEntriesWithSnapshots() {
    SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
    TimelineHashMap<Integer, String> map = new TimelineHashMap<>(snapshotRegistry, NUM_ENTRIES);
    long epoch = 0;
    int j = 0;
    for (int i = 0; i < NUM_ENTRIES; i++) {
        int key = (int) (0xffffffff & ((i * 2862933555777941757L) + 3037000493L));
        if (j > 10 && key % 3 == 0) {
            snapshotRegistry.deleteSnapshotsUpTo(epoch - 1000);
            snapshotRegistry.getOrCreateSnapshot(epoch);
            j = 0;
        } else {
            j++;
        }
        map.put(key, String.valueOf(key));
        epoch++;
    }
    return map;
}
Also used : SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) TimelineHashMap(org.apache.kafka.timeline.TimelineHashMap) LogContext(org.apache.kafka.common.utils.LogContext) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 14 with SnapshotRegistry

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

the class ClientQuotaControlManagerTest method testInvalidEntityTypes.

@Test
public void testInvalidEntityTypes() {
    SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
    ClientQuotaControlManager manager = new ClientQuotaControlManager(snapshotRegistry);
    // Unknown type "foo"
    assertInvalidEntity(manager, entity("foo", "bar"));
    // Null type
    assertInvalidEntity(manager, entity(null, "null"));
    // Valid + unknown combo
    assertInvalidEntity(manager, entity(ClientQuotaEntity.USER, "user-1", "foo", "bar"));
    assertInvalidEntity(manager, entity("foo", "bar", ClientQuotaEntity.IP, "1.2.3.4"));
    // Invalid combinations
    assertInvalidEntity(manager, entity(ClientQuotaEntity.USER, "user-1", ClientQuotaEntity.IP, "1.2.3.4"));
    assertInvalidEntity(manager, entity(ClientQuotaEntity.CLIENT_ID, "user-1", ClientQuotaEntity.IP, "1.2.3.4"));
    // Empty
    assertInvalidEntity(manager, new ClientQuotaEntity(Collections.emptyMap()));
}
Also used : SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) LogContext(org.apache.kafka.common.utils.LogContext) ClientQuotaEntity(org.apache.kafka.common.quota.ClientQuotaEntity) Test(org.junit.jupiter.api.Test)

Example 15 with SnapshotRegistry

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

the class ClientQuotaControlManagerTest method testInvalidQuotaKeys.

@Test
public void testInvalidQuotaKeys() {
    SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
    ClientQuotaControlManager manager = new ClientQuotaControlManager(snapshotRegistry);
    ClientQuotaEntity entity = entity(ClientQuotaEntity.USER, "user-1");
    // Invalid + valid keys
    assertInvalidQuota(manager, entity, quotas("not.a.quota.key", 0.0, QuotaConfigs.REQUEST_PERCENTAGE_OVERRIDE_CONFIG, 99.9));
    // Valid + invalid keys
    assertInvalidQuota(manager, entity, quotas(QuotaConfigs.REQUEST_PERCENTAGE_OVERRIDE_CONFIG, 99.9, "not.a.quota.key", 0.0));
    // Null key
    assertInvalidQuota(manager, entity, quotas(null, 99.9));
}
Also used : SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) LogContext(org.apache.kafka.common.utils.LogContext) ClientQuotaEntity(org.apache.kafka.common.quota.ClientQuotaEntity) Test(org.junit.jupiter.api.Test)

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