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);
}
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);
}
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);
}
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);
}
Aggregations