mirror of
https://github.com/google/nomulus.git
synced 2025-07-09 20:53:26 +02:00
Use merge instead of persist for RegistryLockDao (#310)
* Use merge instead of persist for RegistryLockDao * CR responses
This commit is contained in:
parent
128fde16c3
commit
f98b0f8739
3 changed files with 24 additions and 9 deletions
|
@ -22,6 +22,7 @@ import google.registry.model.transaction.JpaTransactionManagerRule;
|
|||
import google.registry.schema.domain.RegistryLock;
|
||||
import google.registry.schema.domain.RegistryLock.Action;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import javax.persistence.PersistenceException;
|
||||
import org.junit.Rule;
|
||||
|
@ -71,10 +72,10 @@ public final class RegistryLockDaoTest {
|
|||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
RegistryLock secondLock =
|
||||
RegistryLock updatedLock =
|
||||
RegistryLockDao.getByVerificationCode(lock.getVerificationCode());
|
||||
secondLock.setCompletionTimestamp(jpaTmRule.getTxnClock().nowUtc());
|
||||
RegistryLockDao.save(secondLock);
|
||||
updatedLock.setCompletionTimestamp(jpaTmRule.getTxnClock().nowUtc());
|
||||
RegistryLockDao.save(updatedLock);
|
||||
});
|
||||
jpaTm()
|
||||
.transact(
|
||||
|
@ -86,6 +87,23 @@ public final class RegistryLockDaoTest {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateLock_usingSamePrimaryKey() {
|
||||
RegistryLock lock = RegistryLockDao.save(createLock());
|
||||
jpaTmRule.getTxnClock().advanceOneMilli();
|
||||
RegistryLock updatedLock =
|
||||
lock.asBuilder().setCompletionTimestamp(jpaTmRule.getTxnClock().nowUtc()).build();
|
||||
jpaTm().transact(() -> RegistryLockDao.save(updatedLock));
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
RegistryLock fromDatabase =
|
||||
RegistryLockDao.getByVerificationCode(lock.getVerificationCode());
|
||||
assertThat(fromDatabase.getCompletionTimestamp())
|
||||
.isEqualTo(Optional.of(jpaTmRule.getTxnClock().nowUtc()));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_saveNull() {
|
||||
assertThrows(NullPointerException.class, () -> RegistryLockDao.save(null));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue