/** * Delete consumer groups from the cluster with the default options. * * @return The DeleteConsumerGroupResult. */ public DeleteConsumerGroupsResult deleteConsumerGroups(Collection<String> groupIds) { return deleteConsumerGroups(groupIds, new DeleteConsumerGroupsOptions()); }
@Test public void testDeleteConsumerGroups() throws Exception { final HashMap<Integer, Node> nodes = new HashMap<>(); nodes.put(0, new Node(0, "localhost", 8121)); final Cluster cluster = new Cluster( "mockClusterId", nodes.values(), Collections.<PartitionInfo>emptyList(), Collections.<String>emptySet(), Collections.<String>emptySet(), nodes.get(0)); final List<String> groupIds = singletonList("group-0"); try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(cluster)) { env.kafkaClient().setNodeApiVersions(NodeApiVersions.create()); //Retriable FindCoordinatorResponse errors should be retried env.kafkaClient().prepareResponse(new FindCoordinatorResponse(Errors.COORDINATOR_NOT_AVAILABLE, Node.noNode())); env.kafkaClient().prepareResponse(new FindCoordinatorResponse(Errors.COORDINATOR_LOAD_IN_PROGRESS, Node.noNode())); env.kafkaClient().prepareResponse(new FindCoordinatorResponse(Errors.NONE, env.cluster().controller())); final Map<String, Errors> response = new HashMap<>(); response.put("group-0", Errors.NONE); env.kafkaClient().prepareResponse(new DeleteGroupsResponse(response)); final DeleteConsumerGroupsResult result = env.adminClient().deleteConsumerGroups(groupIds); final KafkaFuture<Void> results = result.deletedGroups().get("group-0"); assertNull(results.get()); //should throw error for non-retriable errors env.kafkaClient().prepareResponse(new FindCoordinatorResponse(Errors.GROUP_AUTHORIZATION_FAILED, Node.noNode())); final DeleteConsumerGroupsResult errorResult = env.adminClient().deleteConsumerGroups(groupIds); TestUtils.assertFutureError(errorResult.deletedGroups().get("group-0"), GroupAuthorizationException.class); } }
/** * Removes a consumer's state. * @param id id of consumer group to remove. * @return boolean true if success. * @throws RuntimeException on underlying errors. */ public boolean removeConsumerGroup(final String id) { final DeleteConsumerGroupsResult request = adminClient.deleteConsumerGroups(Collections.singleton(id)); try { request.all().get(); return true; } catch (InterruptedException | ExecutionException e) { // TODO Handle this throw new RuntimeException(e.getMessage(), e); } }
final DeleteConsumerGroupsResult result = admin.deleteConsumerGroups(groups, new DeleteConsumerGroupsOptions().timeoutMs(timeoutMillis)); awaitFutures(timeoutMillis, result.deletedGroups().values());