/*
 * 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 com.facebook.presto.tests;

import com.facebook.presto.tests.tpch.TpchQueryRunnerBuilder;
import org.testng.annotations.Test;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.testng.Assert.assertTrue;

public class TestTransactionManagerIntegration
{
    @Test
    public void testTransactionMetadataCleanup()
            throws Exception
    {
        try (DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder().build()) {
            // test valid queries
            queryRunner.execute("select count(*) from nation");
            queryRunner.execute("select count(*) from lineitem");
            assertTrue(queryRunner.getTransactionManager().getAllTransactionInfos().isEmpty());
            // test invalid queries with different types of semantic error
            assertThatThrownBy(() -> queryRunner.execute("SELECT non_existing_column FROM non_existing_table"))
                    .isInstanceOf(RuntimeException.class);
            assertThatThrownBy(() -> queryRunner.execute("select * from unnest('wrong_type')"))
                    .isInstanceOf(RuntimeException.class);
            assertThatThrownBy(() -> queryRunner.execute("select regionkey from nation group by regionkey having 'wrong_condition'"))
                    .isInstanceOf(RuntimeException.class);
            assertTrue(queryRunner.getTransactionManager().getAllTransactionInfos().isEmpty());
            // test query that fails during plan
            assertThatThrownBy(() -> queryRunner.execute("select 1/0"))
                    .isInstanceOf(RuntimeException.class);
            // test query that fails during execution
            assertThatThrownBy(() -> queryRunner.execute("select regionkey / (regionkey - regionkey) from nation"))
                    .isInstanceOf(RuntimeException.class);
            assertTrue(queryRunner.getTransactionManager().getAllTransactionInfos().isEmpty());
        }
    }
}

@@ -1992,513 +1992,8 @@
 ));%0A
-            // test query that fails during plan%0A            assertThatThrownBy(() -%3E queryRunner.execute(%22select 1/0%22))%0A                    .isInstanceOf(RuntimeException.class);%0A            // test query that fails during execution%0A            assertThatThrownBy(() -%3E queryRunner.execute(%22select regionkey / (regionkey - regionkey) from nation%22))%0A                    .isInstanceOf(RuntimeException.class);%0A            assertTrue(queryRunner.getTransactionManager().getAllTransactionInfos().isEmpty());%0A
     

Remove flaky test in transaction manager