-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from gjorgievskivlatko/servertimestatementsou…
…rce-updatestatements-fix Bugfix - ServerTimeStatementsSource strategies
- Loading branch information
Showing
18 changed files
with
313 additions
and
52 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
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
108 changes: 108 additions & 0 deletions
108
...et/javacrumbs/shedlock/provider/jdbctemplate/AbstractJdbcTemplateStorageAccessorTest.java
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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package net.javacrumbs.shedlock.provider.jdbctemplate; | ||
|
||
import net.javacrumbs.shedlock.core.LockConfiguration; | ||
import net.javacrumbs.shedlock.support.annotation.NonNull; | ||
import net.javacrumbs.shedlock.test.support.jdbc.DbConfig; | ||
import net.javacrumbs.shedlock.test.support.jdbc.JdbcTestUtils; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.sql.Timestamp; | ||
import java.time.Duration; | ||
|
||
import static java.lang.Thread.sleep; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public abstract class AbstractJdbcTemplateStorageAccessorTest { | ||
|
||
private static final String MY_LOCK = "my-lock"; | ||
private static final String OTHER_LOCK = "other-lock"; | ||
|
||
private final JdbcTestUtils testUtils; | ||
|
||
protected AbstractJdbcTemplateStorageAccessorTest(DbConfig dbConfig) { | ||
this.testUtils = new JdbcTestUtils(dbConfig); | ||
} | ||
|
||
@AfterEach | ||
public void cleanup() { | ||
testUtils.clean(); | ||
} | ||
|
||
@Test | ||
void shouldNotUpdateOnInsertIfPreviousDidNotEndWhenNotUsingDbTime() { | ||
shouldNotUpdateOnInsertIfPreviousDidNotEnd(false); | ||
} | ||
|
||
@Test | ||
void shouldNotUpdateOnInsertIfPreviousDidNotEndWhenUsingDbTime() { | ||
shouldNotUpdateOnInsertIfPreviousDidNotEnd(true); | ||
} | ||
|
||
private void shouldNotUpdateOnInsertIfPreviousDidNotEnd(boolean usingDbTime) { | ||
JdbcTemplateStorageAccessor accessor = getAccessor(usingDbTime); | ||
|
||
assertThat( | ||
accessor.insertRecord(new LockConfiguration(MY_LOCK, Duration.ofSeconds(10), Duration.ZERO)) | ||
).isEqualTo(true); | ||
|
||
Timestamp originalLockValidity = testUtils.getLockedUntil(MY_LOCK); | ||
|
||
assertThat( | ||
accessor.insertRecord(new LockConfiguration(MY_LOCK, Duration.ofSeconds(10), Duration.ZERO)) | ||
).isEqualTo(false); | ||
|
||
assertThat(testUtils.getLockedUntil(MY_LOCK)).isEqualTo(originalLockValidity); | ||
} | ||
|
||
@Test | ||
void shouldNotUpdateOtherLockConfigurationsWhenNotUsingDbTime() throws InterruptedException { | ||
shouldNotUpdateOtherLockConfigurations(false); | ||
} | ||
|
||
@Test | ||
void shouldNotUpdateOtherLockConfigurationsWhenUsingDbTime() throws InterruptedException { | ||
shouldNotUpdateOtherLockConfigurations(true); | ||
} | ||
|
||
private void shouldNotUpdateOtherLockConfigurations(boolean usingDbTime) throws InterruptedException { | ||
JdbcTemplateStorageAccessor accessor = getAccessor(usingDbTime); | ||
|
||
Duration lockAtMostFor = Duration.ofMillis(10); | ||
assertThat(accessor.insertRecord(new LockConfiguration(MY_LOCK, lockAtMostFor, Duration.ZERO))).isEqualTo(true); | ||
assertThat(accessor.insertRecord(new LockConfiguration(OTHER_LOCK, lockAtMostFor, Duration.ZERO))).isEqualTo(true); | ||
|
||
Timestamp myLockLockedUntil = testUtils.getLockedUntil(MY_LOCK); | ||
Timestamp otherLockLockedUntil = testUtils.getLockedUntil(OTHER_LOCK); | ||
|
||
// wait for a while so there will be a difference in the timestamp | ||
// when system time is used seems there is no milliseconds in the timestamp so to make a difference we have to wait for at least a second | ||
sleep(1000); | ||
|
||
|
||
// act | ||
assertThat(accessor.updateRecord(new LockConfiguration(MY_LOCK, lockAtMostFor, Duration.ZERO))).isEqualTo(true); | ||
|
||
|
||
// assert | ||
assertThat(testUtils.getLockedUntil(MY_LOCK)).isAfter(myLockLockedUntil); | ||
// check that the other lock has not been affected by "my-lock" update | ||
assertThat(testUtils.getLockedUntil(OTHER_LOCK)).isEqualTo(otherLockLockedUntil); | ||
} | ||
|
||
@NonNull | ||
protected JdbcTemplateStorageAccessor getAccessor(boolean usingDbTime) { | ||
JdbcTemplateLockProvider.Configuration.Builder builder = JdbcTemplateLockProvider | ||
.Configuration.builder() | ||
.withJdbcTemplate(testUtils.getJdbcTemplate()); | ||
if (usingDbTime) { | ||
builder.usingDbTime(); | ||
} | ||
|
||
return new JdbcTemplateStorageAccessor(builder.build()); | ||
} | ||
|
||
protected JdbcTestUtils getTestUtils() { | ||
return testUtils; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ava/net/javacrumbs/shedlock/provider/jdbctemplate/Db2JdbcTemplateStorageAccessorTest.java
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package net.javacrumbs.shedlock.provider.jdbctemplate; | ||
|
||
import net.javacrumbs.shedlock.test.support.jdbc.Db2ServerConfig; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
|
||
class Db2JdbcTemplateStorageAccessorTest extends AbstractJdbcTemplateStorageAccessorTest { | ||
|
||
private static final Db2ServerConfig dbConfig = new Db2ServerConfig(); | ||
|
||
protected Db2JdbcTemplateStorageAccessorTest() { | ||
super(dbConfig); | ||
} | ||
|
||
@BeforeAll | ||
public static void startDb() { | ||
dbConfig.startDb(); | ||
} | ||
|
||
@AfterAll | ||
public static void shutdownDb() { | ||
dbConfig.shutdownDb(); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...java/net/javacrumbs/shedlock/provider/jdbctemplate/H2JdbcTemplateStorageAccessorTest.java
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package net.javacrumbs.shedlock.provider.jdbctemplate; | ||
|
||
import net.javacrumbs.shedlock.test.support.jdbc.H2Config; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
|
||
class H2JdbcTemplateStorageAccessorTest extends AbstractJdbcTemplateStorageAccessorTest { | ||
|
||
private static final H2Config dbConfig = new H2Config(); | ||
|
||
protected H2JdbcTemplateStorageAccessorTest() { | ||
super(dbConfig); | ||
} | ||
|
||
@BeforeAll | ||
public static void startDb() { | ||
dbConfig.startDb(); | ||
} | ||
|
||
@AfterAll | ||
public static void shutdownDb() { | ||
dbConfig.shutdownDb(); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...va/net/javacrumbs/shedlock/provider/jdbctemplate/HsqlJdbcTemplateStorageAccessorTest.java
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package net.javacrumbs.shedlock.provider.jdbctemplate; | ||
|
||
import net.javacrumbs.shedlock.test.support.jdbc.HsqlConfig; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
|
||
class HsqlJdbcTemplateStorageAccessorTest extends AbstractJdbcTemplateStorageAccessorTest { | ||
|
||
private static final HsqlConfig dbConfig = new HsqlConfig(); | ||
|
||
protected HsqlJdbcTemplateStorageAccessorTest() { | ||
super(dbConfig); | ||
} | ||
|
||
@BeforeAll | ||
public static void startDb() { | ||
dbConfig.startDb(); | ||
} | ||
|
||
@AfterAll | ||
public static void shutdownDb() { | ||
dbConfig.shutdownDb(); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...net/javacrumbs/shedlock/provider/jdbctemplate/MariaDbJdbcTemplateStorageAccessorTest.java
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package net.javacrumbs.shedlock.provider.jdbctemplate; | ||
|
||
import net.javacrumbs.shedlock.test.support.jdbc.MariaDbConfig; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
|
||
class MariaDbJdbcTemplateStorageAccessorTest extends AbstractJdbcTemplateStorageAccessorTest { | ||
|
||
private static final MariaDbConfig dbConfig = new MariaDbConfig(); | ||
|
||
protected MariaDbJdbcTemplateStorageAccessorTest() { | ||
super(dbConfig); | ||
} | ||
|
||
@BeforeAll | ||
public static void startDb() { | ||
dbConfig.startDb(); | ||
} | ||
|
||
@AfterAll | ||
public static void shutdownDb() { | ||
dbConfig.shutdownDb(); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...a/net/javacrumbs/shedlock/provider/jdbctemplate/MsSqlJdbcTemplateStorageAccessorTest.java
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package net.javacrumbs.shedlock.provider.jdbctemplate; | ||
|
||
import net.javacrumbs.shedlock.test.support.jdbc.MsSqlServerConfig; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
|
||
class MsSqlJdbcTemplateStorageAccessorTest extends AbstractJdbcTemplateStorageAccessorTest { | ||
|
||
private static final MsSqlServerConfig dbConfig = new MsSqlServerConfig(); | ||
|
||
protected MsSqlJdbcTemplateStorageAccessorTest() { | ||
super(dbConfig); | ||
} | ||
|
||
@BeforeAll | ||
public static void startDb() { | ||
dbConfig.startDb(); | ||
} | ||
|
||
@AfterAll | ||
public static void shutdownDb() { | ||
dbConfig.shutdownDb(); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...a/net/javacrumbs/shedlock/provider/jdbctemplate/MySqlJdbcTemplateStorageAccessorTest.java
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package net.javacrumbs.shedlock.provider.jdbctemplate; | ||
|
||
import net.javacrumbs.shedlock.test.support.jdbc.MySqlConfig; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
|
||
class MySqlJdbcTemplateStorageAccessorTest extends AbstractJdbcTemplateStorageAccessorTest { | ||
|
||
private static final MySqlConfig dbConfig = new MySqlConfig(); | ||
|
||
protected MySqlJdbcTemplateStorageAccessorTest() { | ||
super(dbConfig); | ||
} | ||
|
||
@BeforeAll | ||
public static void startDb() { | ||
dbConfig.startDb(); | ||
} | ||
|
||
@AfterAll | ||
public static void shutdownDb() { | ||
dbConfig.shutdownDb(); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
.../net/javacrumbs/shedlock/provider/jdbctemplate/OracleJdbcTemplateStorageAccessorTest.java
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package net.javacrumbs.shedlock.provider.jdbctemplate; | ||
|
||
import net.javacrumbs.shedlock.test.support.jdbc.OracleServerConfig; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
|
||
class OracleJdbcTemplateStorageAccessorTest extends AbstractJdbcTemplateStorageAccessorTest { | ||
|
||
private static final OracleServerConfig dbConfig = new OracleServerConfig(); | ||
|
||
protected OracleJdbcTemplateStorageAccessorTest() { | ||
super(dbConfig); | ||
} | ||
|
||
@BeforeAll | ||
public static void startDb() { | ||
dbConfig.startDb(); | ||
} | ||
|
||
@AfterAll | ||
public static void shutdownDb() { | ||
dbConfig.shutdownDb(); | ||
} | ||
|
||
} |
Oops, something went wrong.