Skip to content

Commit 226a474

Browse files
feat: fix
1 parent ade21aa commit 226a474

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

shaded-lock-ydb/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>tech.ydb.dialects</groupId>
88
<artifactId>shaded-lock-ydb</artifactId>
9-
<version>0.9.1</version>
9+
<version>0.1.0</version>
1010

1111
<packaging>jar</packaging>
1212

shaded-lock-ydb/src/main/java/tech/ydb/lock/provider/YdbCoordinationServiceLockProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public Optional<SimpleLock> lock(LockConfiguration lockConfiguration) {
5757
if (semaphoreLease.isSuccess()) {
5858
logger.debug("Semaphore acquired");
5959

60+
System.out.println(semaphoreLease.getStatus());
6061
return Optional.of(new YdbSimpleLock(semaphoreLease.getValue()));
6162
} else {
6263
return Optional.empty();

shaded-lock-ydb/src/main/java/tech/ydb/lock/provider/YdbLockProviderConfiguration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
public class YdbLockProviderConfiguration {
1515
@Bean
1616
public YdbCoordinationServiceLockProvider ydbLockProvider(DataSource dataSource) throws SQLException {
17-
return new YdbCoordinationServiceLockProvider(dataSource.getConnection().unwrap(YdbConnection.class));
17+
var provider = new YdbCoordinationServiceLockProvider(dataSource.getConnection().unwrap(YdbConnection.class));
18+
19+
provider.init();
20+
21+
return provider;
1822
}
1923
}

shaded-lock-ydb/src/test/java/tech/ydb/lock/provider/YdbLockProviderTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.concurrent.ExecutionException;
88
import java.util.concurrent.Executors;
99
import java.util.concurrent.Future;
10+
import java.util.concurrent.atomic.AtomicBoolean;
1011
import java.util.concurrent.atomic.AtomicInteger;
1112
import net.javacrumbs.shedlock.core.LockConfiguration;
1213
import net.javacrumbs.shedlock.core.SimpleLock;
@@ -53,27 +54,32 @@ private static String jdbcUrl() {
5354
public void integrationTest() throws ExecutionException, InterruptedException {
5455
var executorServer = Executors.newFixedThreadPool(10);
5556
var atomicInt = new AtomicInteger();
57+
var locked = new AtomicBoolean();
5658
var futures = new ArrayList<Future<?>>();
5759

5860
for (int i = 0; i < 100; i++) {
5961
final var ii = i;
6062
futures.add(executorServer.submit(() -> {
61-
lockProvider.init();
62-
6363
Optional<SimpleLock> optinal = Optional.empty();
6464

6565
while (optinal.isEmpty()) {
6666
optinal = lockProvider.lock(
6767
new LockConfiguration(Instant.now(), "semaphore", Duration.ZERO, Duration.ZERO));
6868

6969
optinal.ifPresent(simpleLock -> {
70+
if (locked.get()) {
71+
throw new RuntimeException();
72+
}
73+
locked.set(true);
74+
7075
try {
7176
Thread.sleep(100);
7277
} catch (InterruptedException e) {
7378
throw new RuntimeException(e);
7479
}
7580

7681
atomicInt.addAndGet(ii);
82+
locked.set(false);
7783
simpleLock.unlock();
7884
});
7985
}

0 commit comments

Comments
 (0)