Search in sources :

Example 6 with SnapshotRegistry

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

the class AclControlManagerTest method testAddAndDelete.

@Test
public void testAddAndDelete() {
    SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
    AclControlManager manager = new AclControlManager(snapshotRegistry, Optional.empty());
    MockClusterMetadataAuthorizer authorizer = new MockClusterMetadataAuthorizer();
    authorizer.loadSnapshot(manager.idToAcl());
    manager.replay(StandardAclWithIdTest.TEST_ACLS.get(0).toRecord(), Optional.empty());
    assertEquals(new ApiMessageAndVersion(TEST_ACLS.get(0).toRecord(), (short) 0), manager.iterator(Long.MAX_VALUE).next().get(0));
    manager.replay(new RemoveAccessControlEntryRecord().setId(TEST_ACLS.get(0).id()), Optional.empty());
    assertFalse(manager.iterator(Long.MAX_VALUE).hasNext());
}
Also used : SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) LogContext(org.apache.kafka.common.utils.LogContext) RemoveAccessControlEntryRecord(org.apache.kafka.common.metadata.RemoveAccessControlEntryRecord) StandardAclWithIdTest(org.apache.kafka.metadata.authorizer.StandardAclWithIdTest) StandardAclTest(org.apache.kafka.metadata.authorizer.StandardAclTest) Test(org.junit.jupiter.api.Test)

Example 7 with SnapshotRegistry

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

the class BrokersToIsrsTest method testIterator.

@Test
public void testIterator() {
    SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
    BrokersToIsrs brokersToIsrs = new BrokersToIsrs(snapshotRegistry);
    assertEquals(toSet(), toSet(brokersToIsrs.iterator(1, false)));
    brokersToIsrs.update(UUIDS[0], 0, null, new int[] { 1, 2, 3 }, -1, 1);
    brokersToIsrs.update(UUIDS[1], 1, null, new int[] { 2, 3, 4 }, -1, 4);
    assertEquals(toSet(new TopicIdPartition(UUIDS[0], 0)), toSet(brokersToIsrs.iterator(1, false)));
    assertEquals(toSet(new TopicIdPartition(UUIDS[0], 0), new TopicIdPartition(UUIDS[1], 1)), toSet(brokersToIsrs.iterator(2, false)));
    assertEquals(toSet(new TopicIdPartition(UUIDS[1], 1)), toSet(brokersToIsrs.iterator(4, false)));
    assertEquals(toSet(), toSet(brokersToIsrs.iterator(5, false)));
    brokersToIsrs.update(UUIDS[1], 2, null, new int[] { 3, 2, 1 }, -1, 3);
    assertEquals(toSet(new TopicIdPartition(UUIDS[0], 0), new TopicIdPartition(UUIDS[1], 1), new TopicIdPartition(UUIDS[1], 2)), toSet(brokersToIsrs.iterator(2, false)));
}
Also used : SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) LogContext(org.apache.kafka.common.utils.LogContext) TopicIdPartition(org.apache.kafka.controller.BrokersToIsrs.TopicIdPartition) Test(org.junit.jupiter.api.Test)

Example 8 with SnapshotRegistry

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

the class BrokersToIsrsTest method testNoLeader.

@Test
public void testNoLeader() {
    SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
    BrokersToIsrs brokersToIsrs = new BrokersToIsrs(snapshotRegistry);
    brokersToIsrs.update(UUIDS[0], 2, null, new int[] { 1, 2, 3 }, -1, 3);
    assertEquals(toSet(new TopicIdPartition(UUIDS[0], 2)), toSet(brokersToIsrs.iterator(3, true)));
    assertEquals(toSet(), toSet(brokersToIsrs.iterator(2, true)));
    assertEquals(toSet(), toSet(brokersToIsrs.partitionsWithNoLeader()));
    brokersToIsrs.update(UUIDS[0], 2, new int[] { 1, 2, 3 }, new int[] { 1, 2, 3 }, 3, -1);
    assertEquals(toSet(new TopicIdPartition(UUIDS[0], 2)), toSet(brokersToIsrs.partitionsWithNoLeader()));
}
Also used : SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) LogContext(org.apache.kafka.common.utils.LogContext) TopicIdPartition(org.apache.kafka.controller.BrokersToIsrs.TopicIdPartition) Test(org.junit.jupiter.api.Test)

Example 9 with SnapshotRegistry

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

the class TimelineHashMapBenchmark method testAddEntriesInTimelineMap.

@Benchmark
public Map<Integer, String> testAddEntriesInTimelineMap() {
    SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
    TimelineHashMap<Integer, String> map = new TimelineHashMap<>(snapshotRegistry, NUM_ENTRIES);
    for (int i = 0; i < NUM_ENTRIES; i++) {
        int key = (int) (0xffffffff & ((i * 2862933555777941757L) + 3037000493L));
        map.put(key, String.valueOf(key));
    }
    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 10 with SnapshotRegistry

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

the class ProducerIdControlManagerTest method setUp.

@BeforeEach
public void setUp() {
    final LogContext logContext = new LogContext();
    String clusterId = Uuid.randomUuid().toString();
    final MockTime time = new MockTime();
    final Random random = new Random();
    snapshotRegistry = new SnapshotRegistry(logContext);
    clusterControl = new ClusterControlManager(logContext, clusterId, time, snapshotRegistry, 1000, new StripedReplicaPlacer(random), new MockControllerMetrics());
    clusterControl.activate();
    for (int i = 0; i < 4; i++) {
        RegisterBrokerRecord brokerRecord = new RegisterBrokerRecord().setBrokerEpoch(100).setBrokerId(i);
        brokerRecord.endPoints().add(new RegisterBrokerRecord.BrokerEndpoint().setSecurityProtocol(SecurityProtocol.PLAINTEXT.id).setPort((short) 9092).setName("PLAINTEXT").setHost(String.format("broker-%02d.example.org", i)));
        clusterControl.replay(brokerRecord);
    }
    this.producerIdControlManager = new ProducerIdControlManager(clusterControl, snapshotRegistry);
}
Also used : Random(java.util.Random) SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) RegisterBrokerRecord(org.apache.kafka.common.metadata.RegisterBrokerRecord) LogContext(org.apache.kafka.common.utils.LogContext) MockTime(org.apache.kafka.common.utils.MockTime) BeforeEach(org.junit.jupiter.api.BeforeEach)

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