-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Added mongodb/specifications as a git submodule #1670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rozza
wants to merge
20
commits into
mongodb:main
Choose a base branch
from
rozza:JAVA-5821
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
dcccfd6
Added mongodb/specifications as a git submodule
rozza afa3c5d
Deleted findOne.json - left over from merge
rozza 2d11d89
Code review updates
rozza f8a2fe5
Filter the data rather than skip
rozza 179e3b4
Revert getLegacyTestData name change
rozza 5f613c4
Ensure finding no files throws an assertion error
rozza 2302f5f
Improve assertion error message
rozza e12b76c
Checkstyle fixes and assertion improvements
rozza 4b0af96
Merge branch 'main' into JAVA-5821
rozza 21cb0b5
Update specifications submodule to main
rozza 7a139b1
Update test runner and revert lookup test skipping
rozza ce9a44c
Skip test until JAVA-5297
rozza a72441e
Skip test until JAVA-5815
rozza 9977755
Ensure schema version is greater that 1
rozza a4f3bea
Merge branch 'main' into JAVA-5821
rozza cc74980
Getmores in sync can also be racy for tailable cursors
rozza 53dedba
Ignore extra getMores in sync test with timeoutMS
rozza ac83a37
Add Java ticket to assume false
rozza 8d1b93e
Skip nsType is present when creating views JAVA-5769
rozza 21f8f1a
Correct file description
rozza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,3 @@ | ||
[submodule "specifications"] | ||
path = driver-core/src/test/resources/specifications | ||
url = https://github.com/mongodb/specifications |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -19,15 +19,14 @@ | |
import org.bson.BsonDocument; | ||
import org.bson.BsonString; | ||
import org.bson.BsonValue; | ||
import org.bson.codecs.BsonDocumentCodec; | ||
import org.bson.codecs.DecoderContext; | ||
import org.bson.json.JsonReader; | ||
import org.bson.assertions.Assertions; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.net.URI; | ||
import java.net.URL; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.FileSystem; | ||
import java.nio.file.FileSystems; | ||
|
@@ -42,21 +41,20 @@ | |
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.bson.assertions.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public final class JsonPoweredTestHelper { | ||
|
||
private static final String SPECIFICATIONS_PREFIX = "/specifications/source/"; | ||
|
||
public static BsonDocument getTestDocument(final String resourcePath) { | ||
BsonDocument testDocument = getTestDocumentWithMetaData(resourcePath); | ||
BsonDocument testDocument = getTestDocumentWithMetaData(SPECIFICATIONS_PREFIX + resourcePath); | ||
testDocument.remove("resourcePath"); | ||
testDocument.remove("fileName"); | ||
return testDocument; | ||
} | ||
|
||
public static Collection<Object[]> getTestData(final String resourcePath) { | ||
List<Object[]> data = new ArrayList<>(); | ||
for (BsonDocument document : getTestDocuments(resourcePath)) { | ||
for (BsonDocument document : getSpecTestDocuments(resourcePath)) { | ||
for (BsonValue test : document.getArray("tests")) { | ||
BsonDocument testDocument = test.asDocument(); | ||
data.add(new Object[]{document.getString("fileName").getValue(), | ||
|
@@ -68,10 +66,19 @@ public static Collection<Object[]> getTestData(final String resourcePath) { | |
return data; | ||
} | ||
|
||
public static List<BsonDocument> getSpecTestDocuments(final String resourcePath) { | ||
return getTestDocuments(SPECIFICATIONS_PREFIX + resourcePath); | ||
} | ||
|
||
public static List<BsonDocument> getTestDocuments(final String resourcePath) { | ||
List<BsonDocument> files = new ArrayList<>(); | ||
try { | ||
URI resource = assertNotNull(JsonPoweredTestHelper.class.getResource(resourcePath)).toURI(); | ||
URL urlResource = JsonPoweredTestHelper.class.getResource(resourcePath); | ||
if (urlResource == null) { | ||
Assertions.fail("No such resource: " + resourcePath); | ||
} | ||
|
||
URI resource = urlResource.toURI(); | ||
try (FileSystem fileSystem = (resource.getScheme().equals("jar") ? FileSystems.newFileSystem(resource, Collections.emptyMap()) : null)) { | ||
Path myPath = Paths.get(resource); | ||
Files.walkFileTree(myPath, new SimpleFileVisitor<Path>() { | ||
|
@@ -89,14 +96,17 @@ public FileVisitResult visitFile(final Path filePath, final BasicFileAttributes | |
}); | ||
} | ||
} catch (Exception e) { | ||
fail("Unable to load resource", e); | ||
Assertions.fail("Unable to load resource: " + resourcePath, e); | ||
} | ||
|
||
if (files.isEmpty()) { | ||
Assertions.fail("No test documents found in: " + resourcePath); | ||
} | ||
return files; | ||
} | ||
|
||
private static BsonDocument getTestDocumentWithMetaData(final String resourcePath) { | ||
JsonReader jsonReader = new JsonReader(resourcePathToString(resourcePath)); | ||
BsonDocument testDocument = new BsonDocumentCodec().decode(jsonReader, DecoderContext.builder().build()); | ||
BsonDocument testDocument = BsonDocument.parse(resourcePathToString(resourcePath)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplification of the parsing code. |
||
testDocument.append("resourcePath", new BsonString(resourcePath)) | ||
.append("fileName", new BsonString(resourcePath.substring(resourcePath.lastIndexOf('/') + 1))); | ||
return testDocument; | ||
|
@@ -107,15 +117,17 @@ private static String resourcePathToString(final String resourcePath) { | |
String line; | ||
String ls = System.lineSeparator(); | ||
try (InputStream inputStream = JsonPoweredTestHelper.class.getResourceAsStream(resourcePath)) { | ||
assertNotNull(inputStream); | ||
if (inputStream == null) { | ||
Assertions.fail("Unable to load resource: " + resourcePath); | ||
} | ||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { | ||
while ((line = reader.readLine()) != null) { | ||
stringBuilder.append(line); | ||
stringBuilder.append(ls); | ||
} | ||
} | ||
} catch (Exception e) { | ||
fail("Unable to load resource", e); | ||
Assertions.fail("Unable to load resource", e); | ||
} | ||
return stringBuilder.toString(); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New helper to auto include the specifications location prefix.