@Test public void testCreatePartitions() throws Exception { try (AdminClientUnitTestEnv env = mockClientEnv()) { env.kafkaClient().setNodeApiVersions(NodeApiVersions.create()); Map<String, ApiError> m = new HashMap<>(); m.put("my_topic", ApiError.NONE); m.put("other_topic", ApiError.fromThrowable(new InvalidTopicException("some detailed reason"))); // Test a call where one filter has an error. env.kafkaClient().prepareResponse(new CreatePartitionsResponse(0, m)); Map<String, NewPartitions> counts = new HashMap<>(); counts.put("my_topic", NewPartitions.increaseTo(3)); counts.put("other_topic", NewPartitions.increaseTo(3, asList(asList(2), asList(3)))); CreatePartitionsResult results = env.adminClient().createPartitions(counts); Map<String, KafkaFuture<Void>> values = results.values(); KafkaFuture<Void> myTopicResult = values.get("my_topic"); myTopicResult.get(); KafkaFuture<Void> otherTopicResult = values.get("other_topic"); try { otherTopicResult.get(); fail("get() should throw ExecutionException"); } catch (ExecutionException e0) { assertTrue(e0.getCause() instanceof InvalidTopicException); InvalidTopicException e = (InvalidTopicException) e0.getCause(); assertEquals("some detailed reason", e.getMessage()); } } }
@Override public void increasePartitions(Topic topic, Handler<AsyncResult<Void>> handler) { final NewPartitions newPartitions = NewPartitions.increaseTo(topic.getNumPartitions()); final Map<String, NewPartitions> request = Collections.singletonMap(topic.getTopicName().toString(), newPartitions); KafkaFuture<Void> future = adminClient.createPartitions(request).values().get(topic.getTopicName().toString()); queueWork(new UniWork<>("increasePartitions", future, handler)); }