/*
 * 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.tests.hive;

import com.google.inject.Inject;
import com.google.inject.name.Named;
import io.prestosql.tempto.ProductTest;

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

public class HiveProductTest
        extends ProductTest
{
    @Inject
    @Named("databases.hive.major_version")
    private int hiveVersionMajor;

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

@@ -700,16 +700,47 @@
 tTest;%0A%0A
+import java.sql.SQLException;%0A%0A
 import s
@@ -793,16 +793,78 @@
 ckState;
+%0Aimport static io.prestosql.tests.utils.QueryExecutors.onHive;
 %0A%0Apublic
@@ -1004,16 +1004,62 @@
 onMajor;
+%0A    private boolean hiveVersionMajorVerified;
 %0A%0A    pr
@@ -1180,32 +1180,579 @@
     
-return hiveVersionMajor;
+if (!hiveVersionMajorVerified) %7B%0A            int detected = detectHiveVersionMajor();%0A            checkState(hiveVersionMajor == detected, %22Hive version major expected: %25s, but was detected as: %25s%22, hiveVersionMajor, detected);%0A            hiveVersionMajorVerified = true;%0A        %7D%0A        return hiveVersionMajor;%0A    %7D%0A%0A    private static int detectHiveVersionMajor()%0A    %7B%0A        try %7B%0A            return onHive().getConnection().getMetaData().getDatabaseMajorVersion();%0A        %7D%0A        catch (SQLException e) %7B%0A            throw new RuntimeException(e);%0A        %7D
 %0A   

Verify Hive version major in product tests