Search in sources :

Example 1 with ApiResult

use of org.apache.kafka.clients.admin.internals.AdminApiHandler.ApiResult in project kafka by apache.

the class AdminApiDriverTest method testCoalescedStaticAndDynamicFulfillment.

@Test
public void testCoalescedStaticAndDynamicFulfillment() {
    Map<String, String> dynamicMapping = map("foo", "c1");
    Map<String, Integer> staticMapping = map("bar", 1);
    TestContext ctx = new TestContext(staticMapping, dynamicMapping);
    // Initially we expect a lookup for the dynamic key and a
    // fulfillment request for the static key
    LookupResult<String> lookupResult = mapped("foo", 1);
    ctx.lookupStrategy().expectLookup(mkSet("foo"), lookupResult);
    ctx.handler.expectRequest(mkSet("bar"), completed("bar", 10L));
    List<RequestSpec<String>> requestSpecs = ctx.driver.poll();
    assertEquals(2, requestSpecs.size());
    RequestSpec<String> lookupSpec = requestSpecs.get(0);
    assertEquals(mkSet("foo"), lookupSpec.keys);
    ctx.assertLookupResponse(lookupSpec, lookupResult);
    // Receive a disconnect from the fulfillment request so that
    // we have an opportunity to coalesce the keys.
    RequestSpec<String> fulfillmentSpec = requestSpecs.get(1);
    assertEquals(mkSet("bar"), fulfillmentSpec.keys);
    ctx.driver.onFailure(ctx.time.milliseconds(), fulfillmentSpec, new DisconnectException());
    // Now we should get two fulfillment requests. One of them will
    // the coalesced dynamic and static keys for broker 1. The other
    // should contain the single dynamic key for broker 0.
    ctx.handler.reset();
    ctx.handler.expectRequest(mkSet("foo", "bar"), completed("foo", 15L, "bar", 30L));
    List<RequestSpec<String>> coalescedSpecs = ctx.driver.poll();
    assertEquals(1, coalescedSpecs.size());
    RequestSpec<String> coalescedSpec = coalescedSpecs.get(0);
    assertEquals(mkSet("foo", "bar"), coalescedSpec.keys);
    // Disconnect in order to ensure that only the dynamic key is unmapped.
    // Then complete the remaining requests.
    ctx.driver.onFailure(ctx.time.milliseconds(), coalescedSpec, new DisconnectException());
    Map<Set<String>, LookupResult<String>> fooLookupRetry = map(mkSet("foo"), mapped("foo", 3));
    Map<Set<String>, ApiResult<String, Long>> barFulfillmentRetry = map(mkSet("bar"), completed("bar", 30L));
    ctx.poll(fooLookupRetry, barFulfillmentRetry);
    Map<Set<String>, ApiResult<String, Long>> fooFulfillmentRetry = map(mkSet("foo"), completed("foo", 15L));
    ctx.poll(emptyMap(), fooFulfillmentRetry);
    ctx.poll(emptyMap(), emptyMap());
}
Also used : HashSet(java.util.HashSet) Utils.mkSet(org.apache.kafka.common.utils.Utils.mkSet) Set(java.util.Set) DisconnectException(org.apache.kafka.common.errors.DisconnectException) ApiResult(org.apache.kafka.clients.admin.internals.AdminApiHandler.ApiResult) LookupResult(org.apache.kafka.clients.admin.internals.AdminApiLookupStrategy.LookupResult) RequestSpec(org.apache.kafka.clients.admin.internals.AdminApiDriver.RequestSpec) Test(org.junit.jupiter.api.Test)

Aggregations

HashSet (java.util.HashSet)1 Set (java.util.Set)1 RequestSpec (org.apache.kafka.clients.admin.internals.AdminApiDriver.RequestSpec)1 ApiResult (org.apache.kafka.clients.admin.internals.AdminApiHandler.ApiResult)1 LookupResult (org.apache.kafka.clients.admin.internals.AdminApiLookupStrategy.LookupResult)1 DisconnectException (org.apache.kafka.common.errors.DisconnectException)1 Utils.mkSet (org.apache.kafka.common.utils.Utils.mkSet)1 Test (org.junit.jupiter.api.Test)1