nastra commented on code in PR #5696:
URL: https://github.com/apache/iceberg/pull/5696#discussion_r962988849


##########
aws/src/test/java/org/apache/iceberg/aws/s3/TestS3FileIO.java:
##########
@@ -250,6 +261,53 @@ public void testPrefixDelete() {
         });
   }
 
+  @Test
+  public void testReadMissingLocation() {
+    String location = "s3://bucket/path/to/data.parquet";
+    InputFile in = s3FileIO.newInputFile(location);
+    AssertHelpers.assertThrows(
+        "Should fail with NotFoundException",
+        NotFoundException.class,
+        "Location does not exist",
+        () -> in.newStream().read());
+  }
+
+  @Test
+  public void testMissingTableMetadata() {
+    Map<String, String> conf = Maps.newHashMap();
+    conf.put(
+        CatalogProperties.URI,
+        "jdbc:sqlite:file::memory:?ic" + 
UUID.randomUUID().toString().replace("-", ""));
+    conf.put(JdbcCatalog.PROPERTY_PREFIX + "username", "user");
+    conf.put(JdbcCatalog.PROPERTY_PREFIX + "password", "password");
+    conf.put(CatalogProperties.WAREHOUSE_LOCATION, "s3://bucket/warehouse");
+    conf.put(CatalogProperties.FILE_IO_IMPL, S3FileIO.class.getName());
+    conf.put(AwsProperties.CLIENT_FACTORY, 
StaticClientFactory.class.getName());
+
+    try (JdbcCatalog catalog = new JdbcCatalog()) {
+      catalog.initialize("test_jdbc_catalog", conf);
+
+      Schema schema = new Schema(Types.NestedField.required(1, "id", 
Types.LongType.get()));
+      TableIdentifier ident = TableIdentifier.of("table_name");
+      BaseTable table = (BaseTable) catalog.createTable(ident, schema);
+
+      // delete the current metadata
+      s3FileIO.deleteFile(table.operations().current().metadataFileLocation());
+
+      long start = System.currentTimeMillis();
+      // to test NotFoundException, load the table again. refreshing the 
existing table doesn't
+      // require reading metadata
+      AssertHelpers.assertThrows(
+          "Should fail to refresh",
+          NotFoundException.class,
+          "Location does not exist",
+          () -> catalog.loadTable(ident));
+      long duration = System.currentTimeMillis() - start;
+
+      Assert.assertTrue("Should take less than 10 seconds", duration < 10_000);

Review Comment:
   nit: It might be worth looking at 
[Awaitility](https://github.com/awaitility/awaitility) in order to test stuff 
like this, but probably not worth adding the lib for a single test



-- 
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]

Reply via email to