Search in sources :

Example 1 with TaskMetricsGroup

use of org.apache.kafka.connect.runtime.WorkerTask.TaskMetricsGroup in project apache-kafka-on-k8s by banzaicloud.

the class WorkerTaskTest method updateMetricsOnListenerEventsForStartupPauseResumeAndShutdown.

@Test
public void updateMetricsOnListenerEventsForStartupPauseResumeAndShutdown() {
    ConnectorTaskId taskId = new ConnectorTaskId("foo", 0);
    ConnectMetrics metrics = new MockConnectMetrics();
    TaskMetricsGroup group = new TaskMetricsGroup(taskId, metrics, statusListener);
    statusListener.onStartup(taskId);
    expectLastCall();
    statusListener.onPause(taskId);
    expectLastCall();
    statusListener.onResume(taskId);
    expectLastCall();
    statusListener.onShutdown(taskId);
    expectLastCall();
    replay(statusListener);
    group.onStartup(taskId);
    assertRunningMetric(group);
    group.onPause(taskId);
    assertPausedMetric(group);
    group.onResume(taskId);
    assertRunningMetric(group);
    group.onShutdown(taskId);
    assertStoppedMetric(group);
    verify(statusListener);
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) TaskMetricsGroup(org.apache.kafka.connect.runtime.WorkerTask.TaskMetricsGroup) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with TaskMetricsGroup

use of org.apache.kafka.connect.runtime.WorkerTask.TaskMetricsGroup in project apache-kafka-on-k8s by banzaicloud.

the class WorkerTaskTest method updateMetricsOnListenerEventsForStartupPauseResumeAndFailure.

@Test
public void updateMetricsOnListenerEventsForStartupPauseResumeAndFailure() {
    ConnectorTaskId taskId = new ConnectorTaskId("foo", 0);
    MockConnectMetrics metrics = new MockConnectMetrics();
    MockTime time = metrics.time();
    ConnectException error = new ConnectException("error");
    TaskMetricsGroup group = new TaskMetricsGroup(taskId, metrics, statusListener);
    statusListener.onStartup(taskId);
    expectLastCall();
    statusListener.onPause(taskId);
    expectLastCall();
    statusListener.onResume(taskId);
    expectLastCall();
    statusListener.onPause(taskId);
    expectLastCall();
    statusListener.onResume(taskId);
    expectLastCall();
    statusListener.onFailure(taskId, error);
    expectLastCall();
    statusListener.onShutdown(taskId);
    expectLastCall();
    replay(statusListener);
    time.sleep(1000L);
    group.onStartup(taskId);
    assertRunningMetric(group);
    time.sleep(2000L);
    group.onPause(taskId);
    assertPausedMetric(group);
    time.sleep(3000L);
    group.onResume(taskId);
    assertRunningMetric(group);
    time.sleep(4000L);
    group.onPause(taskId);
    assertPausedMetric(group);
    time.sleep(5000L);
    group.onResume(taskId);
    assertRunningMetric(group);
    time.sleep(6000L);
    group.onFailure(taskId, error);
    assertFailedMetric(group);
    time.sleep(7000L);
    group.onShutdown(taskId);
    assertStoppedMetric(group);
    verify(statusListener);
    long totalTime = 27000L;
    double pauseTimeRatio = (double) (3000L + 5000L) / totalTime;
    double runningTimeRatio = (double) (2000L + 4000L + 6000L) / totalTime;
    assertEquals(pauseTimeRatio, metrics.currentMetricValueAsDouble(group.metricGroup(), "pause-ratio"), 0.000001d);
    assertEquals(runningTimeRatio, metrics.currentMetricValueAsDouble(group.metricGroup(), "running-ratio"), 0.000001d);
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) MockTime(org.apache.kafka.common.utils.MockTime) ConnectException(org.apache.kafka.connect.errors.ConnectException) TaskMetricsGroup(org.apache.kafka.connect.runtime.WorkerTask.TaskMetricsGroup) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with TaskMetricsGroup

use of org.apache.kafka.connect.runtime.WorkerTask.TaskMetricsGroup in project kafka by apache.

the class WorkerTaskTest method updateMetricsOnListenerEventsForStartupPauseResumeAndShutdown.

