Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在ConsumerRawareRebalanceListener上测试异常_Java_Spring Boot_Apache Kafka_Spring Kafka - Fatal编程技术网

Java 在ConsumerRawareRebalanceListener上测试异常

Java 在ConsumerRawareRebalanceListener上测试异常,java,spring-boot,apache-kafka,spring-kafka,Java,Spring Boot,Apache Kafka,Spring Kafka,按照前面问题的答案中给我的建议,我能够使用Spring Kafka 2.1.x设置一个ConsumerAwarereBalanceListener 但是,下面的代码 Map<TopicPartition, Long> queries = new HashMap<>(); final Long rewindTime = getRewindTime(); for (TopicPartition partition : partitions) { queries.put

按照前面问题的答案中给我的建议,我能够使用Spring Kafka 2.1.x设置一个
ConsumerAwarereBalanceListener

但是,下面的代码

Map<TopicPartition, Long> queries = new HashMap<>();
final Long rewindTime = getRewindTime();
for (TopicPartition partition : partitions) {
    queries.put(partition, rewindTime);
}
Map<TopicPartition, OffsetAndTimestamp> result = consumer.offsetsForTimes(queries);
result.forEach((key, value) -> consumer.seek(key, value.offset()));
我正在尝试编写一个测试,目的是验证这种行为。但是,由于异常发生在与主线程不同的独立线程上,因此我无法检索此类异常

有什么建议吗


非常感谢,

根据
offsetsForTimes()
Javadocs,您的代码中似乎有一个bug:

 * @return a mapping from partition to the timestamp and offset of the first message with timestamp greater
 *         than or equal to the target timestamp. {@code null} will be returned for the partition if there is no
 *         such message.
因此,您肯定应该使用空检查来保护您的
值.offset()

result.entrySet()
            .stream()
            .filter(e -> e.getValue() != null)
            .forEach(e -> consumer.seek(e.getKey(), e.getValue().offset()));

这绝对不重要,也不会带来太多的价值,因为我们不能将其用作简单的lambda
过滤器(Objects::nonNull)
-我们需要检查
映射条目的
值,而不是整个条目。是的,我知道这是一个bug:)但是,我正在尝试编写一个测试,可以显示我的bug。对不起,也许我的问题不太清楚。你能帮我个忙吗?请显示这个错误的堆栈跟踪。也许到时候我们可以找到一个钩子让你互动。补充到我的问题。非常感谢。那绝对正确。您可能有分区,但没有分区的记录
result.entrySet()
            .stream()
            .filter(e -> e.getValue() != null)
            .forEach(e -> consumer.seek(e.getKey(), e.getValue().offset()));