use of org.apache.kafka.common.utils.MockTime in project cruise-control by linkedin.
the class BrokerFailureDetectorTest method testLoadFailedBrokersFromZK.
@Test
public void testLoadFailedBrokersFromZK() throws Exception {
Time mockTime = getMockTime();
Queue<Anomaly> anomalies = new ConcurrentLinkedQueue<>();
BrokerFailureDetector detector = createBrokerFailureDetector(anomalies, mockTime);
try {
detector.startDetection();
int brokerId = 0;
killBroker(brokerId);
long start = System.currentTimeMillis();
while (anomalies.isEmpty() && System.currentTimeMillis() < start + 30000) {
// Wait for the anomalies to be drained.
}
assertEquals(Collections.singletonMap(brokerId, 100L), detector.failedBrokers());
// shutdown, advance the clock and create a new detector.
detector.shutdown();
mockTime.sleep(100L);
detector = createBrokerFailureDetector(anomalies, mockTime);
// start the newly created detector and the broker down time should remain previous time.
detector.startDetection();
assertEquals(Collections.singletonMap(brokerId, 100L), detector.failedBrokers());
} finally {
detector.shutdown();
}
}
use of org.apache.kafka.common.utils.MockTime in project apache-kafka-on-k8s by banzaicloud.
the class WorkerSinkTaskThreadedTest method setup.
@Override
public void setup() {
super.setup();
time = new MockTime();
metrics = new MockConnectMetrics();
Map<String, String> workerProps = new HashMap<>();
workerProps.put("key.converter", "org.apache.kafka.connect.json.JsonConverter");
workerProps.put("value.converter", "org.apache.kafka.connect.json.JsonConverter");
workerProps.put("internal.key.converter", "org.apache.kafka.connect.json.JsonConverter");
workerProps.put("internal.value.converter", "org.apache.kafka.connect.json.JsonConverter");
workerProps.put("internal.key.converter.schemas.enable", "false");
workerProps.put("internal.value.converter.schemas.enable", "false");
workerProps.put("offset.storage.file.filename", "/tmp/connect.offsets");
pluginLoader = PowerMock.createMock(PluginClassLoader.class);
workerConfig = new StandaloneConfig(workerProps);
workerTask = PowerMock.createPartialMock(WorkerSinkTask.class, new String[] { "createConsumer" }, taskId, sinkTask, statusListener, initialState, workerConfig, metrics, keyConverter, valueConverter, headerConverter, TransformationChain.noOp(), pluginLoader, time);
recordsReturned = 0;
}
use of org.apache.kafka.common.utils.MockTime 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.common.utils.MockTime in project apache-kafka-on-k8s by banzaicloud.
the class WorkerTest method testStartConnectorFailure.
@Test
public void testStartConnectorFailure() throws Exception {
expectConverters();
expectStartStorage();
Map<String, String> props = new HashMap<>();
props.put(SinkConnectorConfig.TOPICS_CONFIG, "foo,bar");
props.put(ConnectorConfig.TASKS_MAX_CONFIG, "1");
props.put(ConnectorConfig.NAME_CONFIG, CONNECTOR_ID);
// Bad connector class name
props.put(ConnectorConfig.CONNECTOR_CLASS_CONFIG, "java.util.HashMap");
EasyMock.expect(plugins.currentThreadLoader()).andReturn(delegatingLoader);
EasyMock.expect(plugins.newConnector(EasyMock.anyString())).andThrow(new ConnectException("Failed to find Connector"));
EasyMock.expect(Plugins.compareAndSwapLoaders(delegatingLoader)).andReturn(pluginLoader);
connectorStatusListener.onFailure(EasyMock.eq(CONNECTOR_ID), EasyMock.<ConnectException>anyObject());
EasyMock.expectLastCall();
PowerMock.replayAll();
worker = new Worker(WORKER_ID, new MockTime(), plugins, config, offsetBackingStore);
worker.start();
assertStatistics(worker, 0, 0);
assertFalse(worker.startConnector(CONNECTOR_ID, props, ctx, connectorStatusListener, TargetState.STARTED));
assertStartupStatistics(worker, 1, 1, 0, 0);
assertEquals(Collections.emptySet(), worker.connectorNames());
assertStatistics(worker, 0, 0);
assertStartupStatistics(worker, 1, 1, 0, 0);
assertFalse(worker.stopConnector(CONNECTOR_ID));
assertStatistics(worker, 0, 0);
assertStartupStatistics(worker, 1, 1, 0, 0);
PowerMock.verifyAll();
}
use of org.apache.kafka.common.utils.MockTime in project apache-kafka-on-k8s by banzaicloud.
the class CoordinatorTest method testCreateTask.
@Test
public void testCreateTask() throws Exception {
MockTime time = new MockTime(0, 0, 0);
Scheduler scheduler = new MockScheduler(time);
try (MiniTrogdorCluster cluster = new MiniTrogdorCluster.Builder().addCoordinator("node01").addAgent("node02").scheduler(scheduler).build()) {
new ExpectedTasks().waitFor(cluster.coordinatorClient());
NoOpTaskSpec fooSpec = new NoOpTaskSpec(1, 2);
cluster.coordinatorClient().createTask(new CreateTaskRequest("foo", fooSpec));
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskPending(fooSpec)).build()).waitFor(cluster.coordinatorClient());
time.sleep(2);
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskRunning(fooSpec, 2)).workerState(new WorkerRunning(fooSpec, 2, "")).build()).waitFor(cluster.coordinatorClient()).waitFor(cluster.agentClient("node02"));
time.sleep(3);
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskDone(fooSpec, 2, 5, "", false)).build()).waitFor(cluster.coordinatorClient());
}
}
Aggregations