|
57 | 57 | import org.junit.runner.RunWith; |
58 | 58 | import org.junit.runners.Parameterized; |
59 | 59 |
|
| 60 | +import static org.apache.ignite.configuration.SqlConfiguration.DFLT_SQL_PLAN_HISTORY_SIZE; |
60 | 61 | import static org.apache.ignite.internal.processors.query.running.RunningQueryManager.SQL_PLAN_HIST_VIEW; |
61 | 62 | import static org.apache.ignite.testframework.GridTestUtils.waitForCondition; |
62 | 63 | import static org.junit.Assert.assertNotEquals; |
@@ -101,6 +102,18 @@ public class SqlPlanHistoryIntegrationTest extends GridCommonAbstractTest { |
101 | 102 | ), false |
102 | 103 | ); |
103 | 104 |
|
| 105 | + /** Flag indicating whether SQL is configured by using {@link IgniteConfiguration#setSqlConfiguration(SqlConfiguration)}. */ |
| 106 | + private boolean isSqlConfigured = true; |
| 107 | + |
| 108 | + /** Flag indicating whether the SQL engine is configured within {@link SqlConfiguration}. */ |
| 109 | + private boolean isSqlEngineConfigured = true; |
| 110 | + |
| 111 | + /** |
| 112 | + * Flag indicating whether a custom SQL plan history size is explicitly set within {@link SqlConfiguration}. |
| 113 | + * If {@code false}, the default SQL plan history size will be used. |
| 114 | + */ |
| 115 | + private boolean isPlanHistorySizeSet = true; |
| 116 | + |
104 | 117 | /** SQL plan history size. */ |
105 | 118 | private int planHistorySize = 10; |
106 | 119 |
|
@@ -140,10 +153,18 @@ public static Collection<Object[]> params() { |
140 | 153 | @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { |
141 | 154 | IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); |
142 | 155 |
|
143 | | - cfg.setSqlConfiguration(new SqlConfiguration() |
144 | | - .setSqlPlanHistorySize(planHistorySize) |
145 | | - .setQueryEnginesConfiguration(configureSqlEngine()) |
146 | | - ); |
| 156 | + if (isSqlConfigured) { |
| 157 | + SqlConfiguration sqlCfg = new SqlConfiguration(); |
| 158 | + |
| 159 | + if (isSqlEngineConfigured) { |
| 160 | + sqlCfg.setQueryEnginesConfiguration(configureSqlEngine()); |
| 161 | + |
| 162 | + if (isPlanHistorySizeSet) |
| 163 | + sqlCfg.setSqlPlanHistorySize(planHistorySize); |
| 164 | + } |
| 165 | + |
| 166 | + cfg.setSqlConfiguration(sqlCfg); |
| 167 | + } |
147 | 168 |
|
148 | 169 | return cfg.setCacheConfiguration( |
149 | 170 | configureCache("A", Integer.class, String.class), |
@@ -425,6 +446,45 @@ public void testResetPlanHistoryMetrics() throws Exception { |
425 | 446 | checkReset(() -> queryNode().context().query().runningQueryManager().resetPlanHistoryMetrics()); |
426 | 447 | } |
427 | 448 |
|
| 449 | + /** |
| 450 | + * Checks that the actual SQL plan history remains empty and its size in {@link SqlConfiguration} equals {@code -1} |
| 451 | + * when SQL is not explicitly configured. In such cases, H2 is used as the default engine. |
| 452 | + */ |
| 453 | + @Test |
| 454 | + public void testNoSqlConfiguration() throws Exception { |
| 455 | + isSqlConfigured = false; |
| 456 | + |
| 457 | + checkDefaultHistorySize(true, -1, 0, 1); |
| 458 | + } |
| 459 | + |
| 460 | + /** |
| 461 | + * Checks that the actual SQL plan history remains empty and its size in {@link SqlConfiguration} equals {@code -1} |
| 462 | + * when the SQL engine is not configured. In such cases, H2 is used as the default engine. |
| 463 | + */ |
| 464 | + @Test |
| 465 | + public void testNoSqlEngineConfiguration() throws Exception { |
| 466 | + isSqlEngineConfigured = false; |
| 467 | + |
| 468 | + checkDefaultHistorySize(true, -1, 0, 1); |
| 469 | + } |
| 470 | + |
| 471 | + /** |
| 472 | + * Checks that the actual SQL plan history size and its value in {@link SqlConfiguration} are correct for both |
| 473 | + * Calcite and H2 engines when the history size is not explicitly set. |
| 474 | + */ |
| 475 | + @Test |
| 476 | + public void testDefaultHistorySize() throws Exception { |
| 477 | + isPlanHistorySizeSet = false; |
| 478 | + |
| 479 | + boolean isCalcite = sqlEngine.equals(CalciteQueryEngineConfiguration.ENGINE_NAME); |
| 480 | + |
| 481 | + int expConfHistSize = isCalcite ? DFLT_SQL_PLAN_HISTORY_SIZE : -1; |
| 482 | + int expHistSize = isCalcite ? DFLT_SQL_PLAN_HISTORY_SIZE : 0; |
| 483 | + int qrys = isCalcite ? DFLT_SQL_PLAN_HISTORY_SIZE : 1; |
| 484 | + |
| 485 | + checkDefaultHistorySize(false, expConfHistSize, expHistSize, qrys); |
| 486 | + } |
| 487 | + |
428 | 488 | /** |
429 | 489 | * Checks that there is no 'scanCount' suffix in H2 local query plans even if identical queries are not |
430 | 490 | * executed one after another (when there are other queries executed between them). |
@@ -709,6 +769,38 @@ public void checkEmptyHistory(Runnable setup, boolean startGridFirst) throws Exc |
709 | 769 | assertTrue(getSqlPlanHistory().isEmpty()); |
710 | 770 | } |
711 | 771 |
|
| 772 | + /** |
| 773 | + * @param isSingleEngineCheck Flag indicating whether the test should be run for one SQL engine or for both of them. |
| 774 | + * @param expConfHistSize Expected SQL plan history size in {@link SqlConfiguration}. |
| 775 | + * @param expHistSize Expected actual SQL plan history size. |
| 776 | + * @param qrys Nubmer of queries to be run in the test. |
| 777 | + */ |
| 778 | + public void checkDefaultHistorySize( |
| 779 | + boolean isSingleEngineCheck, |
| 780 | + int expConfHistSize, |
| 781 | + int expHistSize, |
| 782 | + int qrys |
| 783 | + ) throws Exception { |
| 784 | + if (isSingleEngineCheck) |
| 785 | + assumeFalse(sqlEngine == CalciteQueryEngineConfiguration.ENGINE_NAME); |
| 786 | + |
| 787 | + assumeFalse(isClient || loc || isFullyFetched); |
| 788 | + |
| 789 | + startTestGrid(); |
| 790 | + |
| 791 | + int confHistSize = queryNode().configuration().getSqlConfiguration().getSqlPlanHistorySize(); |
| 792 | + |
| 793 | + assertEquals(expConfHistSize, confHistSize); |
| 794 | + |
| 795 | + for (int i = 0; i < qrys; i++) { |
| 796 | + String sql = "select * from A.String where _key <= " + i; |
| 797 | + |
| 798 | + cacheQuery(new SqlFieldsQuery(sql), "A"); |
| 799 | + } |
| 800 | + |
| 801 | + assertEquals(expHistSize, getSqlPlanHistory().size()); |
| 802 | + } |
| 803 | + |
712 | 804 | /** */ |
713 | 805 | private static class Person { |
714 | 806 | /** */ |
|
0 commit comments