From b48d3540045654ea3d168d81b1bd2880eec25e27 Mon Sep 17 00:00:00 2001 From: evanchooly Date: Wed, 19 Jun 2024 03:00:38 -0400 Subject: [PATCH] add a lock file --- .../java/dev/morphia/test/TemplatedTestBase.java | 12 +++++++++--- .../test/query/filters/rand/example1/action.json | 2 -- .../morphia/test/query/filters/rand/example1/lock | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 core/src/test/resources/dev/morphia/test/query/filters/rand/example1/lock diff --git a/core/src/test/java/dev/morphia/test/TemplatedTestBase.java b/core/src/test/java/dev/morphia/test/TemplatedTestBase.java index e189c64b712..bd2c3d007f2 100644 --- a/core/src/test/java/dev/morphia/test/TemplatedTestBase.java +++ b/core/src/test/java/dev/morphia/test/TemplatedTestBase.java @@ -24,6 +24,7 @@ import dev.morphia.query.FindOptions; import dev.morphia.query.MorphiaQuery; +import org.bson.BsonInvalidOperationException; import org.bson.Document; import org.bson.codecs.DecoderContext; import org.bson.json.JsonParseException; @@ -299,7 +300,8 @@ protected String loadResource(String pipelineName) { return resource; } - private List extractDocuments(String line) { + private List extractDocuments(String resource) { + var line = resource; if (line.startsWith("db.")) { if (line.endsWith(")")) { line = line.substring(line.indexOf("(") + 1, line.lastIndexOf(")")).trim(); @@ -313,7 +315,11 @@ private List extractDocuments(String line) { char c = line.charAt(0); line = line.substring(1); if (balanced(current)) { - docs.add(Document.parse(current)); + try { + docs.add(Document.parse(current)); + } catch (BsonInvalidOperationException e) { + throw new RuntimeException("Error parsing " + resource, e); + } current = ""; } else { current += c; @@ -340,7 +346,7 @@ private void extractQueryFilters(List list) { } private static String unwrapArray(String resource) { - String line = resource; + String line = resource.trim(); if (line.startsWith("[")) { line = line.substring(1); } diff --git a/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/action.json b/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/action.json index 667dccaf423..6b696af74c4 100644 --- a/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/action.json +++ b/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/action.json @@ -1,6 +1,5 @@ db.donors.updateMany( {}, - [ { $set: { amount: { $floor: @@ -8,5 +7,4 @@ db.donors.updateMany( } } } - ] ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/lock b/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/lock new file mode 100644 index 00000000000..061f167f206 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/lock @@ -0,0 +1 @@ +unwrap the operators from the array \ No newline at end of file