rdblue commented on code in PR #5118: URL: https://github.com/apache/iceberg/pull/5118#discussion_r905580341
########## core/src/test/java/org/apache/iceberg/rest/responses/TestLoadTableResponse.java: ########## @@ -0,0 +1,371 @@ +/* + * 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.rest.responses; + +import com.fasterxml.jackson.core.JsonProcessingException; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.UUID; +import org.apache.iceberg.AssertHelpers; +import org.apache.iceberg.BaseSnapshot; +import org.apache.iceberg.GenericManifestFile; +import org.apache.iceberg.HistoryEntry; +import org.apache.iceberg.LocalTableOperations; +import org.apache.iceberg.NullOrder; +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.Schema; +import org.apache.iceberg.Snapshot; +import org.apache.iceberg.SnapshotRef; +import org.apache.iceberg.SortOrder; +import org.apache.iceberg.TableMetadata; +import org.apache.iceberg.TableOperations; +import org.apache.iceberg.expressions.Expressions; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.rest.RequestResponseTestBase; +import org.apache.iceberg.types.Types; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import static org.apache.iceberg.Files.localInput; +import static org.apache.iceberg.TestHelpers.assertSameSchemaList; + +public class TestLoadTableResponse extends RequestResponseTestBase<LoadTableResponse> { + + private static final String TEST_METADATA_LOCATION = "s3://bucket/test/location/metadata/v1.metadata.json"; + + private static final String TEST_TABLE_LOCATION = "s3://bucket/test/location"; + + private static final Schema TEST_SCHEMA = new Schema(7, + Types.NestedField.required(1, "x", Types.LongType.get()), + Types.NestedField.required(2, "y", Types.LongType.get(), "comment"), + Types.NestedField.required(3, "z", Types.LongType.get()) + ); + + private static final PartitionSpec SPEC_5 = PartitionSpec.builderFor(TEST_SCHEMA).withSpecId(5).build(); + + private static final SortOrder SORT_ORDER_3 = SortOrder.builderFor(TEST_SCHEMA) + .withOrderId(3) + .asc("y", NullOrder.NULLS_FIRST) + .desc(Expressions.bucket("z", 4), NullOrder.NULLS_LAST) + .build(); + + private static final long SEQ_NO = 34; + private static final int LAST_ASSIGNED_COLUMN_ID = 3; + + private static final long PREVIOUS_SNAPSHOT_ID = System.currentTimeMillis() - new Random(1234).nextInt(3600); + + private static final String TEST_UUIID = "01073077-d2fd-4132-b86c-09d5107e4747"; + + private static final Map<String, String> TABLE_PROPS = ImmutableMap.of( + "format-version", "1", + "owner", "hank"); + + private static final Map<String, String> CONFIG = ImmutableMap.of("foo", "bar"); + + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + public TableOperations ops = new LocalTableOperations(temp); + + @Override + public String[] allFieldsFromSpec() { + return new String[] { "metadataLocation", "metadata", "config" }; + } + + @Override + public LoadTableResponse createExampleInstance() { + TableMetadata metadata = TableMetadata.newTableMetadata( + TEST_SCHEMA, SPEC_5, SORT_ORDER_3, TEST_TABLE_LOCATION, TABLE_PROPS); + // Add location + TableMetadata metadataWithLocation = TableMetadata + .buildFrom(metadata) + .withMetadataLocation(TEST_METADATA_LOCATION) + .build(); + return LoadTableResponse.builder() + .withTableMetadata(metadataWithLocation) + .addAllConfig(CONFIG) + .build(); + } + + @Override + public LoadTableResponse deserialize(String json) throws JsonProcessingException { + LoadTableResponse resp = mapper().readValue(json, LoadTableResponse.class); + resp.validate(); + return resp; + } + + @Test + public void testFailures() { Review Comment: Metadata location is also required according to the spec. -- 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]
