@@ -27,24 +27,27 @@ class KafkaEventSinkDLQ : KafkaEventSinkBase() {
2727
2828 var producerRecord = ProducerRecord (topic, UUID .randomUUID().toString(), JSONUtils .writeValueAsBytes(data))
2929 kafkaProducer.send(producerRecord).get()
30- Assert .assertEventually(ThrowingSupplier <Boolean , Exception > {
31- val query = """
30+ val dlqConsumer = createConsumer<ByteArray , ByteArray >(ByteArrayDeserializer ::class .java.name,
31+ ByteArrayDeserializer ::class .java.name,
32+ dlqTopic)
33+
34+ dlqConsumer.let {
35+ Assert .assertEventually(ThrowingSupplier <Boolean , Exception > {
36+ val query = """
3237 MATCH (c:Customer)
3338 RETURN count(c) AS count
3439 """ .trimIndent()
35- val result = db.execute(query).columnAs<Long >(" count" )
40+ val result = db.execute(query).columnAs<Long >(" count" )
3641
37- val dlqConsumer = createConsumer<ByteArray , ByteArray >(ByteArrayDeserializer ::class .java.name,
38- ByteArrayDeserializer ::class .java.name,
39- dlqTopic)
40- val records = dlqConsumer.poll(5000 )
41- val record = if (records.isEmpty) null else records.records(dlqTopic).iterator().next()
42- val headers = record?.headers()?.map { it.key() to String (it.value()) }?.toMap().orEmpty()
43- val value = if (record != null ) JSONUtils .readValue<Any >(record.value()!! ) else emptyMap<String , Any >()
44- dlqConsumer.close()
45- ! records.isEmpty && headers.size == 7 && value == data && result.hasNext() && result.next() == 0L && ! result.hasNext()
46- && headers[" __streams.errors.exception.class.name" ] == " org.neo4j.graphdb.QueryExecutionException"
47- }, Matchers .equalTo(true ), 30 , TimeUnit .SECONDS )
42+ val records = dlqConsumer.poll(5000 )
43+ val record = if (records.isEmpty) null else records.records(dlqTopic).iterator().next()
44+ val headers = record?.headers()?.map { it.key() to String (it.value()) }?.toMap().orEmpty()
45+ val value = if (record != null ) JSONUtils .readValue<Any >(record.value()!! ) else emptyMap<String , Any >()
46+ ! records.isEmpty && headers.size == 7 && value == data && result.hasNext() && result.next() == 0L && ! result.hasNext()
47+ && headers[" __streams.errors.exception.class.name" ] == " org.neo4j.graphdb.QueryExecutionException"
48+ }, Matchers .equalTo(true ), 30 , TimeUnit .SECONDS )
49+ it.close()
50+ }
4851 }
4952
5053 @Test
@@ -63,24 +66,27 @@ class KafkaEventSinkDLQ : KafkaEventSinkBase() {
6366 var producerRecord = ProducerRecord (topic, UUID .randomUUID().toString(),
6467 data.toByteArray())
6568 kafkaProducer.send(producerRecord).get()
66- Assert .assertEventually(ThrowingSupplier <Boolean , Exception > {
67- val query = """
69+ val dlqConsumer = createConsumer<ByteArray , ByteArray >(ByteArrayDeserializer ::class .java.name,
70+ ByteArrayDeserializer ::class .java.name,
71+ dlqTopic)
72+ dlqConsumer.let {
73+ Assert .assertEventually(ThrowingSupplier <Boolean , Exception > {
74+ val query = """
6875 MATCH (c:Customer)
6976 RETURN count(c) AS count
7077 """ .trimIndent()
71- val result = db.execute(query).columnAs<Long >(" count" )
78+ val result = db.execute(query).columnAs<Long >(" count" )
79+
7280
73- val dlqConsumer = createConsumer<ByteArray , ByteArray >(ByteArrayDeserializer ::class .java.name,
74- ByteArrayDeserializer ::class .java.name,
75- dlqTopic)
76- val records = dlqConsumer.poll(5000 )
77- val record = if (records.isEmpty) null else records.records(dlqTopic).iterator().next()
78- val headers = record?.headers()?.map { it.key() to String (it.value()) }?.toMap().orEmpty()
79- val value = if (record != null ) String (record.value()) else emptyMap<String , Any >()
80- dlqConsumer.close()
81- ! records.isEmpty && headers.size == 7 && data == value && result.hasNext() && result.next() == 0L && ! result.hasNext()
82- && headers[" __streams.errors.exception.class.name" ] == " com.fasterxml.jackson.core.JsonParseException"
83- }, Matchers .equalTo(true ), 30 , TimeUnit .SECONDS )
81+ val records = dlqConsumer.poll(5000 )
82+ val record = if (records.isEmpty) null else records.records(dlqTopic).iterator().next()
83+ val headers = record?.headers()?.map { it.key() to String (it.value()) }?.toMap().orEmpty()
84+ val value = if (record != null ) String (record.value()) else emptyMap<String , Any >()
85+ ! records.isEmpty && headers.size == 7 && data == value && result.hasNext() && result.next() == 0L && ! result.hasNext()
86+ && headers[" __streams.errors.exception.class.name" ] == " com.fasterxml.jackson.core.JsonParseException"
87+ }, Matchers .equalTo(true ), 30 , TimeUnit .SECONDS )
88+ it.close()
89+ }
8490 }
8591
8692}
0 commit comments