-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using Entity.flush does not alert EntityHook subscribers #1225
- Loading branch information
Showing
5 changed files
with
52 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,19 +120,19 @@ class EntityHookTest : DatabaseTestsBase() { | |
|
||
@Test fun testModifiedSimple01() { | ||
withTables(*EntityHookTestData.allTables) { | ||
transaction { | ||
val (_, events1, _) = trackChanges { | ||
val ru = EntityHookTestData.Country.new { | ||
name = "RU" | ||
} | ||
val x = EntityHookTestData.City.new { | ||
EntityHookTestData.City.new { | ||
name = "St. Petersburg" | ||
country = ru | ||
} | ||
|
||
flushCache() | ||
} | ||
|
||
val (_, events, txId) = trackChanges { | ||
assertEquals(2, events1.count()) | ||
|
||
val (_, events2, txId) = trackChanges { | ||
val de = EntityHookTestData.Country.new { | ||
name = "DE" | ||
} | ||
|
@@ -141,10 +141,10 @@ class EntityHookTest : DatabaseTestsBase() { | |
x.country = de | ||
} | ||
// TODO: one may expect change for RU but we do not send it due to performance reasons | ||
assertEquals(2, events.count()) | ||
assertEqualCollections(events.mapNotNull { it.toEntity(EntityHookTestData.City)?.name }, "Munich") | ||
assertEqualCollections(events.mapNotNull { it.toEntity(EntityHookTestData.Country)?.name }, "DE") | ||
events.forEach { | ||
assertEquals(2, events2.count()) | ||
assertEqualCollections(events2.mapNotNull { it.toEntity(EntityHookTestData.City)?.name }, "Munich") | ||
assertEqualCollections(events2.mapNotNull { it.toEntity(EntityHookTestData.Country)?.name }, "DE") | ||
events2.forEach { | ||
assertEquals(txId, it.transactionId) | ||
} | ||
} | ||
|
@@ -297,4 +297,32 @@ class EntityHookTest : DatabaseTestsBase() { | |
assertEquals(EntityChangeType.Updated, updateEvent.changeType) | ||
} | ||
} | ||
|
||
@Test | ||
fun `calling flush notifies EntityHook subscribers`() { | ||
withTables(EntityHookTestData.User.table) { | ||
var hookCalls = 0 | ||
val user = EntityHookTestData.User.new { | ||
name = "[email protected]" | ||
age = 30 | ||
} | ||
user.flush() | ||
|
||
EntityHook.subscribe { | ||
hookCalls++ | ||
} | ||
|
||
user.name = "[email protected]" | ||
assertEquals(0, hookCalls) | ||
|
||
user.flush() | ||
assertEquals(1, hookCalls) | ||
|
||
user.name = "[email protected]" | ||
assertEquals(1, hookCalls) | ||
|
||
commit() | ||
assertEquals(2, hookCalls) | ||
} | ||
} | ||
} |