diff --git a/engine/src/main/java/io/camunda/zeebe/process/test/engine/db/InMemoryDbTransaction.java b/engine/src/main/java/io/camunda/zeebe/process/test/engine/db/InMemoryDbTransaction.java index 9180cb36c..3891846fd 100644 --- a/engine/src/main/java/io/camunda/zeebe/process/test/engine/db/InMemoryDbTransaction.java +++ b/engine/src/main/java/io/camunda/zeebe/process/test/engine/db/InMemoryDbTransaction.java @@ -100,6 +100,7 @@ public InMemoryDbIterator newIterator() { final TreeMap snapshot = new TreeMap<>(); snapshot.putAll(database); snapshot.putAll(transactionCache); + deletedKeys.forEach(snapshot::remove); return new InMemoryDbIterator(snapshot); } diff --git a/engine/src/test/java/io/camunda/zeebe/process/test/engine/db/InMemoryZeebeDbTransactionTest.java b/engine/src/test/java/io/camunda/zeebe/process/test/engine/db/InMemoryZeebeDbTransactionTest.java index 95644b077..51a43580e 100644 --- a/engine/src/test/java/io/camunda/zeebe/process/test/engine/db/InMemoryZeebeDbTransactionTest.java +++ b/engine/src/test/java/io/camunda/zeebe/process/test/engine/db/InMemoryZeebeDbTransactionTest.java @@ -8,6 +8,7 @@ package io.camunda.zeebe.process.test.engine.db; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import io.camunda.zeebe.db.ColumnFamily; import io.camunda.zeebe.db.TransactionContext; @@ -492,6 +493,25 @@ void shouldWriteKeyAfterDeletion() { assertThat(oneColumnFamily.get(oneKey).getValue()).isEqualTo(-2); } + @Test + void shouldNotIterateOverDeletionsInTransaction() throws Exception { + // given + oneKey.wrapLong(1); + oneValue.wrapLong(-1L); + oneColumnFamily.insert(oneKey, oneValue); + transactionContext.getCurrentTransaction().commit(); + + // when - then + transactionContext.runInTransaction( + () -> { + oneColumnFamily.deleteExisting(oneKey); + oneColumnFamily.forEach( + (key, value) -> { + fail("Should not iterate over deleted keys"); + }); + }); + } + private enum ColumnFamilies { DEFAULT, // rocksDB needs a default column family ONE,