-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Yaml test option to force continuations (#3075)
* Carry over from previous PR: Use NoOpConfig, protect from inadvertant execution * Add additionalOptions to the yaml execution context, add force-continuations option * Initial implementation of force continuation execution and aggregated result set * Bug fixes, create test configuration * Add the ability to set maxRows:0 which would differentiate "not set" from "set to 0", so we can skip the forceContinuations option if maxRows explicitly set to 0 * Analyze test failures, add @disabled comments * Style * PMD * Revert use of NoOpConfig since retaining the original SupportedVersionConfig is required for assertions * PR Comments * PR Comments * PR Comments * Style * PR comments
- Loading branch information
1 parent
306ebf7
commit 51ab5c8
Showing
10 changed files
with
582 additions
and
27 deletions.
There are no files selected for viewing
202 changes: 202 additions & 0 deletions
202
...src/main/java/com/apple/foundationdb/relational/yamltests/AbstractAggregateResultSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
/* | ||
* AbstractAggregateResultSet.java | ||
* | ||
* This source file is part of the FoundationDB open source project | ||
* | ||
* Copyright 2015-2025 Apple Inc. and the FoundationDB project authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.apple.foundationdb.relational.yamltests; | ||
|
||
import com.apple.foundationdb.relational.api.RelationalArray; | ||
import com.apple.foundationdb.relational.api.RelationalResultSet; | ||
import com.apple.foundationdb.relational.api.RelationalResultSetMetaData; | ||
import com.apple.foundationdb.relational.api.RelationalStruct; | ||
import com.apple.foundationdb.relational.api.exceptions.ErrorCode; | ||
|
||
import java.sql.SQLException; | ||
|
||
/** | ||
* A result set implementation that aggregates many result sets into one, where each internal result set acts as a row | ||
* in the aggregate. | ||
* TODO: This is a copy of the AbstractMockResultSet. We should clear that tech debt by integrating the types | ||
* TODO: of testing results sets into more reusable code. | ||
*/ | ||
public abstract class AbstractAggregateResultSet implements RelationalResultSet { | ||
private boolean isClosed = false; | ||
private final RelationalResultSetMetaData metadata; | ||
protected RelationalResultSet currentRow; | ||
|
||
protected AbstractAggregateResultSet(RelationalResultSetMetaData metadata) { | ||
this.metadata = metadata; | ||
} | ||
|
||
protected abstract boolean hasNext(); | ||
|
||
protected abstract RelationalResultSet advanceRow() throws SQLException; | ||
|
||
@Override | ||
public boolean next() throws SQLException { | ||
currentRow = advanceRow(); | ||
return currentRow != null; | ||
} | ||
|
||
@Override | ||
public void close() throws SQLException { | ||
isClosed = true; | ||
} | ||
|
||
@Override | ||
public boolean wasNull() throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.wasNull(); | ||
} | ||
|
||
@Override | ||
public String getString(int columnIndex) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getString(columnIndex); | ||
} | ||
|
||
@Override | ||
public boolean getBoolean(int columnIndex) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getBoolean(columnIndex); | ||
} | ||
|
||
@Override | ||
public int getInt(int columnIndex) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getInt(columnIndex); | ||
} | ||
|
||
@Override | ||
public long getLong(int columnIndex) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getLong(columnIndex); | ||
} | ||
|
||
@Override | ||
public float getFloat(int columnIndex) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getFloat(columnIndex); | ||
} | ||
|
||
@Override | ||
public double getDouble(int columnIndex) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getDouble(columnIndex); | ||
} | ||
|
||
@Override | ||
public byte[] getBytes(int columnIndex) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getBytes(columnIndex); | ||
} | ||
|
||
@Override | ||
public Object getObject(int columnIndex) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getObject(columnIndex); | ||
} | ||
|
||
@Override | ||
public RelationalStruct getStruct(int oneBasedPosition) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getStruct(oneBasedPosition); | ||
} | ||
|
||
@Override | ||
public RelationalArray getArray(int oneBasedPosition) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getArray(oneBasedPosition); | ||
} | ||
|
||
@Override | ||
public String getString(String columnLabel) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getString(columnLabel); | ||
} | ||
|
||
@Override | ||
public boolean getBoolean(String columnLabel) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getBoolean(columnLabel); | ||
} | ||
|
||
@Override | ||
public int getInt(String columnLabel) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getInt(columnLabel); | ||
} | ||
|
||
@Override | ||
public long getLong(String columnLabel) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getLong(columnLabel); | ||
} | ||
|
||
@Override | ||
public float getFloat(String columnLabel) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getFloat(columnLabel); | ||
} | ||
|
||
@Override | ||
public double getDouble(String columnLabel) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getDouble(columnLabel); | ||
} | ||
|
||
@Override | ||
public byte[] getBytes(String columnLabel) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getBytes(columnLabel); | ||
} | ||
|
||
@Override | ||
public Object getObject(String columnLabel) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getObject(columnLabel); | ||
} | ||
|
||
@Override | ||
public RelationalStruct getStruct(String fieldName) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getStruct(fieldName); | ||
} | ||
|
||
@Override | ||
public RelationalArray getArray(String fieldName) throws SQLException { | ||
checkCurrentRow(); | ||
return currentRow.getArray(fieldName); | ||
} | ||
|
||
@Override | ||
public RelationalResultSetMetaData getMetaData() throws SQLException { | ||
return metadata; | ||
} | ||
|
||
@Override | ||
public boolean isClosed() throws SQLException { | ||
return isClosed; | ||
} | ||
|
||
private void checkCurrentRow() throws SQLException { | ||
if ((currentRow == null) || isClosed()) { | ||
throw new SQLException("ResultSet exhausted", ErrorCode.INVALID_CURSOR_STATE.getErrorCode()); | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/AggregateResultSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* AggregateResultSet.java | ||
* | ||
* This source file is part of the FoundationDB open source project | ||
* | ||
* Copyright 2015-2025 Apple Inc. and the FoundationDB project authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.apple.foundationdb.relational.yamltests; | ||
|
||
import com.apple.foundationdb.relational.api.Continuation; | ||
import com.apple.foundationdb.relational.api.RelationalResultSet; | ||
import com.apple.foundationdb.relational.api.RelationalResultSetMetaData; | ||
import com.apple.foundationdb.relational.api.exceptions.ErrorCode; | ||
import org.junit.jupiter.api.Assertions; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.sql.SQLException; | ||
import java.util.Iterator; | ||
|
||
/** | ||
* An implementation of a result set that is made up of a set of inner result sets. | ||
* This result set delegates all data get* calls to the inner delegates. | ||
* At this time, each inner result set if assumed to represent a single row. | ||
* TODO: It may be beneficial to create a more sophisticated aggregate that can take inner result sets that have more than | ||
* TODO: one row each. | ||
*/ | ||
public class AggregateResultSet extends AbstractAggregateResultSet { | ||
private final Continuation continuation; | ||
private final Iterator<? extends RelationalResultSet> rowIterator; | ||
|
||
public AggregateResultSet(RelationalResultSetMetaData metadata, Continuation continuation, Iterator<RelationalResultSet> rowIterator) { | ||
super(metadata); | ||
this.continuation = continuation; | ||
this.rowIterator = rowIterator; | ||
} | ||
|
||
@Override | ||
protected boolean hasNext() { | ||
return rowIterator.hasNext(); | ||
} | ||
|
||
@Override | ||
protected RelationalResultSet advanceRow() throws SQLException { | ||
if (!hasNext()) { | ||
return null; | ||
} | ||
if (currentRow != null) { | ||
// Ensure that result sets don't have additional rows. Since we assume maxRows:1 here and advance the "outer" iterator, | ||
// we should assert that the actual result doesn't contain extra "stuff" | ||
Assertions.assertFalse(currentRow.next()); | ||
} | ||
return rowIterator.next(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public Continuation getContinuation() throws SQLException { | ||
if (hasNext()) { | ||
throw new SQLException("Continuation can only be returned once the result set has been exhausted", ErrorCode.UNSUPPORTED_OPERATION.getErrorCode()); | ||
} | ||
return continuation; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.