Source:
<code>public void testDeleteTasksWithPrefix() { String testCluster = "testDeleteTaskWithPrefix"; String connectorType = "connectorType"; ZkClientInterceptingAdapter adapter = createInterceptingZkAdapter(testCluster); adapter.connect(); List<DatastreamTask> tasks = new ArrayList<>(); for (int i = 0; i < 10; i++) { DatastreamTaskImpl dsTask = new DatastreamTaskImpl(); dsTask.setId("task" + i); String taskPrefix = "taskPrefix" + i; dsTask.setTaskPrefix(taskPrefix); dsTask.setConnectorType(connectorType); dsTask.setZkAdapter(adapter); tasks.add(dsTask); } updateInstanceAssignment(adapter, adapter.getInstanceName(), tasks); ZkClient zkClient = Mockito.spy(adapter.getZkClient()); for (int j = 0; j < 8; j++) { adapter.deleteTasksWithPrefix(connectorType, "taskPrefix" + j); } Mockito.verify(zkClient, Mockito.never()).getChildren(any()); Mockito.verify(zkClient, Mockito.never()).getChildren(any(), anyBoolean()); List<String> leftOverTasks = zkClient.getChildren(KeyBuilder.connector(testCluster, connectorType)); Assert.assertEquals(leftOverTasks.size(), 2); adapter.cleanUpOrphanConnectorTasks(false); leftOverTasks = zkClient.getChildren(KeyBuilder.connector(testCluster, connectorType)); Assert.assertEquals(leftOverTasks.size(), 2); adapter.cleanUpOrphanConnectorTasks(true); leftOverTasks = zkClient.getChildren(KeyBuilder.connector(testCluster, connectorType)); Assert.assertEquals(leftOverTasks.size(), 2); updateInstanceAssignment(adapter, adapter.getInstanceName(), new ArrayList<DatastreamTask>()); leftOverTasks = zkClient.getChildren(KeyBuilder.connector(testCluster, connectorType)); Assert.assertEquals(leftOverTasks.size(), 2); <START> adapter.cleanUpOrphanConnectorTasks(true); <END> leftOverTasks = zkClient.getChildren(KeyBuilder.connector(testCluster, connectorType)); Assert.assertEquals(leftOverTasks.size(), 0); adapter.disconnect(); }</code><technical_language>test false updateInstanceAssignments 2 left well</technical_language>

Target:
public void testDeleteTasksWithPrefix() { String testCluster = "testDeleteTaskWithPrefix"; String connectorType = "connectorType"; ZkClientInterceptingAdapter adapter = createInterceptingZkAdapter(testCluster); adapter.connect(); List<DatastreamTask> tasks = new ArrayList<>(); for (int i = 0; i < 10; i++) { DatastreamTaskImpl dsTask = new DatastreamTaskImpl(); dsTask.setId("task" + i); String taskPrefix = "taskPrefix" + i; dsTask.setTaskPrefix(taskPrefix); dsTask.setConnectorType(connectorType); dsTask.setZkAdapter(adapter); tasks.add(dsTask); } updateInstanceAssignment(adapter, adapter.getInstanceName(), tasks); ZkClient zkClient = Mockito.spy(adapter.getZkClient()); for (int j = 0; j < 8; j++) { adapter.deleteTasksWithPrefix(connectorType, "taskPrefix" + j); } Mockito.verify(zkClient, Mockito.never()).getChildren(any()); Mockito.verify(zkClient, Mockito.never()).getChildren(any(), anyBoolean()); List<String> leftOverTasks = zkClient.getChildren(KeyBuilder.connector(testCluster, connectorType)); Assert.assertEquals(leftOverTasks.size(), 2); adapter.cleanUpOrphanConnectorTasks(false); leftOverTasks = zkClient.getChildren(KeyBuilder.connector(testCluster, connectorType)); Assert.assertEquals(leftOverTasks.size(), 2); adapter.cleanUpOrphanConnectorTasks(true); leftOverTasks = zkClient.getChildren(KeyBuilder.connector(testCluster, connectorType)); Assert.assertEquals(leftOverTasks.size(), 2); updateInstanceAssignment(adapter, adapter.getInstanceName(), new ArrayList<DatastreamTask>()); leftOverTasks = zkClient.getChildren(KeyBuilder.connector(testCluster, connectorType)); Assert.assertEquals(leftOverTasks.size(), 2); adapter.cleanUpOrphanConnectorTasks(false); leftOverTasks = zkClient.getChildren(KeyBuilder.connector(testCluster, connectorType)); Assert.assertEquals(leftOverTasks.size(), 2); adapter.cleanUpOrphanConnectorTasks(true); leftOverTasks = zkClient.getChildren(KeyBuilder.connector(testCluster, connectorType)); Assert.assertEquals(leftOverTasks.size(), 0); adapter.disconnect(); }