You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2019/03/20 11:51:40 UTC
[ignite] branch master updated: IGNITE-11557: SQL: Fixed flaky test
SqlSystemViewsSelfTest.testQueryHistoryMetricsModes. This closes #6285.
This is an automated email from the ASF dual-hosted git repository.
vozerov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 243b29f IGNITE-11557: SQL: Fixed flaky test SqlSystemViewsSelfTest.testQueryHistoryMetricsModes. This closes #6285.
243b29f is described below
commit 243b29f6f673e3f20b19deecf9c9218b4823ae62
Author: Yuriy Gerzhedovich <yg...@gridgain.com>
AuthorDate: Wed Mar 20 14:51:31 2019 +0300
IGNITE-11557: SQL: Fixed flaky test SqlSystemViewsSelfTest.testQueryHistoryMetricsModes. This closes #6285.
---
.../apache/ignite/testframework/GridTestUtils.java | 37 +++++++++++++++++-----
.../processors/query/SqlSystemViewsSelfTest.java | 11 ++++---
2 files changed, 35 insertions(+), 13 deletions(-)
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
index 75b5367..b763b8f 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
@@ -46,7 +46,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Properties;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
@@ -2090,9 +2089,9 @@ public final class GridTestUtils {
public static class SqlTestFunctions {
/** Sleep milliseconds. */
- public static volatile long sleepMs = 0;
+ public static volatile long sleepMs;
/** Fail flag. */
- public static volatile boolean fail = false;
+ public static volatile boolean fail;
/**
* Do sleep {@code sleepMs} milliseconds
@@ -2100,13 +2099,21 @@ public final class GridTestUtils {
* @return amount of milliseconds to sleep
*/
@QuerySqlFunction
+ @SuppressWarnings("BusyWait")
public static long sleep() {
- try {
- Thread.sleep(sleepMs);
- }
- catch (InterruptedException ignored) {
- // No-op
+ long end = System.currentTimeMillis() + sleepMs;
+
+ long remainTime =sleepMs;
+
+ do {
+ try {
+ Thread.sleep(remainTime);
+ }
+ catch (InterruptedException ignored) {
+ // No-op
+ }
}
+ while ((remainTime = end - System.currentTimeMillis()) > 0);
return sleepMs;
}
@@ -2123,5 +2130,19 @@ public final class GridTestUtils {
else
return 0;
}
+
+ /**
+ * Function do sleep {@code sleepMs} milliseconds and do fail in case of {@code fail} is true, return 0 otherwise.
+ *
+ * @return amount of milliseconds to sleep in case of {@code fail} is false, fail otherwise.
+ */
+ @QuerySqlFunction
+ public static long sleep_and_can_fail() {
+ long sleep = sleep();
+
+ can_fail();
+
+ return sleep;
+ }
}
}
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlSystemViewsSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlSystemViewsSelfTest.java
index 773d06a..1850eae 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlSystemViewsSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlSystemViewsSelfTest.java
@@ -47,7 +47,6 @@ import org.apache.ignite.cache.query.FieldsQueryCursor;
import org.apache.ignite.cache.query.QueryCursor;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.cache.query.SqlQuery;
-import org.apache.ignite.cache.query.annotations.QuerySqlFunction;
import org.apache.ignite.cluster.ClusterMetrics;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.configuration.CacheConfiguration;
@@ -318,6 +317,7 @@ public class SqlSystemViewsSelfTest extends AbstractIndexingCommonTest {
final String SCHEMA_NAME = "TEST_SCHEMA";
final long MAX_SLEEP = 500;
+ final long MIN_SLEEP = 50;
long tsBeforeRun = System.currentTimeMillis();
@@ -330,9 +330,9 @@ public class SqlSystemViewsSelfTest extends AbstractIndexingCommonTest {
cache.put(100, "200");
- String sql = "SELECT \"STRING\"._KEY, \"STRING\"._VAL FROM \"STRING\" WHERE _key=100 AND sleep()>0 AND can_fail()=0";
+ String sql = "SELECT \"STRING\"._KEY, \"STRING\"._VAL FROM \"STRING\" WHERE _key=100 AND sleep_and_can_fail()>0";
- GridTestUtils.SqlTestFunctions.sleepMs = 50;
+ GridTestUtils.SqlTestFunctions.sleepMs = MIN_SLEEP;
GridTestUtils.SqlTestFunctions.fail = false;
cache.query(new SqlFieldsQuery(sql).setSchema(SCHEMA_NAME)).getAll();
@@ -342,6 +342,7 @@ public class SqlSystemViewsSelfTest extends AbstractIndexingCommonTest {
cache.query(new SqlFieldsQuery(sql).setSchema(SCHEMA_NAME)).getAll();
+ GridTestUtils.SqlTestFunctions.sleepMs = MIN_SLEEP;
GridTestUtils.SqlTestFunctions.fail = true;
GridTestUtils.assertThrows(log,
@@ -386,11 +387,11 @@ public class SqlSystemViewsSelfTest extends AbstractIndexingCommonTest {
assertEquals(0L, secondRow.get(4));
//DURATION_MIN
- assertTrue((Long)firstRow.get(5) > 0);
+ assertTrue((Long)firstRow.get(5) >= MIN_SLEEP);
assertTrue((Long)firstRow.get(5) < (Long)firstRow.get(6));
//DURATION_MAX
- assertTrue((Long)firstRow.get(6) > MAX_SLEEP);
+ assertTrue((Long)firstRow.get(6) >= MAX_SLEEP);
//LAST_START_TIME
assertFalse(((Timestamp)firstRow.get(7)).before(new Timestamp(tsBeforeRun)));