Skip to content
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

Add 'returnDocumentResponses' for "insertMany" #1161

Merged
merged 32 commits into from
Jun 18, 2024
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5d19a40
Start adding wiring for 'returnDocumentPositions'
tatu-at-datastax Jun 11, 2024
f3b0df9
mvn fmt:format
tatu-at-datastax Jun 11, 2024
73645ca
...
tatu-at-datastax Jun 11, 2024
2468222
Fix test signatures
tatu-at-datastax Jun 11, 2024
c02673a
More plumbing, get "returnDocumentPositions" where needed
tatu-at-datastax Jun 11, 2024
f741b3e
Test refactoring
tatu-at-datastax Jun 11, 2024
aa0423c
More test refactoring
tatu-at-datastax Jun 11, 2024
c9975d8
...
tatu-at-datastax Jun 11, 2024
74b07df
Start piping through position of document
tatu-at-datastax Jun 11, 2024
a780120
Add new status keys, clean up ITs
tatu-at-datastax Jun 12, 2024
7526ad2
More plumbing, order failed/ok insertions by input position
tatu-at-datastax Jun 12, 2024
28fcb2b
...
tatu-at-datastax Jun 12, 2024
d99d503
Merge branch 'main' into tatu/c2-3382-return-doc-positions
tatu-at-datastax Jun 12, 2024
616b34a
Fix ITs not to rely on insertion/fail order for unordered case
tatu-at-datastax Jun 12, 2024
499c2e6
Merge branch 'main' into tatu/c2-3382-return-doc-positions
tatu-at-datastax Jun 12, 2024
63451c1
Merge branch 'main' into tatu/c2-3382-return-doc-positions
tatu-at-datastax Jun 12, 2024
009878a
Implement functionality; need tests next
tatu-at-datastax Jun 12, 2024
ca553ea
Add the first test for actual return-on-dups
tatu-at-datastax Jun 12, 2024
6aae747
Refactoring
tatu-at-datastax Jun 12, 2024
60b4c6b
Add test verifying returning of auto-generated UUIDs
tatu-at-datastax Jun 12, 2024
bf45bfa
Bit more testing
tatu-at-datastax Jun 12, 2024
c96cdb6
Merge branch 'main' into tatu/c2-3382-return-doc-positions
tatu-at-datastax Jun 13, 2024
2aa4593
Merge branch 'main' into tatu/c2-3382-return-doc-positions
tatu-at-datastax Jun 17, 2024
6949204
Renaming
tatu-at-datastax Jun 17, 2024
91854a3
Rename setting in integration tests too (returnDocumentPositions->ret…
tatu-at-datastax Jun 17, 2024
8d7d0ea
Merge branch 'main' into tatu/c2-3382-return-doc-positions
tatu-at-datastax Jun 18, 2024
28b4fd0
Some scaffolding for rewrite to new spec
tatu-at-datastax Jun 18, 2024
4f1db6f
Finish initial implementation
tatu-at-datastax Jun 18, 2024
0c655e4
Fix 2 ITs wrt output structure changes
tatu-at-datastax Jun 18, 2024
adfd9fa
comment improvement
tatu-at-datastax Jun 18, 2024
da1aa4d
Comment improvement
tatu-at-datastax Jun 18, 2024
f18572c
Add comments suggested by code review
tatu-at-datastax Jun 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test verifying returning of auto-generated UUIDs
  • Loading branch information
tatu-at-datastax committed Jun 12, 2024
commit 60b4c6bdd45dbe5d95c408224f3ffd6e9bdb1d46
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@
import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Fail.fail;
import static org.hamcrest.Matchers.any;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;
import static org.hamcrest.Matchers.*;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -33,6 +24,7 @@
import java.util.Arrays;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Pattern;
import org.apache.commons.lang3.RandomStringUtils;
import org.bson.types.ObjectId;
import org.junit.jupiter.api.AfterEach;
Expand All @@ -50,6 +42,9 @@
public class InsertIntegrationTest extends AbstractCollectionIntegrationTestBase {
private final ObjectMapper MAPPER = new ObjectMapper();

private static final Pattern UUID_REGEX =
Pattern.compile("[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}");

@AfterEach
public void cleanUpData() {
deleteAllDocuments();
Expand Down Expand Up @@ -1325,14 +1320,8 @@ public void ordered() {
{
"insertMany": {
"documents": [
{
"_id": "doc4",
"username": "user4"
},
{
"_id": "doc5",
"username": "user5"
}
{ "_id": "doc4", "username": "user4" },
{ "_id": "doc5", "username": "user5" }
],
"options" : {
"ordered" : true
Expand All @@ -1349,28 +1338,99 @@ public void ordered() {
.post(CollectionResource.BASE_PATH, namespaceName, collectionName)
.then()
.statusCode(200)
.body("status.insertedIds", contains("doc4", "doc5"))
.body("status.insertedIds", is(Arrays.asList("doc4", "doc5")))
.body("data", is(nullValue()))
.body("errors", is(nullValue()));

verifyDocCount(2);
}

@Test
public void orderedReturnPositions() {
String json =
"""
{
"insertMany": {
"documents": [
{ "_id": "doc1", "username": "user1" },
{ "_id": "doc2", "username": "user2" }
],
"options" : {
"ordered": true, "returnDocumentPositions": true
}
}
}
""";

given()
.headers(getHeaders())
.contentType(ContentType.JSON)
.body(json)
.when()
.post(CollectionResource.BASE_PATH, namespaceName, collectionName)
.then()
.statusCode(200)
.body("data", is(nullValue()))
.body("errors", is(nullValue()))
.body("status.insertedIds", is(nullValue()))
.body("status.failedDocuments", is(nullValue()))
.body(
"status.insertedDocuments",
is(Arrays.asList(Arrays.asList(0, "doc1"), Arrays.asList(1, "doc2"))));

verifyDocCount(2);
}

@Test
public void orderedNoDocIdReturnPositions() {
String json =
"""
{
"insertMany": {
"documents": [
{ "username": "user1" },
{ "username": "user2" }
],
"options" : {
"ordered": true, "returnDocumentPositions": true
}
}
}
""";

given()
.headers(getHeaders())
.contentType(ContentType.JSON)
.body(json)
.when()
.post(CollectionResource.BASE_PATH, namespaceName, collectionName)
.then()
.statusCode(200)
.body("data", is(nullValue()))
.body("errors", is(nullValue()))
.body("status.insertedIds", is(nullValue()))
.body("status.failedDocuments", is(nullValue()))
// now tricky part: [0, <UUID>] check
.body("status.insertedDocuments", hasSize(2))
.body("status.insertedDocuments[0]", hasSize(2))
.body("status.insertedDocuments[0][0]", is(0))
.body("status.insertedDocuments[0][1]", matchesPattern(UUID_REGEX))
.body("status.insertedDocuments[1]", hasSize(2))
.body("status.insertedDocuments[1][0]", is(1))
.body("status.insertedDocuments[1][1]", matchesPattern(UUID_REGEX));

verifyDocCount(2);
}

@Test
public void unordered() {
String json =
"""
{
"insertMany": {
"documents": [
{
"_id": "doc4",
"username": "user4"
},
{
"_id": "doc5",
"username": "user5"
}
{ "_id": "doc4", "username": "user4" },
{ "_id": "doc5", "username": "user5" }
]
}
}
Expand Down
Loading