@Test
public void updateMetricsOnListenerEventsForStartupPauseResumeAndShutdown() {
    ConnectorTaskId taskId = new ConnectorTaskId("foo", 0);
    ConnectMetrics metrics = new MockConnectMetrics();
    TaskMetricsGroup group = new TaskMetricsGroup(taskId, metrics, statusListener);
    statusListener.onStartup(taskId);
    expectLastCall();
    statusListener.onPause(taskId);
    expectLastCall();
    statusListener.onResume(taskId);
    expectLastCall();
    statusListener.onShutdown(taskId);
    expectLastCall();
    replay(statusListener);
    group.onStartup(taskId);
    assertRunningMetric(group);
    group.onPause(taskId);
    assertPausedMetric(group);
    group.onResume(taskId);
    assertRunningMetric(group);
    group.onShutdown(taskId);
    assertStoppedMetric(group);
    verify(statusListener);
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) TaskMetricsGroup(org.apache.kafka.connect.runtime.WorkerTask.TaskMetricsGroup) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) RetryWithToleranceOperatorTest(org.apache.kafka.connect.runtime.errors.RetryWithToleranceOperatorTest) Test(org.junit.Test)

Example 4 with TaskMetricsGroup

use of org.apache.kafka.connect.runtime.WorkerTask.TaskMetricsGroup in project kafka by apache.

the class WorkerTaskTest method updateMetricsOnListenerEventsForStartupPauseResumeAndFailure.

@Test
public void updateMetricsOnListenerEventsForStartupPauseResumeAndFailure() {
    ConnectorTaskId taskId = new ConnectorTaskId("foo", 0);
    MockConnectMetrics metrics = new MockConnectMetrics();
    MockTime time = metrics.time();
    ConnectException error = new ConnectException("error");
    TaskMetricsGroup group = new TaskMetricsGroup(taskId, metrics, statusListener);
    statusListener.onStartup(taskId);
    expectLastCall();
    statusListener.onPause(taskId);
    expectLastCall();
    statusListener.onResume(taskId);
    expectLastCall();
    statusListener.onPause(taskId);
    expectLastCall();
    statusListener.onResume(taskId);
    expectLastCall();
    statusListener.onFailure(taskId, error);
    expectLastCall();
    statusListener.onShutdown(taskId);
    expectLastCall();
    replay(statusListener);
    time.sleep(1000L);
    group.onStartup(taskId);
    assertRunningMetric(group);
    time.sleep(2000L);
    group.onPause(taskId);
    assertPausedMetric(group);
    time.sleep(3000L);
    group.onResume(taskId);
    assertRunningMetric(group);
    time.sleep(4000L);
    group.onPause(taskId);
    assertPausedMetric(group);
    time.sleep(5000L);
    group.onResume(taskId);
    assertRunningMetric(group);
    time.sleep(6000L);
    group.onFailure(taskId, error);
    assertFailedMetric(group);
    time.sleep(7000L);
    group.onShutdown(taskId);
    assertStoppedMetric(group);
    verify(statusListener);
    long totalTime = 27000L;
    double pauseTimeRatio = (double) (3000L + 5000L) / totalTime;
    double runningTimeRatio = (double) (2000L + 4000L + 6000L) / totalTime;
    assertEquals(pauseTimeRatio, metrics.currentMetricValueAsDouble(group.metricGroup(), "pause-ratio"), 0.000001d);
    assertEquals(runningTimeRatio, metrics.currentMetricValueAsDouble(group.metricGroup(), "running-ratio"), 0.000001d);
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) MockTime(org.apache.kafka.common.utils.MockTime) ConnectException(org.apache.kafka.connect.errors.ConnectException) TaskMetricsGroup(org.apache.kafka.connect.runtime.WorkerTask.TaskMetricsGroup) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) RetryWithToleranceOperatorTest(org.apache.kafka.connect.runtime.errors.RetryWithToleranceOperatorTest) Test(org.junit.Test)

Aggregations

TaskMetricsGroup (org.apache.kafka.connect.runtime.WorkerTask.TaskMetricsGroup)4 ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 MockTime (org.apache.kafka.common.utils.MockTime)2 ConnectException (org.apache.kafka.connect.errors.ConnectException)2 RetryWithToleranceOperatorTest (org.apache.kafka.connect.runtime.errors.RetryWithToleranceOperatorTest)2