From 4cb84a110c500f06a52c4896138b06807333ae6f Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Fri, 5 Feb 2016 15:00:36 +0000 Subject: [PATCH] HHH-9635 - Add test for issue --- .../dialect/SQLServer2005DialectTestCase.java | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java b/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java index 13afec312a..2962ac1422 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java @@ -11,6 +11,8 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.hibernate.LockMode; +import org.hibernate.LockOptions; import org.hibernate.engine.spi.RowSelection; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; @@ -190,6 +192,145 @@ public class SQLServer2005DialectTestCase extends BaseUnitTestCase { ); } + @Test + @TestForIssue(jiraKey = "HHH-9635") + public void testAppendLockHintReadPastLocking() { + final String expectedLockHint = "tab1 with (updlock, rowlock, readpast)"; + + LockOptions lockOptions = new LockOptions( LockMode.UPGRADE_SKIPLOCKED ); + String lockHint = dialect.appendLockHint( lockOptions, "tab1" ); + + assertEquals( expectedLockHint, lockHint ); + } + + @Test + @TestForIssue(jiraKey = "HHH-9635") + public void testAppendLockHintReadPastLockingNoTimeOut() { + final String expectedLockHint = "tab1 with (updlock, rowlock, readpast, nowait)"; + + LockOptions lockOptions = new LockOptions( LockMode.UPGRADE_SKIPLOCKED ); + lockOptions.setTimeOut( LockOptions.NO_WAIT ); + String lockHint = dialect.appendLockHint( lockOptions, "tab1" ); + + assertEquals( expectedLockHint, lockHint ); + } + + @Test + @TestForIssue(jiraKey = "HHH-9635") + public void testAppendLockHintPessimisticRead() { + final String expectedLockHint = "tab1 with (holdlock, rowlock)"; + + LockOptions lockOptions = new LockOptions( LockMode.PESSIMISTIC_READ ); + String lockHint = dialect.appendLockHint( lockOptions, "tab1" ); + + assertEquals( expectedLockHint, lockHint ); + } + + @Test + @TestForIssue(jiraKey = "HHH-9635") + public void testAppendLockHintPessimisticReadNoTimeOut() { + final String expectedLockHint = "tab1 with (holdlock, rowlock, nowait)"; + + LockOptions lockOptions = new LockOptions( LockMode.PESSIMISTIC_READ ); + lockOptions.setTimeOut( LockOptions.NO_WAIT ); + String lockHint = dialect.appendLockHint( lockOptions, "tab1" ); + + assertEquals( expectedLockHint, lockHint ); + } + + @Test + @TestForIssue(jiraKey = "HHH-9635") + public void testAppendLockHintWrite() { + final String expectedLockHint = "tab1 with (updlock, rowlock)"; + + LockOptions lockOptions = new LockOptions( LockMode.WRITE ); + String lockHint = dialect.appendLockHint( lockOptions, "tab1" ); + + assertEquals( expectedLockHint, lockHint ); + } + + @Test + @TestForIssue(jiraKey = "HHH-9635") + public void testAppendLockHintWriteWithNoTimeOut() { + final String expectedLockHint = "tab1 with (updlock, rowlock, nowait)"; + + LockOptions lockOptions = new LockOptions( LockMode.WRITE ); + lockOptions.setTimeOut( LockOptions.NO_WAIT ); + + String lockHint = dialect.appendLockHint( lockOptions, "tab1" ); + + assertEquals( expectedLockHint, lockHint ); + } + + @Test + @TestForIssue(jiraKey = "HHH-9635") + public void testAppendLockHintUpgradeNoWait() { + final String expectedLockHint = "tab1 with (updlock, rowlock, nowait)"; + + LockOptions lockOptions = new LockOptions( LockMode.UPGRADE_NOWAIT ); + String lockHint = dialect.appendLockHint( lockOptions, "tab1" ); + + assertEquals( expectedLockHint, lockHint ); + } + + @Test + @TestForIssue(jiraKey = "HHH-9635") + public void testAppendLockHintUpgradeNoWaitNoTimeout() { + final String expectedLockHint = "tab1 with (updlock, rowlock, nowait)"; + + LockOptions lockOptions = new LockOptions( LockMode.UPGRADE_NOWAIT ); + lockOptions.setTimeOut( LockOptions.NO_WAIT ); + String lockHint = dialect.appendLockHint( lockOptions, "tab1" ); + + assertEquals( expectedLockHint, lockHint ); + } + + @Test + @TestForIssue(jiraKey = "HHH-9635") + public void testAppendLockHintUpgrade() { + final String expectedLockHint = "tab1 with (updlock, rowlock)"; + + LockOptions lockOptions = new LockOptions( LockMode.UPGRADE ); + String lockHint = dialect.appendLockHint( lockOptions, "tab1" ); + + assertEquals( expectedLockHint, lockHint ); + } + + @Test + @TestForIssue(jiraKey = "HHH-9635") + public void testAppendLockHintUpgradeNoTimeout() { + final String expectedLockHint = "tab1 with (updlock, rowlock, nowait)"; + + LockOptions lockOptions = new LockOptions( LockMode.UPGRADE ); + lockOptions.setTimeOut( LockOptions.NO_WAIT ); + String lockHint = dialect.appendLockHint( lockOptions, "tab1" ); + + assertEquals( expectedLockHint, lockHint ); + } + + @Test + @TestForIssue(jiraKey = "HHH-9635") + public void testAppendLockHintPessimisticWrite() { + final String expectedLockHint = "tab1 with (updlock, rowlock)"; + + LockOptions lockOptions = new LockOptions( LockMode.UPGRADE ); + String lockHint = dialect.appendLockHint( lockOptions, "tab1" ); + + assertEquals( expectedLockHint, lockHint ); + } + + @Test + @TestForIssue(jiraKey = "HHH-9635") + public void testAppendLockHintPessimisticWriteNoTimeOut() { + final String expectedLockHint = "tab1 with (updlock, rowlock, nowait)"; + + LockOptions lockOptions = new LockOptions( LockMode.UPGRADE ); + lockOptions.setTimeOut( LockOptions.NO_WAIT ); + String lockHint = dialect.appendLockHint( lockOptions, "tab1" ); + + assertEquals( expectedLockHint, lockHint ); + } + private RowSelection toRowSelection(int firstRow, int maxRows) { RowSelection selection = new RowSelection(); selection.setFirstRow( firstRow );