26
26
import com .apple .foundationdb .relational .api .RelationalResultSetMetaData ;
27
27
import com .apple .foundationdb .relational .api .exceptions .RelationalException ;
28
28
import com .apple .foundationdb .relational .api .metrics .RelationalMetric ;
29
+ import com .apple .foundationdb .relational .recordlayer .ContinuationImpl ;
29
30
import com .apple .foundationdb .relational .yamltests .AggregateResultSet ;
30
31
import com .apple .foundationdb .relational .yamltests .YamlConnection ;
31
32
import com .apple .foundationdb .relational .yamltests .command .parameterinjection .Parameter ;
33
+ import com .apple .foundationdb .relational .yamltests .server .SemanticVersion ;
32
34
import org .apache .logging .log4j .LogManager ;
33
35
import org .apache .logging .log4j .Logger ;
34
36
import org .junit .jupiter .api .Assertions ;
@@ -53,6 +55,8 @@ public class QueryExecutor {
53
55
private static final Logger logger = LogManager .getLogger (QueryExecutor .class );
54
56
private static final int FORCED_MAX_ROWS = 1 ; // The maxRows number to use when we are forcing it on the test
55
57
private static final int MAX_CONTINUATIONS_ALLOWED = 100 ;
58
+ @ SuppressWarnings ("PMD.AvoidUsingHardCodedIP" ) // This is not an IP address
59
+ private static final SemanticVersion STRICT_ASSERTIONS_CUTOFF = SemanticVersion .parse ("4.1.9.0" );
56
60
57
61
@ Nonnull
58
62
private final String query ;
@@ -105,10 +109,9 @@ public Continuation execute(@Nonnull YamlConnection connection, @Nullable Contin
105
109
if (continuation == null ) {
106
110
// no continuation - start the query execution from the beginning
107
111
return executeQuery (connection , config , currentQuery , checkCache , maxRows );
108
- } else if (continuation . atBeginning ( )) {
112
+ } else if (checkBeginningContinuation ( continuation , connection )) {
109
113
// Continuation cannot be at beginning if it was returned from a query
110
- reportTestFailure ("Received continuation shouldn't be at beginning" );
111
- return null ;
114
+ return ContinuationImpl .END ;
112
115
} else {
113
116
// Have a continuation - continue
114
117
return executeContinuation (connection , continuation , config , currentQuery , maxRows );
@@ -143,7 +146,7 @@ private Object executeStatementAndCheckCacheIfNeeded(@Nonnull Statement s, final
143
146
final var toReturn = executeStatementAndCheckForceContinuations (s , statementHasQuery , queryString , connection , maxRows );
144
147
final var postMetricCollector = connection .getMetricCollector ();
145
148
final var postValue = postMetricCollector .hasCounter (RelationalMetric .RelationalCount .PLAN_CACHE_TERTIARY_HIT ) ?
146
- postMetricCollector .getCountsForCounter (RelationalMetric .RelationalCount .PLAN_CACHE_TERTIARY_HIT ) : 0 ;
149
+ postMetricCollector .getCountsForCounter (RelationalMetric .RelationalCount .PLAN_CACHE_TERTIARY_HIT ) : 0 ;
147
150
final var planFound = preMetricCollector != postMetricCollector ? postValue == 1 : postValue == preValue + 1 ;
148
151
if (!planFound ) {
149
152
reportTestFailure ("‼️ Expected to retrieve the plan from the cache at line " + lineNumber );
@@ -262,8 +265,9 @@ private Object executeStatementWithForcedContinuations(final @Nonnull Statement
262
265
Continuation continuation = resultSet .getContinuation ();
263
266
int count = 0 ;
264
267
while (!continuation .atEnd ()) {
265
- if (continuation .atBeginning ()) {
266
- reportTestFailure ("Received continuation shouldn't be at beginning" );
268
+ if (checkBeginningContinuation (continuation , connection )) {
269
+ continuation = ContinuationImpl .END ;
270
+ break ;
267
271
}
268
272
try (var s2 = prepareContinuationStatement (connection , continuation , FORCED_MAX_ROWS )) {
269
273
resultSet = (RelationalResultSet )executeStatement (s2 , true , queryString );
@@ -273,7 +277,9 @@ private Object executeStatementWithForcedContinuations(final @Nonnull Statement
273
277
results .add (resultSet );
274
278
} else {
275
279
// We assume that the last result is empty because of the maxRows:1
276
- Assertions .assertFalse (hasNext , "Result has more rows than maxRows allowed" );
280
+ if (STRICT_ASSERTIONS_CUTOFF .lesserVersions (connection .getVersions ()).isEmpty ()) {
281
+ Assertions .assertFalse (hasNext , "End result should not have any associated value when maxRows is 1" );
282
+ }
277
283
}
278
284
}
279
285
count += 1 ; // PMD failure for ++
@@ -290,6 +296,20 @@ private Object executeStatementWithForcedContinuations(final @Nonnull Statement
290
296
}
291
297
}
292
298
299
+ private boolean checkBeginningContinuation (Continuation continuation , YamlConnection connection ) {
300
+ if (continuation .atBeginning ()) {
301
+ if (STRICT_ASSERTIONS_CUTOFF .lesserVersions (connection .getVersions ()).isEmpty ()) {
302
+ reportTestFailure ("Received continuation shouldn't be at beginning" );
303
+ }
304
+ if (logger .isInfoEnabled ()) {
305
+ logger .info ("ignoring beginning continuation check for query '{}' at line {} (connection: {})" ,
306
+ query , lineNumber , connection .getVersions ());
307
+ }
308
+ return true ;
309
+ }
310
+ return false ;
311
+ }
312
+
293
313
private static Object executeStatement (@ Nonnull Statement s , final boolean statementHasQuery , @ Nonnull String q ) throws SQLException {
294
314
final var execResult = statementHasQuery ? ((PreparedStatement ) s ).execute () : s .execute (q );
295
315
return execResult ? s .getResultSet () : s .getUpdateCount ();
0 commit comments