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

relates to #178: insert commands per spec, added oerdered/unordered, better tests #216

Merged
merged 9 commits into from
Mar 8, 2023

Conversation

ivansenic
Copy link
Contributor

What this PR does:

Adaptation to spec for the insertOne & insertMany, including test improvements.

  • removed option class from insertOne command as per spec no options exists
  • added ordered option for the insertMany
  • implemented ordered/unordered insertion
  • implemented fail fast for order version
  • implemented fail silently for unordered
  • improved tests:
    • extended operation tests to ensure all failure modes are tested
    • created/updated tests for command resolvers
    • created tests for commands validation
    • several fixes for the integration tests:
      • add unordered tests
      • simulate possible failure modes (using duplicated entries in insert many)
      • assert no errors & data
      • improved readability
  • fixed swagger examples

Which issue(s) this PR fixes:
Relates to #178.

@ivansenic ivansenic requested a review from a team as a code owner March 2, 2023 14:26
if (null != failedIds && !failedIds().isEmpty()) {

List<CommandResult.Error> errors = new ArrayList<>(failedIds.size());
failedIds.forEach((documentId, throwable) -> errors.add(getError(documentId, throwable)));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently for each failed document, I return an error, should we aggregate? if yes how?

WritableShreddedDocument failed = failFastInsertException.document;

// collect inserted, since it's sequential iterate until failed index
int failedIndex = documents().lastIndexOf(failed);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this logic, since we use concatenate is already ordered and status can be captured with invoke() similar to unordered.

InsertOperationPage response = new InsertOperationPage();
insertDocument(queryExecutor, query, doc) .onItemOrFailure() .invoke( (documentId, error) -> { response.aggregate(doc.id(), error); }))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm but how can I reduce? Where is the response coming from?

Copy link
Contributor

@maheshrajamani maheshrajamani Mar 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ivansenic We can do collect().last()
InsertOperationPage response = new InsertOperationPage(); return Multi.createFrom() .items(documents.stream()) .onItem() .transformToUniAndConcatenate( doc -> insertDocument(queryExecutor, query, doc) .onItemOrFailure() .invoke( (documentId, error) -> { response.aggregate(doc.id(), error); })) .collect() .last() .onItemOrFailure() .transform( (id, error) -> { return response; });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I don't like those side effects, especially when I am using a non-thread-safe structure.. Let me see if I can optimize this..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maheshrajamani this is the bug from the demo, I can not use last index on a document, as if first fails, I would assume that the first was written.. Need to change this :)

.in(InsertOperationPage::new, (agg, in) -> agg.aggregate(in.getItem1().id(), in.getItem2()))

// use object identity to resolve to Supplier<CommandResult>
.map(i -> i);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed in() would have already return Uni< InsertOperationPage>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not compile. The method signature must be

Uni<? extends Supplier<CommandResult>>

so that we can return the Uni<InsertOperationPage>.

I wanted to refactor, but it's not a small change, should be changed in all sub-classes and tests.. Do you think it's worth it?

@ivansenic
Copy link
Contributor Author

@maheshrajamani can you answer to the questions I posted?

@ivansenic ivansenic force-pushed the ise-178-insert-commands branch from 46aa965 to 08a3092 Compare March 8, 2023 11:14
@ivansenic ivansenic merged commit e36f2c3 into main Mar 8, 2023
@ivansenic ivansenic deleted the ise-178-insert-commands branch March 8, 2023 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants