Claudenw commented on code in PR #13345:
URL: https://github.com/apache/iceberg/pull/13345#discussion_r2163110744


##########
core/src/test/java/org/apache/iceberg/jdbc/TestJdbcTableConcurrency.java:
##########
@@ -149,4 +190,1015 @@ public synchronized void testConcurrentConnections() 
throws InterruptedException
     assertThat(executorService.awaitTermination(3, 
TimeUnit.MINUTES)).as("Timeout").isTrue();
     assertThat(Iterables.size(icebergTable.snapshots())).isEqualTo(7);
   }
+
+  @Test
+  public synchronized void testInitializeWithSlowConcurrentConnections()
+      throws InterruptedException, SQLException, ExecutionException, 
ClassNotFoundException {
+    // number of threads and requests to attempt.
+    int parallelism = 2;
+    // verifies that multiple calls to initialize with slow responses will not 
fail.
+    Map<String, String> properties = Maps.newHashMap();
+
+    properties.put(CatalogProperties.WAREHOUSE_LOCATION, 
tableDir.getAbsolutePath());
+    String testingDB = "jdbc:slow:derby:memory:testDb;create=true";
+    new org.apache.derby.jdbc.EmbeddedDriver();
+    properties.put(CatalogProperties.URI, testingDB);
+    SlowDriver slowDriver = new SlowDriver(testingDB);

Review Comment:
   You can try but then the pass/fail of the test is dependent upon the system 
on which it runs.  I feel that if you want to test a condition where a thread 
gets paused between two steps, make it pause.
   
   I would be willing to make the entire wrapper classes a library so that here 
it would simply be creating an instance and overriding the two methods.



##########
core/src/test/java/org/apache/iceberg/jdbc/TestJdbcTableConcurrency.java:
##########
@@ -149,4 +190,1015 @@ public synchronized void testConcurrentConnections() 
throws InterruptedException
     assertThat(executorService.awaitTermination(3, 
TimeUnit.MINUTES)).as("Timeout").isTrue();
     assertThat(Iterables.size(icebergTable.snapshots())).isEqualTo(7);
   }
+
+  @Test
+  public synchronized void testInitializeWithSlowConcurrentConnections()
+      throws InterruptedException, SQLException, ExecutionException, 
ClassNotFoundException {
+    // number of threads and requests to attempt.
+    int parallelism = 2;
+    // verifies that multiple calls to initialize with slow responses will not 
fail.
+    Map<String, String> properties = Maps.newHashMap();
+
+    properties.put(CatalogProperties.WAREHOUSE_LOCATION, 
tableDir.getAbsolutePath());
+    String testingDB = "jdbc:slow:derby:memory:testDb;create=true";
+    new org.apache.derby.jdbc.EmbeddedDriver();
+    properties.put(CatalogProperties.URI, testingDB);
+    SlowDriver slowDriver = new SlowDriver(testingDB);
+
+    Callable<JdbcCatalog> makeCatalog =
+        () -> {
+          JdbcCatalog catalog = new JdbcCatalog();
+          catalog.setConf(new Configuration());
+          catalog.initialize("jdbc", properties);
+          return catalog;
+        };
+
+    try {
+      DriverManager.registerDriver(slowDriver);
+      ExecutorService executorService =
+          MoreExecutors.getExitingExecutorService(
+              (ThreadPoolExecutor) Executors.newFixedThreadPool(parallelism));
+
+      List<Future<JdbcCatalog>> futures = Lists.newArrayList();
+      for (int i = 0; i < parallelism; i++) {
+        futures.add(executorService.submit(makeCatalog));
+      }
+      for (Future<JdbcCatalog> future : futures) {
+        future.get();
+      }
+    } finally {
+      DriverManager.deregisterDriver(slowDriver);
+    }

Review Comment:
   I am not sure what you are asking for here.  the future executes creates and 
initializes the JdbcCatalog which does not return from initialize until the 
initialization is complete.  So the `future.get` at line 227 ensures that the 
creation and initialization has completed for both.
   
   I don't see a Catalog method to call to verify that it is valid/working.  Do 
you have a suggestion?



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to