Search in sources :

Example 1 with ProtocolMetadata

use of org.apache.kafka.common.requests.JoinGroupRequest.ProtocolMetadata in project kafka by apache.

the class ConsumerCoordinatorTest method testProtocolMetadataOrder.

@Test
public void testProtocolMetadataOrder() {
    RoundRobinAssignor roundRobin = new RoundRobinAssignor();
    RangeAssignor range = new RangeAssignor();
    try (Metrics metrics = new Metrics(time)) {
        ConsumerCoordinator coordinator = buildCoordinator(metrics, Arrays.<PartitionAssignor>asList(roundRobin, range), ConsumerConfig.DEFAULT_EXCLUDE_INTERNAL_TOPICS, false);
        List<ProtocolMetadata> metadata = coordinator.metadata();
        assertEquals(2, metadata.size());
        assertEquals(roundRobin.name(), metadata.get(0).name());
        assertEquals(range.name(), metadata.get(1).name());
    }
    try (Metrics metrics = new Metrics(time)) {
        ConsumerCoordinator coordinator = buildCoordinator(metrics, Arrays.<PartitionAssignor>asList(range, roundRobin), ConsumerConfig.DEFAULT_EXCLUDE_INTERNAL_TOPICS, false);
        List<ProtocolMetadata> metadata = coordinator.metadata();
        assertEquals(2, metadata.size());
        assertEquals(range.name(), metadata.get(0).name());
        assertEquals(roundRobin.name(), metadata.get(1).name());
    }
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) RangeAssignor(org.apache.kafka.clients.consumer.RangeAssignor) RoundRobinAssignor(org.apache.kafka.clients.consumer.RoundRobinAssignor) ProtocolMetadata(org.apache.kafka.common.requests.JoinGroupRequest.ProtocolMetadata) Test(org.junit.Test)

Example 2 with ProtocolMetadata

use of org.apache.kafka.common.requests.JoinGroupRequest.ProtocolMetadata in project kafka by apache.

the class WorkerCoordinator method metadata.

@Override
public List<ProtocolMetadata> metadata() {
    configSnapshot = configStorage.snapshot();
    ConnectProtocol.WorkerState workerState = new ConnectProtocol.WorkerState(restUrl, configSnapshot.offset());
    ByteBuffer metadata = ConnectProtocol.serializeMetadata(workerState);
    return Collections.singletonList(new ProtocolMetadata(DEFAULT_SUBPROTOCOL, metadata));
}
Also used : ByteBuffer(java.nio.ByteBuffer) ProtocolMetadata(org.apache.kafka.common.requests.JoinGroupRequest.ProtocolMetadata)

Example 3 with ProtocolMetadata

use of org.apache.kafka.common.requests.JoinGroupRequest.ProtocolMetadata in project kafka by apache.

the class ConsumerCoordinator method metadata.

@Override
public List<ProtocolMetadata> metadata() {
    this.joinedSubscription = subscriptions.subscription();
    List<ProtocolMetadata> metadataList = new ArrayList<>();
    for (PartitionAssignor assignor : assignors) {
        Subscription subscription = assignor.subscription(joinedSubscription);
        ByteBuffer metadata = ConsumerProtocol.serializeSubscription(subscription);
        metadataList.add(new ProtocolMetadata(assignor.name(), metadata));
    }
    return metadataList;
}
Also used : ArrayList(java.util.ArrayList) Subscription(org.apache.kafka.clients.consumer.internals.PartitionAssignor.Subscription) ProtocolMetadata(org.apache.kafka.common.requests.JoinGroupRequest.ProtocolMetadata) ByteBuffer(java.nio.ByteBuffer)

Example 4 with ProtocolMetadata

use of org.apache.kafka.common.requests.JoinGroupRequest.ProtocolMetadata in project kafka by apache.

the class WorkerCoordinatorTest method testMetadata.

// We only test functionality unique to WorkerCoordinator. Most functionality is already well tested via the tests
// that cover AbstractCoordinator & ConsumerCoordinator.
@Test
public void testMetadata() {
    EasyMock.expect(configStorage.snapshot()).andReturn(configState1);
    PowerMock.replayAll();
    List<ProtocolMetadata> serialized = coordinator.metadata();
    assertEquals(1, serialized.size());
    ProtocolMetadata defaultMetadata = serialized.get(0);
    assertEquals(WorkerCoordinator.DEFAULT_SUBPROTOCOL, defaultMetadata.name());
    ConnectProtocol.WorkerState state = ConnectProtocol.deserializeMetadata(defaultMetadata.metadata());
    assertEquals(1, state.offset());
    PowerMock.verifyAll();
}
Also used : ProtocolMetadata(org.apache.kafka.common.requests.JoinGroupRequest.ProtocolMetadata) Test(org.junit.Test)

Aggregations

ProtocolMetadata (org.apache.kafka.common.requests.JoinGroupRequest.ProtocolMetadata)4 ByteBuffer (java.nio.ByteBuffer)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 RangeAssignor (org.apache.kafka.clients.consumer.RangeAssignor)1 RoundRobinAssignor (org.apache.kafka.clients.consumer.RoundRobinAssignor)1 Subscription (org.apache.kafka.clients.consumer.internals.PartitionAssignor.Subscription)1 Metrics (org.apache.kafka.common.metrics.Metrics)1