mirror of
https://github.com/google/nomulus
synced 2026-09-10 01:56:11 +00:00
Improve Transaction gap processing (#1546)
Skip multiple gaps in one pass and write the correct transaction id to datastore.
This commit is contained in:
+16
-12
@@ -208,18 +208,20 @@ public class ReplicateToDatastoreActionTest {
|
||||
TestObject foo = TestObject.create("foo");
|
||||
insertInDb(foo);
|
||||
|
||||
// Fail during the transaction to delete it.
|
||||
try {
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
jpaTm().delete(foo.key());
|
||||
// Explicitly save the transaction entity to force the id update.
|
||||
jpaTm().insert(new TransactionEntity(new byte[] {1, 2, 3}));
|
||||
throw new RuntimeException("fail!!!");
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.atInfo().log("Got expected exception.");
|
||||
// Fail two transactions.
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
try {
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
jpaTm().delete(foo.key());
|
||||
// Explicitly save the transaction entity to force the id update.
|
||||
jpaTm().insert(new TransactionEntity(new byte[] {1, 2, 3}));
|
||||
throw new RuntimeException("fail!!!");
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.atInfo().log("Got expected exception.");
|
||||
}
|
||||
}
|
||||
|
||||
TestObject bar = TestObject.create("bar");
|
||||
@@ -230,11 +232,13 @@ public class ReplicateToDatastoreActionTest {
|
||||
assertThat(txns).hasSize(2);
|
||||
for (TransactionEntity txn : txns) {
|
||||
assertThat(txn.getId()).isNotEqualTo(2);
|
||||
assertThat(txn.getId()).isNotEqualTo(3);
|
||||
applyTransaction(txn);
|
||||
}
|
||||
|
||||
assertThat(ofyTm().transact(() -> ofyTm().loadByKey(foo.key()))).isEqualTo(foo);
|
||||
assertThat(ofyTm().transact(() -> ofyTm().loadByKey(bar.key()))).isEqualTo(bar);
|
||||
assertThat(ofyTm().transact(() -> LastSqlTransaction.load()).getTransactionId()).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user