rdblue commented on code in PR #6948: URL: https://github.com/apache/iceberg/pull/6948#discussion_r1252363188
########## core/src/test/java/org/apache/iceberg/catalog/CatalogTransactionTests.java: ########## @@ -0,0 +1,736 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg.catalog; + +import static org.apache.iceberg.catalog.CatalogTransaction.IsolationLevel.SERIALIZABLE; +import static org.apache.iceberg.catalog.CatalogTransaction.IsolationLevel.SNAPSHOT; +import static org.apache.iceberg.types.Types.NestedField.required; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; +import org.apache.iceberg.BaseTable; +import org.apache.iceberg.DataFile; +import org.apache.iceberg.DataFiles; +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.Schema; +import org.apache.iceberg.Snapshot; +import org.apache.iceberg.SnapshotSummary; +import org.apache.iceberg.Table; +import org.apache.iceberg.TableMetadata; +import org.apache.iceberg.TestCatalogUtil; +import org.apache.iceberg.exceptions.CommitFailedException; +import org.apache.iceberg.exceptions.ValidationException; +import org.apache.iceberg.relocated.com.google.common.collect.Iterables; +import org.apache.iceberg.types.Types; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +public abstract class CatalogTransactionTests< + C extends SupportsCatalogTransactions & SupportsNamespaces & Catalog> { + + @TempDir protected Path metadataDir; + + protected static final Schema SCHEMA = + new Schema( + required(3, "id", Types.IntegerType.get()), required(4, "data", Types.StringType.get())); + + // Partition spec used to create tables + protected static final PartitionSpec SPEC = + PartitionSpec.builderFor(SCHEMA).bucket("data", 16).build(); + + protected static final DataFile FILE_A = + DataFiles.builder(SPEC) + .withPath("/path/to/data-a.parquet") + .withFileSizeInBytes(10) + .withPartitionPath("data_bucket=0") // easy way to set partition data for now + .withRecordCount(1) + .build(); + protected static final DataFile FILE_B = + DataFiles.builder(SPEC) + .withPath("/path/to/data-b.parquet") + .withFileSizeInBytes(10) + .withPartitionPath("data_bucket=1") // easy way to set partition data for now + .withRecordCount(1) + .build(); + protected static final DataFile FILE_C = + DataFiles.builder(SPEC) + .withPath("/path/to/data-c.parquet") + .withFileSizeInBytes(10) + .withPartitionPath("data_bucket=2") // easy way to set partition data for now + .withRecordCount(1) + .build(); + protected static final DataFile FILE_D = + DataFiles.builder(SPEC) + .withPath("/path/to/data-d.parquet") + .withFileSizeInBytes(10) + .withPartitionPath("data_bucket=3") // easy way to set partition data for now + .withRecordCount(1) + .build(); + + protected abstract C catalog(); + + @Test + public void testNulls() { + assertThatThrownBy(() -> new BaseCatalogTransaction(null, null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Invalid origin catalog: null"); + + assertThatThrownBy(() -> new BaseCatalogTransaction(catalog(), null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Invalid isolation level: null"); + } + + @Test + public void catalogTransactionSupport() { + assertThatThrownBy( + () -> new BaseCatalogTransaction(new TestCatalogUtil.TestCatalog(), SERIALIZABLE)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Origin catalog does not support catalog transactions"); + } + + @Test + public void multipleCommits() { + CatalogTransaction catalogTx = catalog().createTransaction(SERIALIZABLE); + catalogTx.commitTransaction(); + assertThatThrownBy(catalogTx::commitTransaction) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Transaction has already committed changes"); + } + + @Test + public void invalidIsolationLevel() { + assertThatThrownBy(() -> catalog().createTransaction(null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Invalid isolation level: null"); + } + + @Test + public void catalogTxWithSingleOp() { Review Comment: Style: unnecessary abbreviation makes code harder to read. Generally prefer "transaction" over "tx" or "txn". -- 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]
