Source:
public void testPartitionManagedLockAcquireFailMetric() throws InterruptedException { String datastreamName = "pizzaStream"; Datastream datastream = KafkaMirrorMakerConnectorTestUtils.createDatastream(datastreamName, _broker, "\\w+Pizza"); DatastreamTaskImpl task = spy(new DatastreamTaskImpl(Collections.singletonList(datastream))); doThrow(DatastreamRuntimeException.class).when(task).acquire(any(Duration.class)); MockDatastreamEventProducer datastreamProducer = new MockDatastreamEventProducer(); task.setEventProducer(datastreamProducer); KafkaBasedConnectorConfig connectorConfig = new KafkaBasedConnectorConfigBuilder() .setConsumerFactory(new LiKafkaConsumerFactory()) .setCommitIntervalMillis(10000) .setEnablePartitionManaged(true) .build(); ZkAdapter zkAdapter = new ZkAdapter(_kafkaCluster.getZkConnection(), "testCluster", null, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, null); task.setZkAdapter(zkAdapter); zkAdapter.connect(); KafkaMirrorMakerConnectorTaskTest connectorTask = new KafkaMirrorMakerConnectorTaskTest(connectorConfig, task, "", false, new KafkaMirrorMakerGroupIdConstructor(false, "testCluster")); Thread t = new Thread(connectorTask, "connector thread"); t.setDaemon(true); t.setUncaughtExceptionHandler((t1, e) -> Assert.assertEquals(DatastreamRuntimeException.class, e.getClass())); t.start(); t.join(); Assert.assertTrue(PollUtils.poll(() -> { Meter metric = DynamicMetricsManager.getInstance() .getMetric(KafkaMirrorMakerConnectorTask.class.getSimpleName() + "." + datastreamName + "." + "taskLockAcquireErrorRate"); return ((metric != null) && (metric.getCount() == 1)); }, POLL_PERIOD_MS, POLL_TIMEOUT_MS), "taskLockAcquireErrorRate metric should have a count of 1"); }

Target:
public void testPartitionManagedLockAcquireFailMetric() throws InterruptedException { String datastreamName = "pizzaStream"; Datastream datastream = KafkaMirrorMakerConnectorTestUtils.createDatastream(datastreamName, _broker, "\\w+Pizza"); DatastreamTaskImpl task = spy(new DatastreamTaskImpl(Collections.singletonList(datastream))); doThrow(DatastreamRuntimeException.class).when(task).acquire(any(Duration.class)); MockDatastreamEventProducer datastreamProducer = new MockDatastreamEventProducer(); task.setEventProducer(datastreamProducer); KafkaBasedConnectorConfig connectorConfig = new KafkaBasedConnectorConfigBuilder() .setConsumerFactory(new LiKafkaConsumerFactory()) .setCommitIntervalMillis(10000) .setEnablePartitionManaged(true) .build(); ZkAdapter zkAdapter = new ZkAdapter(_kafkaCluster.getZkConnection(), "testCluster", null, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, null); task.setZkAdapter(zkAdapter); zkAdapter.connect(); String connectorName = "KafkaMirrorMaker"; KafkaMirrorMakerConnectorTaskTest connectorTask = new KafkaMirrorMakerConnectorTaskTest(connectorConfig, task, connectorName, false, new KafkaMirrorMakerGroupIdConstructor(false, "testCluster")); AtomicReference<Throwable> throwable = new AtomicReference<>(); Thread connectorThread = KafkaMirrorMakerConnectorTestUtils.runKafkaMirrorMakerConnectorTask(connectorTask, (t1, e) -> throwable.set(e), false); connectorThread.join(); Assert.assertEquals(DatastreamRuntimeException.class, throwable.get().getClass()); Meter metric = DynamicMetricsManager.getInstance() .getMetric(connectorName + "." + KafkaMirrorMakerConnectorTask.class.getSimpleName() + "." + datastreamName + "." + "taskLockAcquireErrorRate"); Assert.assertNotNull(metric); Assert.assertEquals(metric.getCount(), 1); MetricsTestUtils.verifyMetrics(new MetricsAware() { @Override public List<BrooklinMetricInfo> getMetricInfos() { return KafkaMirrorMakerConnectorTaskTest.getMetricInfos(connectorName); } }, DynamicMetricsManager.getInstance()); }