nastra commented on code in PR #12194: URL: https://github.com/apache/iceberg/pull/12194#discussion_r2262660689
########## core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java: ########## @@ -2698,6 +2706,133 @@ public void testTableExistsFallbackToGETRequestWithLegacyServer() { verifyTableExistsFallbackToGETRequest(ConfigResponse.builder().build()); } + @Test + public void testETagCreateTableAndLoadTable() { + Map<String, String> respHeaders = Maps.newConcurrentMap(); + + RESTCatalog catalog = setUpETagTest(respHeaders); + + catalog.createTable(TABLE, SCHEMA); + + assertThat(respHeaders).containsKey(HttpHeaders.ETAG); + String eTag = respHeaders.get(HttpHeaders.ETAG); + respHeaders.clear(); + + catalog.loadTable(TABLE); + + assertThat(respHeaders).containsKey(HttpHeaders.ETAG); + assertThat(eTag).isEqualTo(respHeaders.get(HttpHeaders.ETAG)); + respHeaders.clear(); + } + + @Test + public void testETagDifferentTables() { + Map<String, String> respHeaders = Maps.newConcurrentMap(); + + RESTCatalog catalog = setUpETagTest(respHeaders); + + catalog.createTable(TABLE, SCHEMA); + + assertThat(respHeaders).containsKey(HttpHeaders.ETAG); + String eTagTbl1 = respHeaders.get(HttpHeaders.ETAG); + respHeaders.clear(); + + catalog.createTable(TableIdentifier.of(TABLE.namespace(), "table2"), SCHEMA); + + assertThat(respHeaders).containsKey(HttpHeaders.ETAG); + assertThat(eTagTbl1).isNotEqualTo(respHeaders.get(HttpHeaders.ETAG)); + } + + @Test + public void testETagAfterDataUpdate() { + Map<String, String> respHeaders = Maps.newConcurrentMap(); + + RESTCatalog catalog = setUpETagTest(respHeaders); + + catalog.createTable(TABLE, SCHEMA); + + respHeaders.clear(); + + Table tbl = catalog.loadTable(TABLE); + + assertThat(respHeaders).containsKey(HttpHeaders.ETAG); + String eTag = respHeaders.get(HttpHeaders.ETAG); + respHeaders.clear(); + + tbl.newAppend().appendFile(FILE_A).commit(); + + assertThat(respHeaders).containsKey(HttpHeaders.ETAG); + assertThat(eTag).isNotEqualTo(respHeaders.get(HttpHeaders.ETAG)); + } + + @Test + public void testETagAfterMetadataOnlyUpdate() { + Map<String, String> respHeaders = Maps.newConcurrentMap(); + + RESTCatalog catalog = setUpETagTest(respHeaders); + + catalog.createTable(TABLE, SCHEMA); + + respHeaders.clear(); + + Table tbl = catalog.loadTable(TABLE); + + assertThat(respHeaders).containsKey(HttpHeaders.ETAG); + String eTag = respHeaders.get(HttpHeaders.ETAG); + respHeaders.clear(); + + tbl.updateSchema().addColumn("extra", Types.IntegerType.get()).commit(); + + assertThat(respHeaders).containsKey(HttpHeaders.ETAG); + assertThat(eTag).isNotEqualTo(respHeaders.get(HttpHeaders.ETAG)); + } + + @Test + public void testETagRegisterTable() { + Map<String, String> respHeaders = Maps.newConcurrentMap(); + + RESTCatalog catalog = setUpETagTest(respHeaders); + + catalog.createTable(TABLE, SCHEMA); + + respHeaders.clear(); + + Table tbl = catalog.loadTable(TABLE); + + assertThat(respHeaders).containsKey(HttpHeaders.ETAG); + String eTag = respHeaders.get(HttpHeaders.ETAG); + respHeaders.clear(); + + catalog.registerTable( + TableIdentifier.of(TABLE.namespace(), "other_table"), + ((BaseTable) tbl).operations().current().metadataFileLocation()); + + assertThat(respHeaders).containsKey(HttpHeaders.ETAG); + assertThat(eTag).isEqualTo(respHeaders.get(HttpHeaders.ETAG)); + } + + private RESTCatalog setUpETagTest(Map<String, String> respHeaders) { Review Comment: I would rename this to something like `adapterWithResponseHeaders` -- 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