Search in sources :

Example 1 with UpdateFeaturesRequest

use of org.apache.kafka.common.requests.UpdateFeaturesRequest in project kafka by apache.

the class KafkaAdminClientTest method testUpdateFeatures.

private void testUpdateFeatures(Map<String, FeatureUpdate> featureUpdates, ApiError topLevelError, Map<String, ApiError> featureUpdateErrors) throws Exception {
    try (final AdminClientUnitTestEnv env = mockClientEnv()) {
        env.kafkaClient().prepareResponse(body -> body instanceof UpdateFeaturesRequest, UpdateFeaturesResponse.createWithErrors(topLevelError, featureUpdateErrors, 0));
        final Map<String, KafkaFuture<Void>> futures = env.adminClient().updateFeatures(featureUpdates, new UpdateFeaturesOptions().timeoutMs(10000)).values();
        for (final Map.Entry<String, KafkaFuture<Void>> entry : futures.entrySet()) {
            final KafkaFuture<Void> future = entry.getValue();
            final ApiError error = featureUpdateErrors.get(entry.getKey());
            if (topLevelError.error() == Errors.NONE) {
                assertNotNull(error);
                if (error.error() == Errors.NONE) {
                    future.get();
                } else {
                    final ExecutionException e = assertThrows(ExecutionException.class, future::get);
                    assertEquals(e.getCause().getClass(), error.exception().getClass());
                }
            } else {
                final ExecutionException e = assertThrows(ExecutionException.class, future::get);
                assertEquals(e.getCause().getClass(), topLevelError.exception().getClass());
            }
        }
    }
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) UpdateFeaturesRequest(org.apache.kafka.common.requests.UpdateFeaturesRequest) ApiError(org.apache.kafka.common.requests.ApiError) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 KafkaFuture (org.apache.kafka.common.KafkaFuture)1 ApiError (org.apache.kafka.common.requests.ApiError)1 UpdateFeaturesRequest (org.apache.kafka.common.requests.UpdateFeaturesRequest)1