@@ -401,6 +401,63 @@ class KafkaEventSinkIT {
401401 }, equalTo(true ), 30 , TimeUnit .SECONDS )
402402 }
403403
404+ @Test
405+ fun `should fix issue 186 with auto commit false` () {
406+ val product = " product" to " MERGE (p:Product {id: event.id}) ON CREATE SET p.name = event.name"
407+ val customer = " customer" to " MERGE (c:Customer {id: event.id}) ON CREATE SET c.name = event.name"
408+ val bought = " bought" to """
409+ MERGE (c:Customer {id: event.id})
410+ MERGE (p:Product {id: event.id})
411+ MERGE (c)-[:BOUGHT]->(p)
412+ """ .trimIndent()
413+ graphDatabaseBuilder.setConfig(" streams.sink.topic.cypher.${product.first} " , product.second)
414+ graphDatabaseBuilder.setConfig(" streams.sink.topic.cypher.${customer.first} " , customer.second)
415+ graphDatabaseBuilder.setConfig(" streams.sink.topic.cypher.${bought.first} " , bought.second)
416+ graphDatabaseBuilder.setConfig(" kafka.${ConsumerConfig .ENABLE_AUTO_COMMIT_CONFIG } " , " false" )
417+ db = graphDatabaseBuilder.newGraphDatabase() as GraphDatabaseAPI
418+
419+ val props = mapOf (" id" to 1 , " name" to " My Awesome Product" )
420+ var producerRecord = ProducerRecord (product.first, UUID .randomUUID().toString(),
421+ JSONUtils .writeValueAsBytes(props))
422+ kafkaProducer.send(producerRecord).get()
423+ assertEventually(ThrowingSupplier <Boolean , Exception > {
424+ val query = """
425+ MATCH (p:Product)
426+ WHERE properties(p) = {props}
427+ RETURN count(p) AS count
428+ """ .trimIndent()
429+ val result = db.execute(query, mapOf (" props" to props)).columnAs<Long >(" count" )
430+ result.hasNext() && result.next() == 1L && ! result.hasNext()
431+ }, equalTo(true ), 30 , TimeUnit .SECONDS )
432+ }
404433
434+ @Test
435+ fun `should fix issue 186 with auto commit true` () {
436+ val product = " product" to " MERGE (p:Product {id: event.id}) ON CREATE SET p.name = event.name"
437+ val customer = " customer" to " MERGE (c:Customer {id: event.id}) ON CREATE SET c.name = event.name"
438+ val bought = " bought" to """
439+ MERGE (c:Customer {id: event.id})
440+ MERGE (p:Product {id: event.id})
441+ MERGE (c)-[:BOUGHT]->(p)
442+ """ .trimIndent()
443+ graphDatabaseBuilder.setConfig(" streams.sink.topic.cypher.${product.first} " , product.second)
444+ graphDatabaseBuilder.setConfig(" streams.sink.topic.cypher.${customer.first} " , customer.second)
445+ graphDatabaseBuilder.setConfig(" streams.sink.topic.cypher.${bought.first} " , bought.second)
446+ db = graphDatabaseBuilder.newGraphDatabase() as GraphDatabaseAPI
447+
448+ val props = mapOf (" id" to 1 , " name" to " My Awesome Product" )
449+ var producerRecord = ProducerRecord (product.first, UUID .randomUUID().toString(),
450+ JSONUtils .writeValueAsBytes(props))
451+ kafkaProducer.send(producerRecord).get()
452+ assertEventually(ThrowingSupplier <Boolean , Exception > {
453+ val query = """
454+ MATCH (p:Product)
455+ WHERE properties(p) = {props}
456+ RETURN count(p) AS count
457+ """ .trimIndent()
458+ val result = db.execute(query, mapOf (" props" to props)).columnAs<Long >(" count" )
459+ result.hasNext() && result.next() == 1L && ! result.hasNext()
460+ }, equalTo(true ), 30 , TimeUnit .SECONDS )
461+ }
405462
406463}
0 commit comments