Source:
public void stressTestKafkaRpcWithSystemIdAndTestMinionSingleRequest() { EchoRequest request = new EchoRequest("Kafka-RPC"); request.setId(System.currentTimeMillis()); request.setLocation(REMOTE_LOCATION_NAME); request.setSystemId(minionIdentity.getId()); count.set(0); int maxRequests = 100; for (int i = 0; i < maxRequests; i++) { sendRequestAndVerifyResponse(request, 0); } kafkaConfig.put(ConsumerConfig.GROUP_ID_CONFIG, "testMinionCache"); kafkaConfig.put(ConsumerConfig.METADATA_MAX_AGE_CONFIG, "1000"); kafkaConfig.put("key.deserializer", StringDeserializer.class.getCanonicalName()); kafkaConfig.put("value.deserializer", ByteArrayDeserializer.class.getCanonicalName()); KafkaConsumer<String, byte[]> kafkaConsumer = new KafkaConsumer<>(kafkaConfig); AtomicBoolean closed = new AtomicBoolean(false); AtomicInteger messageCount = new AtomicInteger(0); Executors.newSingleThreadExecutor().execute(() -> { try { Pattern pattern = Pattern.compile(".*rpc-response.*"); kafkaConsumer.subscribe(pattern); while (!closed.get()) { ConsumerRecords<String, byte[]> records = kafkaConsumer.poll(Long.MAX_VALUE); for (ConsumerRecord<String, byte[]> record : records) { messageCount.incrementAndGet(); } } } catch (Exception e) { } finally { kafkaConsumer.close(); } }); await().atMost(45, TimeUnit.SECONDS).untilAtomic(count, equalTo(maxRequests)); await().atMost(45, TimeUnit.SECONDS).untilAtomic(messageCount, equalTo(maxRequests)); await().atMost(45, TimeUnit.SECONDS).pollDelay(15, TimeUnit.SECONDS).pollInterval(5, TimeUnit.SECONDS).until(() -> { kafkaRpcServer.getRpcIdCache().cleanUp(); return kafkaRpcServer.getRpcIdCache().size() == 0; } ); closed.set(true); }

Target:
public void stressTestKafkaRpcWithSystemIdAndTestMinionSingleRequest() { EchoRequest request = new EchoRequest("Kafka-RPC"); request.setId(System.currentTimeMillis()); request.setLocation(REMOTE_LOCATION_NAME); request.setSystemId(minionIdentity.getId()); count.set(0); int maxRequests = 100; for (int i = 0; i < maxRequests; i++) { sendRequestAndVerifyResponse(request, 0); } kafkaConfig.put(ConsumerConfig.GROUP_ID_CONFIG, "testMinionCache"); kafkaConfig.put(ConsumerConfig.METADATA_MAX_AGE_CONFIG, "1000"); kafkaConfig.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getCanonicalName()); kafkaConfig.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class.getCanonicalName()); KafkaConsumer<String, byte[]> kafkaConsumer = new KafkaConsumer<>(kafkaConfig); AtomicBoolean closed = new AtomicBoolean(false); AtomicInteger messageCount = new AtomicInteger(0); Executors.newSingleThreadExecutor().execute(() -> { try { Pattern pattern = Pattern.compile(".*rpc-response.*"); kafkaConsumer.subscribe(pattern); while (!closed.get()) { ConsumerRecords<String, byte[]> records = kafkaConsumer.poll(Long.MAX_VALUE); for (ConsumerRecord<String, byte[]> record : records) { messageCount.incrementAndGet(); } } } catch (Exception e) { } finally { kafkaConsumer.close(); } }); await().atMost(45, TimeUnit.SECONDS).untilAtomic(count, equalTo(maxRequests)); await().atMost(45, TimeUnit.SECONDS).untilAtomic(messageCount, equalTo(maxRequests)); await().atMost(45, TimeUnit.SECONDS).pollDelay(15, TimeUnit.SECONDS).pollInterval(5, TimeUnit.SECONDS).until(() -> { kafkaRpcServer.getRpcIdCache().cleanUp(); return kafkaRpcServer.getRpcIdCache().size() == 0; } ); closed.set(true); }