pvary commented on code in PR #18823:
URL: https://github.com/apache/iceberg/pull/18823#discussion_r4663768514
##########
flink/v2.3/flink/src/test/java/org/apache/iceberg/flink/maintenance/api/TestJdbcLockFactory.java:
##########
@@ -103,4 +109,78 @@ void testUncheckedSQLExceptionBypassesRetry() throws
Exception {
.hasMessageContaining("wrapped");
}
}
+
+ @Test
+ void testLockTableInitializationPropagatesDatabaseFailure() {
+ Map<String, String> props = Maps.newHashMap();
+ props.put(INIT_LOCK_TABLES_PROPERTY, "true");
+
+ JdbcLockFactory factory =
+ new JdbcLockFactory(
+ "jdbc:sqlite:file:/nonexistent-iceberg-lock-test-dir/locks.db",
+ "failed-initialization",
+ props);
+
+ assertThatThrownBy(factory::open)
+ .isInstanceOf(UncheckedSQLException.class)
+ .hasMessageContaining("Failed to connect");
+ }
+
+ @Test
+ void testConcurrentLockTableInitialization() throws Exception {
+ Map<String, String> props = Maps.newHashMap();
+ props.put(INIT_LOCK_TABLES_PROPERTY, "true");
+
+ String uri =
+ "jdbc:sqlite:file:lock-init-"
+ + UUID.randomUUID().toString().replace("-", "")
+ + "?mode=memory&cache=shared";
+
+ JdbcLockFactory first = new JdbcLockFactory(uri, "first", props);
+ JdbcLockFactory second = new JdbcLockFactory(uri, "second", props);
+
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+ CountDownLatch ready = new CountDownLatch(2);
+ CountDownLatch startSignal = new CountDownLatch(1);
+
+ try {
+ Future<?> firstResult =
+ executor.submit(
+ () -> {
+ ready.countDown();
+ startSignal.await();
+ first.open();
+ return null;
+ });
+
+ Future<?> secondResult =
+ executor.submit(
+ () -> {
+ ready.countDown();
+ startSignal.await();
+ second.open();
+ return null;
+ });
+
+ assertThat(ready.await(10, TimeUnit.SECONDS)).isTrue();
+ startSignal.countDown();
+
+ firstResult.get(30, TimeUnit.SECONDS);
+ secondResult.get(30, TimeUnit.SECONDS);
+
+ Lock firstLock = first.createLock();
+ Lock secondLock = second.createLock();
+
+ try {
+ assertThat(firstLock.tryLock()).isTrue();
+ assertThat(secondLock.tryLock()).isTrue();
+ } finally {
+ firstLock.unlock();
+ secondLock.unlock();
+ }
+ } finally {
Review Comment:
Shall we close the factories?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]