Search in sources :

Example 46 with Metrics

use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.

the class ConsumerCoordinatorTest method prepareCoordinatorForCloseTest.

private ConsumerCoordinator prepareCoordinatorForCloseTest(boolean useGroupManagement, boolean autoCommit) {
    final String consumerId = "consumer";
    ConsumerCoordinator coordinator = buildCoordinator(new Metrics(), assignors, ConsumerConfig.DEFAULT_EXCLUDE_INTERNAL_TOPICS, autoCommit);
    client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
    coordinator.ensureCoordinatorReady();
    if (useGroupManagement) {
        subscriptions.subscribe(singleton(topic1), rebalanceListener);
        client.prepareResponse(joinGroupFollowerResponse(1, consumerId, "leader", Errors.NONE));
        client.prepareResponse(syncGroupResponse(singletonList(t1p), Errors.NONE));
        coordinator.joinGroupIfNeeded();
    } else
        subscriptions.assignFromUser(singleton(t1p));
    subscriptions.seek(t1p, 100);
    coordinator.poll(time.milliseconds());
    return coordinator;
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics)

Example 47 with Metrics

use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.

the class ConsumerCoordinatorTest method testAutoCommitDynamicAssignment.

@Test
public void testAutoCommitDynamicAssignment() {
    final String consumerId = "consumer";
    ConsumerCoordinator coordinator = buildCoordinator(new Metrics(), assignors, ConsumerConfig.DEFAULT_EXCLUDE_INTERNAL_TOPICS, true);
    subscriptions.subscribe(singleton(topic1), rebalanceListener);
    client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
    coordinator.ensureCoordinatorReady();
    client.prepareResponse(joinGroupFollowerResponse(1, consumerId, "leader", Errors.NONE));
    client.prepareResponse(syncGroupResponse(singletonList(t1p), Errors.NONE));
    coordinator.joinGroupIfNeeded();
    subscriptions.seek(t1p, 100);
    client.prepareResponse(offsetCommitResponse(Collections.singletonMap(t1p, Errors.NONE)));
    time.sleep(autoCommitIntervalMs);
    coordinator.poll(time.milliseconds());
    assertEquals(100L, subscriptions.committed(t1p).offset());
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) Test(org.junit.Test)

Example 48 with Metrics

use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.

the class ConsumerCoordinatorTest method setup.

@Before
public void setup() {
    this.time = new MockTime();
    this.subscriptions = new SubscriptionState(OffsetResetStrategy.EARLIEST);
    this.metadata = new Metadata(0, Long.MAX_VALUE);
    this.metadata.update(cluster, Collections.<String>emptySet(), time.milliseconds());
    this.client = new MockClient(time, metadata);
    this.consumerClient = new ConsumerNetworkClient(client, metadata, time, 100, 1000);
    this.metrics = new Metrics(time);
    this.rebalanceListener = new MockRebalanceListener();
    this.mockOffsetCommitCallback = new MockCommitCallback();
    this.partitionAssignor.clear();
    client.setNode(node);
    this.coordinator = buildCoordinator(metrics, assignors, ConsumerConfig.DEFAULT_EXCLUDE_INTERNAL_TOPICS, autoCommitEnabled);
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) ProtocolMetadata(org.apache.kafka.common.requests.JoinGroupRequest.ProtocolMetadata) Metadata(org.apache.kafka.clients.Metadata) MockTime(org.apache.kafka.common.utils.MockTime) MockClient(org.apache.kafka.clients.MockClient) Before(org.junit.Before)

Example 49 with Metrics

use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.

the class SslTransportLayerTest method testClose.

private void testClose(SecurityProtocol securityProtocol, ChannelBuilder clientChannelBuilder) throws Exception {
    String node = "0";
    server = createEchoServer(securityProtocol);
    clientChannelBuilder.configure(sslClientConfigs);
    this.selector = new Selector(5000, new Metrics(), new MockTime(), "MetricGroup", clientChannelBuilder);
    InetSocketAddress addr = new InetSocketAddress("localhost", server.port());
    selector.connect(node, addr, BUFFER_SIZE, BUFFER_SIZE);
    NetworkTestUtils.waitForChannelReady(selector, node);
    final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
    server.outputChannel(Channels.newChannel(bytesOut));
    server.selector().muteAll();
    byte[] message = TestUtils.randomString(100).getBytes();
    int count = 20;
    final int totalSendSize = count * (message.length + 4);
    for (int i = 0; i < count; i++) {
        selector.send(new NetworkSend(node, ByteBuffer.wrap(message)));
        do {
            selector.poll(0L);
        } while (selector.completedSends().isEmpty());
    }
    server.selector().unmuteAll();
    selector.close(node);
    TestUtils.waitForCondition(new TestCondition() {

        @Override
        public boolean conditionMet() {
            return bytesOut.toByteArray().length == totalSendSize;
        }
    }, 5000, "All requests sent were not processed");
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) InetSocketAddress(java.net.InetSocketAddress) TestCondition(org.apache.kafka.test.TestCondition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MockTime(org.apache.kafka.common.utils.MockTime)

Example 50 with Metrics

use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.

the class SelectorTest method setUp.

@Before
public void setUp() throws Exception {
    Map<String, Object> configs = new HashMap<>();
    this.server = new EchoServer(SecurityProtocol.PLAINTEXT, configs);
    this.server.start();
    this.time = new MockTime();
    this.channelBuilder = new PlaintextChannelBuilder();
    this.channelBuilder.configure(configs);
    this.metrics = new Metrics();
    this.selector = new Selector(5000, this.metrics, time, "MetricGroup", channelBuilder);
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) HashMap(java.util.HashMap) MockTime(org.apache.kafka.common.utils.MockTime) Before(org.junit.Before)

Aggregations

Metrics (org.apache.kafka.common.metrics.Metrics)103 Test (org.junit.Test)76 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)41 HashMap (java.util.HashMap)31 StreamsConfig (org.apache.kafka.streams.StreamsConfig)28 TaskId (org.apache.kafka.streams.processor.TaskId)27 Before (org.junit.Before)22 MockTime (org.apache.kafka.common.utils.MockTime)21 TopicPartition (org.apache.kafka.common.TopicPartition)20 HashSet (java.util.HashSet)19 StreamsMetrics (org.apache.kafka.streams.StreamsMetrics)17 MockClientSupplier (org.apache.kafka.test.MockClientSupplier)17 UUID (java.util.UUID)16 PartitionAssignor (org.apache.kafka.clients.consumer.internals.PartitionAssignor)15 Bytes (org.apache.kafka.common.utils.Bytes)14 MockProcessorSupplier (org.apache.kafka.test.MockProcessorSupplier)14 KStreamBuilder (org.apache.kafka.streams.kstream.KStreamBuilder)13 SubscriptionInfo (org.apache.kafka.streams.processor.internals.assignment.SubscriptionInfo)13 MockProcessorContext (org.apache.kafka.test.MockProcessorContext)13 MockInternalTopicManager (org.apache.kafka.test.MockInternalTopicManager)11