Fix flaky testTransactionMetadataCleanup
*/
package com.facebook.presto.tests;
+import com.facebook.airlift.log.Logger;
import com.facebook.presto.tests.tpch.TpchQueryRunnerBuilder;
+import com.facebook.presto.transaction.TransactionInfo;
+import com.facebook.presto.transaction.TransactionManager;
import org.testng.annotations.Test;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.testng.Assert.assertTrue;
public class TestTransactionManagerIntegration
{
+ private static final Logger log = Logger.get(TestTransactionManagerIntegration.class);
+
@Test
public void testTransactionMetadataCleanup()
throws Exception
{
try (DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder().build()) {
+ log.info("Start running testTransactionMetadataCleanup");
+ TransactionManager transactionManager = queryRunner.getTransactionManager();
// test valid queries
queryRunner.execute("select count(*) from nation");
queryRunner.execute("select count(*) from lineitem");
- assertTrue(queryRunner.getTransactionManager().getAllTransactionInfos().isEmpty());
+ assertTrue(waitForTransactionMetadataCleanup(transactionManager),
+ "Remaining transaction ids: " + transactionManager.getAllTransactionInfos().stream()
+ .map(TransactionInfo::getTransactionId)
+ .collect(toImmutableList()));
// test invalid queries with different types of semantic error
assertThatThrownBy(() -> queryRunner.execute("SELECT non_existing_column FROM non_existing_table"))
.isInstanceOf(RuntimeException.class);
@@ -37,7 +49,27 @@ public class TestTransactionManagerIntegration
.isInstanceOf(RuntimeException.class);
assertThatThrownBy(() -> queryRunner.execute("select regionkey from nation group by regionkey having 'wrong_condition'"))
.isInstanceOf(RuntimeException.class);
- assertTrue(queryRunner.getTransactionManager().getAllTransactionInfos().isEmpty());
+
+ assertTrue(waitForTransactionMetadataCleanup(transactionManager),
+ "Remaining transaction ids: " + transactionManager.getAllTransactionInfos().stream()
+ .map(TransactionInfo::getTransactionId)
+ .collect(toImmutableList()));
+ log.info("Complete test testTransactionMetadataCleanup");
+ }
+ }
+
+ private boolean waitForTransactionMetadataCleanup(TransactionManager transactionManager)
+ throws InterruptedException
+ {
+ long timeout = 5000;
+ long retryInterval = 10;
+ while (timeout > 0) {
+ if (transactionManager.getAllTransactionInfos().isEmpty()) {
+ return true;
+ }
+ MILLISECONDS.sleep(retryInterval);
+ timeout -= retryInterval;
}
+ return false;
}
}
