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

Fixes #893: add IT for InsertMany failure due to doc count exceeding limit #894

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public interface OperationsConfig {
/** Defines the default max size of filter fields. */
int DEFAULT_MAX_FILTER_SIZE = 64;

/**
* Defines the default maximum documents to insert setting for {@code InsertMany} command;
* defaults to 20
*/
public static final int DEFAULT_MAX_DOCUMENT_INSERT_COUNT = 20;

/** @return Defines the default document page size, defaults to <code>20</code>. */
@Max(500)
@Positive
Expand Down Expand Up @@ -84,7 +90,7 @@ public interface OperationsConfig {
*/
@Max(100)
@Positive
@WithDefault("20")
@WithDefault("" + DEFAULT_MAX_DOCUMENT_INSERT_COUNT)
int maxDocumentInsertCount();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.restassured.http.ContentType;
import io.stargate.sgv2.jsonapi.config.DocumentLimitsConfig;
import io.stargate.sgv2.jsonapi.config.OperationsConfig;
import io.stargate.sgv2.jsonapi.config.constants.DocumentConstants;
import io.stargate.sgv2.jsonapi.config.constants.HttpConstants;
import io.stargate.sgv2.jsonapi.testresource.DseTestResource;
Expand Down Expand Up @@ -1388,7 +1389,7 @@ public void emptyDocuments() {
}

@Nested
@Order(4)
@Order(5)
class InsertManyLimitsChecking {
@Test
public void tryInsertTooLongNumber() {
Expand Down Expand Up @@ -1512,6 +1513,59 @@ public void tryInsertTooBigPayload() {
}
}

@Nested
@Order(6)
class InsertManyFails {
@Test
public void insertManyWithTooManyDocuments() {
ArrayNode docs = MAPPER.createArrayNode();
final int MAX_DOCS = OperationsConfig.DEFAULT_MAX_DOCUMENT_INSERT_COUNT;

// We need to both exceed doc count limit AND to create big enough payload to
// trigger message truncation (either by quarkus or client)
// Guessing that 20 x 1k == 20kB should be enough
final String TEXT_1K = "abcd 1234 ".repeat(1_000);

for (int i = 0; i < MAX_DOCS + 1; ++i) {
ObjectNode doc =
MAPPER
.createObjectNode()
.put("_id", "doc" + i)
.put("username", "user" + i)
.put("text", TEXT_1K);
docs.add(doc);
}
String json =
"""
{
"insertMany": {
"documents": %s
}
}
"""
.formatted(docs);

given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(json)
.when()
.post(CollectionResource.BASE_PATH, namespaceName, collectionName)
.then()
.statusCode(200)
.body("data", is(nullValue()))
.body("errors[0].exceptionClass", is("ConstraintViolationException"))
.body(
"errors[0].message",
endsWith(
"not valid. Problem: amount of documents to insert is over the max limit ("
+ docs.size()
+ " vs "
+ MAX_DOCS
+ ")."));
}
}

@Nested
@Order(99)
class Metrics {
Expand Down
Loading