projects
/
demos
/
kafka
/
training
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Tests: Refaktorisiert - Nachrichten werden für alle Tests aufgezeichnet
[demos/kafka/training]
/
src
/
test
/
java
/
de
/
juplo
/
kafka
/
ApplicationTests.java
diff --git
a/src/test/java/de/juplo/kafka/ApplicationTests.java
b/src/test/java/de/juplo/kafka/ApplicationTests.java
index
6f58180
..
4cc4f91
100644
(file)
--- a/
src/test/java/de/juplo/kafka/ApplicationTests.java
+++ b/
src/test/java/de/juplo/kafka/ApplicationTests.java
@@
-69,6
+69,7
@@
class ApplicationTests
EndlessConsumer<String, Long> endlessConsumer;
Map<TopicPartition, Long> oldOffsets;
Map<TopicPartition, Long> newOffsets;
EndlessConsumer<String, Long> endlessConsumer;
Map<TopicPartition, Long> oldOffsets;
Map<TopicPartition, Long> newOffsets;
+ Set<ConsumerRecord<String, Long>> receivedRecords;
/** Tests methods */
/** Tests methods */
@@
-79,12
+80,9
@@
class ApplicationTests
{
send100Messages(i -> new Bytes(longSerializer.serialize(TOPIC, i)));
{
send100Messages(i -> new Bytes(longSerializer.serialize(TOPIC, i)));
- Set<ConsumerRecord<String, Long>> received = new HashSet<>();
- testHandler = record -> received.add(record);
-
await("100 records received")
.atMost(Duration.ofSeconds(30))
await("100 records received")
.atMost(Duration.ofSeconds(30))
- .until(() -> received.size() >= 100);
+ .until(() -> received
Records
.size() >= 100);
await("Offsets committed")
.atMost(Duration.ofSeconds(10))
await("Offsets committed")
.atMost(Duration.ofSeconds(10))
@@
-118,6
+116,9
@@
class ApplicationTests
checkSeenOffsetsForProgress();
compareToCommitedOffsets(newOffsets);
checkSeenOffsetsForProgress();
compareToCommitedOffsets(newOffsets);
+ assertThat(receivedRecords.size())
+ .describedAs("Received not all sent events")
+ .isLessThan(100);
}
}
@@
-129,7
+130,9
@@
class ApplicationTests
{
Long expected = offsetsToCheck.get(tp) + 1;
log.debug("Checking, if the offset for {} is {}", tp, expected);
{
Long expected = offsetsToCheck.get(tp) + 1;
log.debug("Checking, if the offset for {} is {}", tp, expected);
- assertThat(offset).isEqualTo(expected);
+ assertThat(offset)
+ .describedAs("Committed offset corresponds to the offset of the consumer")
+ .isEqualTo(expected);
});
}
});
}
@@
-147,7
+150,9
@@
class ApplicationTests
withProgress.add(tp);
}
});
withProgress.add(tp);
}
});
- assertThat(withProgress).isNotEmpty().describedAs("Found no partitions with any offset-progress");
+ assertThat(withProgress)
+ .describedAs("Some offsets must have changed, compared to the old offset-positions")
+ .isNotEmpty();
}
}
@@
-219,6
+224,7
@@
class ApplicationTests
oldOffsets = new HashMap<>();
newOffsets = new HashMap<>();
oldOffsets = new HashMap<>();
newOffsets = new HashMap<>();
+ receivedRecords = new HashSet<>();
doForCurrentOffsets((tp, offset) ->
{
doForCurrentOffsets((tp, offset) ->
{
@@
-232,6
+238,7
@@
class ApplicationTests
newOffsets.put(
new TopicPartition(record.topic(), record.partition()),
record.offset());
newOffsets.put(
new TopicPartition(record.topic(), record.partition()),
record.offset());
+ receivedRecords.add(record);
testHandler.accept(record);
};
testHandler.accept(record);
};