henrib commented on code in PR #4820: URL: https://github.com/apache/hive/pull/4820#discussion_r1371746550
########## standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/events/TestAlterPartitionsEvent.java: ########## @@ -0,0 +1,116 @@ +/* + * 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.hadoop.hive.metastore.events; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.stream.IntStream; + +import org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest; +import org.apache.hadoop.hive.metastore.api.Partition; +import org.apache.hadoop.hive.metastore.api.Table; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) +@Category(MetastoreUnitTest.class) +public class TestAlterPartitionsEvent { + + private AlterPartitionsEvent event; + private List<Partition> expectedParts; + private Map<Long, List<Partition>> writeIdToParts; + private int batchSize; + private int expectedBatch; + + @Parameterized.Parameters + public static Collection<Object[]> getIteratorToTest() { + List<Partition> parts = new ArrayList<>(); + IntStream.range(0, 10).forEach(i -> { + Partition partition = new Partition(); + partition.setValues(Arrays.asList(i + "", "part" + i)); + partition.setWriteId(i < 5 ? 1 : 2); + parts.add(partition); + }); + Partition partition = new Partition(); + partition.setValues(Arrays.asList(10 + "", "part" + 10)); + partition.setWriteId(3); + parts.add(partition); + + AlterPartitionsEvent event = new AlterPartitionsEvent(parts, parts, new Table(), false, true, null); + Collection<Object[]> params = new ArrayList<>(); + params.add(new Object[]{event, 1000, parts, 3}); + params.add(new Object[]{event, 5, parts, 3}); + params.add(new Object[]{event, 3, parts, 5}); + params.add(new Object[]{event, 2, parts, 7}); + params.add(new Object[]{event, 1, parts, 11}); + params.add(new Object[]{event, -1, parts, 3}); + return params; + } + + public TestAlterPartitionsEvent(AlterPartitionsEvent event, int batchSize, + List<Partition> expectedParts, int expectedBatch) { + this.event = event; + this.batchSize = batchSize; + this.expectedParts = expectedParts; + this.expectedBatch = expectedBatch; + this.writeIdToParts = new HashMap<>(); + expectedParts.stream().forEach(partition -> { Review Comment: computeIfAbsent(...) ########## standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/events/AlterPartitionsEvent.java: ########## Review Comment: After the fact but naming a class as a plural of another is asking for trouble (AlterPartitionEvent vs AlterPartitionsEvent) since they are very similar. AlterPartitionSetEvent for instance could be considered. Incidentally, shouldn't these be sets, the list of partitions ? Can the same partition appear twice in an event ? Shouldn't we see Iterator<Set<Partition>> ? -- 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]
