Skip to content

Commit 28d55f9

Browse files
committed
fix after review
1 parent 8981fab commit 28d55f9

File tree

2 files changed

+21
-40
lines changed

2 files changed

+21
-40
lines changed

modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryAbstractDistributedJoinSelfTest.java

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919

2020
import java.io.Serializable;
2121
import org.apache.ignite.IgniteCache;
22+
import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
2223
import org.apache.ignite.cache.query.annotations.QuerySqlField;
23-
import org.apache.ignite.cache.query.annotations.QuerySqlFunction;
2424
import org.apache.ignite.configuration.CacheConfiguration;
2525
import org.apache.ignite.configuration.IgniteConfiguration;
26-
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
2726
import org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest;
2827
import org.apache.ignite.internal.util.typedef.F;
29-
import org.apache.ignite.internal.util.typedef.internal.U;
28+
import org.apache.ignite.testframework.GridTestUtils;
3029

3130
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
3231
import static org.apache.ignite.cache.CacheMode.PARTITIONED;
@@ -62,10 +61,10 @@ public class IgniteCacheQueryAbstractDistributedJoinSelfTest extends AbstractInd
6261
"order by co._key, pr._key ";
6362

6463
/** */
65-
protected static final String QRY_LONG = "select pe.id, co.id, pr._key\n" +
64+
protected static final String QRY_LONG = "select id1 from (select pe.id as id1, co.id, pr._key\n" +
6665
"from \"pe\".Person pe, \"pr\".Product pr, \"co\".Company co, \"pu\".Purchase pu\n" +
67-
"where pe._key = pu.personId and pu.productId = pr._key and pr.companyId = co._key \n" +
68-
"order by pe.id desc";
66+
"where pe._key = pu.personId and pu.productId = pr._key and pr.companyId = co._key\n" +
67+
"order by pe.id) where id1 > sleep(10)";
6968

7069
/** */
7170
protected static final int GRID_CNT = 2;
@@ -74,7 +73,7 @@ public class IgniteCacheQueryAbstractDistributedJoinSelfTest extends AbstractInd
7473
private static final int PERS_CNT = 600;
7574

7675
/** */
77-
private static final int PURCHASE_CNT = 24_000;
76+
private static final int PURCHASE_CNT = 6_000;
7877

7978
/** */
8079
private static final int COMPANY_CNT = 25;
@@ -100,6 +99,8 @@ public class IgniteCacheQueryAbstractDistributedJoinSelfTest extends AbstractInd
10099
cc.setAtomicityMode(TRANSACTIONAL);
101100
cc.setRebalanceMode(SYNC);
102101
cc.setLongQueryWarningTimeout(15_000);
102+
cc.setAffinity(new RendezvousAffinityFunction(false, 60));
103+
cc.setSqlFunctionClasses(GridTestUtils.SqlTestFunctions.class);
103104

104105
switch (name) {
105106
case "pe":
@@ -252,20 +253,4 @@ protected static class Product implements Serializable {
252253
this.companyId = companyId;
253254
}
254255
}
255-
256-
/** */
257-
public static class Functions {
258-
/** */
259-
@QuerySqlFunction
260-
public static int sleep() {
261-
try {
262-
U.sleep(1_000);
263-
}
264-
catch (IgniteInterruptedCheckedException ignored) {
265-
// No-op.
266-
}
267-
268-
return 0;
269-
}
270-
}
271256
}

modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,20 @@
2525
import javax.cache.CacheException;
2626
import org.apache.ignite.Ignite;
2727
import org.apache.ignite.IgniteCache;
28+
import org.apache.ignite.IgniteException;
2829
import org.apache.ignite.cache.query.QueryCancelledException;
2930
import org.apache.ignite.cache.query.QueryCursor;
3031
import org.apache.ignite.cache.query.SqlFieldsQuery;
3132
import org.apache.ignite.internal.IgniteEx;
32-
import org.apache.ignite.internal.processors.GridProcessor;
33+
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
3334
import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing;
35+
import org.apache.ignite.internal.util.typedef.F;
3436
import org.apache.ignite.internal.util.typedef.X;
3537
import org.apache.ignite.internal.util.typedef.internal.U;
3638
import org.junit.Test;
3739

40+
import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
41+
3842
/**
3943
* Test for cancel of query containing distributed joins.
4044
*/
@@ -90,7 +94,7 @@ public void testTimeout4() throws Exception {
9094
/** */
9195
private void testQueryCancel(Ignite ignite, String cacheName, String sql, int timeoutUnits, TimeUnit timeUnit,
9296
boolean timeout, boolean checkCanceled) throws Exception {
93-
SqlFieldsQuery qry = new SqlFieldsQuery(sql).setDistributedJoins(true);;
97+
SqlFieldsQuery qry = new SqlFieldsQuery(sql).setDistributedJoins(true);
9498

9599
IgniteCache<Object, Object> cache = ignite.cache(cacheName);
96100

@@ -107,44 +111,36 @@ private void testQueryCancel(Ignite ignite, String cacheName, String sql, int ti
107111
}
108112

109113
try (QueryCursor<List<?>> ignored = cursor) {
110-
int resSize = 0;
111-
for (List<?> ignored1 : cursor) {
112-
++resSize;
113-
}
114+
int resSize = F.size(cursor.iterator());
114115

115116
if (checkCanceled)
116117
fail("Query not canceled, result size=" + resSize);
117118
}
118-
catch (CacheException ex) {
119-
log().error("Got expected exception", ex);
119+
catch (CacheException | IgniteException ex) {
120+
log().error("Got exception", ex);
120121

121122
assertNotNull("Must throw correct exception", X.cause(ex, QueryCancelledException.class));
122123
}
123124

124-
// Give some time to clean up.
125-
Thread.sleep(TimeUnit.MILLISECONDS.convert(timeoutUnits, timeUnit) + 1_000);
126-
127125
checkCleanState();
128126
}
129127

130128
/**
131129
* Validates clean state on all participating nodes after query cancellation.
132130
*/
133-
private void checkCleanState() {
131+
private void checkCleanState() throws IgniteInterruptedCheckedException {
134132
for (int i = 0; i < GRID_CNT; i++) {
135133
IgniteEx grid = grid(i);
136134

137135
// Validate everything was cleaned up.
138-
ConcurrentMap<UUID, ?> map = U.field(((IgniteH2Indexing)U.field((GridProcessor)U.field(
139-
grid.context(), "qryProc"), "idx")).mapQueryExecutor(), "qryRess");
140-
141-
String msg = "Map executor state is not cleared";
136+
ConcurrentMap<UUID, ?> map = U.field(
137+
((IgniteH2Indexing)grid.context().query().getIndexing()).mapQueryExecutor(), "qryRess");
142138

143139
// TODO FIXME Current implementation leaves map entry for each node that's ever executed a query.
144140
for (Object result : map.values()) {
145141
Map<Long, ?> m = U.field(result, "res");
146142

147-
assertEquals(msg, 0, m.size());
143+
assertTrue("Map executor state is not cleared", waitForCondition(m::isEmpty, 1_000L));
148144
}
149145
}
150146
}

0 commit comments

Comments
 (0)