@@ -2,7 +2,10 @@ package streams.integrations
22
33import kotlinx.coroutines.async
44import kotlinx.coroutines.runBlocking
5+ import org.hamcrest.Matchers
56import org.junit.Test
7+ import org.neo4j.function.ThrowingSupplier
8+ import streams.Assert
69import streams.events.EntityType
710import streams.events.NodeChange
811import streams.events.NodePayload
@@ -14,6 +17,7 @@ import streams.KafkaTestUtils
1417import streams.serialization.JSONUtils
1518import streams.setConfig
1619import streams.start
20+ import java.util.concurrent.TimeUnit
1721import kotlin.test.assertEquals
1822
1923class KafkaEventRouterSimpleTSE : KafkaEventRouterBaseTSE () {
@@ -131,4 +135,36 @@ class KafkaEventRouterSimpleTSE: KafkaEventRouterBaseTSE() {
131135 }
132136 })
133137 }
138+
139+ @Test
140+ fun testDeleteNode () = runBlocking {
141+ val topic = " testdeletetopic"
142+ db.setConfig(" streams.source.topic.nodes.$topic .from.neo4j" , " Person:Neo4j{*}" )
143+ .setConfig(" streams.source.topic.relationships.$topic .from.neo4j" , " KNOWS{*}" )
144+ .start()
145+ kafkaConsumer.subscribe(listOf (topic))
146+ db.execute(" CREATE (:Person:ToRemove {name:'John Doe', age:42})-[:KNOWS]->(:Person {name:'Jane Doe', age:36})" )
147+ Assert .assertEventually(ThrowingSupplier {
148+ kafkaConsumer.poll(5000 ).count() > 0
149+ }, Matchers .equalTo(true ), 30 , TimeUnit .SECONDS )
150+ db.execute(" MATCH (p:Person {name:'John Doe', age:42}) REMOVE p:ToRemove" )
151+ Assert .assertEventually(ThrowingSupplier {
152+ kafkaConsumer.poll(5000 )
153+ .map { JSONUtils .asStreamsTransactionEvent(it.value()) }
154+ .filter { it.meta.operation == OperationType .updated }
155+ .count() > 0
156+ }, Matchers .equalTo(true ), 30 , TimeUnit .SECONDS )
157+ db.execute(" MATCH (p:Person) DETACH DELETE p" )
158+ val count = db.execute(" MATCH (p:Person {name:'John Doe', age:42}) RETURN count(p) AS count" ) {
159+ it.columnAs<Long >(" count" ).next()
160+ }
161+ assertEquals(0 , count)
162+ Assert .assertEventually(ThrowingSupplier {
163+ val count = kafkaConsumer.poll(5000 )
164+ .map { JSONUtils .asStreamsTransactionEvent(it.value()) }
165+ .filter { it.meta.operation == OperationType .deleted }
166+ .count()
167+ count > 0
168+ }, Matchers .equalTo(true ), 30 , TimeUnit .SECONDS )
169+ }
134170}
0 commit comments