/*
 * Licensed 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 io.prestosql.plugin.hive;

import org.apache.hadoop.net.NetUtils;
import org.testng.SkipException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;

import java.net.UnknownHostException;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;

public class TestHive
        extends AbstractTestHive
{
    private int hiveVersionMajor;

    @Parameters({
            "hive.hadoop2.metastoreHost",
            "hive.hadoop2.metastorePort",
            "hive.hadoop2.databaseName",
            "hive.hadoop2.hiveVersionMajor",
            "hive.hadoop2.timeZone",
    })
    @BeforeClass
    public void initialize(String host, int port, String databaseName, int hiveVersionMajor, String timeZone)
            throws UnknownHostException
    {
        String hadoopMasterIp = System.getProperty("hadoop-master-ip");
        if (hadoopMasterIp != null) {
            // Even though Hadoop is accessed by proxy, Hadoop still tries to resolve hadoop-master
            // (e.g: in: NameNodeProxies.createProxy)
            // This adds a static resolution for hadoop-master to docker container internal ip
            NetUtils.addStaticResolution("hadoop-master", hadoopMasterIp);
        }

        setup(host, port, databaseName, timeZone);

        checkArgument(hiveVersionMajor > 0, "Invalid hiveVersionMajor: %s", hiveVersionMajor);
        this.hiveVersionMajor = hiveVersionMajor;
    }

    private int getHiveVersionMajor()
    {
        checkState(hiveVersionMajor > 0, "hiveVersionMajor not set");
        return hiveVersionMajor;
    }

    @Override
    public void testGetPartitionSplitsTableOfflinePartition()
    {
        if (getHiveVersionMajor() >= 2) {
            throw new SkipException("ALTER TABLE .. ENABLE OFFLINE was removed in Hive 2.0 and this is a prerequisite for this test");
        }

        super.testGetPartitionSplitsTableOfflinePartition();
    }
}

@@ -915,16 +915,82 @@
 ckState;
+%0Aimport static org.assertj.core.api.Assertions.assertThatThrownBy;
 %0A%0Apublic
@@ -2619,11 +2619,1576 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public void testTypesRcBinary()%0A            throws Exception%0A    %7B%0A        if (getHiveVersionMajor() %3E= 3) %7B%0A            // TODO (https://github.com/prestosql/presto/issues/1218) requires https://issues.apache.org/jira/browse/HIVE-22167%0A            assertThatThrownBy(super::testTypesRcBinary)%0A                    .isInstanceOf(AssertionError.class)%0A                    .hasMessage(%22expected %5B2011-05-06 01:23:09.123%5D but found %5B2011-05-06 07:08:09.123%5D%22);%0A            return;%0A        %7D%0A        super.testTypesRcBinary();%0A    %7D%0A%0A    @Override%0A    public void testTypesOrc()%0A            throws Exception%0A    %7B%0A        if (getHiveVersionMajor() %3E= 3) %7B%0A            // TODO (https://github.com/prestosql/presto/issues/1218)%0A            assertThatThrownBy(super::testTypesOrc)%0A                    .isInstanceOf(AssertionError.class)%0A                    .hasMessage(%22expected %5B2011-05-06 01:23:09.123%5D but found %5B2011-05-06 07:08:09.123%5D%22);%0A            return;%0A        %7D%0A        super.testTypesOrc();%0A    %7D%0A%0A    @Override%0A    public void testTypesParquet()%0A            throws Exception%0A    %7B%0A        if (getHiveVersionMajor() %3E= 3) %7B%0A            // TODO (https://github.com/prestosql/presto/issues/1218) requires https://issues.apache.org/jira/browse/HIVE-21002%0A            assertThatThrownBy(super::testTypesParquet)%0A                    .isInstanceOf(AssertionError.class)%0A                    .hasMessage(%22expected %5B2011-05-06 01:23:09.123%5D but found %5B2011-05-06 07:08:09.123%5D%22);%0A            return;%0A        %7D%0A        super.testTypesParquet();%0A    %7D
 %0A%7D%0A

Disable hive tests broken by Hive breaking changes