- */
- @Nonbinding String lockAtMostFor() default "";
-
- /**
- * The lock will be held at least for this period of time. Can be used if you really need to execute the task
- * at most once in given period of time. If the duration of the task is shorter than clock difference between nodes, the task can
- * be theoretically executed more than once (one node after another). By setting this parameter, you can make sure that the
- * lock will be kept at least for given period of time. Can be any format
- * supported by Duration Conversion
- */
- @Nonbinding String lockAtLeastFor() default "";
-}
-
diff --git a/cdi/shedlock-cdi-vintage/src/main/java/net/javacrumbs/shedlock/cdi/internal/LockingNotSupportedException.java b/cdi/shedlock-cdi-vintage/src/main/java/net/javacrumbs/shedlock/cdi/internal/LockingNotSupportedException.java
deleted file mode 100644
index 7532ee44e..000000000
--- a/cdi/shedlock-cdi-vintage/src/main/java/net/javacrumbs/shedlock/cdi/internal/LockingNotSupportedException.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Copyright 2009 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.javacrumbs.shedlock.cdi.internal;
-
-import net.javacrumbs.shedlock.support.LockException;
-
-class LockingNotSupportedException extends LockException {
- LockingNotSupportedException() {
- super("Can not lock method returning value (do not know what to return if it's locked)");
- }
-}
diff --git a/cdi/shedlock-cdi-vintage/src/main/resources/META-INF/beans.xml b/cdi/shedlock-cdi-vintage/src/main/resources/META-INF/beans.xml
deleted file mode 100644
index 75b9e9cce..000000000
--- a/cdi/shedlock-cdi-vintage/src/main/resources/META-INF/beans.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
+ */
+ @Nonbinding
+ String lockAtMostFor() default "";
+
+ /**
+ * The lock will be held at least for this period of time. Can be used if you
+ * really need to execute the task at most once in given period of time. If the
+ * duration of the task is shorter than clock difference between nodes, the task
+ * can be theoretically executed more than once (one node after another). By
+ * setting this parameter, you can make sure that the lock will be kept at least
+ * for given period of time. Can be any format supported by Duration
+ * Conversion
+ */
+ @Nonbinding
+ String lockAtLeastFor() default "";
+}
diff --git a/cdi/shedlock-cdi-vintage/src/main/java/net/javacrumbs/shedlock/cdi/internal/CdiLockConfigurationExtractor.java b/cdi/shedlock-cdi/src/main/java/net/javacrumbs/shedlock/cdi/internal/CdiLockConfigurationExtractor.java
similarity index 66%
rename from cdi/shedlock-cdi-vintage/src/main/java/net/javacrumbs/shedlock/cdi/internal/CdiLockConfigurationExtractor.java
rename to cdi/shedlock-cdi/src/main/java/net/javacrumbs/shedlock/cdi/internal/CdiLockConfigurationExtractor.java
index 3a5e54ab3..39d64de22 100644
--- a/cdi/shedlock-cdi-vintage/src/main/java/net/javacrumbs/shedlock/cdi/internal/CdiLockConfigurationExtractor.java
+++ b/cdi/shedlock-cdi/src/main/java/net/javacrumbs/shedlock/cdi/internal/CdiLockConfigurationExtractor.java
@@ -1,31 +1,27 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.cdi.internal;
-
-import net.javacrumbs.shedlock.cdi.SchedulerLock;
-import net.javacrumbs.shedlock.core.ClockProvider;
-import net.javacrumbs.shedlock.core.LockConfiguration;
+import static java.util.Objects.requireNonNull;
+import static net.javacrumbs.shedlock.cdi.internal.Utils.parseDuration;
import java.lang.reflect.Method;
import java.time.Duration;
import java.util.Optional;
-
-import static java.util.Objects.requireNonNull;
-import static net.javacrumbs.shedlock.cdi.internal.Utils.parseDuration;
+import net.javacrumbs.shedlock.cdi.SchedulerLock;
+import net.javacrumbs.shedlock.core.ClockProvider;
+import net.javacrumbs.shedlock.core.LockConfiguration;
class CdiLockConfigurationExtractor {
private final Duration defaultLockAtMostFor;
@@ -36,7 +32,6 @@ class CdiLockConfigurationExtractor {
this.defaultLockAtLeastFor = requireNonNull(defaultLockAtLeastFor);
}
-
Optional Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.javacrumbs.shedlock.cdi.internal;
+
+import net.javacrumbs.shedlock.support.LockException;
+
+class LockingNotSupportedException extends LockException {
+ LockingNotSupportedException() {
+ super("Can not lock method returning value (do not know what to return if it's locked)");
+ }
+}
diff --git a/cdi/shedlock-cdi-vintage/src/main/java/net/javacrumbs/shedlock/cdi/internal/SchedulerLockInterceptor.java b/cdi/shedlock-cdi/src/main/java/net/javacrumbs/shedlock/cdi/internal/SchedulerLockInterceptor.java
similarity index 78%
rename from cdi/shedlock-cdi-vintage/src/main/java/net/javacrumbs/shedlock/cdi/internal/SchedulerLockInterceptor.java
rename to cdi/shedlock-cdi/src/main/java/net/javacrumbs/shedlock/cdi/internal/SchedulerLockInterceptor.java
index 129fad619..78388a74d 100644
--- a/cdi/shedlock-cdi-vintage/src/main/java/net/javacrumbs/shedlock/cdi/internal/SchedulerLockInterceptor.java
+++ b/cdi/shedlock-cdi/src/main/java/net/javacrumbs/shedlock/cdi/internal/SchedulerLockInterceptor.java
@@ -1,24 +1,23 @@
package net.javacrumbs.shedlock.cdi.internal;
+import static net.javacrumbs.shedlock.cdi.internal.Utils.parseDuration;
+
+import jakarta.annotation.Priority;
+import jakarta.inject.Inject;
+import jakarta.interceptor.AroundInvoke;
+import jakarta.interceptor.Interceptor;
+import jakarta.interceptor.InvocationContext;
+import java.time.Duration;
+import java.util.Objects;
+import java.util.Optional;
import net.javacrumbs.shedlock.cdi.SchedulerLock;
import net.javacrumbs.shedlock.core.DefaultLockingTaskExecutor;
import net.javacrumbs.shedlock.core.LockConfiguration;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.core.LockingTaskExecutor;
+import net.javacrumbs.shedlock.support.annotation.Nullable;
import org.eclipse.microprofile.config.ConfigProvider;
-import javax.annotation.Priority;
-import javax.inject.Inject;
-import javax.interceptor.AroundInvoke;
-import javax.interceptor.Interceptor;
-import javax.interceptor.InvocationContext;
-import java.time.Duration;
-import java.util.Objects;
-import java.util.Optional;
-
-import static net.javacrumbs.shedlock.cdi.internal.Utils.parseDuration;
-
-
@SchedulerLock(name = "?")
@Priority(3001)
@Interceptor
@@ -33,23 +32,24 @@ public SchedulerLockInterceptor(LockProvider lockProvider) {
String lockAtLeastFor = getConfigValue("shedlock.defaults.lock-at-least-for");
Objects.requireNonNull(lockAtMostFor, "shedlock.defaults.lock-at-most-for parameter is mandatory");
this.lockConfigurationExtractor = new CdiLockConfigurationExtractor(
- parseDuration(lockAtMostFor),
- lockAtLeastFor != null ? parseDuration(lockAtLeastFor) : Duration.ZERO
- );
+ parseDuration(lockAtMostFor), lockAtLeastFor != null ? parseDuration(lockAtLeastFor) : Duration.ZERO);
}
+ @Nullable
private static String getConfigValue(String propertyName) {
return ConfigProvider.getConfig().getConfigValue(propertyName).getValue();
}
@AroundInvoke
+ @Nullable
Object lock(InvocationContext context) throws Throwable {
Class> returnType = context.getMethod().getReturnType();
if (!void.class.equals(returnType) && !Void.class.equals(returnType)) {
throw new LockingNotSupportedException();
}
- Optional Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.quarkus.test;
+import static net.javacrumbs.shedlock.core.LockAssert.assertLocked;
+import static org.mockito.Mockito.mock;
+import io.quarkus.arc.profile.IfBuildProfile;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.enterprise.inject.Produces;
+import jakarta.inject.Singleton;
+import java.io.IOException;
import net.javacrumbs.shedlock.cdi.SchedulerLock;
import net.javacrumbs.shedlock.core.LockProvider;
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.Produces;
-import javax.inject.Singleton;
-import java.io.IOException;
-
-import static net.javacrumbs.shedlock.core.LockAssert.assertLocked;
-import static org.mockito.Mockito.mock;
-
public class QuarkusConfig {
@Produces
@Singleton
+ @IfBuildProfile("test")
public LockProvider lockProvider() {
return mock(LockProvider.class);
}
-
@ApplicationScoped
static class TestBean {
@@ -64,12 +61,9 @@ public int returnsValue() {
}
@SchedulerLock(name = "${property.value}", lockAtLeastFor = "${property.lock-at-least-for}")
- public void property() {
-
- }
+ public void property() {}
}
-
interface AnotherTestBean {
void runManually();
}
@@ -79,8 +73,6 @@ static class AnotherTestBeanImpl implements AnotherTestBean {
@Override
@SchedulerLock(name = "classAnnotation")
- public void runManually() {
-
- }
+ public void runManually() {}
}
}
diff --git a/cdi/test/quarkus-test/src/test/java/net/javacrumbs/shedlock/quarkus/test/QuarkusShedlockTest.java b/cdi/test/quarkus-test/src/test/java/net/javacrumbs/shedlock/quarkus/test/QuarkusShedlockTest.java
index 6f556634e..bec2a4fa4 100644
--- a/cdi/test/quarkus-test/src/test/java/net/javacrumbs/shedlock/quarkus/test/QuarkusShedlockTest.java
+++ b/cdi/test/quarkus-test/src/test/java/net/javacrumbs/shedlock/quarkus/test/QuarkusShedlockTest.java
@@ -1,21 +1,30 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.quarkus.test;
+import static net.javacrumbs.shedlock.quarkus.test.TestUtils.hasParams;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
+
import io.quarkus.test.junit.QuarkusTest;
+import jakarta.inject.Inject;
+import java.io.IOException;
+import java.util.Optional;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.core.SimpleLock;
import net.javacrumbs.shedlock.quarkus.test.QuarkusConfig.AnotherTestBean;
@@ -26,19 +35,6 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-import javax.inject.Inject;
-import java.io.IOException;
-import java.util.Optional;
-
-import static net.javacrumbs.shedlock.quarkus.test.TestUtils.hasParams;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoInteractions;
-import static org.mockito.Mockito.when;
-
-
@QuarkusTest
class QuarkusShedlockTest {
@Inject
@@ -92,7 +88,9 @@ void shouldFailOnReturnType() {
}
@Test
- @Disabled // Not implemented, waiting if anyone is going to use it. When needed, get the code from Quarkus SchedulerUtils
+ @Disabled // Not implemented, waiting if anyone is going to use it. When needed, get the
+ // code from
+ // Quarkus SchedulerUtils
void shouldReadConfigurationProperty() {
testBean.property();
verify(lockProvider).lock(hasParams("property", 30_000, 1_000));
diff --git a/cdi/test/quarkus-test/src/test/java/net/javacrumbs/shedlock/quarkus/test/TestUtils.java b/cdi/test/quarkus-test/src/test/java/net/javacrumbs/shedlock/quarkus/test/TestUtils.java
index 5a76b6c19..ff5c0dae3 100644
--- a/cdi/test/quarkus-test/src/test/java/net/javacrumbs/shedlock/quarkus/test/TestUtils.java
+++ b/cdi/test/quarkus-test/src/test/java/net/javacrumbs/shedlock/quarkus/test/TestUtils.java
@@ -1,30 +1,27 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.quarkus.test;
+import static org.mockito.ArgumentMatchers.argThat;
+
+import java.time.Instant;
import net.javacrumbs.shedlock.core.ClockProvider;
import net.javacrumbs.shedlock.core.LockConfiguration;
import org.mockito.ArgumentMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.time.Instant;
-
-import static org.mockito.ArgumentMatchers.argThat;
-
public class TestUtils {
private static final int GAP = 1000;
@@ -36,14 +33,15 @@ public static LockConfiguration hasParams(String name, long lockAtMostFor, long
@Override
public boolean matches(LockConfiguration c) {
return name.equals(c.getName())
- && isNearTo(lockAtMostFor, c.getLockAtMostUntil())
- && isNearTo(lockAtLeastFor, c.getLockAtLeastUntil());
+ && isNearTo(lockAtMostFor, c.getLockAtMostUntil())
+ && isNearTo(lockAtLeastFor, c.getLockAtLeastUntil());
}
@Override
public String toString() {
Instant now = ClockProvider.now();
- return "hasParams(\"" + name + "\", " + now.plusMillis(lockAtMostFor) + ", " + now.plusMillis(lockAtLeastFor) + ")";
+ return "hasParams(\"" + name + "\", " + now.plusMillis(lockAtMostFor) + ", "
+ + now.plusMillis(lockAtLeastFor) + ")";
}
});
}
diff --git a/micronaut/shedlock-micronaut/src/main/java/net/javacrumbs/shedlock/micronaut/SchedulerLock.java b/micronaut/shedlock-micronaut/src/main/java/net/javacrumbs/shedlock/micronaut/SchedulerLock.java
deleted file mode 100644
index 5967da724..000000000
--- a/micronaut/shedlock-micronaut/src/main/java/net/javacrumbs/shedlock/micronaut/SchedulerLock.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Copyright 2009 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.javacrumbs.shedlock.micronaut;
-
-
-import io.micronaut.aop.Around;
-import io.micronaut.context.annotation.Executable;
-import io.micronaut.context.annotation.Type;
-import net.javacrumbs.shedlock.micronaut.internal.SchedulerLockInterceptor;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-@Documented
-@Retention(RUNTIME)
-@Target({ElementType.TYPE, ElementType.METHOD})
-@Around
-@Executable
-@Type(SchedulerLockInterceptor.class)
-public @interface SchedulerLock {
- /**
- * Lock name.
- */
- String name();
-
- /**
- * How long the lock should be kept in case the machine which obtained the lock died before releasing it.
- * This is just a fallback, under normal circumstances the lock is released as soon the tasks finishes. Can be any format
- * supported by Duration Conversion
- *
- */
- String lockAtMostFor() default "";
-
- /**
- * The lock will be held at least for this period of time. Can be used if you really need to execute the task
- * at most once in given period of time. If the duration of the task is shorter than clock difference between nodes, the task can
- * be theoretically executed more than once (one node after another). By setting this parameter, you can make sure that the
- * lock will be kept at least for given period of time. Can be any format
- * supported by Duration Conversion
- */
- String lockAtLeastFor() default "";
-}
diff --git a/micronaut/shedlock-micronaut/src/main/java/net/javacrumbs/shedlock/micronaut/internal/LockingNotSupportedException.java b/micronaut/shedlock-micronaut/src/main/java/net/javacrumbs/shedlock/micronaut/internal/LockingNotSupportedException.java
deleted file mode 100644
index a9f7f7df7..000000000
--- a/micronaut/shedlock-micronaut/src/main/java/net/javacrumbs/shedlock/micronaut/internal/LockingNotSupportedException.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Copyright 2009 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.javacrumbs.shedlock.micronaut.internal;
-
-import net.javacrumbs.shedlock.support.LockException;
-
-class LockingNotSupportedException extends LockException {
- LockingNotSupportedException() {
- super("Can not lock method returning value (do not know what to return if it's locked)");
- }
-}
diff --git a/micronaut/shedlock-micronaut/src/main/java/net/javacrumbs/shedlock/micronaut/internal/SchedulerLockInterceptor.java b/micronaut/shedlock-micronaut/src/main/java/net/javacrumbs/shedlock/micronaut/internal/SchedulerLockInterceptor.java
deleted file mode 100644
index 0c03592ee..000000000
--- a/micronaut/shedlock-micronaut/src/main/java/net/javacrumbs/shedlock/micronaut/internal/SchedulerLockInterceptor.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * Copyright 2009 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.javacrumbs.shedlock.micronaut.internal;
-
-import io.micronaut.aop.MethodInterceptor;
-import io.micronaut.aop.MethodInvocationContext;
-import io.micronaut.context.annotation.Value;
-import io.micronaut.core.convert.ConversionService;
-import jakarta.inject.Singleton;
-import net.javacrumbs.shedlock.core.DefaultLockingTaskExecutor;
-import net.javacrumbs.shedlock.core.LockConfiguration;
-import net.javacrumbs.shedlock.core.LockProvider;
-import net.javacrumbs.shedlock.core.LockingTaskExecutor;
-
-import java.time.Duration;
-import java.util.Optional;
-
-@Singleton
-public class SchedulerLockInterceptor implements MethodInterceptor Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.javacrumbs.shedlock.micronaut;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import io.micronaut.aop.Around;
+import io.micronaut.context.annotation.Executable;
+import io.micronaut.context.annotation.Type;
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import net.javacrumbs.shedlock.micronaut.internal.SchedulerLockInterceptor;
+
+@Documented
+@Retention(RUNTIME)
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Around
+@Executable
+@Type(SchedulerLockInterceptor.class)
+public @interface SchedulerLock {
+ /** Lock name. */
+ String name();
+
+ /**
+ * How long the lock should be kept in case the machine which obtained the lock
+ * died before releasing it. This is just a fallback, under normal circumstances
+ * the lock is released as soon the tasks finishes. Can be any format supported
+ * by Duration
+ * Conversion
+ *
+ *
+ */
+ String lockAtMostFor() default "";
+
+ /**
+ * The lock will be held at least for this period of time. Can be used if you
+ * really need to execute the task at most once in given period of time. If the
+ * duration of the task is shorter than clock difference between nodes, the task
+ * can be theoretically executed more than once (one node after another). By
+ * setting this parameter, you can make sure that the lock will be kept at least
+ * for given period of time. Can be any format supported by Duration
+ * Conversion
+ */
+ String lockAtLeastFor() default "";
+}
diff --git a/micronaut/shedlock-micronaut4/src/main/java/net/javacrumbs/shedlock/micronaut/internal/LockingNotSupportedException.java b/micronaut/shedlock-micronaut4/src/main/java/net/javacrumbs/shedlock/micronaut/internal/LockingNotSupportedException.java
new file mode 100644
index 000000000..fdd16259c
--- /dev/null
+++ b/micronaut/shedlock-micronaut4/src/main/java/net/javacrumbs/shedlock/micronaut/internal/LockingNotSupportedException.java
@@ -0,0 +1,22 @@
+/**
+ * Copyright 2009 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.javacrumbs.shedlock.micronaut.internal;
+
+import net.javacrumbs.shedlock.support.LockException;
+
+class LockingNotSupportedException extends LockException {
+ LockingNotSupportedException() {
+ super("Can not lock method returning value (do not know what to return if it's locked)");
+ }
+}
diff --git a/micronaut/shedlock-micronaut/src/main/java/net/javacrumbs/shedlock/micronaut/internal/MicronautLockConfigurationExtractor.java b/micronaut/shedlock-micronaut4/src/main/java/net/javacrumbs/shedlock/micronaut/internal/MicronautLockConfigurationExtractor.java
similarity index 58%
rename from micronaut/shedlock-micronaut/src/main/java/net/javacrumbs/shedlock/micronaut/internal/MicronautLockConfigurationExtractor.java
rename to micronaut/shedlock-micronaut4/src/main/java/net/javacrumbs/shedlock/micronaut/internal/MicronautLockConfigurationExtractor.java
index 47322919e..b8317c79a 100644
--- a/micronaut/shedlock-micronaut/src/main/java/net/javacrumbs/shedlock/micronaut/internal/MicronautLockConfigurationExtractor.java
+++ b/micronaut/shedlock-micronaut4/src/main/java/net/javacrumbs/shedlock/micronaut/internal/MicronautLockConfigurationExtractor.java
@@ -1,45 +1,42 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.micronaut.internal;
+import static java.util.Objects.requireNonNull;
+
import io.micronaut.core.annotation.AnnotationValue;
import io.micronaut.core.convert.ConversionService;
import io.micronaut.core.util.StringUtils;
import io.micronaut.inject.ExecutableMethod;
+import java.time.Duration;
+import java.util.Optional;
import net.javacrumbs.shedlock.core.ClockProvider;
import net.javacrumbs.shedlock.core.LockConfiguration;
import net.javacrumbs.shedlock.micronaut.SchedulerLock;
-import java.time.Duration;
-import java.util.Optional;
-
-import static java.util.Objects.requireNonNull;
-
class MicronautLockConfigurationExtractor {
private final Duration defaultLockAtMostFor;
private final Duration defaultLockAtLeastFor;
- private final ConversionService> conversionService;
+ private final ConversionService conversionService;
- MicronautLockConfigurationExtractor(Duration defaultLockAtMostFor, Duration defaultLockAtLeastFor, ConversionService> conversionService) {
+ MicronautLockConfigurationExtractor(
+ Duration defaultLockAtMostFor, Duration defaultLockAtLeastFor, ConversionService conversionService) {
this.defaultLockAtMostFor = requireNonNull(defaultLockAtMostFor);
this.defaultLockAtLeastFor = requireNonNull(defaultLockAtLeastFor);
this.conversionService = conversionService;
}
-
Optional http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.javacrumbs.shedlock.micronaut.internal;
+
+import io.micronaut.aop.MethodInterceptor;
+import io.micronaut.aop.MethodInvocationContext;
+import io.micronaut.context.annotation.Value;
+import io.micronaut.core.convert.ConversionService;
+import jakarta.inject.Singleton;
+import java.time.Duration;
+import java.util.Optional;
+import net.javacrumbs.shedlock.core.DefaultLockingTaskExecutor;
+import net.javacrumbs.shedlock.core.LockConfiguration;
+import net.javacrumbs.shedlock.core.LockProvider;
+import net.javacrumbs.shedlock.core.LockingTaskExecutor;
+import net.javacrumbs.shedlock.support.annotation.Nullable;
+
+@Singleton
+public class SchedulerLockInterceptor implements MethodInterceptor Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.micronaut.internal;
+import static net.javacrumbs.shedlock.core.LockAssert.assertLocked;
+import static org.mockito.Mockito.mock;
import io.micronaut.context.annotation.Factory;
import jakarta.inject.Singleton;
+import java.io.IOException;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.micronaut.SchedulerLock;
-import java.io.IOException;
-
-import static net.javacrumbs.shedlock.core.LockAssert.assertLocked;
-import static org.mockito.Mockito.mock;
-
@Factory
public class MethodProxyAopConfig {
@@ -34,7 +30,6 @@ public LockProvider lockProvider() {
return mock(LockProvider.class);
}
-
@Singleton
static class TestBean {
@@ -63,12 +58,9 @@ public int returnsValue() {
}
@SchedulerLock(name = "${property.value}", lockAtLeastFor = "${property.lock-at-least-for}")
- public void property() {
-
- }
+ public void property() {}
}
-
interface AnotherTestBean {
void runManually();
}
@@ -78,8 +70,6 @@ static class AnotherTestBeanImpl implements AnotherTestBean {
@Override
@SchedulerLock(name = "classAnnotation")
- public void runManually() {
-
- }
+ public void runManually() {}
}
}
diff --git a/micronaut/shedlock-micronaut/src/test/java/net/javacrumbs/shedlock/micronaut/internal/MethodProxyAopTest.java b/micronaut/shedlock-micronaut4/src/test/java/net/javacrumbs/shedlock/micronaut/internal/MethodProxyAopTest.java
similarity index 85%
rename from micronaut/shedlock-micronaut/src/test/java/net/javacrumbs/shedlock/micronaut/internal/MethodProxyAopTest.java
rename to micronaut/shedlock-micronaut4/src/test/java/net/javacrumbs/shedlock/micronaut/internal/MethodProxyAopTest.java
index c8eddf133..9e68726a7 100644
--- a/micronaut/shedlock-micronaut/src/test/java/net/javacrumbs/shedlock/micronaut/internal/MethodProxyAopTest.java
+++ b/micronaut/shedlock-micronaut4/src/test/java/net/javacrumbs/shedlock/micronaut/internal/MethodProxyAopTest.java
@@ -1,22 +1,30 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.micronaut.internal;
+import static net.javacrumbs.shedlock.micronaut.internal.TestUtils.hasParams;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
+
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import jakarta.inject.Inject;
+import java.io.IOException;
+import java.util.Optional;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.core.SimpleLock;
import net.javacrumbs.shedlock.micronaut.internal.MethodProxyAopConfig.AnotherTestBean;
@@ -25,18 +33,6 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-import java.io.IOException;
-import java.util.Optional;
-
-import static net.javacrumbs.shedlock.micronaut.internal.TestUtils.hasParams;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoInteractions;
-import static org.mockito.Mockito.when;
-
-
@MicronautTest
class MethodProxyAopTest {
@Inject
diff --git a/micronaut/shedlock-micronaut/src/test/java/net/javacrumbs/shedlock/micronaut/internal/TestUtils.java b/micronaut/shedlock-micronaut4/src/test/java/net/javacrumbs/shedlock/micronaut/internal/TestUtils.java
similarity index 66%
rename from micronaut/shedlock-micronaut/src/test/java/net/javacrumbs/shedlock/micronaut/internal/TestUtils.java
rename to micronaut/shedlock-micronaut4/src/test/java/net/javacrumbs/shedlock/micronaut/internal/TestUtils.java
index 66b9f743e..d5306f077 100644
--- a/micronaut/shedlock-micronaut/src/test/java/net/javacrumbs/shedlock/micronaut/internal/TestUtils.java
+++ b/micronaut/shedlock-micronaut4/src/test/java/net/javacrumbs/shedlock/micronaut/internal/TestUtils.java
@@ -1,30 +1,27 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.micronaut.internal;
+import static org.mockito.ArgumentMatchers.argThat;
+
+import java.time.Instant;
import net.javacrumbs.shedlock.core.ClockProvider;
import net.javacrumbs.shedlock.core.LockConfiguration;
import org.mockito.ArgumentMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.time.Instant;
-
-import static org.mockito.ArgumentMatchers.argThat;
-
public class TestUtils {
private static final int GAP = 1000;
@@ -36,14 +33,15 @@ public static LockConfiguration hasParams(String name, long lockAtMostFor, long
@Override
public boolean matches(LockConfiguration c) {
return name.equals(c.getName())
- && isNearTo(lockAtMostFor, c.getLockAtMostUntil())
- && isNearTo(lockAtLeastFor, c.getLockAtLeastUntil());
+ && isNearTo(lockAtMostFor, c.getLockAtMostUntil())
+ && isNearTo(lockAtLeastFor, c.getLockAtLeastUntil());
}
@Override
public String toString() {
Instant now = ClockProvider.now();
- return "hasParams(\"" + name + "\", " + now.plusMillis(lockAtMostFor) + ", " + now.plusMillis(lockAtLeastFor) + ")";
+ return "hasParams(\"" + name + "\", " + now.plusMillis(lockAtMostFor) + ", "
+ + now.plusMillis(lockAtLeastFor) + ")";
}
});
}
diff --git a/micronaut/shedlock-micronaut/src/test/resources/application.yml b/micronaut/shedlock-micronaut4/src/test/resources/application.yml
similarity index 100%
rename from micronaut/shedlock-micronaut/src/test/resources/application.yml
rename to micronaut/shedlock-micronaut4/src/test/resources/application.yml
diff --git a/micronaut/test/micronaut-jdbc-new/pom.xml b/micronaut/test/micronaut-jdbc-new/pom.xml
deleted file mode 100644
index fa6a2da80..000000000
--- a/micronaut/test/micronaut-jdbc-new/pom.xml
+++ /dev/null
@@ -1,229 +0,0 @@
-
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.javacrumbs.micronaut.test;
+
+import io.micronaut.runtime.Micronaut;
+
+public class Application {
+
+ public static void main(String[] args) {
+ Micronaut.run(Application.class);
+ }
+}
diff --git a/micronaut/test/micronaut4-jdbc-template/src/main/java/net/javacrumbs/micronaut/test/Configuration.java b/micronaut/test/micronaut4-jdbc-template/src/main/java/net/javacrumbs/micronaut/test/Configuration.java
new file mode 100644
index 000000000..1eba19b9f
--- /dev/null
+++ b/micronaut/test/micronaut4-jdbc-template/src/main/java/net/javacrumbs/micronaut/test/Configuration.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright 2009 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.javacrumbs.micronaut.test;
+
+import io.micronaut.context.annotation.Factory;
+import jakarta.inject.Singleton;
+import javax.sql.DataSource;
+import net.javacrumbs.shedlock.core.LockProvider;
+import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.transaction.PlatformTransactionManager;
+
+@Factory
+public class Configuration {
+
+ @Singleton
+ public LockProvider lockProvider(DataSource dataSource, PlatformTransactionManager transactionManager) {
+ return new JdbcTemplateLockProvider(new JdbcTemplate(dataSource), transactionManager);
+ }
+}
diff --git a/micronaut/test/micronaut-jdbc/src/main/java/net/javacrumbs/micronaut/test/ScheduledTasks.java b/micronaut/test/micronaut4-jdbc-template/src/main/java/net/javacrumbs/micronaut/test/ScheduledTasks.java
similarity index 61%
rename from micronaut/test/micronaut-jdbc/src/main/java/net/javacrumbs/micronaut/test/ScheduledTasks.java
rename to micronaut/test/micronaut4-jdbc-template/src/main/java/net/javacrumbs/micronaut/test/ScheduledTasks.java
index 42410580e..701cd6623 100644
--- a/micronaut/test/micronaut-jdbc/src/main/java/net/javacrumbs/micronaut/test/ScheduledTasks.java
+++ b/micronaut/test/micronaut4-jdbc-template/src/main/java/net/javacrumbs/micronaut/test/ScheduledTasks.java
@@ -1,28 +1,25 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.micronaut.test;
+import static net.javacrumbs.shedlock.core.LockAssert.assertLocked;
+
import io.micronaut.scheduling.annotation.Scheduled;
import jakarta.inject.Singleton;
-import net.javacrumbs.shedlock.micronaut.SchedulerLock;
-
import java.util.Date;
import java.util.concurrent.atomic.AtomicBoolean;
-
-import static net.javacrumbs.shedlock.core.LockAssert.assertLocked;
+import net.javacrumbs.shedlock.micronaut.SchedulerLock;
@Singleton
public class ScheduledTasks {
diff --git a/micronaut/test/micronaut4-jdbc-template/src/main/java/net/javacrumbs/micronaut/test/package-info.java b/micronaut/test/micronaut4-jdbc-template/src/main/java/net/javacrumbs/micronaut/test/package-info.java
new file mode 100644
index 000000000..bc49d14f8
--- /dev/null
+++ b/micronaut/test/micronaut4-jdbc-template/src/main/java/net/javacrumbs/micronaut/test/package-info.java
@@ -0,0 +1,6 @@
+@NonNullApi
+@NonNullFields
+package net.javacrumbs.micronaut.test;
+
+import net.javacrumbs.shedlock.support.annotation.NonNullApi;
+import net.javacrumbs.shedlock.support.annotation.NonNullFields;
diff --git a/micronaut/test/micronaut-jdbc-template/src/main/resources/application.yml b/micronaut/test/micronaut4-jdbc-template/src/main/resources/application.yml
similarity index 100%
rename from micronaut/test/micronaut-jdbc-template/src/main/resources/application.yml
rename to micronaut/test/micronaut4-jdbc-template/src/main/resources/application.yml
diff --git a/micronaut/test/micronaut-jdbc-template/src/main/resources/db/liquibase-changelog.xml b/micronaut/test/micronaut4-jdbc-template/src/main/resources/db/liquibase-changelog.xml
similarity index 100%
rename from micronaut/test/micronaut-jdbc-template/src/main/resources/db/liquibase-changelog.xml
rename to micronaut/test/micronaut4-jdbc-template/src/main/resources/db/liquibase-changelog.xml
diff --git a/micronaut/test/micronaut-jdbc-template/src/main/resources/logback.xml b/micronaut/test/micronaut4-jdbc-template/src/main/resources/logback.xml
similarity index 93%
rename from micronaut/test/micronaut-jdbc-template/src/main/resources/logback.xml
rename to micronaut/test/micronaut4-jdbc-template/src/main/resources/logback.xml
index b8844d63e..050c0dc7c 100644
--- a/micronaut/test/micronaut-jdbc-template/src/main/resources/logback.xml
+++ b/micronaut/test/micronaut4-jdbc-template/src/main/resources/logback.xml
@@ -1,7 +1,6 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.micronaut.test;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.awaitility.Awaitility.await;
-
@MicronautTest
public class ApplicationTest {
@Inject
diff --git a/micronaut/test/micronaut-jdbc/micronaut-cli.yml b/micronaut/test/micronaut4-jdbc/micronaut-cli.yml
similarity index 100%
rename from micronaut/test/micronaut-jdbc/micronaut-cli.yml
rename to micronaut/test/micronaut4-jdbc/micronaut-cli.yml
diff --git a/micronaut/test/micronaut-jdbc/pom.xml b/micronaut/test/micronaut4-jdbc/pom.xml
similarity index 77%
rename from micronaut/test/micronaut-jdbc/pom.xml
rename to micronaut/test/micronaut4-jdbc/pom.xml
index 97a8c5dfe..ddeb68dc7 100644
--- a/micronaut/test/micronaut-jdbc/pom.xml
+++ b/micronaut/test/micronaut4-jdbc/pom.xml
@@ -5,12 +5,12 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.javacrumbs.micronaut.test;
+
+import io.micronaut.runtime.Micronaut;
+
+public class Application {
+
+ public static void main(String[] args) {
+ Micronaut.run(Application.class);
+ }
+}
diff --git a/micronaut/test/micronaut4-jdbc/src/main/java/net/javacrumbs/micronaut/test/Configuration.java b/micronaut/test/micronaut4-jdbc/src/main/java/net/javacrumbs/micronaut/test/Configuration.java
new file mode 100644
index 000000000..e88ef74bd
--- /dev/null
+++ b/micronaut/test/micronaut4-jdbc/src/main/java/net/javacrumbs/micronaut/test/Configuration.java
@@ -0,0 +1,30 @@
+/**
+ * Copyright 2009 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.javacrumbs.micronaut.test;
+
+import io.micronaut.context.annotation.Factory;
+import io.micronaut.transaction.TransactionOperations;
+import jakarta.inject.Singleton;
+import java.sql.Connection;
+import net.javacrumbs.shedlock.core.LockProvider;
+import net.javacrumbs.shedlock.provider.jdbc.micronaut.MicronautJdbcLockProvider;
+
+@Factory
+public class Configuration {
+
+ @Singleton
+ public LockProvider lockProvider(TransactionOperations Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.micronaut.test;
+import static net.javacrumbs.shedlock.core.LockAssert.assertLocked;
+
import io.micronaut.scheduling.annotation.Scheduled;
import jakarta.inject.Singleton;
-import net.javacrumbs.shedlock.micronaut.SchedulerLock;
-
import java.util.Date;
import java.util.concurrent.atomic.AtomicBoolean;
-
-import static net.javacrumbs.shedlock.core.LockAssert.assertLocked;
+import net.javacrumbs.shedlock.micronaut.SchedulerLock;
@Singleton
public class ScheduledTasks {
diff --git a/micronaut/test/micronaut4-jdbc/src/main/java/net/javacrumbs/micronaut/test/package-info.java b/micronaut/test/micronaut4-jdbc/src/main/java/net/javacrumbs/micronaut/test/package-info.java
new file mode 100644
index 000000000..bc49d14f8
--- /dev/null
+++ b/micronaut/test/micronaut4-jdbc/src/main/java/net/javacrumbs/micronaut/test/package-info.java
@@ -0,0 +1,6 @@
+@NonNullApi
+@NonNullFields
+package net.javacrumbs.micronaut.test;
+
+import net.javacrumbs.shedlock.support.annotation.NonNullApi;
+import net.javacrumbs.shedlock.support.annotation.NonNullFields;
diff --git a/micronaut/test/micronaut-jdbc/src/main/resources/application.yml b/micronaut/test/micronaut4-jdbc/src/main/resources/application.yml
similarity index 100%
rename from micronaut/test/micronaut-jdbc/src/main/resources/application.yml
rename to micronaut/test/micronaut4-jdbc/src/main/resources/application.yml
diff --git a/micronaut/test/micronaut-jdbc/src/main/resources/db/liquibase-changelog.xml b/micronaut/test/micronaut4-jdbc/src/main/resources/db/liquibase-changelog.xml
similarity index 100%
rename from micronaut/test/micronaut-jdbc/src/main/resources/db/liquibase-changelog.xml
rename to micronaut/test/micronaut4-jdbc/src/main/resources/db/liquibase-changelog.xml
diff --git a/micronaut/test/micronaut-jdbc/src/main/resources/logback.xml b/micronaut/test/micronaut4-jdbc/src/main/resources/logback.xml
similarity index 93%
rename from micronaut/test/micronaut-jdbc/src/main/resources/logback.xml
rename to micronaut/test/micronaut4-jdbc/src/main/resources/logback.xml
index b8844d63e..050c0dc7c 100644
--- a/micronaut/test/micronaut-jdbc/src/main/resources/logback.xml
+++ b/micronaut/test/micronaut4-jdbc/src/main/resources/logback.xml
@@ -1,7 +1,6 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.micronaut.test;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.awaitility.Awaitility.await;
-
@MicronautTest
public class ApplicationTest {
@Inject
diff --git a/mvnw b/mvnw
new file mode 100755
index 000000000..19529ddf8
--- /dev/null
+++ b/mvnw
@@ -0,0 +1,259 @@
+#!/bin/sh
+# ----------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ----------------------------------------------------------------------------
+
+# ----------------------------------------------------------------------------
+# Apache Maven Wrapper startup batch script, version 3.3.2
+#
+# Optional ENV vars
+# -----------------
+# JAVA_HOME - location of a JDK home dir, required when download maven via java source
+# MVNW_REPOURL - repo url base for downloading maven distribution
+# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
+# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
+# ----------------------------------------------------------------------------
+
+set -euf
+[ "${MVNW_VERBOSE-}" != debug ] || set -x
+
+# OS specific support.
+native_path() { printf %s\\n "$1"; }
+case "$(uname)" in
+CYGWIN* | MINGW*)
+ [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
+ native_path() { cygpath --path --windows "$1"; }
+ ;;
+esac
+
+# set JAVACMD and JAVACCMD
+set_java_home() {
+ # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
+ if [ -n "${JAVA_HOME-}" ]; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ]; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ JAVACCMD="$JAVA_HOME/jre/sh/javac"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ JAVACCMD="$JAVA_HOME/bin/javac"
+
+ if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
+ echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
+ echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
+ return 1
+ fi
+ fi
+ else
+ JAVACMD="$(
+ 'set' +e
+ 'unset' -f command 2>/dev/null
+ 'command' -v java
+ )" || :
+ JAVACCMD="$(
+ 'set' +e
+ 'unset' -f command 2>/dev/null
+ 'command' -v javac
+ )" || :
+
+ if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
+ echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
+ return 1
+ fi
+ fi
+}
+
+# hash string like Java String::hashCode
+hash_string() {
+ str="${1:-}" h=0
+ while [ -n "$str" ]; do
+ char="${str%"${str#?}"}"
+ h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
+ str="${str#?}"
+ done
+ printf %x\\n $h
+}
+
+verbose() { :; }
+[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
+
+die() {
+ printf %s\\n "$1" >&2
+ exit 1
+}
+
+trim() {
+ # MWRAPPER-139:
+ # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
+ # Needed for removing poorly interpreted newline sequences when running in more
+ # exotic environments such as mingw bash on Windows.
+ printf "%s" "${1}" | tr -d '[:space:]'
+}
+
+# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
+while IFS="=" read -r key value; do
+ case "${key-}" in
+ distributionUrl) distributionUrl=$(trim "${value-}") ;;
+ distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
+ esac
+done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties"
+[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties"
+
+case "${distributionUrl##*/}" in
+maven-mvnd-*bin.*)
+ MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
+ case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
+ *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
+ :Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
+ :Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
+ :Linux*x86_64*) distributionPlatform=linux-amd64 ;;
+ *)
+ echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
+ distributionPlatform=linux-amd64
+ ;;
+ esac
+ distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
+ ;;
+maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
+*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
+esac
+
+# apply MVNW_REPOURL and calculate MAVEN_HOME
+# maven home pattern: ~/.m2/wrapper/dists/{apache-maven- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.arangodb;
+import static net.javacrumbs.shedlock.support.Utils.getHostname;
+
import com.arangodb.ArangoCollection;
import com.arangodb.ArangoDBException;
import com.arangodb.ArangoDatabase;
@@ -25,6 +25,8 @@
import com.arangodb.model.DocumentReadOptions;
import com.arangodb.model.DocumentUpdateOptions;
import com.arangodb.model.StreamTransactionOptions;
+import java.time.Instant;
+import java.util.Optional;
import net.javacrumbs.shedlock.core.AbstractSimpleLock;
import net.javacrumbs.shedlock.core.ClockProvider;
import net.javacrumbs.shedlock.core.LockConfiguration;
@@ -32,17 +34,11 @@
import net.javacrumbs.shedlock.core.SimpleLock;
import net.javacrumbs.shedlock.support.LockException;
import net.javacrumbs.shedlock.support.Utils;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
-
-import java.time.Instant;
-import java.util.Optional;
-
-import static net.javacrumbs.shedlock.support.Utils.getHostname;
/**
- * Arango Lock Provider needs existing collection
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.arangodb;
+import static net.javacrumbs.shedlock.core.ClockProvider.now;
+import static net.javacrumbs.shedlock.provider.arangodb.ArangoLockProvider.COLLECTION_NAME;
+import static net.javacrumbs.shedlock.provider.arangodb.ArangoLockProvider.LOCKED_AT;
+import static net.javacrumbs.shedlock.provider.arangodb.ArangoLockProvider.LOCKED_BY;
+import static net.javacrumbs.shedlock.provider.arangodb.ArangoLockProvider.LOCK_UNTIL;
+import static org.assertj.core.api.Assertions.assertThat;
+
import com.arangodb.ArangoCollection;
import com.arangodb.ArangoDB;
import com.arangodb.ArangoDatabase;
import com.arangodb.entity.BaseDocument;
+import java.time.Instant;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.test.support.AbstractLockProviderIntegrationTest;
import org.junit.jupiter.api.AfterAll;
@@ -30,16 +36,6 @@
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
-import java.time.Instant;
-
-import static net.javacrumbs.shedlock.core.ClockProvider.now;
-import static net.javacrumbs.shedlock.provider.arangodb.ArangoLockProvider.COLLECTION_NAME;
-import static net.javacrumbs.shedlock.provider.arangodb.ArangoLockProvider.LOCKED_AT;
-import static net.javacrumbs.shedlock.provider.arangodb.ArangoLockProvider.LOCKED_BY;
-import static net.javacrumbs.shedlock.provider.arangodb.ArangoLockProvider.LOCK_UNTIL;
-import static org.assertj.core.api.Assertions.assertThat;
-
-
@Testcontainers
public class ArangoLockProviderIntegrationTest extends AbstractLockProviderIntegrationTest {
@@ -62,11 +58,11 @@ static void beforeAll() {
arangoContainer.start();
arango = new ArangoDB.Builder()
- .host(DB_HOSTNAME, arangoContainer.getMappedPort(DB_PORT))
- .user(DB_USER)
- .password(DB_PASSWORD)
- .useSsl(false)
- .build();
+ .host(DB_HOSTNAME, arangoContainer.getMappedPort(DB_PORT))
+ .user(DB_USER)
+ .password(DB_PASSWORD)
+ .useSsl(false)
+ .build();
if (!arango.getDatabases().contains(DB_NAME)) {
arango.createDatabase(DB_NAME);
@@ -75,7 +71,7 @@ static void beforeAll() {
arangoDatabase = arango.db(DB_NAME);
if (arangoDatabase.getCollections().stream()
- .anyMatch(collectionEntity -> collectionEntity.getName().equals(COLLECTION_NAME))) {
+ .anyMatch(collectionEntity -> collectionEntity.getName().equals(COLLECTION_NAME))) {
arangoCollection = arangoDatabase.collection(COLLECTION_NAME);
arangoCollection.drop();
}
diff --git a/providers/cassandra/shedlock-provider-cassandra/pom.xml b/providers/cassandra/shedlock-provider-cassandra/pom.xml
index 1cf0b0b64..3738e282f 100644
--- a/providers/cassandra/shedlock-provider-cassandra/pom.xml
+++ b/providers/cassandra/shedlock-provider-cassandra/pom.xml
@@ -3,16 +3,16 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.cassandra;
+import static java.util.Objects.requireNonNull;
+
import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlSession;
import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
-
-import static java.util.Objects.requireNonNull;
+import net.javacrumbs.shedlock.support.annotation.Nullable;
/**
* Cassandra Lock Provider needs a keyspace and uses a lock table Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.cassandra;
+import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal;
+import static java.util.Objects.requireNonNull;
+
import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlSession;
@@ -23,39 +24,41 @@
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.core.servererrors.QueryExecutionException;
import com.datastax.oss.driver.api.querybuilder.QueryBuilder;
+import java.time.Instant;
+import java.util.Optional;
import net.javacrumbs.shedlock.core.ClockProvider;
import net.javacrumbs.shedlock.core.LockConfiguration;
import net.javacrumbs.shedlock.provider.cassandra.CassandraLockProvider.Configuration;
import net.javacrumbs.shedlock.support.AbstractStorageAccessor;
import net.javacrumbs.shedlock.support.Utils;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
+import net.javacrumbs.shedlock.support.annotation.Nullable;
-import java.time.Instant;
-import java.util.Optional;
-
-import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal;
-import static java.util.Objects.requireNonNull;
-
-/**
- * StorageAccessor for cassandra.
- **/
+/** StorageAccessor for cassandra. */
/*
- * In theory, all the reads (find() method calls) in update methods are not necessary,
- * but it's a performance optimization. Moreover, the fuzzTest sometimes fails without them.
+ * In theory, all the reads (find() method calls) in update methods are not
+ * necessary, but it's a performance optimization. Moreover, the fuzzTest
+ * sometimes fails without them.
*/
class CassandraStorageAccessor extends AbstractStorageAccessor {
private final String hostname;
private final CqlIdentifier table;
+
+ @Nullable
private final CqlIdentifier keyspace;
+
private final String lockName;
private final String lockUntil;
private final String lockedAt;
private final String lockedBy;
private final CqlSession cqlSession;
+
+ @Nullable
private final ConsistencyLevel consistencyLevel;
+
+ @Nullable
private final ConsistencyLevel serialConsistencyLevel;
- CassandraStorageAccessor(@NonNull Configuration configuration) {
+ CassandraStorageAccessor(Configuration configuration) {
requireNonNull(configuration, "configuration can not be null");
this.hostname = Utils.getHostname();
this.table = configuration.getTable();
@@ -70,7 +73,7 @@ class CassandraStorageAccessor extends AbstractStorageAccessor {
}
@Override
- public boolean insertRecord(@NonNull LockConfiguration lockConfiguration) {
+ public boolean insertRecord(LockConfiguration lockConfiguration) {
if (find(lockConfiguration.getName()).isPresent()) {
return false;
}
@@ -84,9 +87,9 @@ public boolean insertRecord(@NonNull LockConfiguration lockConfiguration) {
}
@Override
- public boolean updateRecord(@NonNull LockConfiguration lockConfiguration) {
+ public boolean updateRecord(LockConfiguration lockConfiguration) {
Optional Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.cassandra;
import java.time.Instant;
-class Lock {
- private final Instant lockUntil;
- private final Instant lockedAt;
- private final String lockedBy;
-
- Lock(Instant lockUntil, Instant lockedAt, String lockedBy) {
- this.lockUntil = lockUntil;
- this.lockedAt = lockedAt;
- this.lockedBy = lockedBy;
- }
-
- Instant getLockUntil() {
- return lockUntil;
- }
-
- Instant getLockedAt() {
- return lockedAt;
- }
-
- String getLockedBy() {
- return lockedBy;
- }
-}
+record Lock(Instant lockUntil, Instant lockedAt, String lockedBy) {}
diff --git a/providers/cassandra/shedlock-provider-cassandra/src/main/java/net/javacrumbs/shedlock/provider/cassandra/package-info.java b/providers/cassandra/shedlock-provider-cassandra/src/main/java/net/javacrumbs/shedlock/provider/cassandra/package-info.java
new file mode 100644
index 000000000..08eae344e
--- /dev/null
+++ b/providers/cassandra/shedlock-provider-cassandra/src/main/java/net/javacrumbs/shedlock/provider/cassandra/package-info.java
@@ -0,0 +1,6 @@
+@NonNullApi
+@NonNullFields
+package net.javacrumbs.shedlock.provider.cassandra;
+
+import net.javacrumbs.shedlock.support.annotation.NonNullApi;
+import net.javacrumbs.shedlock.support.annotation.NonNullFields;
diff --git a/providers/cassandra/shedlock-provider-cassandra/src/test/java/net/javacrumbs/shedlock/provider/cassandra/CassandraLockProviderIntegrationTest.java b/providers/cassandra/shedlock-provider-cassandra/src/test/java/net/javacrumbs/shedlock/provider/cassandra/CassandraLockProviderIntegrationTest.java
index fa9023ada..789bb3795 100644
--- a/providers/cassandra/shedlock-provider-cassandra/src/test/java/net/javacrumbs/shedlock/provider/cassandra/CassandraLockProviderIntegrationTest.java
+++ b/providers/cassandra/shedlock-provider-cassandra/src/test/java/net/javacrumbs/shedlock/provider/cassandra/CassandraLockProviderIntegrationTest.java
@@ -1,23 +1,27 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.cassandra;
+import static com.datastax.oss.driver.api.core.CqlIdentifier.fromCql;
+import static net.javacrumbs.shedlock.core.ClockProvider.now;
+import static net.javacrumbs.shedlock.provider.cassandra.CassandraLockProvider.DEFAULT_TABLE;
+import static org.assertj.core.api.Assertions.assertThat;
+
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.querybuilder.QueryBuilder;
+import java.net.InetSocketAddress;
import net.javacrumbs.shedlock.provider.cassandra.CassandraLockProvider.Configuration;
import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
import net.javacrumbs.shedlock.test.support.AbstractStorageBasedLockProviderIntegrationTest;
@@ -27,15 +31,9 @@
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
-import java.net.InetSocketAddress;
-
-import static com.datastax.oss.driver.api.core.CqlIdentifier.fromCql;
-import static net.javacrumbs.shedlock.core.ClockProvider.now;
-import static net.javacrumbs.shedlock.provider.cassandra.CassandraLockProvider.DEFAULT_TABLE;
-import static org.assertj.core.api.Assertions.assertThat;
-
/**
- * Integration test uses local instance of Cassandra running on localhost at port 9042 using keyspace shedlock and table lock
+ * Integration test uses local instance of Cassandra running on localhost at
+ * port 9042 using keyspace shedlock and table lock
*
* @see net.javacrumbs.shedlock.provider.cassandra.CassandraLockProvider
*/
@@ -46,20 +44,20 @@ public class CassandraLockProviderIntegrationTest extends AbstractStorageBasedLo
@Container
public static final MyCassandraContainer cassandra = new MyCassandraContainer()
- .withInitScript("shedlock.cql")
- .withEnv("CASSANDRA_DC", "local")
- .withEnv("CASSANDRA_ENDPOINT_SNITCH", "GossipingPropertyFileSnitch");
+ .withInitScript("shedlock.cql")
+ .withEnv("CASSANDRA_DC", "local")
+ .withEnv("CASSANDRA_ENDPOINT_SNITCH", "GossipingPropertyFileSnitch");
@BeforeAll
public static void startCassandra() {
- String containerIpAddress = cassandra.getContainerIpAddress();
+ String containerIpAddress = cassandra.getHost();
int containerPort = cassandra.getMappedPort(9042);
InetSocketAddress containerEndPoint = new InetSocketAddress(containerIpAddress, containerPort);
session = CqlSession.builder()
- .addContactPoint(containerEndPoint)
- .withLocalDatacenter("local")
- .build();
+ .addContactPoint(containerEndPoint)
+ .withLocalDatacenter("local")
+ .build();
}
@AfterEach
@@ -69,34 +67,34 @@ public void after() {
@Override
protected StorageBasedLockProvider getLockProvider() {
- return new CassandraLockProvider(
- Configuration.builder()
+ return new CassandraLockProvider(Configuration.builder()
.withCqlSession(session)
.withKeyspace(KEYSPACE)
- .build()
- );
+ .build());
}
@Override
protected void assertUnlocked(String lockName) {
Lock lock = findLock(lockName);
- assertThat(lock.getLockUntil()).isBefore(now());
- assertThat(lock.getLockedAt()).isBefore(now());
- assertThat(lock.getLockedBy()).isNotEmpty();
+ assertThat(lock.lockUntil()).isBefore(now());
+ assertThat(lock.lockedAt()).isBefore(now());
+ assertThat(lock.lockedBy()).isNotEmpty();
}
@Override
protected void assertLocked(String lockName) {
Lock lock = findLock(lockName);
- assertThat(lock.getLockUntil()).isAfter(now());
- assertThat(lock.getLockedAt()).isBefore(now());
- assertThat(lock.getLockedBy()).isNotEmpty();
+ assertThat(lock.lockUntil()).isAfter(now());
+ assertThat(lock.lockedAt()).isBefore(now());
+ assertThat(lock.lockedBy()).isNotEmpty();
}
private Lock findLock(String lockName) {
- CassandraStorageAccessor cassandraStorageAccessor = new CassandraStorageAccessor(
- Configuration.builder().withCqlSession(session).withKeyspace(KEYSPACE).withTableName(DEFAULT_TABLE).build()
- );
+ CassandraStorageAccessor cassandraStorageAccessor = new CassandraStorageAccessor(Configuration.builder()
+ .withCqlSession(session)
+ .withKeyspace(KEYSPACE)
+ .withTableName(DEFAULT_TABLE)
+ .build());
return cassandraStorageAccessor.find(lockName).get();
}
diff --git a/providers/consul/shedlock-provider-consul/pom.xml b/providers/consul/shedlock-provider-consul/pom.xml
index 1d56ce40c..ef431cbfb 100644
--- a/providers/consul/shedlock-provider-consul/pom.xml
+++ b/providers/consul/shedlock-provider-consul/pom.xml
@@ -3,13 +3,13 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.consul;
+import static java.util.Objects.requireNonNull;
+import static net.javacrumbs.shedlock.core.ClockProvider.now;
+
import com.ecwid.consul.v1.ConsulClient;
import com.ecwid.consul.v1.QueryParams;
import com.ecwid.consul.v1.kv.model.PutParams;
import com.ecwid.consul.v1.session.model.NewSession;
import com.ecwid.consul.v1.session.model.Session;
-import net.javacrumbs.shedlock.core.LockConfiguration;
-import net.javacrumbs.shedlock.core.LockProvider;
-import net.javacrumbs.shedlock.core.SimpleLock;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.time.Duration;
import java.util.Optional;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-
-import static java.util.Objects.requireNonNull;
-import static net.javacrumbs.shedlock.core.ClockProvider.now;
+import net.javacrumbs.shedlock.core.LockConfiguration;
+import net.javacrumbs.shedlock.core.LockProvider;
+import net.javacrumbs.shedlock.core.SimpleLock;
+import net.javacrumbs.shedlock.support.annotation.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
- * This lock provider registers a new session for lock and on unlock this session is removed together with all associated locks. The main point you need to be aware about is that consul holds session for up to twice TTL. That means,
- * even if the session TTL is set to 10 seconds, consul will hold still this session for 20 seconds.
- * This is an expected behaviour and it's impossible to change it.
- * This is the reason consul recommends to set the lowest possible TTL
- * and constantly extend it. With this lock it means that even if your lockAtMostFor is less that 20 seconds, the timeout will be
- * higher than 10 seconds and most likely will be 20.
+ * The main point you need to be aware about is that consul holds session for up
+ * to twice TTL. That means, even if the session TTL is set to 10 seconds,
+ * consul will hold still this session for 20 seconds. This is an
+ * expected
+ * behaviour and it's impossible to change it. This is the reason consul
+ * recommends to set
+ * the lowest possible TTL and constantly extend it. With this lock it means
+ * that even if your lockAtMostFor is less that 20 seconds, the timeout will be
+ * higher than 10 seconds and most likely will be 20.
*
- * The lock is acquired for the time specified in {@code @SchedulerLock.lockAtMostFor}. Please note that this lock provider
- * doesn't make any correction to the aforementioned TTL behaviour so most likely your locked session will live for
- * longer than specified in lockAtMostFor. In this lock provider there is no session renewal done in the background.
+ * The lock is acquired for the time specified in
+ * {@code @SchedulerLock.lockAtMostFor}. Please note that this lock provider
+ * doesn't make any correction to the aforementioned TTL behaviour so most
+ * likely your locked session will live for longer than specified in
+ * lockAtMostFor. In this lock provider there is no session renewal done in the
+ * background.
*
* @author Artur Kalimullin
*/
@@ -63,42 +69,36 @@ public class ConsulLockProvider implements LockProvider, AutoCloseable {
private final Configuration configuration;
- public ConsulLockProvider(@NonNull ConsulClient consulClient) {
- this(Configuration.builder()
- .withConsulClient(consulClient)
- .build()
- );
+ public ConsulLockProvider(ConsulClient consulClient) {
+ this(Configuration.builder().withConsulClient(consulClient).build());
}
- public ConsulLockProvider(@NonNull ConsulClient consulClient, Duration minSessionTtl) {
+ public ConsulLockProvider(ConsulClient consulClient, Duration minSessionTtl) {
this(Configuration.builder()
- .withConsulClient(consulClient)
- .withMinSessionTtl(minSessionTtl)
- .build()
- );
+ .withConsulClient(consulClient)
+ .withMinSessionTtl(minSessionTtl)
+ .build());
}
public ConsulLockProvider(
- @NonNull ConsulClient consulClient,
- Duration minSessionTtl,
- String consulLockPostfix,
- Duration gracefulShutdownInterval) {
+ ConsulClient consulClient,
+ Duration minSessionTtl,
+ String consulLockPostfix,
+ Duration gracefulShutdownInterval) {
this(Configuration.builder()
- .withConsulClient(consulClient)
- .withMinSessionTtl(minSessionTtl)
- .withConsulLockPostfix(consulLockPostfix)
- .withGracefulShutdownInterval(gracefulShutdownInterval)
- .build()
- );
+ .withConsulClient(consulClient)
+ .withMinSessionTtl(minSessionTtl)
+ .withConsulLockPostfix(consulLockPostfix)
+ .withGracefulShutdownInterval(gracefulShutdownInterval)
+ .build());
}
- public ConsulLockProvider(@NonNull Configuration configuration) {
+ public ConsulLockProvider(Configuration configuration) {
this.configuration = configuration;
}
@Override
- @NonNull
- public Optional Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.consul;
@@ -22,9 +20,8 @@ class ConsulSimpleLock extends AbstractSimpleLock {
private final ConsulLockProvider consulLockProvider;
private final String sessionId;
- public ConsulSimpleLock(LockConfiguration lockConfiguration,
- ConsulLockProvider consulLockProvider,
- String sessionId) {
+ public ConsulSimpleLock(
+ LockConfiguration lockConfiguration, ConsulLockProvider consulLockProvider, String sessionId) {
super(lockConfiguration);
this.consulLockProvider = consulLockProvider;
this.sessionId = sessionId;
diff --git a/providers/consul/shedlock-provider-consul/src/main/java/net/javacrumbs/shedlock/provider/consul/package-info.java b/providers/consul/shedlock-provider-consul/src/main/java/net/javacrumbs/shedlock/provider/consul/package-info.java
new file mode 100644
index 000000000..71ee0b922
--- /dev/null
+++ b/providers/consul/shedlock-provider-consul/src/main/java/net/javacrumbs/shedlock/provider/consul/package-info.java
@@ -0,0 +1,6 @@
+@NonNullApi
+@NonNullFields
+package net.javacrumbs.shedlock.provider.consul;
+
+import net.javacrumbs.shedlock.support.annotation.NonNullApi;
+import net.javacrumbs.shedlock.support.annotation.NonNullFields;
diff --git a/providers/consul/shedlock-provider-consul/src/test/java/net/javacrumbs/shedlock/provider/consul/ConsulLockProviderIntegrationTest.java b/providers/consul/shedlock-provider-consul/src/test/java/net/javacrumbs/shedlock/provider/consul/ConsulLockProviderIntegrationTest.java
index 45508db86..79d04f5d7 100644
--- a/providers/consul/shedlock-provider-consul/src/test/java/net/javacrumbs/shedlock/provider/consul/ConsulLockProviderIntegrationTest.java
+++ b/providers/consul/shedlock-provider-consul/src/test/java/net/javacrumbs/shedlock/provider/consul/ConsulLockProviderIntegrationTest.java
@@ -1,25 +1,29 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.consul;
+import static java.lang.Thread.sleep;
+import static org.assertj.core.api.Assertions.assertThat;
+
import com.ecwid.consul.v1.ConsulClient;
import com.ecwid.consul.v1.QueryParams;
import com.ecwid.consul.v1.Response;
import com.ecwid.consul.v1.kv.model.GetValue;
import com.ecwid.consul.v1.session.model.Session;
+import java.time.Duration;
+import java.util.List;
+import java.util.Optional;
import net.javacrumbs.shedlock.core.LockConfiguration;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.core.SimpleLock;
@@ -32,13 +36,6 @@
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
-import java.time.Duration;
-import java.util.List;
-import java.util.Optional;
-
-import static java.lang.Thread.sleep;
-import static org.assertj.core.api.Assertions.assertThat;
-
@Testcontainers
class ConsulLockProviderIntegrationTest extends AbstractLockProviderIntegrationTest {
@@ -56,16 +53,15 @@ public static void startConsul() {
public void checkSessions() {
Response http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.consul;
-import com.ecwid.consul.v1.ConsulClient;
-import com.ecwid.consul.v1.QueryParams;
-import com.ecwid.consul.v1.Response;
-import com.ecwid.consul.v1.kv.model.PutParams;
-import net.javacrumbs.shedlock.core.ClockProvider;
-import net.javacrumbs.shedlock.core.LockConfiguration;
-import net.javacrumbs.shedlock.core.SimpleLock;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import java.time.Duration;
-import java.util.Optional;
-import java.util.UUID;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.anyString;
@@ -39,15 +23,31 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import com.ecwid.consul.v1.ConsulClient;
+import com.ecwid.consul.v1.QueryParams;
+import com.ecwid.consul.v1.Response;
+import com.ecwid.consul.v1.kv.model.PutParams;
+import java.time.Duration;
+import java.util.Optional;
+import java.util.UUID;
+import net.javacrumbs.shedlock.core.ClockProvider;
+import net.javacrumbs.shedlock.core.LockConfiguration;
+import net.javacrumbs.shedlock.core.SimpleLock;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
class ConsulLockProviderTest {
- // lower values may produce false negatives because scheduler may not complete necessary tasks in time
+ // lower values may produce false negatives because scheduler may not complete
+ // necessary tasks in
+ // time
private static final Duration SMALL_MIN_TTL = Duration.ofMillis(200);
private final ConsulClient mockConsulClient = mock(ConsulClient.class);
private final ConsulLockProvider lockProvider = new ConsulLockProvider(mockConsulClient, SMALL_MIN_TTL);
@BeforeEach
void setUp() {
- when(mockConsulClient.sessionCreate(any(), any(), any())).thenReturn(new Response<>(UUID.randomUUID().toString(), null, null, null));
+ when(mockConsulClient.sessionCreate(any(), any(), any()))
+ .thenReturn(new Response<>(UUID.randomUUID().toString(), null, null, null));
mockLock(any(), true);
}
@@ -90,15 +90,18 @@ void destroysSessionIfLockIsAlreadyObtained() {
@Test
void doesNotBlockSchedulerInCaseOfFailure() {
when(mockConsulClient.sessionDestroy(any(), any(), any()))
- .thenThrow(new RuntimeException("Sasuke is not in Konoha, Naruto alone is unable to destroy session :("))
- .thenReturn(new Response<>(null, null, null, null));
+ .thenThrow(
+ new RuntimeException("Sasuke is not in Konoha, Naruto alone is unable to destroy session :("))
+ .thenReturn(new Response<>(null, null, null, null));
- Optional Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.couchbase.javaclient3;
+import static net.javacrumbs.shedlock.support.Utils.toIsoString;
+
import com.couchbase.client.core.error.CasMismatchException;
import com.couchbase.client.core.error.DocumentExistsException;
import com.couchbase.client.java.Bucket;
@@ -22,20 +22,18 @@
import com.couchbase.client.java.json.JsonObject;
import com.couchbase.client.java.kv.GetResult;
import com.couchbase.client.java.kv.ReplaceOptions;
+import java.time.Instant;
import net.javacrumbs.shedlock.core.ClockProvider;
import net.javacrumbs.shedlock.core.LockConfiguration;
import net.javacrumbs.shedlock.support.AbstractStorageAccessor;
import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
-
-import java.time.Instant;
-
-import static net.javacrumbs.shedlock.support.Utils.toIsoString;
/**
* Distributed lock using CouchbaseDB
+ *
*
* It uses a collection that contains documents like this:
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.couchbase.javaclient3;
+import static java.time.Instant.parse;
+import static net.javacrumbs.shedlock.core.ClockProvider.now;
+import static net.javacrumbs.shedlock.provider.couchbase.javaclient3.CouchbaseLockProvider.LOCKED_AT;
+import static net.javacrumbs.shedlock.provider.couchbase.javaclient3.CouchbaseLockProvider.LOCKED_BY;
+import static net.javacrumbs.shedlock.provider.couchbase.javaclient3.CouchbaseLockProvider.LOCK_UNTIL;
+import static org.assertj.core.api.Assertions.assertThat;
+
import com.couchbase.client.core.env.SeedNode;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
@@ -22,6 +27,11 @@
import com.couchbase.client.java.Collection;
import com.couchbase.client.java.json.JsonObject;
import com.couchbase.client.java.kv.GetResult;
+import java.time.Duration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
import net.javacrumbs.shedlock.test.support.AbstractStorageBasedLockProviderIntegrationTest;
import org.junit.jupiter.api.AfterAll;
@@ -31,20 +41,6 @@
import org.testcontainers.couchbase.BucketDefinition;
import org.testcontainers.couchbase.CouchbaseContainer;
-import java.time.Duration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-
-import static java.time.Instant.parse;
-import static java.util.Collections.singletonList;
-import static net.javacrumbs.shedlock.core.ClockProvider.now;
-import static net.javacrumbs.shedlock.provider.couchbase.javaclient3.CouchbaseLockProvider.LOCKED_AT;
-import static net.javacrumbs.shedlock.provider.couchbase.javaclient3.CouchbaseLockProvider.LOCKED_BY;
-import static net.javacrumbs.shedlock.provider.couchbase.javaclient3.CouchbaseLockProvider.LOCK_UNTIL;
-import static org.assertj.core.api.Assertions.assertThat;
-
public class CouchbaseLockProviderIntegrationTest extends AbstractStorageBasedLockProviderIntegrationTest {
private static final String BUCKET_NAME = "test";
@@ -56,12 +52,12 @@ public class CouchbaseLockProviderIntegrationTest extends AbstractStorageBasedLo
private static CouchbaseContainer container;
@BeforeAll
- public static void startCouchbase () {
+ public static void startCouchbase() {
container = new CouchbaseContainer().withBucket(new BucketDefinition(BUCKET_NAME));
container.start();
- Set Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.dynamodb2;
+import static java.util.Collections.singletonMap;
+import static java.util.Objects.requireNonNull;
+import static net.javacrumbs.shedlock.core.ClockProvider.now;
+import static net.javacrumbs.shedlock.support.Utils.toIsoString;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
import net.javacrumbs.shedlock.core.AbstractSimpleLock;
-import net.javacrumbs.shedlock.core.ClockProvider;
import net.javacrumbs.shedlock.core.LockConfiguration;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.core.SimpleLock;
import net.javacrumbs.shedlock.support.Utils;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
+import net.javacrumbs.shedlock.support.annotation.Nullable;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
import software.amazon.awssdk.services.dynamodb.model.ConditionalCheckFailedException;
import software.amazon.awssdk.services.dynamodb.model.ReturnValue;
import software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest;
-
-import java.time.Instant;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-
-import static java.util.Collections.singletonMap;
-import static java.util.Objects.requireNonNull;
-import static net.javacrumbs.shedlock.support.Utils.toIsoString;
+import software.amazon.awssdk.utils.StringUtils;
/**
- * Distributed lock using DynamoDB.
- * Depends on
* It uses a table with the following structure:
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.dynamodb2;
+import static net.javacrumbs.shedlock.provider.dynamodb2.DynamoDBLockProvider.ID;
+
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition;
import software.amazon.awssdk.services.dynamodb.model.CreateTableRequest;
@@ -24,38 +24,58 @@
import software.amazon.awssdk.services.dynamodb.model.ResourceInUseException;
import software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType;
-import static net.javacrumbs.shedlock.provider.dynamodb2.DynamoDBLockProvider.ID;
-
public class DynamoDBUtils {
/**
* Creates a locking table with the given name.
+ *
*
* This method does not check if a table with the given name exists already.
*
- * @param ddbClient v2 of DynamoDBClient
- * @param tableName table to be used
- * @param throughput AWS {@link ProvisionedThroughput throughput requirements} for the given lock setup
- * @return the table name
+ * @param ddbClient
+ * v2 of DynamoDBClient
+ * @param tableName
+ * table to be used
+ * @param throughput
+ * AWS {@link ProvisionedThroughput throughput requirements} for the
+ * given lock setup
+ * @return the table name
+ * @throws ResourceInUseException
+ * The operation conflicts with the resource's availability. You
+ * attempted to recreate an existing table.
+ */
+ public static String createLockTable(DynamoDbClient ddbClient, String tableName, ProvisionedThroughput throughput) {
+ return createLockTable(ddbClient, tableName, throughput, ID);
+ }
+ /**
+ * Creates a locking table with the given name.
+ *
+ *
+ * This method does not check if a table with the given name exists already.
*
+ * @param ddbClient
+ * v2 of DynamoDBClient
+ * @param tableName
+ * table to be used
+ * @param throughput
+ * AWS {@link ProvisionedThroughput throughput requirements} for the
+ * given lock setup
+ * @return the table name
* @throws ResourceInUseException
- * The operation conflicts with the resource's availability. You attempted to recreate an
- * existing table.
+ * The operation conflicts with the resource's availability. You
+ * attempted to recreate an existing table.
*/
public static String createLockTable(
- DynamoDbClient ddbClient,
- String tableName,
- ProvisionedThroughput throughput
- ) {
+ DynamoDbClient ddbClient, String tableName, ProvisionedThroughput throughput, String partitionKeyName) {
CreateTableRequest request = CreateTableRequest.builder()
.tableName(tableName)
.keySchema(KeySchemaElement.builder()
- .attributeName(ID)
+ .attributeName(partitionKeyName)
.keyType(KeyType.HASH)
.build())
.attributeDefinitions(AttributeDefinition.builder()
- .attributeName(ID)
+ .attributeName(partitionKeyName)
.attributeType(ScalarAttributeType.S)
.build())
.provisionedThroughput(throughput)
diff --git a/providers/dynamodb/shedlock-provider-dynamodb2/src/main/java/net/javacrumbs/shedlock/provider/dynamodb2/package-info.java b/providers/dynamodb/shedlock-provider-dynamodb2/src/main/java/net/javacrumbs/shedlock/provider/dynamodb2/package-info.java
new file mode 100644
index 000000000..4acf303e1
--- /dev/null
+++ b/providers/dynamodb/shedlock-provider-dynamodb2/src/main/java/net/javacrumbs/shedlock/provider/dynamodb2/package-info.java
@@ -0,0 +1,6 @@
+@NonNullApi
+@NonNullFields
+package net.javacrumbs.shedlock.provider.dynamodb2;
+
+import net.javacrumbs.shedlock.support.annotation.NonNullApi;
+import net.javacrumbs.shedlock.support.annotation.NonNullFields;
diff --git a/providers/dynamodb/shedlock-provider-dynamodb2/src/test/java/net/javacrumbs/shedlock/provider/dynamodb2/AbstractDynamoDBLockProviderIntegrationTest.java b/providers/dynamodb/shedlock-provider-dynamodb2/src/test/java/net/javacrumbs/shedlock/provider/dynamodb2/AbstractDynamoDBLockProviderIntegrationTest.java
new file mode 100644
index 000000000..3bef41dad
--- /dev/null
+++ b/providers/dynamodb/shedlock-provider-dynamodb2/src/test/java/net/javacrumbs/shedlock/provider/dynamodb2/AbstractDynamoDBLockProviderIntegrationTest.java
@@ -0,0 +1,103 @@
+/**
+ * Copyright 2009 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.javacrumbs.shedlock.provider.dynamodb2;
+
+import static java.time.Instant.now;
+import static net.javacrumbs.shedlock.provider.dynamodb2.DynamoDBLockProvider.LOCKED_AT;
+import static net.javacrumbs.shedlock.provider.dynamodb2.DynamoDBLockProvider.LOCKED_BY;
+import static net.javacrumbs.shedlock.provider.dynamodb2.DynamoDBLockProvider.LOCK_UNTIL;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.net.URI;
+import java.time.Instant;
+import java.util.Map;
+import net.javacrumbs.shedlock.test.support.AbstractLockProviderIntegrationTest;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
+import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
+import software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest;
+import software.amazon.awssdk.services.dynamodb.model.TableStatus;
+
+@Testcontainers
+public abstract class AbstractDynamoDBLockProviderIntegrationTest extends AbstractLockProviderIntegrationTest {
+ protected static final String ID = "_id2";
+
+ @Container
+ static final DynamoDbContainer dynamoDbContainer =
+ new DynamoDbContainer("amazon/dynamodb-local:2.6.1").withExposedPorts(8000);
+
+ protected static final String TABLE_NAME = "Shedlock";
+ protected static DynamoDbClient dynamodb;
+
+ protected static void waitForTableBeingActive() {
+ while (getTableStatus() != TableStatus.ACTIVE)
+ ;
+ }
+
+ private static TableStatus getTableStatus() {
+ return dynamodb.describeTable(
+ DescribeTableRequest.builder().tableName(TABLE_NAME).build())
+ .table()
+ .tableStatus();
+ }
+
+ /**
+ * Create a standard AWS v2 SDK client pointing to the local DynamoDb instance
+ *
+ * @return A DynamoDbClient pointing to the local DynamoDb instance
+ */
+ protected static DynamoDbClient createClient() {
+ String endpoint = "http://" + dynamoDbContainer.getHost() + ":" + dynamoDbContainer.getFirstMappedPort();
+ return DynamoDbClient.builder()
+ .endpointOverride(URI.create(endpoint))
+ // The region is meaningless for local DynamoDb but required for client builder
+ // validation
+ .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("dummy", "dummy")))
+ .region(Region.US_EAST_1)
+ .build();
+ }
+
+ @Override
+ protected void assertUnlocked(String lockName) {
+ Map Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.dynamodb2;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
import net.javacrumbs.shedlock.core.LockProvider;
-import net.javacrumbs.shedlock.test.support.AbstractLockProviderIntegrationTest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
-import org.testcontainers.containers.GenericContainer;
-import org.testcontainers.junit.jupiter.Container;
-import org.testcontainers.junit.jupiter.Testcontainers;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
import software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest;
-import software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest;
import software.amazon.awssdk.services.dynamodb.model.GetItemRequest;
-import software.amazon.awssdk.services.dynamodb.model.GetItemResponse;
import software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughput;
import software.amazon.awssdk.services.dynamodb.model.ScanRequest;
-import software.amazon.awssdk.services.dynamodb.model.TableStatus;
-
-import java.net.URI;
-import java.time.Instant;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import static net.javacrumbs.shedlock.provider.dynamodb2.DynamoDBLockProvider.ID;
-import static net.javacrumbs.shedlock.provider.dynamodb2.DynamoDBLockProvider.LOCKED_AT;
-import static net.javacrumbs.shedlock.provider.dynamodb2.DynamoDBLockProvider.LOCKED_BY;
-import static net.javacrumbs.shedlock.provider.dynamodb2.DynamoDBLockProvider.LOCK_UNTIL;
-import static org.assertj.core.api.Assertions.assertThat;
-
-@Testcontainers
-public class DynamoDBLockProviderIntegrationTest extends AbstractLockProviderIntegrationTest {
- @Container
- public static final DynamoDbContainer dynamoDbContainer =
- new DynamoDbContainer("quay.io/testcontainers/dynalite:v1.2.1-1")
- .withExposedPorts(4567);
-
-
- private static final String TABLE_NAME = "Shedlock";
- private static DynamoDbClient dynamodb;
+public class DynamoDBLockProviderIntegrationTest extends AbstractDynamoDBLockProviderIntegrationTest {
+ private static final String ID = "_id2";
@BeforeAll
- static void createLockProvider() {
+ static void createLockTable() {
dynamodb = createClient();
- String lockTable = DynamoDBUtils.createLockTable(
- dynamodb,
- TABLE_NAME,
- ProvisionedThroughput.builder()
- .readCapacityUnits(1L)
- .writeCapacityUnits(1L)
- .build()
- );
- while (getTableStatus(lockTable) != TableStatus.ACTIVE) ;
- }
-
- private static TableStatus getTableStatus(String lockTable) {
- return dynamodb.describeTable(DescribeTableRequest.builder().tableName(lockTable).build()).table().tableStatus();
- }
-
- /**
- * Create a standard AWS v2 SDK client pointing to the local DynamoDb instance
- *
- * @return A DynamoDbClient pointing to the local DynamoDb instance
- */
- static DynamoDbClient createClient() {
- String endpoint = "http://" + dynamoDbContainer.getContainerIpAddress() + ":" + dynamoDbContainer.getFirstMappedPort();
- return DynamoDbClient.builder()
- .endpointOverride(URI.create(endpoint))
- // The region is meaningless for local DynamoDb but required for client builder validation
- .region(Region.US_EAST_1)
- .credentialsProvider(StaticCredentialsProvider.create(
- AwsBasicCredentials.create("dummy-key", "dummy-secret"))
- )
- .build();
+ DynamoDBUtils.createLockTable(
+ dynamodb,
+ TABLE_NAME,
+ ProvisionedThroughput.builder()
+ .readCapacityUnits(1L)
+ .writeCapacityUnits(1L)
+ .build(),
+ ID);
+ waitForTableBeingActive();
}
@AfterEach
public void truncateLockTable() {
- List
+ * Arango Lock Provider needs existing collection
* Example creating a collection through init scripts (javascript)
+ *
*
* db._useDatabase("DB_NAME");
* db._create("COLLECTION_NAME");
@@ -60,53 +56,59 @@ public class ArangoLockProvider implements LockProvider {
/**
* Instantiates a new Arango lock provider.
*
- * @param arangoDatabase the arango database
+ * @param arangoDatabase
+ * the arango database
*/
- public ArangoLockProvider(@NonNull ArangoDatabase arangoDatabase) {
+ public ArangoLockProvider(ArangoDatabase arangoDatabase) {
this(arangoDatabase.collection(COLLECTION_NAME));
}
/**
* Instantiates a new Arango lock provider.
*
- * @param arangoCollection the arango collection
+ * @param arangoCollection
+ * the arango collection
*/
- public ArangoLockProvider(@NonNull ArangoCollection arangoCollection) {
+ public ArangoLockProvider(ArangoCollection arangoCollection) {
this.arangoCollection = arangoCollection;
}
@Override
- @NonNull
- public Optional
@@ -35,42 +33,50 @@
public class CassandraLockProvider extends StorageBasedLockProvider {
static final String DEFAULT_TABLE = "lock";
- public CassandraLockProvider(@NonNull CqlSession cqlSession) {
+ public CassandraLockProvider(CqlSession cqlSession) {
this(cqlSession, DEFAULT_TABLE, ConsistencyLevel.QUORUM);
}
- public CassandraLockProvider(@NonNull CqlSession cqlSession, @NonNull String table, @NonNull ConsistencyLevel consistencyLevel) {
- this(Configuration.builder().withCqlSession(cqlSession).withTableName(table).withConsistencyLevel(consistencyLevel).build());
+ public CassandraLockProvider(CqlSession cqlSession, String table, ConsistencyLevel consistencyLevel) {
+ this(Configuration.builder()
+ .withCqlSession(cqlSession)
+ .withTableName(table)
+ .withConsistencyLevel(consistencyLevel)
+ .build());
}
- public CassandraLockProvider(@NonNull Configuration configuration) {
+ public CassandraLockProvider(Configuration configuration) {
super(new CassandraStorageAccessor(configuration));
}
- /**
- * Convenience class to specify configuration
- */
+ /** Convenience class to specify configuration */
public static final class Configuration {
private final CqlIdentifier table;
private final ColumnNames columnNames;
private final CqlSession cqlSession;
+
+ @Nullable
private final ConsistencyLevel consistencyLevel;
+
+ @Nullable
private final ConsistencyLevel serialConsistencyLevel;
+
+ @Nullable
private final CqlIdentifier keyspace;
Configuration(
- @NonNull CqlSession cqlSession,
- @NonNull CqlIdentifier table,
- @NonNull ColumnNames columnNames,
- @NonNull ConsistencyLevel consistencyLevel,
- @NonNull ConsistencyLevel serialConsistencyLevel,
- CqlIdentifier keyspace
- ) {
+ CqlSession cqlSession,
+ CqlIdentifier table,
+ ColumnNames columnNames,
+ @Nullable ConsistencyLevel consistencyLevel,
+ @Nullable ConsistencyLevel serialConsistencyLevel,
+ @Nullable CqlIdentifier keyspace) {
this.table = requireNonNull(table, "table can not be null");
this.columnNames = requireNonNull(columnNames, "columnNames can not be null");
this.cqlSession = requireNonNull(cqlSession, "cqlSession can not be null");
this.consistencyLevel = requireNonNull(consistencyLevel, "consistencyLevel can not be null");
- this.serialConsistencyLevel = requireNonNull(serialConsistencyLevel, "serialConsistencyLevel can not be null");
+ this.serialConsistencyLevel =
+ requireNonNull(serialConsistencyLevel, "serialConsistencyLevel can not be null");
this.keyspace = keyspace;
}
@@ -86,14 +92,17 @@ public CqlSession getCqlSession() {
return cqlSession;
}
+ @Nullable
public ConsistencyLevel getConsistencyLevel() {
return consistencyLevel;
}
+ @Nullable
public ConsistencyLevel getSerialConsistencyLevel() {
return serialConsistencyLevel;
}
+ @Nullable
public CqlIdentifier getKeyspace() {
return keyspace;
}
@@ -102,22 +111,26 @@ public static Configuration.Builder builder() {
return new Configuration.Builder();
}
- /**
- * Convenience builder class to build Configuration
- */
+ /** Convenience builder class to build Configuration */
public static final class Builder {
private CqlIdentifier table = CqlIdentifier.fromCql(DEFAULT_TABLE);
private ColumnNames columnNames = new ColumnNames("name", "lockUntil", "lockedAt", "lockedBy");
private CqlSession cqlSession;
+
+ @Nullable
private ConsistencyLevel consistencyLevel = ConsistencyLevel.QUORUM;
+
+ @Nullable
private ConsistencyLevel serialConsistencyLevel = ConsistencyLevel.SERIAL;
+
+ @Nullable
private CqlIdentifier keyspace;
- public Builder withTableName(@NonNull String table) {
+ public Builder withTableName(String table) {
return withTableName(CqlIdentifier.fromCql(table));
}
- public Builder withTableName(@NonNull CqlIdentifier table) {
+ public Builder withTableName(CqlIdentifier table) {
this.table = table;
return this;
}
@@ -127,41 +140,40 @@ public Builder withColumnNames(ColumnNames columnNames) {
return this;
}
- public Builder withCqlSession(@NonNull CqlSession cqlSession) {
+ public Builder withCqlSession(CqlSession cqlSession) {
this.cqlSession = cqlSession;
return this;
}
- public Builder withConsistencyLevel(@NonNull ConsistencyLevel consistencyLevel) {
+ public Builder withConsistencyLevel(ConsistencyLevel consistencyLevel) {
this.consistencyLevel = consistencyLevel;
return this;
}
/**
- * Since Shedlock internally uses CAS (Compare And Set) operations
- * This configuration helps to have a granular control on the CAS consistency.
+ * Since Shedlock internally uses CAS (Compare And Set) operations This
+ * configuration helps to have a granular control on the CAS consistency.
+ *
* @return Builder
*/
-
- public Builder withSerialConsistencyLevel(@NonNull ConsistencyLevel serialConsistencyLevel) {
+ public Builder withSerialConsistencyLevel(ConsistencyLevel serialConsistencyLevel) {
this.serialConsistencyLevel = serialConsistencyLevel;
return this;
}
- public Builder withKeyspace(@NonNull CqlIdentifier keyspace) {
+ public Builder withKeyspace(CqlIdentifier keyspace) {
this.keyspace = keyspace;
return this;
}
public CassandraLockProvider.Configuration build() {
- return new CassandraLockProvider.Configuration(cqlSession, table, columnNames, consistencyLevel, serialConsistencyLevel, keyspace);
+ return new CassandraLockProvider.Configuration(
+ cqlSession, table, columnNames, consistencyLevel, serialConsistencyLevel, keyspace);
}
}
}
- /**
- * Convenience class to specify column names
- */
+ /** Convenience class to specify column names */
public static final class ColumnNames {
private final String lockName;
private final String lockUntil;
@@ -169,7 +181,8 @@ public static final class ColumnNames {
private final String lockedBy;
/**
- * Each column names are optional and if not specified the default column name would be considered.
+ * Each column names are optional and if not specified the default column name
+ * would be considered.
*/
public ColumnNames(String lockName, String lockUntil, String lockedAt, String lockedBy) {
this.lockName = requireNonNull(lockName, "'lockName' column name can not be null");
diff --git a/providers/cassandra/shedlock-provider-cassandra/src/main/java/net/javacrumbs/shedlock/provider/cassandra/CassandraStorageAccessor.java b/providers/cassandra/shedlock-provider-cassandra/src/main/java/net/javacrumbs/shedlock/provider/cassandra/CassandraStorageAccessor.java
index 006af888f..ff95f316d 100644
--- a/providers/cassandra/shedlock-provider-cassandra/src/main/java/net/javacrumbs/shedlock/provider/cassandra/CassandraStorageAccessor.java
+++ b/providers/cassandra/shedlock-provider-cassandra/src/main/java/net/javacrumbs/shedlock/provider/cassandra/CassandraStorageAccessor.java
@@ -1,20 +1,21 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * > sessionListResponse = consulClient.getSessionList(QueryParams.DEFAULT);
assertThat(sessionListResponse.getValue())
- .as("There should no sessions remain in consul after all locks have been released.")
- .isEmpty();
+ .as("There should no sessions remain in consul after all locks have been released.")
+ .isEmpty();
}
@Override
protected LockProvider getLockProvider() {
- return new ConsulLockProvider(
- ConsulLockProvider.Configuration.builder()
- .withConsulClient(consulClient).build()
- );
+ return new ConsulLockProvider(ConsulLockProvider.Configuration.builder()
+ .withConsulClient(consulClient)
+ .build());
}
@Override
@@ -87,7 +83,9 @@ private GetValue getLockValue(String lockName) {
@Test
@Override
public void shouldTimeout() throws InterruptedException {
- // as consul has 10 seconds ttl minimum and has double ttl unlocking time, you have to wait for 20 seconds for the unlock time.
+ // as consul has 10 seconds ttl minimum and has double ttl unlocking time, you
+ // have to wait for
+ // 20 seconds for the unlock time.
Duration lockAtMostFor = Duration.ofSeconds(11);
LockConfiguration configWithShortTimeout = lockConfig(LOCK_NAME1, lockAtMostFor, Duration.ZERO);
Optional
* {
* "_id" : "lock name",
@@ -45,24 +43,21 @@
* }
*
*
- * lockedAt and lockedBy are just for troubleshooting and are not read by the code
+ * lockedAt and lockedBy are just for troubleshooting and are not read by the
+ * code
*
*
- *
*/
public class CouchbaseLockProvider extends StorageBasedLockProvider {
@@ -92,12 +87,12 @@ private static class CouchbaseAccessor extends AbstractStorageAccessor {
}
@Override
- public boolean insertRecord(@NonNull LockConfiguration lockConfiguration) {
+ public boolean insertRecord(LockConfiguration lockConfiguration) {
JsonObject content = JsonObject.create()
- .put(LOCK_NAME, lockConfiguration.getName())
- .put(LOCK_UNTIL, toIsoString(lockConfiguration.getLockAtMostUntil()))
- .put(LOCKED_AT, toIsoString(ClockProvider.now()))
- .put(LOCKED_BY, getHostname());
+ .put(LOCK_NAME, lockConfiguration.getName())
+ .put(LOCK_UNTIL, toIsoString(lockConfiguration.getLockAtMostUntil()))
+ .put(LOCKED_AT, toIsoString(ClockProvider.now()))
+ .put(LOCKED_BY, getHostname());
try {
collection.insert(lockConfiguration.getName(), content);
@@ -112,7 +107,7 @@ private Instant parse(Object instant) {
}
@Override
- public boolean updateRecord(@NonNull LockConfiguration lockConfiguration) {
+ public boolean updateRecord(LockConfiguration lockConfiguration) {
GetResult result = collection.get(lockConfiguration.getName());
JsonObject document = result.contentAsObject();
@@ -127,8 +122,10 @@ public boolean updateRecord(@NonNull LockConfiguration lockConfiguration) {
document.put(LOCKED_BY, getHostname());
try {
- collection.replace(lockConfiguration.getName(), document,
- ReplaceOptions.replaceOptions().cas(result.cas()));
+ collection.replace(
+ lockConfiguration.getName(),
+ document,
+ ReplaceOptions.replaceOptions().cas(result.cas()));
} catch (CasMismatchException e) {
return false;
}
@@ -136,7 +133,7 @@ public boolean updateRecord(@NonNull LockConfiguration lockConfiguration) {
}
@Override
- public boolean extend(@NonNull LockConfiguration lockConfiguration) {
+ public boolean extend(LockConfiguration lockConfiguration) {
GetResult result = collection.get(lockConfiguration.getName());
JsonObject document = result.contentAsObject();
@@ -149,8 +146,10 @@ public boolean extend(@NonNull LockConfiguration lockConfiguration) {
document.put(LOCK_UNTIL, toIsoString(lockConfiguration.getLockAtMostUntil()));
try {
- collection.replace(lockConfiguration.getName(), document,
- ReplaceOptions.replaceOptions().cas(result.cas()));
+ collection.replace(
+ lockConfiguration.getName(),
+ document,
+ ReplaceOptions.replaceOptions().cas(result.cas()));
} catch (CasMismatchException e) {
return false;
}
@@ -158,7 +157,7 @@ public boolean extend(@NonNull LockConfiguration lockConfiguration) {
}
@Override
- public void unlock(@NonNull LockConfiguration lockConfiguration) {
+ public void unlock(LockConfiguration lockConfiguration) {
GetResult result = collection.get(lockConfiguration.getName());
JsonObject document = result.contentAsObject();
@@ -166,6 +165,4 @@ public void unlock(@NonNull LockConfiguration lockConfiguration) {
collection.replace(lockConfiguration.getName(), document);
}
}
-
}
-
diff --git a/providers/couchbase/shedlock-provider-couchbase-javaclient3/src/main/java/net/javacrumbs/shedlock/provider/couchbase/javaclient3/package-info.java b/providers/couchbase/shedlock-provider-couchbase-javaclient3/src/main/java/net/javacrumbs/shedlock/provider/couchbase/javaclient3/package-info.java
new file mode 100644
index 000000000..a51222f0f
--- /dev/null
+++ b/providers/couchbase/shedlock-provider-couchbase-javaclient3/src/main/java/net/javacrumbs/shedlock/provider/couchbase/javaclient3/package-info.java
@@ -0,0 +1,6 @@
+@NonNullApi
+@NonNullFields
+package net.javacrumbs.shedlock.provider.couchbase.javaclient3;
+
+import net.javacrumbs.shedlock.support.annotation.NonNullApi;
+import net.javacrumbs.shedlock.support.annotation.NonNullFields;
diff --git a/providers/couchbase/shedlock-provider-couchbase-javaclient3/src/test/java/net/javacrumbs/shedlock/provider/couchbase/javaclient3/CouchbaseLockProviderIntegrationTest.java b/providers/couchbase/shedlock-provider-couchbase-javaclient3/src/test/java/net/javacrumbs/shedlock/provider/couchbase/javaclient3/CouchbaseLockProviderIntegrationTest.java
index 9a3f7333f..56ea605bc 100644
--- a/providers/couchbase/shedlock-provider-couchbase-javaclient3/src/test/java/net/javacrumbs/shedlock/provider/couchbase/javaclient3/CouchbaseLockProviderIntegrationTest.java
+++ b/providers/couchbase/shedlock-provider-couchbase-javaclient3/src/test/java/net/javacrumbs/shedlock/provider/couchbase/javaclient3/CouchbaseLockProviderIntegrationTest.java
@@ -1,20 +1,25 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * software.amazon.awssdk:dynamodb
.
+ * Distributed lock using DynamoDB. Depends on
+ * software.amazon.awssdk:dynamodb
.
+ *
*
* {
* "_id" : "lock name",
@@ -55,19 +54,14 @@
* and are not read by the code.
*
*
- *
*/
public class DynamoDBLockProvider implements LockProvider {
@@ -75,42 +69,71 @@ public class DynamoDBLockProvider implements LockProvider {
static final String LOCKED_AT = "lockedAt";
static final String LOCKED_BY = "lockedBy";
static final String ID = "_id";
+ static final String SORT = "_SortKey";
private static final String OBTAIN_LOCK_QUERY =
"set " + LOCK_UNTIL + " = :lockUntil, " + LOCKED_AT + " = :lockedAt, " + LOCKED_BY + " = :lockedBy";
private static final String OBTAIN_LOCK_CONDITION =
LOCK_UNTIL + " <= :lockedAt or attribute_not_exists(" + LOCK_UNTIL + ")";
- private static final String RELEASE_LOCK_QUERY =
- "set " + LOCK_UNTIL + " = :lockUntil";
+ private static final String RELEASE_LOCK_QUERY = "set " + LOCK_UNTIL + " = :lockUntil";
private final String hostname;
private final DynamoDbClient dynamoDbClient;
private final String tableName;
+ private final String partitionKeyName;
+
+ @Nullable
+ private final String sortKeyName;
/**
* Uses DynamoDB to coordinate locks
*
- * @param dynamoDbClient v2 of DynamoDB client
- * @param tableName the lock table name
+ * @param dynamoDbClient
+ * v2 of DynamoDB client
+ * @param tableName
+ * the lock table name
*/
- public DynamoDBLockProvider(@NonNull DynamoDbClient dynamoDbClient, @NonNull String tableName) {
+ public DynamoDBLockProvider(DynamoDbClient dynamoDbClient, String tableName) {
+ this(dynamoDbClient, tableName, ID);
+ }
+
+ /**
+ * Uses DynamoDB to coordinate locks
+ *
+ * @param dynamoDbClient v2 of DynamoDB client
+ * @param tableName the lock table name
+ * @param partitionKeyName the partitionKey name of table
+ */
+ public DynamoDBLockProvider(DynamoDbClient dynamoDbClient, String tableName, String partitionKeyName) {
+ this(dynamoDbClient, tableName, partitionKeyName, null);
+ }
+
+ /**
+ * Uses DynamoDB to coordinate locks
+ *
+ * @param dynamoDbClient v2 of DynamoDB client
+ * @param tableName the lock table name
+ * @param partitionKeyName the partitionKey name of table
+ * @param sortKeyName the sortKey name of table
+ */
+ public DynamoDBLockProvider(
+ DynamoDbClient dynamoDbClient, String tableName, String partitionKeyName, @Nullable String sortKeyName) {
this.dynamoDbClient = requireNonNull(dynamoDbClient, "dynamoDbClient can not be null");
this.tableName = requireNonNull(tableName, "tableName can not be null");
+ this.partitionKeyName = requireNonNull(partitionKeyName, "partitionKeyName can not be null");
+ this.sortKeyName = sortKeyName;
this.hostname = Utils.getHostname();
}
@Override
- @NonNull
- public Optionalfilter _id == :name AND lock_until <= :now
.
- * lock_until
is set to now or lockAtLeastUntil whichever is later.
- * filter _id == :name AND lock_until <= :now
+ *
.
+ * lock_until
is set to now or
+ * lockAtLeastUntil whichever is later.
*
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + *
http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and + *
Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package net.javacrumbs.shedlock.provider.ignite; +import static net.javacrumbs.shedlock.support.Utils.getHostname; + +import java.time.Instant; +import java.util.Optional; import net.javacrumbs.shedlock.core.AbstractSimpleLock; import net.javacrumbs.shedlock.core.ExtensibleLockProvider; import net.javacrumbs.shedlock.core.LockConfiguration; @@ -22,50 +24,39 @@ import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; -import java.time.Instant; -import java.util.Optional; - -import static net.javacrumbs.shedlock.support.Utils.getHostname; - /** * Distributed lock using Apache Ignite. + * *
* It uses a {@link String} key (lock name) and {@link LockValue} value. - *
* - *lockedAt and lockedBy are just for troubleshooting and are not read by the code.
+ *+ * lockedAt and lockedBy are just for troubleshooting and are not read by the + * code. Creating a lock: * - * Creating a lock: *
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + *
http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and + *
Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package net.javacrumbs.shedlock.provider.ignite; import java.time.Instant; -/** - * Value object for ShedLock cache. - */ +/** Value object for ShedLock cache. */ +// Don't convert to record, does not work class LockValue { /** Locked at time. */ private final Instant lockedAt; @@ -31,9 +28,12 @@ class LockValue { private final String lockedBy; /** - * @param lockedAt Locked at time. - * @param lockUntil Locked until time. - * @param lockedBy Locked by hostname. + * @param lockedAt + * Locked at time. + * @param lockUntil + * Locked until time. + * @param lockedBy + * Locked by hostname. */ public LockValue(Instant lockedAt, Instant lockUntil, String lockedBy) { this.lockedAt = lockedAt; diff --git a/providers/ignite/shedlock-provider-ignite/src/test/java/net/javacrumbs/shedlock/provider/ignite/IgniteLockProviderTest.java b/providers/ignite/shedlock-provider-ignite/src/test/java/net/javacrumbs/shedlock/provider/ignite/IgniteLockProviderTest.java index eca4f2fbf..f7486b667 100644 --- a/providers/ignite/shedlock-provider-ignite/src/test/java/net/javacrumbs/shedlock/provider/ignite/IgniteLockProviderTest.java +++ b/providers/ignite/shedlock-provider-ignite/src/test/java/net/javacrumbs/shedlock/provider/ignite/IgniteLockProviderTest.java @@ -1,20 +1,22 @@ /** * Copyright 2009 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + *
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + *
http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and + *
Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.ignite;
+import static net.javacrumbs.shedlock.provider.ignite.IgniteLockProvider.DEFAULT_SHEDLOCK_CACHE_NAME;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.Instant;
import net.javacrumbs.shedlock.core.ExtensibleLockProvider;
import net.javacrumbs.shedlock.test.support.AbstractExtensibleLockProviderIntegrationTest;
import org.apache.ignite.Ignite;
@@ -24,14 +26,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
-import java.time.Instant;
-
-import static net.javacrumbs.shedlock.provider.ignite.IgniteLockProvider.DEFAULT_SHEDLOCK_CACHE_NAME;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Test for {@link IgniteLockProvider}.
- */
+/** Test for {@link IgniteLockProvider}. */
public class IgniteLockProviderTest extends AbstractExtensibleLockProviderIntegrationTest {
private static Ignite ignite;
private static IgniteCache Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbc.internal;
-import net.javacrumbs.shedlock.core.ClockProvider;
-import net.javacrumbs.shedlock.core.LockConfiguration;
-import net.javacrumbs.shedlock.support.AbstractStorageAccessor;
-import net.javacrumbs.shedlock.support.LockException;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
+import static java.util.Objects.requireNonNull;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;
import java.sql.Timestamp;
import java.util.function.BiFunction;
+import net.javacrumbs.shedlock.core.ClockProvider;
+import net.javacrumbs.shedlock.core.LockConfiguration;
+import net.javacrumbs.shedlock.support.AbstractStorageAccessor;
+import net.javacrumbs.shedlock.support.LockException;
-import static java.util.Objects.requireNonNull;
-
-/**
- * Internal class, please do not use.
- */
+/** Internal class, please do not use. */
public abstract class AbstractJdbcStorageAccessor extends AbstractStorageAccessor {
private final String tableName;
- public AbstractJdbcStorageAccessor(@NonNull String tableName) {
+ public AbstractJdbcStorageAccessor(String tableName) {
this.tableName = requireNonNull(tableName, "tableName can not be null");
}
@Override
- public boolean insertRecord(@NonNull LockConfiguration lockConfiguration) {
- // Try to insert if the record does not exist (not optimal, but the simplest platform agnostic way)
+ public boolean insertRecord(LockConfiguration lockConfiguration) {
+ // Try to insert if the record does not exist (not optimal, but the simplest
+ // platform agnostic
+ // way)
String sql = "INSERT INTO " + tableName + "(name, lock_until, locked_at, locked_by) VALUES(?, ?, ?, ?)";
- return executeCommand(sql, statement -> {
- statement.setString(1, lockConfiguration.getName());
- statement.setTimestamp(2, Timestamp.from(lockConfiguration.getLockAtMostUntil()));
- statement.setTimestamp(3, Timestamp.from(ClockProvider.now()));
- statement.setString(4, getHostname());
- int insertedRows = statement.executeUpdate();
- return insertedRows > 0;
- }, this::handleInsertionException);
+ return executeCommand(
+ sql,
+ statement -> {
+ statement.setString(1, lockConfiguration.getName());
+ statement.setTimestamp(2, Timestamp.from(lockConfiguration.getLockAtMostUntil()));
+ statement.setTimestamp(3, Timestamp.from(ClockProvider.now()));
+ statement.setString(4, getHostname());
+ int insertedRows = statement.executeUpdate();
+ return insertedRows > 0;
+ },
+ this::handleInsertionException);
}
@Override
- public boolean updateRecord(@NonNull LockConfiguration lockConfiguration) {
- String sql = "UPDATE " + tableName + " SET lock_until = ?, locked_at = ?, locked_by = ? WHERE name = ? AND lock_until <= ?";
- return executeCommand(sql, statement -> {
- Timestamp now = Timestamp.from(ClockProvider.now());
- statement.setTimestamp(1, Timestamp.from(lockConfiguration.getLockAtMostUntil()));
- statement.setTimestamp(2, now);
- statement.setString(3, getHostname());
- statement.setString(4, lockConfiguration.getName());
- statement.setTimestamp(5, now);
- int updatedRows = statement.executeUpdate();
- return updatedRows > 0;
- }, this::handleUpdateException);
+ public boolean updateRecord(LockConfiguration lockConfiguration) {
+ String sql = "UPDATE " + tableName
+ + " SET lock_until = ?, locked_at = ?, locked_by = ? WHERE name = ? AND lock_until <= ?";
+ return executeCommand(
+ sql,
+ statement -> {
+ Timestamp now = Timestamp.from(ClockProvider.now());
+ statement.setTimestamp(1, Timestamp.from(lockConfiguration.getLockAtMostUntil()));
+ statement.setTimestamp(2, now);
+ statement.setString(3, getHostname());
+ statement.setString(4, lockConfiguration.getName());
+ statement.setTimestamp(5, now);
+ int updatedRows = statement.executeUpdate();
+ return updatedRows > 0;
+ },
+ this::handleUpdateException);
}
@Override
- public boolean extend(@NonNull LockConfiguration lockConfiguration) {
+ public boolean extend(LockConfiguration lockConfiguration) {
String sql = "UPDATE " + tableName + " SET lock_until = ? WHERE name = ? AND locked_by = ? AND lock_until > ? ";
logger.debug("Extending lock={} until={}", lockConfiguration.getName(), lockConfiguration.getLockAtMostUntil());
- return executeCommand(sql, statement -> {
- statement.setTimestamp(1, Timestamp.from(lockConfiguration.getLockAtMostUntil()));
- statement.setString(2, lockConfiguration.getName());
- statement.setString(3, getHostname());
- statement.setTimestamp(4, Timestamp.from(ClockProvider.now()));
- return statement.executeUpdate() > 0;
- }, this::handleUnlockException);
+ return executeCommand(
+ sql,
+ statement -> {
+ statement.setTimestamp(1, Timestamp.from(lockConfiguration.getLockAtMostUntil()));
+ statement.setString(2, lockConfiguration.getName());
+ statement.setString(3, getHostname());
+ statement.setTimestamp(4, Timestamp.from(ClockProvider.now()));
+ return statement.executeUpdate() > 0;
+ },
+ this::handleUnlockException);
}
@Override
- public void unlock(@NonNull LockConfiguration lockConfiguration) {
+ public void unlock(LockConfiguration lockConfiguration) {
String sql = "UPDATE " + tableName + " SET lock_until = ? WHERE name = ?";
- executeCommand(sql, statement -> {
- statement.setTimestamp(1, Timestamp.from(lockConfiguration.getUnlockTime()));
- statement.setString(2, lockConfiguration.getName());
- statement.executeUpdate();
- return null;
- }, this::handleUnlockException);
+ executeCommand(
+ sql,
+ statement -> {
+ statement.setTimestamp(1, Timestamp.from(lockConfiguration.getUnlockTime()));
+ statement.setString(2, lockConfiguration.getName());
+ statement.executeUpdate();
+ return null;
+ },
+ this::handleUnlockException);
}
protected abstract Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbc.micronaut;
import io.micronaut.transaction.TransactionOperations;
-import io.micronaut.transaction.jdbc.DataSourceTransactionManager;
-import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
-
-import javax.sql.DataSource;
import java.sql.Connection;
+import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
/**
- * Lock provided by plain JDBC, using the Micronaut Data transaction manager. It uses a table that contains lock_name and locked_until.
+ * Lock provided by plain JDBC, using the Micronaut Data transaction manager. It
+ * uses a table that contains lock_name and locked_until.
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbc.micronaut;
+import static java.util.Objects.requireNonNull;
+
import io.micronaut.transaction.TransactionDefinition;
import io.micronaut.transaction.TransactionOperations;
-import net.javacrumbs.shedlock.provider.jdbc.internal.AbstractJdbcStorageAccessor;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
-
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.function.BiFunction;
-
-import static java.util.Objects.requireNonNull;
+import net.javacrumbs.shedlock.provider.jdbc.internal.AbstractJdbcStorageAccessor;
class MicronautJdbcStorageAccessor extends AbstractJdbcStorageAccessor {
- private final TransactionOperations Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbc.micronaut;
diff --git a/providers/jdbc/shedlock-provider-jdbc-micronaut/src/test/java/net/javacrumbs/shedlock/provider/jdbc/micronaut/MySqlJdbcLockProviderIntegrationTest.java b/providers/jdbc/shedlock-provider-jdbc-micronaut/src/test/java/net/javacrumbs/shedlock/provider/jdbc/micronaut/MySqlJdbcLockProviderIntegrationTest.java
index 67d845131..9db0944ab 100644
--- a/providers/jdbc/shedlock-provider-jdbc-micronaut/src/test/java/net/javacrumbs/shedlock/provider/jdbc/micronaut/MySqlJdbcLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-provider-jdbc-micronaut/src/test/java/net/javacrumbs/shedlock/provider/jdbc/micronaut/MySqlJdbcLockProviderIntegrationTest.java
@@ -1,16 +1,14 @@
/**
* Copyright 2009-2021 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbc.micronaut;
diff --git a/providers/jdbc/shedlock-provider-jdbc-micronaut/src/test/java/net/javacrumbs/shedlock/provider/jdbc/micronaut/PostgresJdbcLockProviderIntegrationTest.java b/providers/jdbc/shedlock-provider-jdbc-micronaut/src/test/java/net/javacrumbs/shedlock/provider/jdbc/micronaut/PostgresJdbcLockProviderIntegrationTest.java
index 2abb2b515..25273a770 100644
--- a/providers/jdbc/shedlock-provider-jdbc-micronaut/src/test/java/net/javacrumbs/shedlock/provider/jdbc/micronaut/PostgresJdbcLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-provider-jdbc-micronaut/src/test/java/net/javacrumbs/shedlock/provider/jdbc/micronaut/PostgresJdbcLockProviderIntegrationTest.java
@@ -1,16 +1,14 @@
/**
* Copyright 2009-2021 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbc.micronaut;
diff --git a/providers/jdbc/shedlock-provider-jdbc-template/pom.xml b/providers/jdbc/shedlock-provider-jdbc-template/pom.xml
index eb0e1e855..1e230872c 100644
--- a/providers/jdbc/shedlock-provider-jdbc-template/pom.xml
+++ b/providers/jdbc/shedlock-provider-jdbc-template/pom.xml
@@ -3,13 +3,13 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
-import net.javacrumbs.shedlock.core.LockConfiguration;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
-
-import java.util.HashMap;
import java.util.Map;
+import net.javacrumbs.shedlock.core.LockConfiguration;
class Db2ServerTimeStatementsSource extends SqlStatementsSource {
private static final String now = "(CURRENT TIMESTAMP - CURRENT TIMEZONE)";
- private static final String lockAtMostFor = "("+ now + " + :lockAtMostForMicros MICROSECONDS)";
+ private static final String lockAtMostFor = "(" + now + " + :lockAtMostForMicros MICROSECONDS)";
Db2ServerTimeStatementsSource(JdbcTemplateLockProvider.Configuration configuration) {
super(configuration);
@@ -31,33 +26,40 @@ class Db2ServerTimeStatementsSource extends SqlStatementsSource {
@Override
String getInsertStatement() {
- return "INSERT INTO " + tableName() + "(" + name() + ", " + lockUntil() + ", " + lockedAt() + ", " + lockedBy() + ") VALUES(:name, " + lockAtMostFor + ", " + now + ", :lockedBy)";
+ return "INSERT INTO " + tableName() + "(" + name() + ", " + lockUntil() + ", " + lockedAt() + ", " + lockedBy()
+ + ") VALUES(:name, " + lockAtMostFor + ", " + now + ", :lockedBy)";
}
@Override
public String getUpdateStatement() {
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + ", " + lockedAt() + " = " + now + ", " + lockedBy() + " = :lockedBy WHERE " + name() + " = :name AND " + lockUntil() + " <= " + now;
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + ", " + lockedAt() + " = " + now
+ + ", " + lockedBy() + " = :lockedBy WHERE " + name() + " = :name AND " + lockUntil() + " <= " + now;
}
@Override
public String getUnlockStatement() {
String lockAtLeastFor = "(" + lockedAt() + "+ :lockAtLeastForMicros MICROSECONDS)";
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = CASE WHEN " + lockAtLeastFor + " > " + now + " THEN " + lockAtLeastFor + " ELSE " + now + " END WHERE " + name() + " = :name AND " + lockedBy() + " = :lockedBy";
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = CASE WHEN " + lockAtLeastFor + " > " + now
+ + " THEN " + lockAtLeastFor + " ELSE " + now + " END WHERE " + name() + " = :name AND " + lockedBy()
+ + " = :lockedBy";
}
@Override
public String getExtendStatement() {
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + " WHERE " + name() + " = :name AND " + lockedBy() + " = :lockedBy AND " + lockUntil() + " > " + now;
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + " WHERE " + name()
+ + " = :name AND " + lockedBy() + " = :lockedBy AND " + lockUntil() + " > " + now;
}
@Override
- @NonNull
- Map Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
-import net.javacrumbs.shedlock.core.LockConfiguration;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
-
-import java.util.HashMap;
import java.util.Map;
+import net.javacrumbs.shedlock.core.LockConfiguration;
class H2ServerTimeStatementsSource extends SqlStatementsSource {
private static final String now = "CURRENT_TIMESTAMP(3)";
@@ -31,33 +26,40 @@ class H2ServerTimeStatementsSource extends SqlStatementsSource {
@Override
String getInsertStatement() {
- return "INSERT INTO " + tableName() + "(" + name() + ", " + lockUntil() + ", " + lockedAt() + ", " + lockedBy() + ") VALUES(:name, " + lockAtMostFor + ", " + now + ", :lockedBy)";
+ return "INSERT INTO " + tableName() + "(" + name() + ", " + lockUntil() + ", " + lockedAt() + ", " + lockedBy()
+ + ") VALUES(:name, " + lockAtMostFor + ", " + now + ", :lockedBy)";
}
@Override
public String getUpdateStatement() {
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + ", " + lockedAt() + " = " + now + ", " + lockedBy() + " = :lockedBy WHERE " + name() + " = :name AND " + lockUntil() + " <= " + now;
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + ", " + lockedAt() + " = " + now
+ + ", " + lockedBy() + " = :lockedBy WHERE " + name() + " = :name AND " + lockUntil() + " <= " + now;
}
@Override
public String getUnlockStatement() {
String lockAtLeastFor = "TIMESTAMPADD(MICROSECOND, :lockAtLeastForMicros, " + lockedAt() + ")";
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = CASE WHEN " + lockAtLeastFor + " > " + now + " THEN " + lockAtLeastFor + " ELSE " + now + " END WHERE " + name() + " = :name AND " + lockedBy() + " = :lockedBy";
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = CASE WHEN " + lockAtLeastFor + " > " + now
+ + " THEN " + lockAtLeastFor + " ELSE " + now + " END WHERE " + name() + " = :name AND " + lockedBy()
+ + " = :lockedBy";
}
@Override
public String getExtendStatement() {
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + " WHERE " + name() + " = :name AND " + lockedBy() + " = :lockedBy AND " + lockUntil() + " > " + now;
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + " WHERE " + name()
+ + " = :name AND " + lockedBy() + " = :lockedBy AND " + lockUntil() + " > " + now;
}
@Override
- @NonNull
- Map Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
-import net.javacrumbs.shedlock.core.LockConfiguration;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
-
-import java.util.HashMap;
import java.util.Map;
+import net.javacrumbs.shedlock.core.LockConfiguration;
class HsqlServerTimeStatementsSource extends SqlStatementsSource {
private static final String now = "CURRENT_TIMESTAMP(3)";
@@ -31,33 +26,40 @@ class HsqlServerTimeStatementsSource extends SqlStatementsSource {
@Override
String getInsertStatement() {
- return "INSERT INTO " + tableName() + "(" + name() + ", " + lockUntil() + ", " + lockedAt() + ", " + lockedBy() + ") VALUES(:name, " + lockAtMostFor + ", " + now + ", :lockedBy)";
+ return "INSERT INTO " + tableName() + "(" + name() + ", " + lockUntil() + ", " + lockedAt() + ", " + lockedBy()
+ + ") VALUES(:name, " + lockAtMostFor + ", " + now + ", :lockedBy)";
}
@Override
public String getUpdateStatement() {
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + ", " + lockedAt() + " = " + now + ", " + lockedBy() + " = :lockedBy WHERE " + name() + " = :name AND " + lockUntil() + " <= " + now;
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + ", " + lockedAt() + " = " + now
+ + ", " + lockedBy() + " = :lockedBy WHERE " + name() + " = :name AND " + lockUntil() + " <= " + now;
}
@Override
public String getUnlockStatement() {
String lockAtLeastFor = "TIMESTAMPADD(MICROSECOND, :lockAtLeastForMicros, " + lockedAt() + ")";
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = CASE WHEN " + lockAtLeastFor + " > " + now + " THEN " + lockAtLeastFor + " ELSE " + now + " END WHERE " + name() + " = :name AND " + lockedBy() + " = :lockedBy";
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = CASE WHEN " + lockAtLeastFor + " > " + now
+ + " THEN " + lockAtLeastFor + " ELSE " + now + " END WHERE " + name() + " = :name AND " + lockedBy()
+ + " = :lockedBy";
}
@Override
public String getExtendStatement() {
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + " WHERE " + name() + " = :name AND " + lockedBy() + " = :lockedBy AND " + lockUntil() + " > " + now;
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + " WHERE " + name()
+ + " = :name AND " + lockedBy() + " = :lockedBy AND " + lockUntil() + " > " + now;
}
@Override
- @NonNull
- Map Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
+import static java.util.Objects.requireNonNull;
+
+import java.util.TimeZone;
+import javax.sql.DataSource;
import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
import net.javacrumbs.shedlock.support.Utils;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
import net.javacrumbs.shedlock.support.annotation.Nullable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.PlatformTransactionManager;
-import javax.sql.DataSource;
-import java.util.TimeZone;
-
-import static java.util.Objects.requireNonNull;
-
/**
- * Lock provided by JdbcTemplate. It uses a table that contains lock_name and locked_until.
+ * Lock provided by JdbcTemplate. It uses a table that contains lock_name and
+ * locked_until.
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
+import static java.util.Objects.requireNonNull;
+
+import java.util.Map;
import net.javacrumbs.shedlock.core.LockConfiguration;
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.Configuration;
import net.javacrumbs.shedlock.support.AbstractStorageAccessor;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
+import net.javacrumbs.shedlock.support.annotation.Nullable;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.DuplicateKeyException;
@@ -32,26 +33,23 @@
import org.springframework.transaction.TransactionSystemException;
import org.springframework.transaction.support.TransactionTemplate;
-import java.util.Map;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * Spring JdbcTemplate based implementation usable in JTA environment
- */
+/** Spring JdbcTemplate based implementation usable in JTA environment */
class JdbcTemplateStorageAccessor extends AbstractStorageAccessor {
private final NamedParameterJdbcTemplate jdbcTemplate;
private final TransactionTemplate transactionTemplate;
private final Configuration configuration;
+
+ @Nullable
private SqlStatementsSource sqlStatementsSource;
- JdbcTemplateStorageAccessor(@NonNull Configuration configuration) {
+ JdbcTemplateStorageAccessor(Configuration configuration) {
requireNonNull(configuration, "configuration can not be null");
this.jdbcTemplate = new NamedParameterJdbcTemplate(configuration.getJdbcTemplate());
this.configuration = configuration;
- PlatformTransactionManager transactionManager = configuration.getTransactionManager() != null ?
- configuration.getTransactionManager() :
- new DataSourceTransactionManager(configuration.getJdbcTemplate().getDataSource());
+ PlatformTransactionManager transactionManager = configuration.getTransactionManager() != null
+ ? configuration.getTransactionManager()
+ : new DataSourceTransactionManager(
+ configuration.getJdbcTemplate().getDataSource());
this.transactionTemplate = new TransactionTemplate(transactionManager);
this.transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
@@ -62,33 +60,41 @@ class JdbcTemplateStorageAccessor extends AbstractStorageAccessor {
}
@Override
- public boolean insertRecord(@NonNull LockConfiguration lockConfiguration) {
+ public boolean insertRecord(LockConfiguration lockConfiguration) {
try {
String sql = sqlStatementsSource().getInsertStatement();
return execute(sql, lockConfiguration);
- } catch (DuplicateKeyException | ConcurrencyFailureException e) {
+ } catch (DuplicateKeyException | ConcurrencyFailureException | TransactionSystemException e) {
+ logger.debug("Duplicate key", e);
return false;
- } catch (DataIntegrityViolationException | BadSqlGrammarException | UncategorizedSQLException | TransactionSystemException e) {
+ } catch (DataIntegrityViolationException | BadSqlGrammarException | UncategorizedSQLException e) {
+ if (configuration.isThrowUnexpectedException()) {
+ throw e;
+ }
logger.error("Unexpected exception", e);
return false;
}
}
@Override
- public boolean updateRecord(@NonNull LockConfiguration lockConfiguration) {
+ public boolean updateRecord(LockConfiguration lockConfiguration) {
String sql = sqlStatementsSource().getUpdateStatement();
try {
return execute(sql, lockConfiguration);
} catch (ConcurrencyFailureException e) {
+ logger.debug("Serialization exception", e);
return false;
- } catch (DataIntegrityViolationException | TransactionSystemException e) {
+ } catch (DataIntegrityViolationException | TransactionSystemException | UncategorizedSQLException e) {
+ if (configuration.isThrowUnexpectedException()) {
+ throw e;
+ }
logger.error("Unexpected exception", e);
return false;
}
}
@Override
- public boolean extend(@NonNull LockConfiguration lockConfiguration) {
+ public boolean extend(LockConfiguration lockConfiguration) {
String sql = sqlStatementsSource().getExtendStatement();
logger.debug("Extending lock={} until={}", lockConfiguration.getName(), lockConfiguration.getLockAtMostUntil());
@@ -96,13 +102,16 @@ public boolean extend(@NonNull LockConfiguration lockConfiguration) {
}
@Override
- public void unlock(@NonNull LockConfiguration lockConfiguration) {
- try {
- doUnlock(lockConfiguration);
- } catch (ConcurrencyFailureException e) {
- logger.info("Unlock failed due to TransactionSystemException - retrying");
- doUnlock(lockConfiguration);
+ public void unlock(LockConfiguration lockConfiguration) {
+ for (int i = 0; i < 10; i++) {
+ try {
+ doUnlock(lockConfiguration);
+ return;
+ } catch (ConcurrencyFailureException | TransactionSystemException e) {
+ logger.info("Unlock failed due to TransactionSystemException - retrying attempt {}", i + 1);
+ }
}
+ logger.error("Unlock failed after 10 attempts");
}
private void doUnlock(LockConfiguration lockConfiguration) {
@@ -115,8 +124,7 @@ private boolean execute(String sql, LockConfiguration lockConfiguration) throws
return transactionTemplate.execute(status -> jdbcTemplate.update(sql, params(lockConfiguration)) > 0);
}
- @NonNull
- private Map Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
-import net.javacrumbs.shedlock.core.LockConfiguration;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
-
-import java.util.HashMap;
import java.util.Map;
+import net.javacrumbs.shedlock.core.LockConfiguration;
class MsSqlServerTimeStatementsSource extends SqlStatementsSource {
private static final String now = "SYSUTCDATETIME()";
@@ -31,32 +26,40 @@ class MsSqlServerTimeStatementsSource extends SqlStatementsSource {
@Override
String getInsertStatement() {
- return "INSERT INTO " + tableName() + "(" + name() + ", " + lockUntil() + ", " + lockedAt() + ", " + lockedBy() + ") VALUES(:name, " + lockAtMostFor + ", " + now + ", :lockedBy)";
+ return "INSERT INTO " + tableName() + "(" + name() + ", " + lockUntil() + ", " + lockedAt() + ", " + lockedBy()
+ + ") VALUES(:name, " + lockAtMostFor + ", " + now + ", :lockedBy)";
}
@Override
public String getUpdateStatement() {
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + ", " + lockedAt() + " = " + now + ", " + lockedBy() + " = :lockedBy WHERE " + name() + " = :name AND " + lockUntil() + " <= " + now;
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + ", " + lockedAt() + " = " + now
+ + ", " + lockedBy() + " = :lockedBy WHERE " + name() + " = :name AND " + lockUntil() + " <= " + now;
}
@Override
public String getUnlockStatement() {
String lockAtLeastFor = "DATEADD(millisecond, :lockAtLeastForMillis, " + lockedAt() + ")";
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = CASE WHEN " + lockAtLeastFor + " > " + now + " THEN " + lockAtLeastFor + " ELSE " + now + " END WHERE " + name() + " = :name AND " + lockedBy() + " = :lockedBy";
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = CASE WHEN " + lockAtLeastFor + " > " + now
+ + " THEN " + lockAtLeastFor + " ELSE " + now + " END WHERE " + name() + " = :name AND " + lockedBy()
+ + " = :lockedBy";
}
@Override
public String getExtendStatement() {
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + " WHERE " + name() + " = :name AND " + lockedBy() + " = :lockedBy AND " + lockUntil() + " > " + now;
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + " WHERE " + name()
+ + " = :name AND " + lockedBy() + " = :lockedBy AND " + lockUntil() + " > " + now;
}
@Override
- @NonNull Map Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
-import net.javacrumbs.shedlock.core.LockConfiguration;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
-
-import java.util.HashMap;
import java.util.Map;
+import net.javacrumbs.shedlock.core.LockConfiguration;
class MySqlServerTimeStatementsSource extends SqlStatementsSource {
private static final String now = "UTC_TIMESTAMP(3)";
@@ -31,32 +26,39 @@ class MySqlServerTimeStatementsSource extends SqlStatementsSource {
@Override
String getInsertStatement() {
- return "INSERT INTO " + tableName() + "(" + name() + ", " + lockUntil() + ", " + lockedAt() + ", " + lockedBy() + ") VALUES(:name, " + lockAtMostFor + ", " + now + ", :lockedBy)";
+ return "INSERT IGNORE INTO " + tableName() + "(" + name() + ", " + lockUntil() + ", " + lockedAt() + ", "
+ + lockedBy() + ") VALUES(:name, " + lockAtMostFor + ", " + now + ", :lockedBy)";
}
@Override
public String getUpdateStatement() {
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + ", " + lockedAt() + " = " + now + ", " + lockedBy() + " = :lockedBy WHERE " + name() + " = :name AND " + lockUntil() + " <= " + now;
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + ", " + lockedAt() + " = " + now
+ + ", " + lockedBy() + " = :lockedBy WHERE " + name() + " = :name AND " + lockUntil() + " <= " + now;
}
@Override
public String getUnlockStatement() {
String lockAtLeastFor = "TIMESTAMPADD(MICROSECOND, :lockAtLeastForMicros, " + lockedAt() + ")";
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = IF (" + lockAtLeastFor + " > " + now + " , " + lockAtLeastFor + ", " + now + ") WHERE " + name() + " = :name AND " + lockedBy() + " = :lockedBy";
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = IF (" + lockAtLeastFor + " > " + now + " , "
+ + lockAtLeastFor + ", " + now + ") WHERE " + name() + " = :name AND " + lockedBy() + " = :lockedBy";
}
@Override
public String getExtendStatement() {
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + " WHERE " + name() + " = :name AND " + lockedBy() + " = :lockedBy AND " + lockUntil() + " > " + now;
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + " WHERE " + name()
+ + " = :name AND " + lockedBy() + " = :lockedBy AND " + lockUntil() + " > " + now;
}
@Override
- @NonNull Map Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
-import net.javacrumbs.shedlock.core.LockConfiguration;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
-
-import java.util.HashMap;
import java.util.Map;
+import net.javacrumbs.shedlock.core.LockConfiguration;
class OracleServerTimeStatementsSource extends SqlStatementsSource {
private static final String now = "SYS_EXTRACT_UTC(SYSTIMESTAMP)";
@@ -33,33 +28,43 @@ class OracleServerTimeStatementsSource extends SqlStatementsSource {
@Override
String getInsertStatement() {
- return "INSERT INTO " + tableName() + "(" + name() + ", " + lockUntil() + ", " + lockedAt() + ", " + lockedBy() + ") VALUES(:name, " + lockAtMostFor + ", " + now + ", :lockedBy)";
+ return "MERGE INTO " + tableName() + " USING (SELECT 1 FROM dual) ON (" + name()
+ + " = :name) WHEN MATCHED THEN UPDATE SET " + lockUntil() + " = " + lockAtMostFor + ", " + lockedAt()
+ + " = " + now + ", " + lockedBy() + " = :lockedBy WHERE " + name() + " = :name AND " + lockUntil()
+ + " <= " + now + " WHEN NOT MATCHED THEN INSERT(" + name() + ", " + lockUntil() + ", " + lockedAt()
+ + ", " + lockedBy() + ") VALUES(:name, " + lockAtMostFor + ", " + now + ", :lockedBy)";
}
@Override
public String getUpdateStatement() {
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + ", " + lockedAt() + " = " + now + ", " + lockedBy() + " = :lockedBy WHERE " + name() + " = :name AND " + lockUntil() + " <= " + now;
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + ", " + lockedAt() + " = " + now
+ + ", " + lockedBy() + " = :lockedBy WHERE " + name() + " = :name AND " + lockUntil() + " <= " + now;
}
@Override
public String getUnlockStatement() {
String lockAtLeastFor = lockedAt() + " + :lockAtLeastFor";
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = CASE WHEN " + lockAtLeastFor + " > " + now + " THEN " + lockAtLeastFor + " ELSE " + now + " END WHERE " + name() + " = :name AND " + lockedBy() + " = :lockedBy";
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = CASE WHEN " + lockAtLeastFor + " > " + now
+ + " THEN " + lockAtLeastFor + " ELSE " + now + " END WHERE " + name() + " = :name AND " + lockedBy()
+ + " = :lockedBy";
}
@Override
public String getExtendStatement() {
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + " WHERE " + name() + " = :name AND " + lockedBy() + " = :lockedBy AND " + lockUntil() + " > " + now;
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + " WHERE " + name()
+ + " = :name AND " + lockedBy() + " = :lockedBy AND " + lockUntil() + " > " + now;
}
@Override
- @NonNull
- Map Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
-import net.javacrumbs.shedlock.core.LockConfiguration;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
-
-import java.util.HashMap;
import java.util.Map;
+import net.javacrumbs.shedlock.core.LockConfiguration;
class PostgresSqlServerTimeStatementsSource extends SqlStatementsSource {
private static final String now = "timezone('utc', CURRENT_TIMESTAMP)";
@@ -31,13 +26,15 @@ class PostgresSqlServerTimeStatementsSource extends SqlStatementsSource {
@Override
String getInsertStatement() {
- return "INSERT INTO " + tableName() + "(" + name() + ", " + lockUntil() + ", " + lockedAt() + ", " + lockedBy() + ") VALUES(:name, " + lockAtMostFor + ", " + now + ", :lockedBy)" +
- " ON CONFLICT (" + name() + ") DO UPDATE" + updateClause();
+ return "INSERT INTO " + tableName() + "(" + name() + ", " + lockUntil() + ", " + lockedAt() + ", " + lockedBy()
+ + ") VALUES(:name, " + lockAtMostFor + ", " + now + ", :lockedBy)" + " ON CONFLICT (" + name()
+ + ") DO UPDATE" + updateClause();
}
- @NonNull
private String updateClause() {
- return " SET " + lockUntil() + " = " + lockAtMostFor + ", " + lockedAt() + " = " + now + ", " + lockedBy() + " = :lockedBy WHERE " + tableName() + "." + name() + " = :name AND " + tableName() + "." + lockUntil() + " <= " + now;
+ return " SET " + lockUntil() + " = " + lockAtMostFor + ", " + lockedAt() + " = " + now + ", " + lockedBy()
+ + " = :lockedBy WHERE " + tableName() + "." + name() + " = :name AND " + tableName() + "." + lockUntil()
+ + " <= " + now;
}
@Override
@@ -48,21 +45,27 @@ public String getUpdateStatement() {
@Override
public String getUnlockStatement() {
String lockAtLeastFor = lockedAt() + " + cast(:lockAtLeastForInterval as interval)";
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = CASE WHEN " + lockAtLeastFor + " > " + now + " THEN " + lockAtLeastFor + " ELSE " + now + " END WHERE " + name() + " = :name AND " + lockedBy() + " = :lockedBy";
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = CASE WHEN " + lockAtLeastFor + " > " + now
+ + " THEN " + lockAtLeastFor + " ELSE " + now + " END WHERE " + name() + " = :name AND " + lockedBy()
+ + " = :lockedBy";
}
@Override
public String getExtendStatement() {
- return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor +" WHERE " + name() + " = :name AND " + lockedBy() + " = :lockedBy AND " + lockUntil() + " > " + now;
+ return "UPDATE " + tableName() + " SET " + lockUntil() + " = " + lockAtMostFor + " WHERE " + name()
+ + " = :name AND " + lockedBy() + " = :lockedBy AND " + lockUntil() + " > " + now;
}
@Override
- @NonNull Map Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
@@ -22,9 +20,8 @@ class PostgresSqlStatementsSource extends SqlStatementsSource {
@Override
String getInsertStatement() {
- return super.getInsertStatement() + " ON CONFLICT (" + name() + ") DO UPDATE " +
- "SET " + lockUntil() + " = :lockUntil, " + lockedAt() + " = :now, " + lockedBy() + " = :lockedBy " +
- "WHERE " + tableName() + "." + lockUntil() + " <= :now";
+ return super.getInsertStatement() + " ON CONFLICT (" + name() + ") DO UPDATE " + "SET " + lockUntil()
+ + " = :lockUntil, " + lockedAt() + " = :now, " + lockedBy() + " = :lockedBy " + "WHERE " + tableName()
+ + "." + lockUntil() + " <= :now";
}
-
}
diff --git a/providers/jdbc/shedlock-provider-jdbc-template/src/main/java/net/javacrumbs/shedlock/provider/jdbctemplate/SqlStatementsSource.java b/providers/jdbc/shedlock-provider-jdbc-template/src/main/java/net/javacrumbs/shedlock/provider/jdbctemplate/SqlStatementsSource.java
index c116bf3a9..a7300948b 100644
--- a/providers/jdbc/shedlock-provider-jdbc-template/src/main/java/net/javacrumbs/shedlock/provider/jdbctemplate/SqlStatementsSource.java
+++ b/providers/jdbc/shedlock-provider-jdbc-template/src/main/java/net/javacrumbs/shedlock/provider/jdbctemplate/SqlStatementsSource.java
@@ -1,35 +1,31 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
-import net.javacrumbs.shedlock.core.ClockProvider;
-import net.javacrumbs.shedlock.core.LockConfiguration;
-import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.Configuration;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.jdbc.core.ConnectionCallback;
-
import java.sql.Timestamp;
import java.time.Instant;
import java.util.Calendar;
import java.util.Date;
-import java.util.HashMap;
import java.util.Map;
+import java.util.Objects;
import java.util.TimeZone;
+import net.javacrumbs.shedlock.core.ClockProvider;
+import net.javacrumbs.shedlock.core.LockConfiguration;
+import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.jdbc.core.ConnectionCallback;
class SqlStatementsSource {
protected final Configuration configuration;
@@ -41,41 +37,15 @@ class SqlStatementsSource {
}
static SqlStatementsSource create(Configuration configuration) {
- String databaseProductName = getDatabaseProductName(configuration);
+ DatabaseProduct databaseProduct = getDatabaseProduct(configuration);
if (configuration.getUseDbTime()) {
- switch (databaseProductName) {
- case "PostgreSQL":
- logger.debug("Using PostgresSqlServerTimeStatementsSource");
- return new PostgresSqlServerTimeStatementsSource(configuration);
- case "Microsoft SQL Server":
- logger.debug("Using MsSqlServerTimeStatementsSource");
- return new MsSqlServerTimeStatementsSource(configuration);
- case "Oracle":
- logger.debug("Using OracleServerTimeStatementsSource");
- return new OracleServerTimeStatementsSource(configuration);
- case "MySQL":
- logger.debug("Using MySqlServerTimeStatementsSource");
- return new MySqlServerTimeStatementsSource(configuration);
- case "MariaDB":
- logger.debug("Using MySqlServerTimeStatementsSource (for MariaDB)");
- return new MySqlServerTimeStatementsSource(configuration);
- case "HSQL Database Engine":
- logger.debug("Using HsqlServerTimeStatementsSource");
- return new HsqlServerTimeStatementsSource(configuration);
- case "H2":
- logger.debug("Using H2ServerTimeStatementsSource");
- return new H2ServerTimeStatementsSource(configuration);
- default:
- if (databaseProductName.startsWith("DB2")) {
- logger.debug("Using Db2ServerTimeStatementsSource");
- return new Db2ServerTimeStatementsSource(configuration);
- }
- throw new UnsupportedOperationException("DB time is not supported for '" + databaseProductName + "'");
- }
+ var statementsSource = databaseProduct.getDbTimeStatementSource(configuration);
+ logger.debug("Using {}", statementsSource.getClass().getSimpleName());
+ return statementsSource;
} else {
- if ("PostgreSQL".equals(databaseProductName)) {
- logger.debug("Using PostgresSqlServerTimeStatementsSource");
+ if (Objects.equals(databaseProduct, DatabaseProduct.POSTGRES_SQL)) {
+ logger.debug("Using PostgresSqlStatementsSource");
return new PostgresSqlStatementsSource(configuration);
} else {
logger.debug("Using SqlStatementsSource");
@@ -84,27 +54,34 @@ static SqlStatementsSource create(Configuration configuration) {
}
}
- private static String getDatabaseProductName(Configuration configuration) {
+ private static DatabaseProduct getDatabaseProduct(final Configuration configuration) {
+ if (configuration.getDatabaseProduct() != null) {
+ return configuration.getDatabaseProduct();
+ }
try {
- return configuration.getJdbcTemplate().execute((ConnectionCallback Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
+import static net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.Configuration.builder;
+import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
+
import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
import net.javacrumbs.shedlock.test.support.jdbc.AbstractJdbcLockProviderIntegrationTest;
import net.javacrumbs.shedlock.test.support.jdbc.DbConfig;
@@ -24,9 +25,6 @@
import org.junit.jupiter.api.TestInstance;
import org.springframework.jdbc.core.JdbcTemplate;
-import static net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.Configuration.builder;
-import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
-
@TestInstance(PER_CLASS)
public abstract class AbstractJdbcTemplateLockProviderIntegrationTest {
private final DbConfig dbConfig;
@@ -35,7 +33,6 @@ public AbstractJdbcTemplateLockProviderIntegrationTest(DbConfig dbConfig) {
this.dbConfig = dbConfig;
}
-
@BeforeAll
public void startDb() {
dbConfig.startDb();
@@ -45,6 +42,7 @@ public void startDb() {
public void shutdownDb() {
dbConfig.shutdownDb();
}
+
@Nested
class ClientTime extends AbstractJdbcLockProviderIntegrationTest {
@Override
@@ -55,9 +53,8 @@ protected DbConfig getDbConfig() {
@Override
protected StorageBasedLockProvider getLockProvider() {
return new JdbcTemplateLockProvider(builder()
- .withJdbcTemplate(new JdbcTemplate(getDatasource()))
- .build()
- );
+ .withJdbcTemplate(new JdbcTemplate(getDatasource()))
+ .build());
}
@Override
@@ -75,12 +72,10 @@ protected DbConfig getDbConfig() {
@Override
protected StorageBasedLockProvider getLockProvider() {
- return new JdbcTemplateLockProvider(JdbcTemplateLockProvider.Configuration
- .builder()
- .withJdbcTemplate(new JdbcTemplate(getDatasource()))
- .usingDbTime()
- .build()
- );
+ return new JdbcTemplateLockProvider(JdbcTemplateLockProvider.Configuration.builder()
+ .withJdbcTemplate(new JdbcTemplate(getDatasource()))
+ .usingDbTime()
+ .build());
}
@Override
@@ -96,5 +91,3 @@ class StorageAccessor extends AbstractJdbcTemplateStorageAccessorTest {
}
}
}
-
-
diff --git a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/AbstractJdbcTemplateStorageAccessorTest.java b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/AbstractJdbcTemplateStorageAccessorTest.java
index 044d5970e..4fd51ea66 100644
--- a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/AbstractJdbcTemplateStorageAccessorTest.java
+++ b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/AbstractJdbcTemplateStorageAccessorTest.java
@@ -1,34 +1,30 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
+import static java.lang.Thread.sleep;
+import static net.javacrumbs.shedlock.core.ClockProvider.now;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.sql.Timestamp;
+import java.time.Duration;
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 net.javacrumbs.shedlock.core.ClockProvider.now;
-import static org.assertj.core.api.Assertions.assertThat;
-
public abstract class AbstractJdbcTemplateStorageAccessorTest {
private static final String MY_LOCK = "my-lock";
@@ -58,15 +54,13 @@ void shouldNotUpdateOnInsertIfPreviousDidNotEndWhenUsingDbTime() {
private void shouldNotUpdateOnInsertIfPreviousDidNotEnd(boolean usingDbTime) {
JdbcTemplateStorageAccessor accessor = getAccessor(usingDbTime);
- assertThat(
- accessor.insertRecord(lockConfig(MY_LOCK, Duration.ofSeconds(10)))
- ).isEqualTo(true);
+ assertThat(accessor.insertRecord(lockConfig(MY_LOCK, Duration.ofSeconds(10))))
+ .isEqualTo(true);
Timestamp originalLockValidity = testUtils.getLockedUntil(MY_LOCK);
- assertThat(
- accessor.insertRecord(lockConfig(MY_LOCK, Duration.ofSeconds(10)))
- ).isEqualTo(false);
+ assertThat(accessor.insertRecord(lockConfig(MY_LOCK, Duration.ofSeconds(10))))
+ .isEqualTo(false);
assertThat(testUtils.getLockedUntil(MY_LOCK)).isEqualTo(originalLockValidity);
}
@@ -92,13 +86,14 @@ private void shouldNotUpdateOtherLockConfigurations(boolean usingDbTime) throws
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
+ // 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(now(), MY_LOCK, lockAtMostFor, Duration.ZERO))).isEqualTo(true);
-
+ assertThat(accessor.updateRecord(new LockConfiguration(now(), MY_LOCK, lockAtMostFor, Duration.ZERO)))
+ .isEqualTo(true);
// assert
assertThat(testUtils.getLockedUntil(MY_LOCK)).isAfter(myLockLockedUntil);
@@ -106,16 +101,13 @@ private void shouldNotUpdateOtherLockConfigurations(boolean usingDbTime) throws
assertThat(testUtils.getLockedUntil(OTHER_LOCK)).isEqualTo(otherLockLockedUntil);
}
- @NonNull
private LockConfiguration lockConfig(String myLock, Duration lockAtMostFor) {
return new LockConfiguration(now(), myLock, lockAtMostFor, Duration.ZERO);
}
- @NonNull
protected JdbcTemplateStorageAccessor getAccessor(boolean usingDbTime) {
- JdbcTemplateLockProvider.Configuration.Builder builder = JdbcTemplateLockProvider
- .Configuration.builder()
- .withJdbcTemplate(testUtils.getJdbcTemplate());
+ JdbcTemplateLockProvider.Configuration.Builder builder =
+ JdbcTemplateLockProvider.Configuration.builder().withJdbcTemplate(testUtils.getJdbcTemplate());
if (usingDbTime) {
builder.usingDbTime();
}
diff --git a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/DatabaseProductTest.java b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/DatabaseProductTest.java
new file mode 100644
index 000000000..d5d827829
--- /dev/null
+++ b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/DatabaseProductTest.java
@@ -0,0 +1,13 @@
+package net.javacrumbs.shedlock.provider.jdbctemplate;
+
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+
+import org.junit.jupiter.api.Test;
+
+class DatabaseProductTest {
+
+ @Test
+ void shouldMatchDb2() {
+ assertThat(DatabaseProduct.matchProductName("dB2 for zOS 456")).isEqualTo(DatabaseProduct.DB2);
+ }
+}
diff --git a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/Db2JdbcTemplateLockProviderIntegrationTest.java b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/Db2JdbcTemplateLockProviderIntegrationTest.java
index 155f527a6..c472578b3 100644
--- a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/Db2JdbcTemplateLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/Db2JdbcTemplateLockProviderIntegrationTest.java
@@ -1,16 +1,14 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
diff --git a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/H2JdbcTemplateLockProviderIntegrationTest.java b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/H2JdbcTemplateLockProviderIntegrationTest.java
index 48d10cce4..a66742b42 100644
--- a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/H2JdbcTemplateLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/H2JdbcTemplateLockProviderIntegrationTest.java
@@ -1,16 +1,14 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
diff --git a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/HsqlJdbcTemplateLockProviderIntegrationTest.java b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/HsqlJdbcTemplateLockProviderIntegrationTest.java
index 75d2f408a..12ffb4b19 100644
--- a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/HsqlJdbcTemplateLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/HsqlJdbcTemplateLockProviderIntegrationTest.java
@@ -1,35 +1,32 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
-import net.javacrumbs.shedlock.core.LockConfiguration;
-import net.javacrumbs.shedlock.core.SimpleLock;
-import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.ColumnNames;
-import net.javacrumbs.shedlock.test.support.jdbc.HsqlConfig;
-import org.junit.jupiter.api.Test;
-import org.springframework.jdbc.core.JdbcTemplate;
+import static net.javacrumbs.shedlock.core.ClockProvider.now;
+import static net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.Configuration.builder;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.Duration;
import java.util.Optional;
-
-import static net.javacrumbs.shedlock.core.ClockProvider.now;
-import static net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.Configuration.builder;
+import net.javacrumbs.shedlock.core.LockConfiguration;
+import net.javacrumbs.shedlock.core.SimpleLock;
+import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.ColumnNames;
+import net.javacrumbs.shedlock.test.support.jdbc.HsqlConfig;
+import org.junit.jupiter.api.Test;
+import org.springframework.jdbc.core.JdbcTemplate;
public class HsqlJdbcTemplateLockProviderIntegrationTest extends AbstractJdbcTemplateLockProviderIntegrationTest {
private static final HsqlConfig dbConfig = new HsqlConfig();
@@ -40,21 +37,21 @@ public HsqlJdbcTemplateLockProviderIntegrationTest() {
@Test
public void shouldBeAbleToSetCustomColumnNames() throws SQLException {
- try (
- Connection conn = dbConfig.getDataSource().getConnection();
- Statement statement = conn.createStatement()
- ) {
- statement.execute("CREATE TABLE shdlck(n VARCHAR(64), lck_untl TIMESTAMP(3), lckd_at TIMESTAMP(3), lckd_by VARCHAR(255), PRIMARY KEY (n))");
+ try (Connection conn = dbConfig.getDataSource().getConnection();
+ Statement statement = conn.createStatement()) {
+ statement.execute(
+ "CREATE TABLE shdlck(n VARCHAR(64), lck_untl TIMESTAMP(3), lckd_at TIMESTAMP(3), lckd_by VARCHAR(255), PRIMARY KEY (n))");
}
JdbcTemplateLockProvider provider = new JdbcTemplateLockProvider(builder()
- .withTableName("shdlck")
- .withColumnNames(new ColumnNames("n", "lck_untl", "lckd_at", "lckd_by"))
- .withJdbcTemplate(new JdbcTemplate(dbConfig.getDataSource()))
- .withLockedByValue("my-value")
- .build());
-
- Optional Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
-import org.junit.jupiter.api.Test;
-import org.springframework.jdbc.core.JdbcTemplate;
-
-import java.util.TimeZone;
-
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
+import java.util.TimeZone;
+import org.junit.jupiter.api.Test;
+import org.springframework.jdbc.core.JdbcTemplate;
class JdbcTemplateLockProviderTest {
@Test
void shouldNotEnableBothTimezoneAndServerTime() {
- assertThatThrownBy(
- () -> JdbcTemplateLockProvider.Configuration.builder()
- .withTimeZone(TimeZone.getTimeZone("Europe/Prague"))
+ assertThatThrownBy(() -> JdbcTemplateLockProvider.Configuration.builder()
+ .withTimeZone(TimeZone.getTimeZone("Europe/Prague"))
+ .withJdbcTemplate(mock(JdbcTemplate.class))
+ .usingDbTime()
+ .build())
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ void shouldTableAndColumNamesUpperCase() {
+ final var config = JdbcTemplateLockProvider.Configuration.builder()
+ .withJdbcTemplate(mock(JdbcTemplate.class))
+ .withDbUpperCase(true)
+ .build();
+
+ assertThat(config.getTableName()).isUpperCase();
+ assertThat(config.getColumnNames().getName()).isUpperCase();
+ assertThat(config.getColumnNames().getLockedBy()).isUpperCase();
+ assertThat(config.getColumnNames().getLockedAt()).isUpperCase();
+ assertThat(config.getColumnNames().getLockUntil()).isUpperCase();
+ }
+
+ @Test
+ void shouldTableAndColumNamesLowerCaseByDefault() {
+ final var config = JdbcTemplateLockProvider.Configuration.builder()
.withJdbcTemplate(mock(JdbcTemplate.class))
- .usingDbTime()
- .build()
- ).isInstanceOf(IllegalArgumentException.class);
+ .build();
+
+ assertThat(config.getTableName()).isLowerCase();
+ assertThat(config.getColumnNames().getName()).isLowerCase();
+ assertThat(config.getColumnNames().getLockedBy()).isLowerCase();
+ assertThat(config.getColumnNames().getLockedAt()).isLowerCase();
+ assertThat(config.getColumnNames().getLockUntil()).isLowerCase();
}
}
diff --git a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/JdbcTemplateStorageAccessorTest.java b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/JdbcTemplateStorageAccessorTest.java
index a489d2ea9..171777088 100644
--- a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/JdbcTemplateStorageAccessorTest.java
+++ b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/JdbcTemplateStorageAccessorTest.java
@@ -1,41 +1,89 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
-import org.junit.jupiter.api.Test;
-import org.springframework.jdbc.core.JdbcTemplate;
-
-import javax.sql.DataSource;
-
+import static java.time.Duration.ZERO;
+import static net.javacrumbs.shedlock.core.ClockProvider.now;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
+
+import java.time.Duration;
+import javax.sql.DataSource;
+import net.javacrumbs.shedlock.core.LockConfiguration;
+import org.jetbrains.annotations.NotNull;
+import org.junit.jupiter.api.Test;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.PreparedStatementCreator;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.TransactionSystemException;
class JdbcTemplateStorageAccessorTest {
+ private final DataSource dataSource = mock(DataSource.class);
+ private final LockConfiguration lockConfiguration =
+ new LockConfiguration(now(), "name", Duration.ofSeconds(1), ZERO);
+
@Test
void shouldDoLazyInit() {
- DataSource dataSource = mock(DataSource.class);
- new JdbcTemplateStorageAccessor(
- JdbcTemplateLockProvider.Configuration
- .builder()
+
+ new JdbcTemplateStorageAccessor(JdbcTemplateLockProvider.Configuration.builder()
.withJdbcTemplate(new JdbcTemplate(dataSource))
- .build()
- );
+ .build());
verifyNoInteractions(dataSource);
}
+ @Test
+ void shouldCatchUnexpectedException() {
+ TransactionSystemException exception = new TransactionSystemException("test");
+ JdbcTemplateStorageAccessor jdbcTemplateStorageAccessor = createJdbcTemplateStorageAccessor(exception, false);
+
+ assertThat(jdbcTemplateStorageAccessor.updateRecord(lockConfiguration)).isFalse();
+ }
+
+ @Test
+ void shouldThrowUnexpectedException() {
+ TransactionSystemException exception = new TransactionSystemException("test");
+ JdbcTemplateStorageAccessor jdbcTemplateStorageAccessor = createJdbcTemplateStorageAccessor(exception, true);
+
+ assertThatThrownBy(() -> jdbcTemplateStorageAccessor.updateRecord(lockConfiguration))
+ .isEqualTo(exception);
+ }
+
+ @NotNull
+ private JdbcTemplateStorageAccessor createJdbcTemplateStorageAccessor(
+ TransactionSystemException exception, boolean throwUnexpectedException) {
+ JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
+ when(jdbcTemplate.getDataSource()).thenReturn(dataSource);
+ PlatformTransactionManager txManager = mock(PlatformTransactionManager.class);
+
+ JdbcTemplateStorageAccessor jdbcTemplateStorageAccessor =
+ new JdbcTemplateStorageAccessor(JdbcTemplateLockProvider.Configuration.builder()
+ .withJdbcTemplate(jdbcTemplate)
+ .withTransactionManager(txManager)
+ .withThrowUnexpectedException(throwUnexpectedException)
+ .build());
+
+ mockUpdateThrowsException(jdbcTemplate, exception);
+ return jdbcTemplateStorageAccessor;
+ }
+
+ private static void mockUpdateThrowsException(JdbcTemplate jdbcTemplate, TransactionSystemException ex) {
+ when(jdbcTemplate.update(any(PreparedStatementCreator.class))).thenThrow(ex);
+ }
}
diff --git a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/MariaDbJdbcTemplateLockProviderIntegrationTest.java b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/MariaDbJdbcTemplateLockProviderIntegrationTest.java
index 7a075dff2..6cde33edc 100644
--- a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/MariaDbJdbcTemplateLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/MariaDbJdbcTemplateLockProviderIntegrationTest.java
@@ -1,16 +1,14 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
diff --git a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/MsSqlServerJdbcTemplateLockProviderIntegrationTest.java b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/MsSqlServerJdbcTemplateLockProviderIntegrationTest.java
index ac16d7e97..f333af2f7 100644
--- a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/MsSqlServerJdbcTemplateLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/MsSqlServerJdbcTemplateLockProviderIntegrationTest.java
@@ -1,23 +1,22 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
import net.javacrumbs.shedlock.test.support.jdbc.MsSqlServerConfig;
-public class MsSqlServerJdbcTemplateLockProviderIntegrationTest extends AbstractJdbcTemplateLockProviderIntegrationTest {
+public class MsSqlServerJdbcTemplateLockProviderIntegrationTest
+ extends AbstractJdbcTemplateLockProviderIntegrationTest {
private static final MsSqlServerConfig dbConfig = new MsSqlServerConfig();
public MsSqlServerJdbcTemplateLockProviderIntegrationTest() {
diff --git a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/MultiTenancyLockProviderIntegrationTest.java b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/MultiTenancyLockProviderIntegrationTest.java
index 8d8a2fca9..83a60ada3 100644
--- a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/MultiTenancyLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/MultiTenancyLockProviderIntegrationTest.java
@@ -1,25 +1,31 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
+import static net.javacrumbs.shedlock.core.ClockProvider.now;
+import static net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.Configuration.builder;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.time.Duration;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
import net.javacrumbs.shedlock.core.ClockProvider;
import net.javacrumbs.shedlock.core.LockConfiguration;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.core.SimpleLock;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
import net.javacrumbs.shedlock.test.support.jdbc.H2Config;
import net.javacrumbs.shedlock.test.support.jdbc.HsqlConfig;
import net.javacrumbs.shedlock.test.support.jdbc.JdbcTestUtils;
@@ -28,19 +34,10 @@
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
-import java.time.Duration;
-import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import static net.javacrumbs.shedlock.core.ClockProvider.now;
-import static net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.Configuration.builder;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
public class MultiTenancyLockProviderIntegrationTest {
public static final String LOCK_NAME = "lock_name";
- public static final LockConfiguration LOCK_CONFIGURATION = new LockConfiguration(now(), LOCK_NAME, Duration.ofSeconds(60), Duration.ZERO);
+ public static final LockConfiguration LOCK_CONFIGURATION =
+ new LockConfiguration(now(), LOCK_NAME, Duration.ofSeconds(60), Duration.ZERO);
private static final JdbcTestUtils h2TestUtils;
private static final JdbcTestUtils hsqlTestUtils;
@@ -61,7 +58,8 @@ void shouldUseDifferDatabaseForEachTennant() {
Optional Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
@@ -23,5 +21,4 @@ public class MySqlJdbcTemplateLockProviderIntegrationTest extends AbstractJdbcTe
protected MySqlJdbcTemplateLockProviderIntegrationTest() {
super(dbConfig);
}
-
}
diff --git a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/OracleJdbcTemplateLockProviderIntegrationTest.java b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/OracleJdbcTemplateLockProviderIntegrationTest.java
index 0322e9f84..b35735977 100644
--- a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/OracleJdbcTemplateLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/OracleJdbcTemplateLockProviderIntegrationTest.java
@@ -1,16 +1,14 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
diff --git a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/PostgresJdbcTemplateLockProviderIntegrationTest.java b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/PostgresJdbcTemplateLockProviderIntegrationTest.java
index d4c59b11c..8a96c0aa9 100644
--- a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/PostgresJdbcTemplateLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/PostgresJdbcTemplateLockProviderIntegrationTest.java
@@ -1,40 +1,37 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
-import net.javacrumbs.shedlock.core.ClockProvider;
-import net.javacrumbs.shedlock.core.LockConfiguration;
-import net.javacrumbs.shedlock.test.support.jdbc.PostgresConfig;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Nested;
-import org.junit.jupiter.api.Test;
-import org.springframework.jdbc.core.JdbcTemplate;
+import static java.lang.Thread.sleep;
+import static net.javacrumbs.shedlock.core.ClockProvider.now;
+import static net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.Configuration.builder;
+import static org.assertj.core.api.Assertions.assertThat;
-import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.Timestamp;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.util.TimeZone;
-
-import static java.lang.Thread.sleep;
-import static net.javacrumbs.shedlock.core.ClockProvider.now;
-import static net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.Configuration.builder;
-import static org.assertj.core.api.Assertions.assertThat;
+import javax.sql.DataSource;
+import net.javacrumbs.shedlock.core.ClockProvider;
+import net.javacrumbs.shedlock.core.LockConfiguration;
+import net.javacrumbs.shedlock.test.support.jdbc.PostgresConfig;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.springframework.jdbc.core.JdbcTemplate;
public class PostgresJdbcTemplateLockProviderIntegrationTest extends AbstractJdbcTemplateLockProviderIntegrationTest {
private static final PostgresConfig dbConfig = new PostgresConfig();
@@ -59,24 +56,23 @@ void shouldHonorTimezone() {
TimeZone originalTimezone = TimeZone.getDefault();
-
DataSource datasource = dbConfig.getDataSource();
TimeZone.setDefault(timezone);
try {
JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
- jdbcTemplate.execute("CREATE TABLE shedlock_tz(name VARCHAR(64), lock_until TIMESTAMP WITH TIME ZONE, locked_at TIMESTAMP WITH TIME ZONE, locked_by VARCHAR(255), PRIMARY KEY (name))");
+ jdbcTemplate.execute(
+ "CREATE TABLE shedlock_tz(name VARCHAR(64), lock_until TIMESTAMP WITH TIME ZONE, locked_at TIMESTAMP WITH TIME ZONE, locked_by VARCHAR(255), PRIMARY KEY (name))");
JdbcTemplateLockProvider provider = new JdbcTemplateLockProvider(builder()
- .withJdbcTemplate(new JdbcTemplate(datasource))
- .withTableName("shedlock_tz")
- .withTimeZone(timezone)
- .withIsolationLevel(Connection.TRANSACTION_SERIALIZABLE)
- .build());
+ .withJdbcTemplate(new JdbcTemplate(datasource))
+ .withTableName("shedlock_tz")
+ .withTimeZone(timezone)
+ .withIsolationLevel(Connection.TRANSACTION_SERIALIZABLE)
+ .build());
-
- provider.lock(new LockConfiguration(now, "timezone_test",Duration.ofSeconds(10), Duration.ZERO));
+ provider.lock(new LockConfiguration(now, "timezone_test", Duration.ofSeconds(10), Duration.ZERO));
new JdbcTemplate(datasource).query("SELECT * FROM shedlock_tz where name='timezone_test'", rs -> {
Timestamp timestamp = rs.getTimestamp("lock_until");
assertThat(timestamp.getTimezoneOffset()).isEqualTo(7 * 60);
@@ -110,23 +106,21 @@ void shouldUpdateOnInsertAfterValidityOfPreviousEndedWhenUsingDbTime() throws In
private void shouldUpdateOnInsertAfterValidityOfPreviousEnded(boolean usingDbTime) throws InterruptedException {
JdbcTemplateStorageAccessor accessor = getAccessor(usingDbTime);
-
accessor.insertRecord(new LockConfiguration(now(), OTHER_LOCK, Duration.ofSeconds(5), Duration.ZERO));
Timestamp otherLockValidity = getTestUtils().getLockedUntil(OTHER_LOCK);
- assertThat(
- accessor.insertRecord(new LockConfiguration(now(), MY_LOCK, Duration.ofMillis(10), Duration.ZERO))
- ).isEqualTo(true);
+ assertThat(accessor.insertRecord(
+ new LockConfiguration(now(), MY_LOCK, Duration.ofMillis(10), Duration.ZERO)))
+ .isEqualTo(true);
sleep(10);
- assertThat(
- accessor.insertRecord(new LockConfiguration(now(), MY_LOCK, Duration.ofMillis(10), Duration.ZERO))
- ).isEqualTo(true);
+ assertThat(accessor.insertRecord(
+ new LockConfiguration(now(), MY_LOCK, Duration.ofMillis(10), Duration.ZERO)))
+ .isEqualTo(true);
// check that the other lock has not been affected by "my-lock" update
assertThat(getTestUtils().getLockedUntil(OTHER_LOCK)).isEqualTo(otherLockValidity);
}
}
-
}
diff --git a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/PostgresSerializableJdbcTemplateLockProviderIntegrationTest.java b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/PostgresSerializableJdbcTemplateLockProviderIntegrationTest.java
index ab854464c..cc6e09de2 100644
--- a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/PostgresSerializableJdbcTemplateLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/PostgresSerializableJdbcTemplateLockProviderIntegrationTest.java
@@ -1,20 +1,21 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
+import static net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.Configuration.builder;
+
+import java.sql.Connection;
import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
import net.javacrumbs.shedlock.test.support.jdbc.AbstractJdbcLockProviderIntegrationTest;
import net.javacrumbs.shedlock.test.support.jdbc.DbConfig;
@@ -23,11 +24,8 @@
import org.junit.jupiter.api.BeforeAll;
import org.springframework.jdbc.core.JdbcTemplate;
-import java.sql.Connection;
-
-import static net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.Configuration.builder;
-
-public class PostgresSerializableJdbcTemplateLockProviderIntegrationTest extends AbstractJdbcLockProviderIntegrationTest {
+public class PostgresSerializableJdbcTemplateLockProviderIntegrationTest
+ extends AbstractJdbcLockProviderIntegrationTest {
private static final PostgresConfig dbConfig = new PostgresConfig();
@BeforeAll
@@ -53,9 +51,7 @@ protected boolean useDbTime() {
@Override
protected StorageBasedLockProvider getLockProvider() {
- return new JdbcTemplateLockProvider(builder()
- .withJdbcTemplate(new JdbcTemplate(getDatasource()))
- .build()
- );
+ return new JdbcTemplateLockProvider(
+ builder().withJdbcTemplate(new JdbcTemplate(getDatasource())).build());
}
}
diff --git a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/ServerTimeTest.java b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/ServerTimeTest.java
index 96fd23509..3b094d8b0 100644
--- a/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/ServerTimeTest.java
+++ b/providers/jdbc/shedlock-provider-jdbc-template/src/test/java/net/javacrumbs/shedlock/provider/jdbctemplate/ServerTimeTest.java
@@ -1,34 +1,31 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbctemplate;
-import net.javacrumbs.shedlock.core.LockConfiguration;
-import net.javacrumbs.shedlock.core.SimpleLock;
-import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
-import net.javacrumbs.shedlock.test.support.jdbc.JdbcTestUtils;
-import org.junit.jupiter.api.Test;
+import static net.javacrumbs.shedlock.core.ClockProvider.now;
+import static org.assertj.core.api.Assertions.assertThat;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Optional;
-
-import static net.javacrumbs.shedlock.core.ClockProvider.now;
-import static org.assertj.core.api.Assertions.assertThat;
+import net.javacrumbs.shedlock.core.LockConfiguration;
+import net.javacrumbs.shedlock.core.SimpleLock;
+import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
+import net.javacrumbs.shedlock.test.support.jdbc.JdbcTestUtils;
+import org.junit.jupiter.api.Test;
public interface ServerTimeTest {
@@ -41,16 +38,20 @@ public interface ServerTimeTest {
@Test
default void lockUntilShouldBeInUtc() {
Instant time = Instant.now();
- Optional Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbc;
-import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
-
import javax.sql.DataSource;
+import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
/**
- * Lock provided by plain JDBC. It uses a table that contains lock_name and locked_until.
+ * Lock provided by plain JDBC. It uses a table that contains lock_name and
+ * locked_until.
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbc;
-import net.javacrumbs.shedlock.provider.jdbc.internal.AbstractJdbcStorageAccessor;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
+import static java.util.Objects.requireNonNull;
-import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.function.BiFunction;
-
-import static java.util.Objects.requireNonNull;
+import javax.sql.DataSource;
+import net.javacrumbs.shedlock.provider.jdbc.internal.AbstractJdbcStorageAccessor;
class JdbcStorageAccessor extends AbstractJdbcStorageAccessor {
private final DataSource dataSource;
- JdbcStorageAccessor(@NonNull DataSource dataSource, @NonNull String tableName) {
+ JdbcStorageAccessor(DataSource dataSource, String tableName) {
super(tableName);
this.dataSource = requireNonNull(dataSource, "dataSource can not be null");
}
@Override
protected Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbc;
diff --git a/providers/jdbc/shedlock-provider-jdbc/src/test/java/net/javacrumbs/shedlock/provider/jdbc/MySqlJdbcLockProviderIntegrationTest.java b/providers/jdbc/shedlock-provider-jdbc/src/test/java/net/javacrumbs/shedlock/provider/jdbc/MySqlJdbcLockProviderIntegrationTest.java
index c8f58a5be..aece61ba0 100644
--- a/providers/jdbc/shedlock-provider-jdbc/src/test/java/net/javacrumbs/shedlock/provider/jdbc/MySqlJdbcLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-provider-jdbc/src/test/java/net/javacrumbs/shedlock/provider/jdbc/MySqlJdbcLockProviderIntegrationTest.java
@@ -1,16 +1,14 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbc;
diff --git a/providers/jdbc/shedlock-provider-jdbc/src/test/java/net/javacrumbs/shedlock/provider/jdbc/PostgresJdbcLockProviderIntegrationTest.java b/providers/jdbc/shedlock-provider-jdbc/src/test/java/net/javacrumbs/shedlock/provider/jdbc/PostgresJdbcLockProviderIntegrationTest.java
index 6bf9c94d4..e2e08a993 100644
--- a/providers/jdbc/shedlock-provider-jdbc/src/test/java/net/javacrumbs/shedlock/provider/jdbc/PostgresJdbcLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-provider-jdbc/src/test/java/net/javacrumbs/shedlock/provider/jdbc/PostgresJdbcLockProviderIntegrationTest.java
@@ -1,16 +1,14 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jdbc;
diff --git a/providers/jdbc/shedlock-provider-jooq/pom.xml b/providers/jdbc/shedlock-provider-jooq/pom.xml
index 363e5d75b..f5ba05f23 100644
--- a/providers/jdbc/shedlock-provider-jooq/pom.xml
+++ b/providers/jdbc/shedlock-provider-jooq/pom.xml
@@ -3,13 +3,13 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jooq;
import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
import org.jooq.DSLContext;
-
public class JooqLockProvider extends StorageBasedLockProvider {
- public JooqLockProvider(@NonNull DSLContext dslContext) {
+ public JooqLockProvider(DSLContext dslContext) {
super(new JooqStorageAccessor(dslContext));
}
}
diff --git a/providers/jdbc/shedlock-provider-jooq/src/main/java/net/javacrumbs/shedlock/provider/jooq/JooqStorageAccessor.java b/providers/jdbc/shedlock-provider-jooq/src/main/java/net/javacrumbs/shedlock/provider/jooq/JooqStorageAccessor.java
index 4d7649d5c..5c1d5acb9 100644
--- a/providers/jdbc/shedlock-provider-jooq/src/main/java/net/javacrumbs/shedlock/provider/jooq/JooqStorageAccessor.java
+++ b/providers/jdbc/shedlock-provider-jooq/src/main/java/net/javacrumbs/shedlock/provider/jooq/JooqStorageAccessor.java
@@ -1,25 +1,23 @@
package net.javacrumbs.shedlock.provider.jooq;
+import static net.javacrumbs.shedlock.provider.jooq.Shedlock.SHEDLOCK;
+import static org.jooq.impl.DSL.currentLocalDateTime;
+import static org.jooq.impl.DSL.inline;
+import static org.jooq.impl.DSL.localDateTimeAdd;
+import static org.jooq.impl.DSL.when;
+
+import java.io.Serializable;
+import java.time.Duration;
+import java.time.LocalDateTime;
+import java.util.Map;
import net.javacrumbs.shedlock.core.LockConfiguration;
import net.javacrumbs.shedlock.support.AbstractStorageAccessor;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
import org.jooq.DSLContext;
import org.jooq.Field;
import org.jooq.Record;
import org.jooq.TableField;
import org.jooq.types.DayToSecond;
-import java.io.Serializable;
-import java.time.Duration;
-import java.time.LocalDateTime;
-import java.util.Map;
-
-import static net.javacrumbs.shedlock.provider.jooq.Shedlock.SHEDLOCK;
-import static org.jooq.impl.DSL.currentLocalDateTime;
-import static org.jooq.impl.DSL.inline;
-import static org.jooq.impl.DSL.localDateTimeAdd;
-import static org.jooq.impl.DSL.when;
-
class JooqStorageAccessor extends AbstractStorageAccessor {
private final DSLContext dslContext;
private final Shedlock t = SHEDLOCK;
@@ -29,44 +27,61 @@ class JooqStorageAccessor extends AbstractStorageAccessor {
}
@Override
- public boolean insertRecord(@NonNull LockConfiguration lockConfiguration) {
- return dslContext.transactionResult(tx -> tx.dsl().insertInto(t)
- .set(data(lockConfiguration))
- .onConflictDoNothing()
- .execute() > 0);
+ public boolean insertRecord(LockConfiguration lockConfiguration) {
+ return dslContext.transactionResult(tx -> tx.dsl()
+ .insertInto(t)
+ .set(data(lockConfiguration))
+ .onConflictDoNothing()
+ .execute()
+ > 0);
}
@Override
- public boolean updateRecord(@NonNull LockConfiguration lockConfiguration) {
- return dslContext.transactionResult(tx -> tx.dsl().update(t)
- .set(data(lockConfiguration))
- .where(t.NAME.eq(lockConfiguration.getName()).and(t.LOCK_UNTIL.le(now())))
- .execute() > 0);
+ public boolean updateRecord(LockConfiguration lockConfiguration) {
+ return dslContext.transactionResult(tx -> tx.dsl()
+ .update(t)
+ .set(data(lockConfiguration))
+ .where(t.NAME.eq(lockConfiguration.getName()).and(t.LOCK_UNTIL.le(now())))
+ .execute()
+ > 0);
}
@Override
public void unlock(LockConfiguration lockConfiguration) {
- Field
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jooq;
+import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
+
import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
import net.javacrumbs.shedlock.test.support.jdbc.AbstractJdbcLockProviderIntegrationTest;
import net.javacrumbs.shedlock.test.support.jdbc.DbConfig;
@@ -24,8 +24,6 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
-import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
-
@TestInstance(PER_CLASS)
public abstract class AbstractJooqLockProviderIntegrationTest extends AbstractJdbcLockProviderIntegrationTest {
private final DbConfig dbConfig;
@@ -52,7 +50,6 @@ protected boolean useDbTime() {
return true;
}
-
@BeforeAll
public void startDb() {
dbConfig.startDb();
@@ -63,5 +60,3 @@ public void shutdownDb() {
dbConfig.shutdownDb();
}
}
-
-
diff --git a/providers/jdbc/shedlock-provider-jooq/src/test/java/net/javacrumbs/shedlock/provider/jooq/HsqlJooqLockProviderIntegrationTest.java b/providers/jdbc/shedlock-provider-jooq/src/test/java/net/javacrumbs/shedlock/provider/jooq/HsqlJooqLockProviderIntegrationTest.java
index 274b22bf7..ee1337f3a 100644
--- a/providers/jdbc/shedlock-provider-jooq/src/test/java/net/javacrumbs/shedlock/provider/jooq/HsqlJooqLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-provider-jooq/src/test/java/net/javacrumbs/shedlock/provider/jooq/HsqlJooqLockProviderIntegrationTest.java
@@ -1,16 +1,14 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jooq;
@@ -26,6 +24,11 @@ public class HsqlJooqLockProviderIntegrationTest extends AbstractJooqLockProvide
private static final DbConfig dbConfig = new HsqlConfig();
public HsqlJooqLockProviderIntegrationTest() {
- super(dbConfig, DSL.using(dbConfig.getDataSource(), SQLDialect.HSQLDB, new Settings().withRenderNameCase(RenderNameCase.UPPER)));
+ super(
+ dbConfig,
+ DSL.using(
+ dbConfig.getDataSource(),
+ SQLDialect.HSQLDB,
+ new Settings().withRenderNameCase(RenderNameCase.UPPER)));
}
}
diff --git a/providers/jdbc/shedlock-provider-jooq/src/test/java/net/javacrumbs/shedlock/provider/jooq/MariaDbJooqLockProviderIntegrationTest.java b/providers/jdbc/shedlock-provider-jooq/src/test/java/net/javacrumbs/shedlock/provider/jooq/MariaDbJooqLockProviderIntegrationTest.java
index db7f79930..13f9cc875 100644
--- a/providers/jdbc/shedlock-provider-jooq/src/test/java/net/javacrumbs/shedlock/provider/jooq/MariaDbJooqLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-provider-jooq/src/test/java/net/javacrumbs/shedlock/provider/jooq/MariaDbJooqLockProviderIntegrationTest.java
@@ -1,16 +1,14 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jooq;
diff --git a/providers/jdbc/shedlock-provider-jooq/src/test/java/net/javacrumbs/shedlock/provider/jooq/MySqlJooqLockProviderIntegrationTest.java b/providers/jdbc/shedlock-provider-jooq/src/test/java/net/javacrumbs/shedlock/provider/jooq/MySqlJooqLockProviderIntegrationTest.java
index 8f8e08f50..e9ce09a25 100644
--- a/providers/jdbc/shedlock-provider-jooq/src/test/java/net/javacrumbs/shedlock/provider/jooq/MySqlJooqLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-provider-jooq/src/test/java/net/javacrumbs/shedlock/provider/jooq/MySqlJooqLockProviderIntegrationTest.java
@@ -1,16 +1,14 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jooq;
diff --git a/providers/jdbc/shedlock-provider-jooq/src/test/java/net/javacrumbs/shedlock/provider/jooq/PostgresJooqLockProviderIntegrationTest.java b/providers/jdbc/shedlock-provider-jooq/src/test/java/net/javacrumbs/shedlock/provider/jooq/PostgresJooqLockProviderIntegrationTest.java
index 7770781c1..f010e6d6b 100644
--- a/providers/jdbc/shedlock-provider-jooq/src/test/java/net/javacrumbs/shedlock/provider/jooq/PostgresJooqLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-provider-jooq/src/test/java/net/javacrumbs/shedlock/provider/jooq/PostgresJooqLockProviderIntegrationTest.java
@@ -1,16 +1,14 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.jooq;
diff --git a/providers/jdbc/shedlock-provider-jooq/src/test/resources/logback-test.xml b/providers/jdbc/shedlock-provider-jooq/src/test/resources/logback-test.xml
new file mode 100644
index 000000000..c64bdcd7e
--- /dev/null
+++ b/providers/jdbc/shedlock-provider-jooq/src/test/resources/logback-test.xml
@@ -0,0 +1,14 @@
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.test.support.jdbc;
@@ -24,8 +22,7 @@ abstract class AbstractContainerBasedDbConfig Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.test.support.jdbc;
import com.zaxxer.hikari.HikariDataSource;
-
import javax.sql.DataSource;
+import net.javacrumbs.shedlock.support.annotation.Nullable;
abstract class AbstractDbConfig implements DbConfig {
+ @Nullable
private HikariDataSource dataSource;
protected static final String TEST_SCHEMA_NAME = "shedlock_test";
+
+ @Nullable
private Integer transactionIsolation;
@Override
@@ -46,9 +47,7 @@ public final void startDb() {
dataSource = newDataSource;
}
- protected void doStartDb() {
-
- }
+ protected void doStartDb() {}
@Override
public final void shutdownDb() {
@@ -56,9 +55,7 @@ public final void shutdownDb() {
doShutdownDb();
}
- protected void doShutdownDb() {
-
- }
+ protected void doShutdownDb() {}
public void setTransactionIsolation(int transactionIsolation) {
this.transactionIsolation = transactionIsolation;
diff --git a/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/AbstractJdbcLockProviderIntegrationTest.java b/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/AbstractJdbcLockProviderIntegrationTest.java
index f6b3ce579..d2dcfcc7f 100644
--- a/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/AbstractJdbcLockProviderIntegrationTest.java
+++ b/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/AbstractJdbcLockProviderIntegrationTest.java
@@ -1,20 +1,26 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.test.support.jdbc;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.sql.Timestamp;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
+import javax.sql.DataSource;
import net.javacrumbs.shedlock.core.ClockProvider;
import net.javacrumbs.shedlock.core.LockConfiguration;
import net.javacrumbs.shedlock.core.SimpleLock;
@@ -24,15 +30,6 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
-import javax.sql.DataSource;
-import java.sql.Timestamp;
-import java.time.Instant;
-import java.time.temporal.ChronoUnit;
-import java.util.Optional;
-import java.util.concurrent.ExecutionException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
public abstract class AbstractJdbcLockProviderIntegrationTest extends AbstractStorageBasedLockProviderIntegrationTest {
protected JdbcTestUtils testUtils;
@@ -53,22 +50,33 @@ public void cleanup() {
@Override
protected void assertUnlocked(String lockName) {
JdbcTestUtils.LockInfo lockInfo = getLockInfo(lockName);
- Instant now = useDbTime() ? lockInfo.getDbTime(): ClockProvider.now();
- assertThat(lockInfo.getLockUntil()).describedAs("is unlocked").isBeforeOrEqualTo(now.truncatedTo(ChronoUnit.MILLIS).plusMillis(1));
+ Instant now = useDbTime() ? lockInfo.getDbTime() : ClockProvider.now();
+ assertThat(lockInfo.getLockUntil())
+ .describedAs("is unlocked")
+ .isBeforeOrEqualTo(now.truncatedTo(ChronoUnit.MILLIS).plusMillis(1));
}
@Override
protected void assertLocked(String lockName) {
JdbcTestUtils.LockInfo lockInfo = getLockInfo(lockName);
- Instant now = useDbTime() ? lockInfo.getDbTime(): ClockProvider.now();
+ Instant now = useDbTime() ? lockInfo.getDbTime() : ClockProvider.now();
- assertThat(lockInfo.getLockUntil()).describedAs(getClass().getName() + " is locked").isAfter(now);
+ assertThat(lockInfo.getLockUntil())
+ .describedAs(getClass().getName() + " is locked")
+ .isAfter(now);
}
@Test
public void shouldCreateLockIfRecordAlreadyExists() {
Timestamp previousLockTime = Timestamp.from(Instant.now().minus(1, ChronoUnit.DAYS));
- testUtils.getJdbcTemplate().update("INSERT INTO shedlock(name, lock_until, locked_at, locked_by) VALUES(?, ?, ?, ?)", LOCK_NAME1, previousLockTime, previousLockTime, "me");
+ testUtils
+ .getJdbcTemplate()
+ .update(
+ "INSERT INTO shedlock(name, lock_until, locked_at, locked_by) VALUES(?, ?, ?, ?)",
+ LOCK_NAME1,
+ previousLockTime,
+ previousLockTime,
+ "me");
assertUnlocked(LOCK_NAME1);
shouldCreateLock();
}
@@ -81,7 +89,8 @@ public void fuzzTestShouldWorkWithTransaction() throws ExecutionException, Inter
@Test
@Disabled
public void shouldNotFailIfKeyNameTooLong() {
- LockConfiguration configuration = lockConfig("lock name that is too long Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
+ LockConfiguration configuration = lockConfig(
+ "lock name that is too long Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
Optional Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.test.support.jdbc;
@@ -18,6 +16,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.Db2Container;
+import org.testcontainers.utility.DockerImageName;
public final class Db2ServerConfig extends AbstractDbConfig {
@@ -26,9 +25,9 @@ public final class Db2ServerConfig extends AbstractDbConfig {
@Override
protected void doStartDb() {
- db2 = new Db2Container()
- .acceptLicense()
- .withLogConsumer(outputFrame -> logger.debug(outputFrame.getUtf8String()));
+ db2 = new Db2Container(DockerImageName.parse("icr.io/db2_community/db2"))
+ .acceptLicense()
+ .withLogConsumer(outputFrame -> logger.debug(outputFrame.getUtf8String()));
db2.start();
}
@@ -40,7 +39,6 @@ protected void doShutdownDb() {
@Override
public String getJdbcUrl() {
return db2.getJdbcUrl();
-
}
@Override
diff --git a/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/DbConfig.java b/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/DbConfig.java
index 964722220..2926b610b 100644
--- a/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/DbConfig.java
+++ b/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/DbConfig.java
@@ -1,16 +1,14 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.test.support.jdbc;
diff --git a/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/H2Config.java b/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/H2Config.java
index cd0b73b38..5f744ed17 100644
--- a/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/H2Config.java
+++ b/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/H2Config.java
@@ -1,16 +1,14 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.test.support.jdbc;
diff --git a/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/HsqlConfig.java b/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/HsqlConfig.java
index 86e7db460..565cb2037 100644
--- a/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/HsqlConfig.java
+++ b/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/HsqlConfig.java
@@ -1,16 +1,14 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.test.support.jdbc;
diff --git a/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/JdbcTestUtils.java b/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/JdbcTestUtils.java
index 834c05ede..8b9998b13 100644
--- a/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/JdbcTestUtils.java
+++ b/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/JdbcTestUtils.java
@@ -1,25 +1,22 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.test.support.jdbc;
-import org.springframework.jdbc.core.JdbcTemplate;
-
-import javax.sql.DataSource;
import java.sql.Timestamp;
import java.time.Instant;
+import javax.sql.DataSource;
+import org.springframework.jdbc.core.JdbcTemplate;
public final class JdbcTestUtils {
@@ -38,11 +35,16 @@ public Timestamp getLockedUntil(String lockName) {
}
public LockInfo getLockInfo(String lockName) {
- return jdbcTemplate.query("SELECT name, lock_until, " + dbConfig.nowExpression() + " as db_time FROM shedlock WHERE name = ?", (rs, rowNum) -> new LockInfo(
- rs.getString("name"),
- rs.getTimestamp("lock_until").toInstant(),
- rs.getTimestamp("db_time").toInstant()
- ), lockName).get(0);
+ return jdbcTemplate
+ .query(
+ "SELECT name, lock_until, " + dbConfig.nowExpression()
+ + " as db_time FROM shedlock WHERE name = ?",
+ (rs, rowNum) -> new LockInfo(
+ rs.getString("name"),
+ rs.getTimestamp("lock_until").toInstant(),
+ rs.getTimestamp("db_time").toInstant()),
+ lockName)
+ .get(0);
}
public void clean() {
@@ -82,11 +84,7 @@ public Instant getDbTime() {
@Override
public String toString() {
- return "LockInfo{" +
- "name='" + name + '\'' +
- ", lockUntil=" + lockUntil +
- ", dbTime=" + dbTime +
- '}';
+ return "LockInfo{" + "name='" + name + '\'' + ", lockUntil=" + lockUntil + ", dbTime=" + dbTime + '}';
}
}
}
diff --git a/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/MariaDbConfig.java b/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/MariaDbConfig.java
index 3edd63d40..cc14a35d4 100644
--- a/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/MariaDbConfig.java
+++ b/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/MariaDbConfig.java
@@ -1,16 +1,14 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.test.support.jdbc;
@@ -20,10 +18,9 @@
public class MariaDbConfig extends AbstractContainerBasedDbConfig Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.test.support.jdbc;
+import static org.testcontainers.containers.MSSQLServerContainer.MS_SQL_SERVER_PORT;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.MSSQLServerContainer;
-import static org.testcontainers.containers.MSSQLServerContainer.MS_SQL_SERVER_PORT;
-
public final class MsSqlServerConfig extends AbstractContainerBasedDbConfig Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.test.support.jdbc;
@@ -20,10 +18,10 @@
public class MySqlConfig extends AbstractContainerBasedDbConfig Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.test.support.jdbc;
@@ -19,7 +17,7 @@
public final class OracleServerConfig extends AbstractContainerBasedDbConfig Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.test.support.jdbc;
@@ -20,9 +18,9 @@
public class PostgresConfig extends AbstractContainerBasedDbConfig Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.test.support.jdbc;
+import java.util.concurrent.ExecutionException;
+import javax.sql.DataSource;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.test.support.FuzzTester;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;
-import javax.sql.DataSource;
-import java.util.concurrent.ExecutionException;
-
public class TransactionalFuzzTester {
- public static void fuzzTestShouldWorkWithTransaction(LockProvider lockProvider, DataSource dataSource) throws ExecutionException, InterruptedException {
+ public static void fuzzTestShouldWorkWithTransaction(LockProvider lockProvider, DataSource dataSource)
+ throws ExecutionException, InterruptedException {
new FuzzTester(lockProvider) {
@Override
protected Void task(int iterations, Job job) {
- TransactionTemplate transactionTemplate = new TransactionTemplate(new DataSourceTransactionManager(dataSource));
+ TransactionTemplate transactionTemplate =
+ new TransactionTemplate(new DataSourceTransactionManager(dataSource));
return transactionTemplate.execute(status -> super.task(iterations, job));
}
diff --git a/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/package-info.java b/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/package-info.java
new file mode 100644
index 000000000..06ee0e2d5
--- /dev/null
+++ b/providers/jdbc/shedlock-test-support-jdbc/src/main/java/net/javacrumbs/shedlock/test/support/jdbc/package-info.java
@@ -0,0 +1,6 @@
+@NonNullApi
+@NonNullFields
+package net.javacrumbs.shedlock.test.support.jdbc;
+
+import net.javacrumbs.shedlock.support.annotation.NonNullApi;
+import net.javacrumbs.shedlock.support.annotation.NonNullFields;
diff --git a/providers/memcached/shedlock-provider-memcached-spy/pom.xml b/providers/memcached/shedlock-provider-memcached-spy/pom.xml
index 85d104563..4c8be27f6 100644
--- a/providers/memcached/shedlock-provider-memcached-spy/pom.xml
+++ b/providers/memcached/shedlock-provider-memcached-spy/pom.xml
@@ -3,13 +3,13 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.mongo.reactivestreams;
+import static com.mongodb.client.model.Filters.and;
+import static com.mongodb.client.model.Filters.eq;
+import static com.mongodb.client.model.Filters.gt;
+import static com.mongodb.client.model.Filters.lte;
+import static com.mongodb.client.model.Updates.combine;
+import static com.mongodb.client.model.Updates.set;
+
import com.mongodb.MongoServerException;
import com.mongodb.client.model.FindOneAndUpdateOptions;
import com.mongodb.reactivestreams.client.MongoCollection;
import com.mongodb.reactivestreams.client.MongoDatabase;
+import java.time.Instant;
+import java.util.Optional;
import net.javacrumbs.shedlock.core.AbstractSimpleLock;
import net.javacrumbs.shedlock.core.ClockProvider;
import net.javacrumbs.shedlock.core.ExtensibleLockProvider;
@@ -26,24 +33,18 @@
import net.javacrumbs.shedlock.core.SimpleLock;
import net.javacrumbs.shedlock.support.LockException;
import net.javacrumbs.shedlock.support.Utils;
+import net.javacrumbs.shedlock.support.annotation.Nullable;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.reactivestreams.Publisher;
-import java.time.Instant;
-import java.util.Optional;
-
-import static com.mongodb.client.model.Filters.and;
-import static com.mongodb.client.model.Filters.eq;
-import static com.mongodb.client.model.Filters.gt;
-import static com.mongodb.client.model.Filters.lte;
-import static com.mongodb.client.model.Updates.combine;
-import static com.mongodb.client.model.Updates.set;
-
/**
- * Distributed lock using Reactive MongoDB. Requires mongodb-driver-reactivestreams
+ * Distributed lock using Reactive MongoDB. Requires
+ * mongodb-driver-reactivestreams
+ *
*
* It uses a collection that contains documents like this:
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.mongo.reactivestreams;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
import net.javacrumbs.shedlock.support.annotation.Nullable;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
/**
- * Subscriber that expects a single result and allows locking until complete or error
+ * Subscriber that expects a single result and allows locking until complete or
+ * error
*
* @param Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.mongo.reactivestreams;
+import static com.mongodb.client.model.Filters.eq;
+import static net.javacrumbs.shedlock.provider.mongo.reactivestreams.ReactiveStreamsMongoLockProvider.DEFAULT_SHEDLOCK_COLLECTION_NAME;
+import static net.javacrumbs.shedlock.provider.mongo.reactivestreams.ReactiveStreamsMongoLockProvider.ID;
+import static net.javacrumbs.shedlock.provider.mongo.reactivestreams.ReactiveStreamsMongoLockProvider.LOCKED_AT;
+import static net.javacrumbs.shedlock.provider.mongo.reactivestreams.ReactiveStreamsMongoLockProvider.LOCKED_BY;
+import static net.javacrumbs.shedlock.provider.mongo.reactivestreams.ReactiveStreamsMongoLockProvider.LOCK_UNTIL;
+import static net.javacrumbs.shedlock.provider.mongo.reactivestreams.ReactiveStreamsMongoLockProvider.execute;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assumptions.assumeThat;
+
import com.mongodb.client.result.DeleteResult;
import com.mongodb.reactivestreams.client.MongoClient;
import com.mongodb.reactivestreams.client.MongoClients;
import com.mongodb.reactivestreams.client.MongoCollection;
-import de.flapdoodle.embed.mongo.MongodExecutable;
-import de.flapdoodle.embed.mongo.MongodProcess;
-import de.flapdoodle.embed.mongo.MongodStarter;
-import de.flapdoodle.embed.mongo.config.MongodConfig;
-import de.flapdoodle.embed.mongo.distribution.Version;
+import java.util.Date;
import net.javacrumbs.shedlock.core.ExtensibleLockProvider;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.test.support.AbstractExtensibleLockProviderIntegrationTest;
@@ -32,48 +36,29 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.testcontainers.containers.MongoDBContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
-import java.io.IOException;
-import java.util.Date;
-
-import static com.mongodb.client.model.Filters.eq;
-import static net.javacrumbs.shedlock.provider.mongo.reactivestreams.ReactiveStreamsMongoLockProvider.DEFAULT_SHEDLOCK_COLLECTION_NAME;
-import static net.javacrumbs.shedlock.provider.mongo.reactivestreams.ReactiveStreamsMongoLockProvider.ID;
-import static net.javacrumbs.shedlock.provider.mongo.reactivestreams.ReactiveStreamsMongoLockProvider.LOCKED_AT;
-import static net.javacrumbs.shedlock.provider.mongo.reactivestreams.ReactiveStreamsMongoLockProvider.LOCKED_BY;
-import static net.javacrumbs.shedlock.provider.mongo.reactivestreams.ReactiveStreamsMongoLockProvider.LOCK_UNTIL;
-import static net.javacrumbs.shedlock.provider.mongo.reactivestreams.ReactiveStreamsMongoLockProvider.execute;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assumptions.assumeThat;
-
+@Testcontainers
public class ReactiveStreamsMongoLockProviderIntegrationTest extends AbstractExtensibleLockProviderIntegrationTest {
- private static final MongodStarter starter = MongodStarter.getDefaultInstance();
-
private static final String DB_NAME = "db";
- private static MongodExecutable mongodExe;
- private static MongodProcess mongod;
+ @Container
+ public static final MongoDBContainer container = new MongoDBContainer("mongo:6");
private static MongoClient mongo;
@BeforeAll
- public static void startMongo() throws IOException {
- mongodExe = starter.prepare(MongodConfig.builder()
- .version(Version.Main.V3_6)
- .build());
- mongod = mongodExe.start();
-
- mongo = MongoClients.create("mongodb://localhost:" + mongod.getConfig().net().getPort());
+ public static void startMongo() {
+ mongo = MongoClients.create("mongodb://" + container.getHost() + ":" + container.getFirstMappedPort());
}
@AfterAll
public static void stopMongo() {
mongo.close();
- mongod.stop();
- mongodExe.stop();
}
-
@BeforeEach
public void cleanDb() {
execute(mongo.getDatabase(DB_NAME).drop());
@@ -87,8 +72,8 @@ protected ExtensibleLockProvider getLockProvider() {
@Override
protected void assertUnlocked(String lockName) {
Document lockDocument = getLockDocument(lockName);
- assertThat((Date) lockDocument.get(LOCK_UNTIL)).isBeforeOrEqualsTo(now());
- assertThat((Date) lockDocument.get(LOCKED_AT)).isBeforeOrEqualsTo(now());
+ assertThat((Date) lockDocument.get(LOCK_UNTIL)).isBeforeOrEqualTo(now());
+ assertThat((Date) lockDocument.get(LOCKED_AT)).isBeforeOrEqualTo(now());
assertThat((String) lockDocument.get(LOCKED_BY)).isNotEmpty();
}
@@ -100,7 +85,7 @@ private Date now() {
protected void assertLocked(String lockName) {
Document lockDocument = getLockDocument(lockName);
assertThat((Date) lockDocument.get(LOCK_UNTIL)).isAfter(now());
- assertThat((Date) lockDocument.get(LOCKED_AT)).isBeforeOrEqualsTo(now());
+ assertThat((Date) lockDocument.get(LOCKED_AT)).isBeforeOrEqualTo(now());
assertThat((String) lockDocument.get(LOCKED_BY)).isNotEmpty();
}
diff --git a/providers/mongo/shedlock-provider-mongo/pom.xml b/providers/mongo/shedlock-provider-mongo/pom.xml
index 38a5b51cc..7617358aa 100644
--- a/providers/mongo/shedlock-provider-mongo/pom.xml
+++ b/providers/mongo/shedlock-provider-mongo/pom.xml
@@ -3,13 +3,13 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.mongo;
+import static com.mongodb.client.model.Filters.and;
+import static com.mongodb.client.model.Filters.eq;
+import static com.mongodb.client.model.Filters.gt;
+import static com.mongodb.client.model.Filters.lte;
+import static com.mongodb.client.model.Updates.combine;
+import static com.mongodb.client.model.Updates.set;
+
import com.mongodb.MongoServerException;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.FindOneAndUpdateOptions;
+import java.time.Instant;
+import java.util.Optional;
import net.javacrumbs.shedlock.core.AbstractSimpleLock;
import net.javacrumbs.shedlock.core.ClockProvider;
import net.javacrumbs.shedlock.core.ExtensibleLockProvider;
@@ -28,20 +35,13 @@
import org.bson.Document;
import org.bson.conversions.Bson;
-import java.time.Instant;
-import java.util.Optional;
-
-import static com.mongodb.client.model.Filters.and;
-import static com.mongodb.client.model.Filters.eq;
-import static com.mongodb.client.model.Filters.gt;
-import static com.mongodb.client.model.Filters.lte;
-import static com.mongodb.client.model.Updates.combine;
-import static com.mongodb.client.model.Updates.set;
-
/**
- * Distributed lock using MongoDB >= 2.6. Requires mongo-java-driver > 3.4.0
+ * Distributed lock using MongoDB >= 2.6. Requires mongo-java-driver >
+ * 3.4.0
+ *
*
* It uses a collection that contains documents like this:
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.mongo;
+import static com.mongodb.client.model.Filters.eq;
+import static net.javacrumbs.shedlock.provider.mongo.MongoLockProvider.DEFAULT_SHEDLOCK_COLLECTION_NAME;
+import static net.javacrumbs.shedlock.provider.mongo.MongoLockProvider.ID;
+import static net.javacrumbs.shedlock.provider.mongo.MongoLockProvider.LOCKED_AT;
+import static net.javacrumbs.shedlock.provider.mongo.MongoLockProvider.LOCKED_BY;
+import static net.javacrumbs.shedlock.provider.mongo.MongoLockProvider.LOCK_UNTIL;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assumptions.assumeThat;
+
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.result.DeleteResult;
-import de.flapdoodle.embed.mongo.MongodExecutable;
-import de.flapdoodle.embed.mongo.MongodProcess;
-import de.flapdoodle.embed.mongo.MongodStarter;
-import de.flapdoodle.embed.mongo.config.MongodConfig;
-import de.flapdoodle.embed.mongo.distribution.Version;
+import java.util.Date;
import net.javacrumbs.shedlock.core.ExtensibleLockProvider;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.test.support.AbstractExtensibleLockProviderIntegrationTest;
@@ -32,55 +35,38 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.testcontainers.containers.MongoDBContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
-import java.io.IOException;
-import java.util.Date;
-
-import static com.mongodb.client.model.Filters.eq;
-import static net.javacrumbs.shedlock.provider.mongo.MongoLockProvider.DEFAULT_SHEDLOCK_COLLECTION_NAME;
-import static net.javacrumbs.shedlock.provider.mongo.MongoLockProvider.ID;
-import static net.javacrumbs.shedlock.provider.mongo.MongoLockProvider.LOCKED_AT;
-import static net.javacrumbs.shedlock.provider.mongo.MongoLockProvider.LOCKED_BY;
-import static net.javacrumbs.shedlock.provider.mongo.MongoLockProvider.LOCK_UNTIL;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assumptions.assumeThat;
-
+@Testcontainers
public class MongoLockProviderIntegrationTest extends AbstractExtensibleLockProviderIntegrationTest {
- private static final MongodStarter starter = MongodStarter.getDefaultInstance();
private static final String DB_NAME = "db";
- private static MongodExecutable mongodExe;
- private static MongodProcess mongod;
+ @Container
+ public static final MongoDBContainer container = new MongoDBContainer("mongo:6");
private static MongoClient mongo;
@BeforeAll
- public static void startMongo() throws IOException {
- mongodExe = starter.prepare(MongodConfig.builder()
- .version(Version.Main.V3_6)
- .build());
- mongod = mongodExe.start();
-
- mongo = MongoClients.create("mongodb://localhost:"+mongod.getConfig().net().getPort());
+ public static void startMongo() {
+ mongo = MongoClients.create("mongodb://" + container.getHost() + ":" + container.getFirstMappedPort());
}
@AfterAll
public static void stopMongo() {
mongo.close();
- mongod.stop();
- mongodExe.stop();
}
-
@BeforeEach
public void cleanDb() {
- mongo.getDatabase(DB_NAME).drop();
+ getMongo().getDatabase(DB_NAME).drop();
}
@Override
protected ExtensibleLockProvider getLockProvider() {
- return new MongoLockProvider(mongo.getDatabase(DB_NAME));
+ return new MongoLockProvider(getMongo().getDatabase(DB_NAME));
}
@Override
@@ -104,7 +90,7 @@ protected void assertLocked(String lockName) {
}
private MongoCollection Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.neo4j;
import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
import net.javacrumbs.shedlock.support.annotation.Nullable;
import org.neo4j.driver.Driver;
/**
- * Lock provided by Neo4j Graph API. It uses a collection that stores each lock as a node.
+ * Lock provided by Neo4j Graph API. It uses a collection that stores each lock
+ * as a node.
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.neo4j;
+import static java.util.Objects.requireNonNull;
+
+import java.util.Map;
+import java.util.function.BiFunction;
+import java.util.function.Function;
import net.javacrumbs.shedlock.core.ClockProvider;
import net.javacrumbs.shedlock.core.LockConfiguration;
import net.javacrumbs.shedlock.support.AbstractStorageAccessor;
import net.javacrumbs.shedlock.support.LockException;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
import net.javacrumbs.shedlock.support.annotation.Nullable;
import org.neo4j.driver.Driver;
import org.neo4j.driver.Result;
@@ -27,19 +29,14 @@
import org.neo4j.driver.SessionConfig;
import org.neo4j.driver.Transaction;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-
-import static java.util.Objects.requireNonNull;
-
class Neo4jStorageAccessor extends AbstractStorageAccessor {
private final String collectionName;
private final Driver driver;
+
+ @Nullable
private final String databaseName;
- public Neo4jStorageAccessor(@NonNull Driver driver, @NonNull String collectionName, @Nullable String databaseName) {
+ public Neo4jStorageAccessor(Driver driver, String collectionName, @Nullable String databaseName) {
this.collectionName = requireNonNull(collectionName, "collectionName can not be null");
this.driver = requireNonNull(driver, "driver can not be null");
this.databaseName = databaseName;
@@ -47,90 +44,106 @@ public Neo4jStorageAccessor(@NonNull Driver driver, @NonNull String collectionNa
}
private void createLockNameUniqueConstraint() {
- try (
- Session session = getSession();
- Transaction transaction = session.beginTransaction()
- ) {
- transaction.run(String.format("CREATE CONSTRAINT UNIQUE_%s_name IF NOT EXISTS ON (lock:%s) ASSERT lock.name IS UNIQUE", collectionName, collectionName));
+ try (Session session = getSession();
+ Transaction transaction = session.beginTransaction()) {
+ transaction.run(String.format(
+ "CREATE CONSTRAINT UNIQUE_%s_name IF NOT EXISTS FOR (lock:%s) REQUIRE lock.name IS UNIQUE",
+ collectionName, collectionName));
transaction.commit();
}
}
@Override
- public boolean insertRecord(@NonNull LockConfiguration lockConfiguration) {
+ public boolean insertRecord(LockConfiguration lockConfiguration) {
// Try to insert if the record does not exists
- String cypher = String.format("CREATE (lock:%s {name: $lockName, lock_until: $lockUntil, locked_at: $now, locked_by: $lockedBy })", collectionName);
+ String cypher = String.format(
+ "CYPHER runtime = slotted CREATE (lock:%s {name: $lockName, lock_until: $lockUntil, locked_at: $now, locked_by: $lockedBy })",
+ collectionName);
Map Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.javacrumbs.shedlock.provider.neo4j;
+
+import static java.lang.Thread.sleep;
+import static net.javacrumbs.shedlock.core.ClockProvider.now;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.Duration;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import net.javacrumbs.shedlock.core.ClockProvider;
+import net.javacrumbs.shedlock.core.LockConfiguration;
+import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
+import net.javacrumbs.shedlock.test.support.AbstractStorageBasedLockProviderIntegrationTest;
+import net.javacrumbs.shedlock.test.support.FuzzTester;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.neo4j.driver.Session;
+import org.neo4j.driver.Transaction;
+import org.slf4j.LoggerFactory;
+
+public abstract class AbstractNeo4jLockProviderIntegrationTest extends AbstractStorageBasedLockProviderIntegrationTest {
+ private static final String MY_LOCK = "my-lock";
+ private static final String OTHER_LOCK = "other-lock";
+
+ protected abstract Neo4jTestUtils getNeo4jTestUtils();
+
+ @Override
+ protected StorageBasedLockProvider getLockProvider() {
+ return new Neo4jLockProvider(getNeo4jTestUtils().getDriver());
+ }
+
+ @AfterEach
+ public void cleanup() {
+ getNeo4jTestUtils().clean();
+ }
+
+ @Override
+ protected void assertUnlocked(String lockName) {
+ Neo4jTestUtils.LockInfo lockInfo = getLockInfo(lockName);
+ Instant now = ClockProvider.now();
+ assertThat(lockInfo.getLockUntil())
+ .describedAs("is unlocked")
+ .isBeforeOrEqualTo(now.truncatedTo(ChronoUnit.MILLIS).plusMillis(1));
+ }
+
+ @Override
+ protected void assertLocked(String lockName) {
+ Neo4jTestUtils.LockInfo lockInfo = getLockInfo(lockName);
+ Instant now = ClockProvider.now();
+
+ assertThat(lockInfo.getLockUntil())
+ .describedAs(getClass().getName() + " is locked")
+ .isAfter(now);
+ }
+
+ @Test
+ public void shouldCreateLockIfRecordAlreadyExists() {
+ Map Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.javacrumbs.shedlock.provider.neo4j;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.neo4j.driver.AuthTokens;
+import org.neo4j.driver.GraphDatabase;
+import org.testcontainers.containers.Neo4jContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.utility.DockerImageName;
+
+@Testcontainers
+public class EnterpriseNeo4jLockProviderIntegrationTest extends AbstractNeo4jLockProviderIntegrationTest {
+ private static Neo4jTestUtils testUtils;
+
+ @Container
+ private static final MyNeo4jContainer container = new MyNeo4jContainer();
+
+ @BeforeAll
+ static void startDb() {
+ testUtils = new Neo4jTestUtils(GraphDatabase.driver(container.getBoltUrl(), AuthTokens.none()));
+ }
+
+ @Override
+ protected Neo4jTestUtils getNeo4jTestUtils() {
+ return testUtils;
+ }
+
+ private static class MyNeo4jContainer extends Neo4jContainer Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.neo4j;
-import net.javacrumbs.shedlock.core.ClockProvider;
-import net.javacrumbs.shedlock.core.LockConfiguration;
-import net.javacrumbs.shedlock.support.StorageBasedLockProvider;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
-import net.javacrumbs.shedlock.test.support.AbstractStorageBasedLockProviderIntegrationTest;
-import net.javacrumbs.shedlock.test.support.FuzzTester;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestInstance;
import org.neo4j.driver.AuthTokens;
-import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
-import org.neo4j.driver.Session;
-import org.neo4j.driver.Transaction;
-import org.slf4j.LoggerFactory;
import org.testcontainers.containers.Neo4jContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
-import java.time.Duration;
-import java.time.Instant;
-import java.time.temporal.ChronoUnit;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ExecutionException;
+@Testcontainers
+public class Neo4jLockProviderIntegrationTest extends AbstractNeo4jLockProviderIntegrationTest {
+ private static Neo4jTestUtils testUtils;
-import static java.lang.Thread.sleep;
-import static net.javacrumbs.shedlock.core.ClockProvider.now;
-import static org.assertj.core.api.Assertions.assertThat;
-
-@TestInstance(TestInstance.Lifecycle.PER_CLASS)
-public class Neo4jLockProviderIntegrationTest extends AbstractStorageBasedLockProviderIntegrationTest {
- protected Neo4jTestUtils testUtils;
- protected MyNeo4jContainer container;
- private Driver driver;
-
- private static final String MY_LOCK = "my-lock";
- private static final String OTHER_LOCK = "other-lock";
+ @Container
+ private static final MyNeo4jContainer container = new MyNeo4jContainer();
@BeforeAll
- public void startDb() {
- container = new MyNeo4jContainer();
- container.start();
- driver = GraphDatabase.driver(container.getBoltUrl(), AuthTokens.none());
- }
-
- @AfterAll
- public void shutDownDb() {
- container.stop();
+ static void startDb() {
+ testUtils = new Neo4jTestUtils(GraphDatabase.driver(container.getBoltUrl(), AuthTokens.none()));
}
@Override
- protected StorageBasedLockProvider getLockProvider() {
- return new Neo4jLockProvider(testUtils.getDriver());
- }
-
- @BeforeEach
- public void initTestUtils() {
- testUtils = new Neo4jTestUtils(driver);
- }
-
- @AfterEach
- public void cleanup() {
- testUtils.clean();
- }
-
- @Override
- protected void assertUnlocked(String lockName) {
- Neo4jTestUtils.LockInfo lockInfo = getLockInfo(lockName);
- Instant now = ClockProvider.now();
- assertThat(lockInfo.getLockUntil()).describedAs("is unlocked").isBeforeOrEqualTo(now.truncatedTo(ChronoUnit.MILLIS).plusMillis(1));
- }
-
- @Override
- protected void assertLocked(String lockName) {
- Neo4jTestUtils.LockInfo lockInfo = getLockInfo(lockName);
- Instant now = ClockProvider.now();
-
- assertThat(lockInfo.getLockUntil()).describedAs(getClass().getName() + " is locked").isAfter(now);
- }
-
- @Test
- public void shouldCreateLockIfRecordAlreadyExists() {
- Map Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.neo4j;
-import org.neo4j.driver.Driver;
-import org.neo4j.driver.Result;
-import org.neo4j.driver.Session;
-import org.neo4j.driver.Transaction;
+import static java.util.Collections.singletonMap;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
-
-import static java.util.Collections.singletonMap;
+import org.neo4j.driver.Driver;
+import org.neo4j.driver.Result;
+import org.neo4j.driver.Session;
+import org.neo4j.driver.Transaction;
public final class Neo4jTestUtils {
@@ -39,7 +36,8 @@ public void executeTransactionally(String query) {
executeTransactionally(query, new HashMap<>(), null);
}
- public Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.javacrumbs.shedlock.provider.opensearch.java;
+
+import static java.net.HttpURLConnection.HTTP_CONFLICT;
+import static net.javacrumbs.shedlock.core.ClockProvider.now;
+import static net.javacrumbs.shedlock.support.Utils.getHostname;
+
+import java.io.IOException;
+import java.time.Instant;
+import java.util.Map;
+import java.util.Optional;
+import net.javacrumbs.shedlock.core.AbstractSimpleLock;
+import net.javacrumbs.shedlock.core.LockConfiguration;
+import net.javacrumbs.shedlock.core.LockProvider;
+import net.javacrumbs.shedlock.core.SimpleLock;
+import net.javacrumbs.shedlock.support.LockException;
+import org.opensearch.client.json.JsonData;
+import org.opensearch.client.opensearch.OpenSearchClient;
+import org.opensearch.client.opensearch._types.InlineScript;
+import org.opensearch.client.opensearch._types.OpenSearchException;
+import org.opensearch.client.opensearch._types.Refresh;
+import org.opensearch.client.opensearch._types.Result;
+import org.opensearch.client.opensearch._types.Script;
+import org.opensearch.client.opensearch.core.UpdateRequest;
+import org.opensearch.client.opensearch.core.UpdateRequest.Builder;
+import org.opensearch.client.opensearch.core.UpdateResponse;
+import org.opensearch.client.transport.httpclient5.ResponseException;
+
+/**
+ * Lock using OpenSearch >= . Requires opensearch-rest-high-level-client >
+ * 1.1.0
+ *
+ *
+ * It uses a collection that contains documents like this:
+ *
+ *
+ * lockedAt and lockedBy are just for troubleshooting and are not read by the
+ * code
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.javacrumbs.shedlock.provider.opensearch.java;
+
+import static java.time.Instant.now;
+import static java.time.Instant.ofEpochMilli;
+import static net.javacrumbs.shedlock.provider.opensearch.java.OpenSearchLockProvider.LOCKED_AT;
+import static net.javacrumbs.shedlock.provider.opensearch.java.OpenSearchLockProvider.LOCKED_BY;
+import static net.javacrumbs.shedlock.provider.opensearch.java.OpenSearchLockProvider.LOCK_UNTIL;
+import static net.javacrumbs.shedlock.provider.opensearch.java.OpenSearchLockProvider.NAME;
+import static net.javacrumbs.shedlock.provider.opensearch.java.OpenSearchLockProvider.SCHEDLOCK_DEFAULT_INDEX;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Date;
+import java.util.Map;
+import net.javacrumbs.shedlock.core.LockProvider;
+import net.javacrumbs.shedlock.test.support.AbstractLockProviderIntegrationTest;
+import org.apache.hc.client5.http.auth.AuthScope;
+import org.apache.hc.client5.http.auth.CredentialsProvider;
+import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
+import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
+import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
+import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
+import org.apache.hc.core5.http.HttpHost;
+import org.junit.jupiter.api.BeforeEach;
+import org.opensearch.client.opensearch.OpenSearchClient;
+import org.opensearch.client.opensearch.core.GetRequest;
+import org.opensearch.client.opensearch.core.GetResponse;
+import org.opensearch.client.transport.OpenSearchTransport;
+import org.opensearch.client.transport.httpclient5.ApacheHttpClient5TransportBuilder;
+import org.opensearch.testcontainers.OpensearchContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.utility.DockerImageName;
+
+@Testcontainers
+public class OpenSearchLockProviderTest extends AbstractLockProviderIntegrationTest {
+
+ @Container
+ private static final OpensearchContainer> container =
+ new OpensearchContainer<>(DockerImageName.parse("opensearchproject/opensearch:2"));
+
+ private OpenSearchClient openSearchClient;
+ private OpenSearchLockProvider lockProvider;
+
+ @BeforeEach
+ public void setUp() {
+ openSearchClient = openSearchClient();
+ lockProvider = new OpenSearchLockProvider(openSearchClient);
+ }
+
+ @Override
+ protected LockProvider getLockProvider() {
+ return lockProvider;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void assertUnlocked(String lockName) {
+ GetRequest getRequest =
+ GetRequest.of(builder -> builder.index(SCHEDLOCK_DEFAULT_INDEX).id(lockName));
+
+ try {
+ GetResponse Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.opensearch;
+import static net.javacrumbs.shedlock.core.ClockProvider.now;
+import static net.javacrumbs.shedlock.support.Utils.getHostname;
+import static org.opensearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
+
+import java.io.IOException;
+import java.time.Instant;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Optional;
import net.javacrumbs.shedlock.core.AbstractSimpleLock;
import net.javacrumbs.shedlock.core.LockConfiguration;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.core.SimpleLock;
import net.javacrumbs.shedlock.support.LockException;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
import org.opensearch.OpenSearchException;
import org.opensearch.action.DocWriteResponse;
import org.opensearch.action.update.UpdateRequest;
import org.opensearch.action.update.UpdateResponse;
import org.opensearch.client.RequestOptions;
import org.opensearch.client.RestHighLevelClient;
-import org.opensearch.rest.RestStatus;
+import org.opensearch.core.rest.RestStatus;
import org.opensearch.script.Script;
import org.opensearch.script.ScriptType;
-import java.io.IOException;
-import java.time.Instant;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-
-import static net.javacrumbs.shedlock.core.ClockProvider.now;
-import static net.javacrumbs.shedlock.support.Utils.getHostname;
-import static org.opensearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
-
/**
- * Lock using OpenSearch >= .
- * Requires opensearch-rest-high-level-client > 1.1.0
+ * Lock using OpenSearch >= . Requires opensearch-rest-high-level-client >
+ * 1.1.0
+ *
*
* It uses a collection that contains documents like this:
+ *
*
- * lockedAt and lockedBy are just for troubleshooting and are not read by the code
+ * lockedAt and lockedBy are just for troubleshooting and are not read by the
+ * code
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.opensearch;
-import net.javacrumbs.container.OpenSearchContainer;
+import static net.javacrumbs.shedlock.provider.opensearch.OpenSearchLockProvider.LOCKED_AT;
+import static net.javacrumbs.shedlock.provider.opensearch.OpenSearchLockProvider.LOCKED_BY;
+import static net.javacrumbs.shedlock.provider.opensearch.OpenSearchLockProvider.LOCK_UNTIL;
+import static net.javacrumbs.shedlock.provider.opensearch.OpenSearchLockProvider.NAME;
+import static net.javacrumbs.shedlock.provider.opensearch.OpenSearchLockProvider.SCHEDLOCK_DEFAULT_INDEX;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.Map;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.test.support.AbstractLockProviderIntegrationTest;
import org.apache.http.HttpHost;
@@ -26,38 +34,24 @@
import org.opensearch.client.RequestOptions;
import org.opensearch.client.RestClient;
import org.opensearch.client.RestHighLevelClient;
+import org.opensearch.testcontainers.OpensearchContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
-
-import java.io.IOException;
-import java.time.Duration;
-import java.util.Date;
-import java.util.Map;
-
-import static net.javacrumbs.shedlock.provider.opensearch.OpenSearchLockProvider.LOCKED_AT;
-import static net.javacrumbs.shedlock.provider.opensearch.OpenSearchLockProvider.LOCKED_BY;
-import static net.javacrumbs.shedlock.provider.opensearch.OpenSearchLockProvider.LOCK_UNTIL;
-import static net.javacrumbs.shedlock.provider.opensearch.OpenSearchLockProvider.NAME;
-import static net.javacrumbs.shedlock.provider.opensearch.OpenSearchLockProvider.SCHEDLOCK_DEFAULT_INDEX;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
+import org.testcontainers.utility.DockerImageName;
@Testcontainers
public class OpenSearchLockProviderTest extends AbstractLockProviderIntegrationTest {
@Container
- private static final OpenSearchContainer container = new OpenSearchContainer("opensearchproject/opensearch:1.1.0")
- .withStartupTimeout(Duration.ofMinutes(2))
- .withEnv("plugins.security.disabled", "true")
- .withStartupAttempts(2);
+ private static final OpensearchContainer> container =
+ new OpensearchContainer<>(DockerImageName.parse("opensearchproject/opensearch:2"));
+
private RestHighLevelClient highLevelClient;
private OpenSearchLockProvider lockProvider;
@BeforeEach
public void setUp() {
- highLevelClient = new RestHighLevelClient(
- RestClient.builder(HttpHost.create(container.getHttpHostAddress()))
- );
+ highLevelClient = new RestHighLevelClient(RestClient.builder(HttpHost.create(container.getHttpHostAddress())));
lockProvider = new OpenSearchLockProvider(highLevelClient);
}
diff --git a/providers/r2dbc/shedlock-provider-r2dbc/pom.xml b/providers/r2dbc/shedlock-provider-r2dbc/pom.xml
index 23c309b08..afb6e0ec3 100644
--- a/providers/r2dbc/shedlock-provider-r2dbc/pom.xml
+++ b/providers/r2dbc/shedlock-provider-r2dbc/pom.xml
@@ -5,12 +5,16 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.r2dbc;
-import net.javacrumbs.shedlock.test.support.jdbc.DbConfig;
import net.javacrumbs.shedlock.test.support.jdbc.MariaDbConfig;
+import org.junit.jupiter.api.Disabled;
+@Disabled("No R2DBC 1.0.0 compatible driver")
public class MariaR2dbcLockProviderIntegrationTest extends AbstractR2dbcTest {
- private static final DbConfig dbConfig = new MariaDbConfig();
- @Override
- protected DbConfig getDbConfig() {
- return dbConfig;
+ public MariaR2dbcLockProviderIntegrationTest() {
+ super(new MariaDbConfig());
}
}
diff --git a/providers/r2dbc/shedlock-provider-r2dbc/src/test/java/net/javacrumbs/shedlock/provider/r2dbc/MsSqlR2dbcLockProviderIntegrationTest.java b/providers/r2dbc/shedlock-provider-r2dbc/src/test/java/net/javacrumbs/shedlock/provider/r2dbc/MsSqlR2dbcLockProviderIntegrationTest.java
index 2dd484d41..6f7b845a3 100644
--- a/providers/r2dbc/shedlock-provider-r2dbc/src/test/java/net/javacrumbs/shedlock/provider/r2dbc/MsSqlR2dbcLockProviderIntegrationTest.java
+++ b/providers/r2dbc/shedlock-provider-r2dbc/src/test/java/net/javacrumbs/shedlock/provider/r2dbc/MsSqlR2dbcLockProviderIntegrationTest.java
@@ -1,28 +1,24 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.r2dbc;
-import net.javacrumbs.shedlock.test.support.jdbc.DbConfig;
import net.javacrumbs.shedlock.test.support.jdbc.MsSqlServerConfig;
+import org.junit.jupiter.api.Disabled;
+@Disabled("Maven build does not finish when enabled")
public class MsSqlR2dbcLockProviderIntegrationTest extends AbstractR2dbcTest {
- private static final DbConfig dbConfig = new MsSqlServerConfig();
-
- @Override
- protected DbConfig getDbConfig() {
- return dbConfig;
+ public MsSqlR2dbcLockProviderIntegrationTest() {
+ super(new MsSqlServerConfig());
}
}
diff --git a/providers/r2dbc/shedlock-provider-r2dbc/src/test/java/net/javacrumbs/shedlock/provider/r2dbc/MySqlR2dbcLockProviderIntegrationTest.java b/providers/r2dbc/shedlock-provider-r2dbc/src/test/java/net/javacrumbs/shedlock/provider/r2dbc/MySqlR2dbcLockProviderIntegrationTest.java
index 3ae40fead..b073b22e1 100644
--- a/providers/r2dbc/shedlock-provider-r2dbc/src/test/java/net/javacrumbs/shedlock/provider/r2dbc/MySqlR2dbcLockProviderIntegrationTest.java
+++ b/providers/r2dbc/shedlock-provider-r2dbc/src/test/java/net/javacrumbs/shedlock/provider/r2dbc/MySqlR2dbcLockProviderIntegrationTest.java
@@ -1,28 +1,22 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.r2dbc;
-import net.javacrumbs.shedlock.test.support.jdbc.DbConfig;
import net.javacrumbs.shedlock.test.support.jdbc.MySqlConfig;
public class MySqlR2dbcLockProviderIntegrationTest extends AbstractR2dbcTest {
- private static final DbConfig dbConfig = new MySqlConfig();
-
- @Override
- protected DbConfig getDbConfig() {
- return dbConfig;
+ public MySqlR2dbcLockProviderIntegrationTest() {
+ super(new MySqlConfig());
}
}
diff --git a/providers/r2dbc/shedlock-provider-r2dbc/src/test/java/net/javacrumbs/shedlock/provider/r2dbc/OracleR2dbcLockProviderIntegrationTest.java b/providers/r2dbc/shedlock-provider-r2dbc/src/test/java/net/javacrumbs/shedlock/provider/r2dbc/OracleR2dbcLockProviderIntegrationTest.java
index ac8c1bade..10e0cccb1 100644
--- a/providers/r2dbc/shedlock-provider-r2dbc/src/test/java/net/javacrumbs/shedlock/provider/r2dbc/OracleR2dbcLockProviderIntegrationTest.java
+++ b/providers/r2dbc/shedlock-provider-r2dbc/src/test/java/net/javacrumbs/shedlock/provider/r2dbc/OracleR2dbcLockProviderIntegrationTest.java
@@ -1,33 +1,22 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.r2dbc;
-import net.javacrumbs.shedlock.test.support.jdbc.DbConfig;
import net.javacrumbs.shedlock.test.support.jdbc.OracleServerConfig;
public class OracleR2dbcLockProviderIntegrationTest extends AbstractR2dbcTest {
- private static final DbConfig dbConfig = new OracleServerConfig();
-
- @Override
- protected DbConfig getDbConfig() {
- return dbConfig;
- }
-
- @Override
- protected boolean usePool() {
- return false;
+ public OracleR2dbcLockProviderIntegrationTest() {
+ super(new OracleServerConfig());
}
}
diff --git a/providers/r2dbc/shedlock-provider-r2dbc/src/test/java/net/javacrumbs/shedlock/provider/r2dbc/PostgresR2dbcLockProviderIntegrationTest.java b/providers/r2dbc/shedlock-provider-r2dbc/src/test/java/net/javacrumbs/shedlock/provider/r2dbc/PostgresR2dbcLockProviderIntegrationTest.java
index d8897bffb..a3901977a 100644
--- a/providers/r2dbc/shedlock-provider-r2dbc/src/test/java/net/javacrumbs/shedlock/provider/r2dbc/PostgresR2dbcLockProviderIntegrationTest.java
+++ b/providers/r2dbc/shedlock-provider-r2dbc/src/test/java/net/javacrumbs/shedlock/provider/r2dbc/PostgresR2dbcLockProviderIntegrationTest.java
@@ -1,28 +1,22 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.r2dbc;
-import net.javacrumbs.shedlock.test.support.jdbc.DbConfig;
import net.javacrumbs.shedlock.test.support.jdbc.PostgresConfig;
public class PostgresR2dbcLockProviderIntegrationTest extends AbstractR2dbcTest {
- private static final DbConfig dbConfig = new PostgresConfig();
-
- @Override
- protected DbConfig getDbConfig() {
- return dbConfig;
+ public PostgresR2dbcLockProviderIntegrationTest() {
+ super(new PostgresConfig());
}
}
diff --git a/providers/redis/shedlock-provider-redis-jedis4/pom.xml b/providers/redis/shedlock-provider-redis-jedis4/pom.xml
index b3a234a01..3078be97c 100644
--- a/providers/redis/shedlock-provider-redis-jedis4/pom.xml
+++ b/providers/redis/shedlock-provider-redis-jedis4/pom.xml
@@ -3,45 +3,39 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.redis.jedis4;
-import net.javacrumbs.shedlock.core.AbstractSimpleLock;
-import net.javacrumbs.shedlock.core.ClockProvider;
+import static net.javacrumbs.shedlock.provider.redis.support.InternalRedisLockProvider.DEFAULT_KEY_PREFIX;
+import static net.javacrumbs.shedlock.provider.redis.support.InternalRedisLockProvider.ENV_DEFAULT;
+import static redis.clients.jedis.params.SetParams.setParams;
+
+import java.util.List;
+import java.util.Optional;
+import net.javacrumbs.shedlock.core.ExtensibleLockProvider;
import net.javacrumbs.shedlock.core.LockConfiguration;
-import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.core.SimpleLock;
-import net.javacrumbs.shedlock.support.LockException;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
+import net.javacrumbs.shedlock.provider.redis.support.InternalRedisLockProvider;
+import net.javacrumbs.shedlock.provider.redis.support.InternalRedisLockTemplate;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.commands.JedisCommands;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.util.Pool;
-import java.time.Duration;
-import java.time.Instant;
-import java.util.Optional;
-
-import static net.javacrumbs.shedlock.support.Utils.getHostname;
-import static net.javacrumbs.shedlock.support.Utils.toIsoString;
-import static redis.clients.jedis.params.SetParams.setParams;
-
/**
- * Uses Redis's `SET resource-name anystring NX PX max-lock-ms-time` as locking mechanism.
+ * Uses Redis's `SET resource-name anystring NX PX max-lock-ms-time` as locking
+ * mechanism.
+ *
*
- * See https://redis.io/commands/set
+ * See Set command
*/
-public class JedisLockProvider implements LockProvider {
-
- private static final String KEY_PREFIX = "job-lock";
- private static final String ENV_DEFAULT = "default";
+public class JedisLockProvider implements ExtensibleLockProvider {
- private final JedisTemplate jedisTemplate;
- private final String environment;
+ private final InternalRedisLockProvider internalRedisLockProvider;
- public JedisLockProvider(@NonNull Pool Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.javacrumbs.shedlock.provider.redis.jedis4;
-import net.javacrumbs.shedlock.core.LockProvider;
-import net.javacrumbs.shedlock.test.support.AbstractLockProviderIntegrationTest;
+import static net.javacrumbs.shedlock.provider.redis.testsupport.RedisContainer.ENV;
+import static net.javacrumbs.shedlock.provider.redis.testsupport.RedisContainer.PORT;
+
+import net.javacrumbs.shedlock.core.ExtensibleLockProvider;
+import net.javacrumbs.shedlock.provider.redis.testsupport.AbstractRedisIntegrationTest;
+import net.javacrumbs.shedlock.provider.redis.testsupport.AbstractRedisSafeUpdateIntegrationTest;
+import net.javacrumbs.shedlock.provider.redis.testsupport.RedisContainer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.testcontainers.junit.jupiter.Container;
@@ -26,79 +29,104 @@
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;
-import static net.javacrumbs.shedlock.provider.redis.jedis4.RedisContainer.ENV;
-import static net.javacrumbs.shedlock.provider.redis.jedis4.RedisContainer.PORT;
-import static org.assertj.core.api.Assertions.assertThat;
-
@Testcontainers
-public class JedisLockProviderIntegrationTest {
+public class JedisLockProviderIntegrationTest {
@Container
public static final RedisContainer redis = new RedisContainer(PORT);
@Nested
- class Cluster extends AbstractLockProviderIntegrationTest {
- private LockProvider lockProvider;
+ class Cluster extends AbstractRedisIntegrationTest {
+ private ExtensibleLockProvider lockProvider;
private JedisCluster jedisCluster;
@BeforeEach
public void createLockProvider() {
- jedisCluster = new JedisCluster(new HostAndPort(redis.getContainerIpAddress(), redis.getFirstMappedPort()));
+ jedisCluster = new JedisCluster(new HostAndPort(redis.getHost(), redis.getFirstMappedPort()));
lockProvider = new JedisLockProvider(jedisCluster, ENV);
}
+
@Override
- protected void assertUnlocked(String lockName) {
- assertThat(getLock(lockName)).isNull();
+ protected String getLock(String lockName) {
+ return jedisCluster.get(buildKey(lockName, ENV));
}
@Override
- protected void assertLocked(String lockName) {
- assertThat(getLock(lockName)).isNotNull();
+ protected ExtensibleLockProvider getLockProvider() {
+ return lockProvider;
}
+ }
+
+ @Nested
+ class ClusterSafeUpdate extends AbstractRedisSafeUpdateIntegrationTest {
+ private ExtensibleLockProvider lockProvider;
- private String getLock(String lockName) {
- return jedisCluster.get(JedisLockProvider.buildKey(lockName, ENV));
+ private JedisCluster jedisCluster;
+
+ @BeforeEach
+ public void createLockProvider() {
+ jedisCluster = new JedisCluster(new HostAndPort(redis.getHost(), redis.getFirstMappedPort()));
+ lockProvider = new JedisLockProvider(jedisCluster, ENV, true);
}
@Override
- protected LockProvider getLockProvider() {
+ protected String getLock(String lockName) {
+ return jedisCluster.get(buildKey(lockName, ENV));
+ }
+
+ @Override
+ protected ExtensibleLockProvider getLockProvider() {
return lockProvider;
}
}
@Nested
- class Pool extends AbstractLockProviderIntegrationTest {
- private LockProvider lockProvider;
+ class Pool extends AbstractRedisIntegrationTest {
+ private ExtensibleLockProvider lockProvider;
private JedisPool jedisPool;
@BeforeEach
public void createLockProvider() {
- jedisPool = new JedisPool(redis.getContainerIpAddress(), redis.getMappedPort(PORT));
+ jedisPool = new JedisPool(redis.getHost(), redis.getMappedPort(PORT));
lockProvider = new JedisLockProvider(jedisPool, ENV);
}
@Override
- protected void assertUnlocked(String lockName) {
+ protected String getLock(String lockName) {
try (Jedis jedis = jedisPool.getResource()) {
- assertThat(getLock(lockName, jedis)).isNull();
+ return jedis.get(buildKey(lockName, ENV));
}
}
@Override
- protected void assertLocked(String lockName) {
- try (Jedis jedis = jedisPool.getResource()) {
- assertThat(getLock(lockName, jedis)).isNotNull();
- }
+ protected ExtensibleLockProvider getLockProvider() {
+ return lockProvider;
+ }
+ }
+
+ @Nested
+ class PoolSafeUpdate extends AbstractRedisSafeUpdateIntegrationTest {
+ private ExtensibleLockProvider lockProvider;
+
+ private JedisPool jedisPool;
+
+ @BeforeEach
+ public void createLockProvider() {
+ jedisPool = new JedisPool(redis.getHost(), redis.getMappedPort(PORT));
+ lockProvider = new JedisLockProvider(jedisPool, ENV, true);
}
- private String getLock(String lockName, Jedis jedis) {
- return jedis.get(JedisLockProvider.buildKey(lockName, ENV));
+ @Override
+ protected String getLock(String lockName) {
+ try (Jedis jedis = jedisPool.getResource()) {
+ return jedis.get(buildKey(lockName, ENV));
+ }
}
@Override
- protected LockProvider getLockProvider() {
+ protected ExtensibleLockProvider getLockProvider() {
return lockProvider;
}
}
diff --git a/providers/redis/shedlock-provider-redis-jedis4/src/test/java/net/javacrumbs/shedlock/provider/redis/jedis4/RedisContainer.java b/providers/redis/shedlock-provider-redis-jedis4/src/test/java/net/javacrumbs/shedlock/provider/redis/jedis4/RedisContainer.java
deleted file mode 100644
index b761dacff..000000000
--- a/providers/redis/shedlock-provider-redis-jedis4/src/test/java/net/javacrumbs/shedlock/provider/redis/jedis4/RedisContainer.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * Copyright 2009 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.javacrumbs.shedlock.provider.redis.jedis4;
-
-import com.playtika.test.redis.RedisProperties;
-import com.playtika.test.redis.wait.RedisClusterStatusCheck;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testcontainers.containers.FixedHostPortGenericContainer;
-import org.testcontainers.utility.MountableFile;
-
-class RedisContainer extends FixedHostPortGenericContainer Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.javacrumbs.shedlock.provider.redis.lettuce;
+
+import static net.javacrumbs.shedlock.provider.redis.support.InternalRedisLockProvider.DEFAULT_KEY_PREFIX;
+import static net.javacrumbs.shedlock.provider.redis.support.InternalRedisLockProvider.ENV_DEFAULT;
+
+import io.lettuce.core.ScriptOutputType;
+import io.lettuce.core.SetArgs;
+import io.lettuce.core.api.StatefulRedisConnection;
+import java.util.Optional;
+import net.javacrumbs.shedlock.core.ExtensibleLockProvider;
+import net.javacrumbs.shedlock.core.LockConfiguration;
+import net.javacrumbs.shedlock.core.SimpleLock;
+import net.javacrumbs.shedlock.provider.redis.support.InternalRedisLockProvider;
+import net.javacrumbs.shedlock.provider.redis.support.InternalRedisLockTemplate;
+
+/**
+ * Uses Redis's `SET resource-name anystring NX PX max-lock-ms-time` as locking
+ * mechanism.
+ *
+ *
+ * See Set command
+ */
+public class LettuceLockProvider implements ExtensibleLockProvider {
+
+ private final InternalRedisLockProvider internalRedisLockProvider;
+
+ public LettuceLockProvider(StatefulRedisConnection Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.javacrumbs.shedlock.provider.redis.lettuce;
+
+import static net.javacrumbs.shedlock.provider.redis.testsupport.RedisContainer.ENV;
+import static net.javacrumbs.shedlock.provider.redis.testsupport.RedisContainer.PORT;
+
+import io.lettuce.core.RedisClient;
+import io.lettuce.core.api.StatefulRedisConnection;
+import net.javacrumbs.shedlock.core.ExtensibleLockProvider;
+import net.javacrumbs.shedlock.provider.redis.testsupport.AbstractRedisIntegrationTest;
+import net.javacrumbs.shedlock.provider.redis.testsupport.AbstractRedisSafeUpdateIntegrationTest;
+import net.javacrumbs.shedlock.provider.redis.testsupport.RedisContainer;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Nested;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+
+@Testcontainers
+public class LettuceLockProviderIntegrationTest {
+
+ @Container
+ public static final RedisContainer redis = new RedisContainer(PORT);
+
+ private static RedisClient createClient() {
+ String uri = String.format("redis://%s:%d", redis.getHost(), redis.getFirstMappedPort());
+ return RedisClient.create(uri);
+ }
+
+ @Nested
+ class Cluster extends AbstractRedisIntegrationTest {
+
+ private ExtensibleLockProvider lockProvider;
+ private StatefulRedisConnection
- *
*/
public class MicronautJdbcLockProvider extends StorageBasedLockProvider {
private static final String DEFAULT_TABLE_NAME = "shedlock";
- public MicronautJdbcLockProvider(@NonNull DataSource datasource) {
- this(new DataSourceTransactionManager(datasource), DEFAULT_TABLE_NAME);
- }
-
- public MicronautJdbcLockProvider(@NonNull TransactionOperations
- *
*/
public class JdbcTemplateLockProvider extends StorageBasedLockProvider {
private static final String DEFAULT_TABLE_NAME = "shedlock";
- public JdbcTemplateLockProvider(@NonNull JdbcTemplate jdbcTemplate) {
+ public JdbcTemplateLockProvider(JdbcTemplate jdbcTemplate) {
this(jdbcTemplate, (PlatformTransactionManager) null);
}
- public JdbcTemplateLockProvider(@NonNull JdbcTemplate jdbcTemplate, @Nullable PlatformTransactionManager transactionManager) {
+ public JdbcTemplateLockProvider(
+ JdbcTemplate jdbcTemplate, @Nullable PlatformTransactionManager transactionManager) {
this(jdbcTemplate, transactionManager, DEFAULT_TABLE_NAME);
}
- public JdbcTemplateLockProvider(@NonNull JdbcTemplate jdbcTemplate, @NonNull String tableName) {
+ public JdbcTemplateLockProvider(JdbcTemplate jdbcTemplate, String tableName) {
this(jdbcTemplate, null, tableName);
}
- public JdbcTemplateLockProvider(@NonNull DataSource dataSource) {
+ public JdbcTemplateLockProvider(DataSource dataSource) {
this(new JdbcTemplate(dataSource));
}
- public JdbcTemplateLockProvider(@NonNull DataSource dataSource, @NonNull String tableName) {
+ public JdbcTemplateLockProvider(DataSource dataSource, String tableName) {
this(new JdbcTemplate(dataSource), tableName);
}
- public JdbcTemplateLockProvider(@NonNull JdbcTemplate jdbcTemplate, @Nullable PlatformTransactionManager transactionManager, @NonNull String tableName) {
+ public JdbcTemplateLockProvider(
+ JdbcTemplate jdbcTemplate, @Nullable PlatformTransactionManager transactionManager, String tableName) {
this(Configuration.builder()
- .withJdbcTemplate(jdbcTemplate)
- .withTransactionManager(transactionManager)
- .withTableName(tableName)
- .build()
- );
+ .withJdbcTemplate(jdbcTemplate)
+ .withTransactionManager(transactionManager)
+ .withTableName(tableName)
+ .build());
}
- public JdbcTemplateLockProvider(@NonNull Configuration configuration) {
+ public JdbcTemplateLockProvider(Configuration configuration) {
super(new JdbcTemplateStorageAccessor(configuration));
}
public static final class Configuration {
private final JdbcTemplate jdbcTemplate;
+
+ @Nullable
+ private final DatabaseProduct databaseProduct;
+
+ @Nullable
private final PlatformTransactionManager transactionManager;
+
private final String tableName;
+
+ @Nullable
private final TimeZone timeZone;
+
private final ColumnNames columnNames;
private final String lockedByValue;
private final boolean useDbTime;
+
+ @Nullable
private final Integer isolationLevel;
+ private final boolean throwUnexpectedException;
+
Configuration(
- @NonNull JdbcTemplate jdbcTemplate,
- @Nullable PlatformTransactionManager transactionManager,
- @NonNull String tableName,
- @Nullable TimeZone timeZone,
- @NonNull ColumnNames columnNames,
- @NonNull String lockedByValue,
- boolean useDbTime,
- @Nullable Integer isolationLevel) {
+ JdbcTemplate jdbcTemplate,
+ @Nullable DatabaseProduct databaseProduct,
+ @Nullable PlatformTransactionManager transactionManager,
+ String tableName,
+ @Nullable TimeZone timeZone,
+ ColumnNames columnNames,
+ String lockedByValue,
+ boolean useDbTime,
+ @Nullable Integer isolationLevel,
+ boolean throwUnexpectedException) {
this.jdbcTemplate = requireNonNull(jdbcTemplate, "jdbcTemplate can not be null");
+ this.databaseProduct = databaseProduct;
this.transactionManager = transactionManager;
this.tableName = requireNonNull(tableName, "tableName can not be null");
this.timeZone = timeZone;
@@ -117,12 +125,19 @@ public static final class Configuration {
throw new IllegalArgumentException("Can not set both useDbTime and timeZone");
}
this.useDbTime = useDbTime;
+ this.throwUnexpectedException = throwUnexpectedException;
}
public JdbcTemplate getJdbcTemplate() {
return jdbcTemplate;
}
+ @Nullable
+ public DatabaseProduct getDatabaseProduct() {
+ return databaseProduct;
+ }
+
+ @Nullable
public PlatformTransactionManager getTransactionManager() {
return transactionManager;
}
@@ -131,6 +146,7 @@ public String getTableName() {
return tableName;
}
+ @Nullable
public TimeZone getTimeZone() {
return timeZone;
}
@@ -147,36 +163,54 @@ public boolean getUseDbTime() {
return useDbTime;
}
+ @Nullable
public Integer getIsolationLevel() {
return isolationLevel;
}
+ public boolean isThrowUnexpectedException() {
+ return throwUnexpectedException;
+ }
+
public static Configuration.Builder builder() {
return new Configuration.Builder();
}
-
public static final class Builder {
private JdbcTemplate jdbcTemplate;
+
+ @Nullable
+ private DatabaseProduct databaseProduct;
+
+ @Nullable
private PlatformTransactionManager transactionManager;
+
private String tableName = DEFAULT_TABLE_NAME;
+
+ @Nullable
private TimeZone timeZone;
+
private String lockedByValue = Utils.getHostname();
private ColumnNames columnNames = new ColumnNames("name", "lock_until", "locked_at", "locked_by");
+ private boolean dbUpperCase = false;
private boolean useDbTime = false;
+
+ @Nullable
private Integer isolationLevel;
- public Builder withJdbcTemplate(@NonNull JdbcTemplate jdbcTemplate) {
+ private boolean throwUnexpectedException = false;
+
+ public Builder withJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
return this;
}
- public Builder withTransactionManager(PlatformTransactionManager transactionManager) {
+ public Builder withTransactionManager(@Nullable PlatformTransactionManager transactionManager) {
this.transactionManager = transactionManager;
return this;
}
- public Builder withTableName(@NonNull String tableName) {
+ public Builder withTableName(String tableName) {
this.tableName = tableName;
return this;
}
@@ -191,6 +225,23 @@ public Builder withColumnNames(ColumnNames columnNames) {
return this;
}
+ public Builder withDbUpperCase(final boolean dbUpperCase) {
+ this.dbUpperCase = dbUpperCase;
+ return this;
+ }
+
+ /**
+ * This is only needed if your database product can't be automatically detected.
+ *
+ * @param databaseProduct
+ * Database product
+ * @return ConfigurationBuilder
+ */
+ public Builder withDatabaseProduct(final DatabaseProduct databaseProduct) {
+ this.databaseProduct = databaseProduct;
+ return this;
+ }
+
/**
* Value stored in 'locked_by' column. Please use only for debugging purposes.
*/
@@ -205,19 +256,33 @@ public Builder usingDbTime() {
}
/**
- * Sets the isolation level for ShedLock. See {@link java.sql.Connection} for constant definitions.
- * for constant definitions
+ * Sets the isolation level for ShedLock. See {@link java.sql.Connection} for
+ * constant definitions. for constant definitions
*/
public Builder withIsolationLevel(int isolationLevel) {
this.isolationLevel = isolationLevel;
return this;
}
+ public Builder withThrowUnexpectedException(boolean throwUnexpectedException) {
+ this.throwUnexpectedException = throwUnexpectedException;
+ return this;
+ }
+
public JdbcTemplateLockProvider.Configuration build() {
- return new JdbcTemplateLockProvider.Configuration(jdbcTemplate, transactionManager, tableName, timeZone, columnNames, lockedByValue, useDbTime, isolationLevel);
+ return new JdbcTemplateLockProvider.Configuration(
+ jdbcTemplate,
+ databaseProduct,
+ transactionManager,
+ dbUpperCase ? tableName.toUpperCase() : tableName,
+ timeZone,
+ dbUpperCase ? columnNames.toUpperCase() : columnNames,
+ lockedByValue,
+ useDbTime,
+ isolationLevel,
+ throwUnexpectedException);
}
}
-
}
public static final class ColumnNames {
@@ -248,6 +313,10 @@ public String getLockedAt() {
public String getLockedBy() {
return lockedBy;
}
- }
+ private ColumnNames toUpperCase() {
+ return new ColumnNames(
+ name.toUpperCase(), lockUntil.toUpperCase(), lockedAt.toUpperCase(), lockedBy.toUpperCase());
+ }
+ }
}
diff --git a/providers/jdbc/shedlock-provider-jdbc-template/src/main/java/net/javacrumbs/shedlock/provider/jdbctemplate/JdbcTemplateStorageAccessor.java b/providers/jdbc/shedlock-provider-jdbc-template/src/main/java/net/javacrumbs/shedlock/provider/jdbctemplate/JdbcTemplateStorageAccessor.java
index 0130f3c89..d10c6cc71 100644
--- a/providers/jdbc/shedlock-provider-jdbc-template/src/main/java/net/javacrumbs/shedlock/provider/jdbctemplate/JdbcTemplateStorageAccessor.java
+++ b/providers/jdbc/shedlock-provider-jdbc-template/src/main/java/net/javacrumbs/shedlock/provider/jdbctemplate/JdbcTemplateStorageAccessor.java
@@ -1,24 +1,25 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ *
- *
*/
public class JdbcLockProvider extends StorageBasedLockProvider {
- public JdbcLockProvider(@NonNull DataSource datasource) {
+ public JdbcLockProvider(DataSource datasource) {
this(datasource, "shedlock");
}
- public JdbcLockProvider(@NonNull DataSource datasource, @NonNull String tableName) {
+ public JdbcLockProvider(DataSource datasource, String tableName) {
super(new JdbcStorageAccessor(datasource, tableName));
}
}
diff --git a/providers/jdbc/shedlock-provider-jdbc/src/main/java/net/javacrumbs/shedlock/provider/jdbc/JdbcStorageAccessor.java b/providers/jdbc/shedlock-provider-jdbc/src/main/java/net/javacrumbs/shedlock/provider/jdbc/JdbcStorageAccessor.java
index aef34ed02..dd4982950 100644
--- a/providers/jdbc/shedlock-provider-jdbc/src/main/java/net/javacrumbs/shedlock/provider/jdbc/JdbcStorageAccessor.java
+++ b/providers/jdbc/shedlock-provider-jdbc/src/main/java/net/javacrumbs/shedlock/provider/jdbc/JdbcStorageAccessor.java
@@ -1,45 +1,38 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * public.shedlock
- */
+ /** The reference instance of public.shedlock
*/
public static final Shedlock SHEDLOCK = new Shedlock();
- public static final UniqueKeypublic.shedlock.name
.
- */
- public final TableFieldpublic.shedlock.name
. */
+ public final TableFieldpublic.shedlock.lock_until
.
- */
- public final TableFieldpublic.shedlock.lock_until
. */
+ public final TableFieldpublic.shedlock.locked_at
.
- */
- public final TableFieldpublic.shedlock.locked_at
. */
+ public final TableFieldpublic.shedlock.locked_by
.
- */
- public final TableFieldpublic.shedlock.locked_by
. */
+ public final TableFieldpublic.shedlock
table reference
- */
+ /** Create an aliased public.shedlock
table reference */
public Shedlock(String alias) {
this(DSL.name(alias), SHEDLOCK);
}
- /**
- * Create an aliased public.shedlock
table reference
- */
+ /** Create an aliased public.shedlock
table reference */
public Shedlock(Name alias) {
this(alias, SHEDLOCK);
}
- /**
- * Create a public.shedlock
table reference
- */
+ /** Create a public.shedlock
table reference */
public Shedlock() {
this(DSL.name("shedlock"), null);
}
@@ -94,7 +75,6 @@ public
* {
* "_id" : "lock name",
@@ -53,22 +54,18 @@
* }
*
*
- * lockedAt and lockedBy are just for troubleshooting and are not read by the code
+ * lockedAt and lockedBy are just for troubleshooting and are not read by the
+ * code
*
*
- *
*/
public class ReactiveStreamsMongoLockProvider implements ExtensibleLockProvider {
@@ -81,9 +78,7 @@ public class ReactiveStreamsMongoLockProvider implements ExtensibleLockProvider
private final String hostname;
private final MongoCollection
* {
* "_id" : "lock name",
@@ -51,22 +51,18 @@
* }
*
*
- * lockedAt and lockedBy are just for troubleshooting and are not read by the code
+ * lockedAt and lockedBy are just for troubleshooting and are not read by the
+ * code
*
*
- *
*/
public class MongoLockProvider implements ExtensibleLockProvider {
@@ -79,9 +75,7 @@ public class MongoLockProvider implements ExtensibleLockProvider {
private final String hostname;
private final MongoCollection
- *
*/
public class Neo4jLockProvider extends StorageBasedLockProvider {
- public Neo4jLockProvider(@NonNull Driver driver) {
+ public Neo4jLockProvider(Driver driver) {
this(driver, "shedlock", null);
}
- public Neo4jLockProvider(@NonNull Driver graphDatabaseService, @NonNull String collectionName, @Nullable String databaseName) {
+ public Neo4jLockProvider(Driver graphDatabaseService, String collectionName, @Nullable String databaseName) {
super(new Neo4jStorageAccessor(graphDatabaseService, collectionName, databaseName));
}
}
diff --git a/providers/neo4j/shedlock-provider-neo4j/src/main/java/net/javacrumbs/shedlock/provider/neo4j/Neo4jStorageAccessor.java b/providers/neo4j/shedlock-provider-neo4j/src/main/java/net/javacrumbs/shedlock/provider/neo4j/Neo4jStorageAccessor.java
index 7d377cc5b..d4cd3e256 100644
--- a/providers/neo4j/shedlock-provider-neo4j/src/main/java/net/javacrumbs/shedlock/provider/neo4j/Neo4jStorageAccessor.java
+++ b/providers/neo4j/shedlock-provider-neo4j/src/main/java/net/javacrumbs/shedlock/provider/neo4j/Neo4jStorageAccessor.java
@@ -1,25 +1,27 @@
/**
* Copyright 2009 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ *
+ * {
+ * "name" : "lock name",
+ * "lockUntil" : {
+ * "type": "date",
+ * "format": "epoch_millis"
+ * },
+ * "lockedAt" : {
+ * "type": "date",
+ * "format": "epoch_millis"
+ * }:
+ * "lockedBy" : "hostname"
+ * }
+ *
+ *
+ *
+ *
+ */
+public class OpenSearchLockProvider implements LockProvider {
+ static final String SCHEDLOCK_DEFAULT_INDEX = "shedlock";
+ static final String LOCK_UNTIL = "lockUntil";
+ static final String LOCKED_AT = "lockedAt";
+ static final String LOCKED_BY = "lockedBy";
+ static final String NAME = "name";
+
+ private static final String UPDATE_SCRIPT = "if (ctx._source." + LOCK_UNTIL + " <= " + "params." + LOCKED_AT
+ + ") { " + "ctx._source." + LOCKED_BY + " = params." + LOCKED_BY + "; " + "ctx._source." + LOCKED_AT
+ + " = params." + LOCKED_AT + "; " + "ctx._source." + LOCK_UNTIL + " = params." + LOCK_UNTIL + "; "
+ + "} else { " + "ctx.op = 'none' " + "}";
+ private static final String UNLOCK_UPDATE_SCRIPT = "ctx._source.lockUntil = params.unlockTime";
+ private static final String PAINLESS_SCRIPT_LANG = "painless";
+ private static final String UNLOCK_TIME = "unlockTime";
+
+ private final OpenSearchClient openSearchClient;
+ private final String hostname;
+ private final String index;
+
+ public OpenSearchLockProvider(OpenSearchClient openSearchClient) {
+ this(openSearchClient, SCHEDLOCK_DEFAULT_INDEX);
+ }
+
+ public OpenSearchLockProvider(OpenSearchClient openSearchClient, String index) {
+ this.openSearchClient = openSearchClient;
+ this.index = index;
+ this.hostname = getHostname();
+ }
+
+ @Override
+ public Optional
* {
* "name" : "lock name",
@@ -61,25 +58,25 @@
* "lockedBy" : "hostname"
* }
*
+ *
*
- *
+ *
+ * @deprecated Use shedlock-provider-opensearch-java module
*/
+@Deprecated(forRemoval = true)
public class OpenSearchLockProvider implements LockProvider {
static final String SCHEDLOCK_DEFAULT_INDEX = "shedlock";
static final String LOCK_UNTIL = "lockUntil";
@@ -87,44 +84,33 @@ public class OpenSearchLockProvider implements LockProvider {
static final String LOCKED_BY = "lockedBy";
static final String NAME = "name";
-
- private static final String UPDATE_SCRIPT =
- "if (ctx._source." + LOCK_UNTIL + " <= " + "params." + LOCKED_AT + ") { " +
- "ctx._source." + LOCKED_BY + " = params." + LOCKED_BY + "; " +
- "ctx._source." + LOCKED_AT + " = params." + LOCKED_AT + "; " +
- "ctx._source." + LOCK_UNTIL + " = params." + LOCK_UNTIL + "; " +
- "} else { " +
- "ctx.op = 'none' " +
- "}";
+ private static final String UPDATE_SCRIPT = "if (ctx._source." + LOCK_UNTIL + " <= " + "params." + LOCKED_AT
+ + ") { " + "ctx._source." + LOCKED_BY + " = params." + LOCKED_BY + "; " + "ctx._source." + LOCKED_AT
+ + " = params." + LOCKED_AT + "; " + "ctx._source." + LOCK_UNTIL + " = params." + LOCK_UNTIL + "; "
+ + "} else { " + "ctx.op = 'none' " + "}";
private final RestHighLevelClient highLevelClient;
private final String hostname;
private final String index;
- private OpenSearchLockProvider(@NonNull RestHighLevelClient highLevelClient, @NonNull String index) {
+ public OpenSearchLockProvider(RestHighLevelClient highLevelClient, String index) {
this.highLevelClient = highLevelClient;
this.hostname = getHostname();
this.index = index;
}
- public OpenSearchLockProvider(@NonNull RestHighLevelClient highLevelClient) {
+ public OpenSearchLockProvider(RestHighLevelClient highLevelClient) {
this(highLevelClient, SCHEDLOCK_DEFAULT_INDEX);
}
@Override
- @NonNull
- public Optional
- *
*/
public class R2dbcLockProvider extends StorageBasedLockProvider {
- public R2dbcLockProvider(@NonNull ConnectionFactory connectionFactory) {
+ public R2dbcLockProvider(ConnectionFactory connectionFactory) {
this(connectionFactory, "shedlock");
}
- public R2dbcLockProvider(@NonNull ConnectionFactory connectionFactory, @NonNull String tableName) {
+ public R2dbcLockProvider(ConnectionFactory connectionFactory, String tableName) {
super(new R2dbcStorageAccessor(connectionFactory, tableName));
}
}
diff --git a/providers/r2dbc/shedlock-provider-r2dbc/src/main/java/net/javacrumbs/shedlock/provider/r2dbc/R2dbcStorageAccessor.java b/providers/r2dbc/shedlock-provider-r2dbc/src/main/java/net/javacrumbs/shedlock/provider/r2dbc/R2dbcStorageAccessor.java
index 5d392d2ec..013683b9e 100644
--- a/providers/r2dbc/shedlock-provider-r2dbc/src/main/java/net/javacrumbs/shedlock/provider/r2dbc/R2dbcStorageAccessor.java
+++ b/providers/r2dbc/shedlock-provider-r2dbc/src/main/java/net/javacrumbs/shedlock/provider/r2dbc/R2dbcStorageAccessor.java
@@ -15,45 +15,43 @@
*/
package net.javacrumbs.shedlock.provider.r2dbc;
+import static java.util.Objects.requireNonNull;
+
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.Statement;
-import net.javacrumbs.shedlock.support.annotation.NonNull;
-import reactor.core.publisher.Mono;
-
import java.util.function.BiFunction;
import java.util.function.Function;
-
-import static java.util.Objects.requireNonNull;
+import net.javacrumbs.shedlock.support.annotation.Nullable;
+import reactor.core.publisher.Mono;
class R2dbcStorageAccessor extends AbstractR2dbcStorageAccessor {
private final ConnectionFactory connectionFactory;
+
+ @Nullable
private R2dbcAdapter adapter;
- R2dbcStorageAccessor(@NonNull ConnectionFactory connectionFactory, @NonNull String tableName) {
+ R2dbcStorageAccessor(ConnectionFactory connectionFactory, String tableName) {
super(tableName);
this.connectionFactory = requireNonNull(connectionFactory, "dataSource can not be null");
}
@Override
protected