-
Notifications
You must be signed in to change notification settings - Fork 74
MLE-32904 Incremental write now supportings matching on a field #1980
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
rjrudin
wants to merge
1
commit into
develop
Choose a base branch
from
feature/32904-incremental-write-source-uri
base: develop
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.
+312
−12
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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
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
107 changes: 107 additions & 0 deletions
107
...t/java/com/marklogic/client/datamovement/filter/IncrementalWriteSourceUriKeyNameTest.java
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,107 @@ | ||
| /* | ||
| * Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. | ||
| */ | ||
| package com.marklogic.client.datamovement.filter; | ||
|
|
||
| import com.marklogic.client.document.DocumentWriteOperation; | ||
| import com.marklogic.client.impl.DocumentWriteOperationImpl; | ||
| import com.marklogic.client.io.DocumentMetadataHandle; | ||
| import com.marklogic.client.io.StringHandle; | ||
| import com.marklogic.client.test.Common; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| class IncrementalWriteSourceUriKeyNameTest extends AbstractIncrementalWriteTest { | ||
|
|
||
| private static final String SOURCE_URI_KEY_NAME = "incrementalWriteSourceUri"; | ||
| private static final String SOURCE_URI = "/incremental/test/source-uri-doc.xml"; | ||
| private static final String RELOCATED_URI = "/incremental/test/relocated-doc.xml"; | ||
|
|
||
| @Override | ||
| @BeforeEach | ||
| void setup() { | ||
| super.setup(); | ||
| filter = IncrementalWriteFilter.newBuilder() | ||
| .sourceUriKeyName(SOURCE_URI_KEY_NAME) | ||
| .onDocumentsSkipped(docs -> skippedCount.addAndGet(docs.length)) | ||
| .build(); | ||
| } | ||
|
|
||
| @Test | ||
| void stampsSourceUriMetadataAutomatically() { | ||
| writeDoc(SOURCE_URI, "<doc>original content</doc>"); | ||
|
|
||
| DocumentMetadataHandle metadata = Common.client.newDocumentManager().readMetadata(SOURCE_URI, | ||
| new DocumentMetadataHandle()); | ||
| assertEquals(SOURCE_URI, metadata.getMetadataValues().get(SOURCE_URI_KEY_NAME), | ||
| "The filter should automatically stamp the configured metadata key with the document's own URI."); | ||
| } | ||
|
|
||
| @Test | ||
| void matchesAfterExternalRelocation() { | ||
| // Initial write via the filter. | ||
| writeDoc(SOURCE_URI, "<doc>original content</doc>"); | ||
| assertEquals(1, writtenCount.get()); | ||
| assertEquals(0, skippedCount.get()); | ||
|
|
||
| relocateDocument(); | ||
|
|
||
| // Same source URI, unchanged content - should be recognized as unchanged even though the document | ||
| // now physically lives at a different URI, because the lookup matches on the source-URI field value. | ||
| writeDoc(SOURCE_URI, "<doc>original content</doc>"); | ||
| assertEquals(1, writtenCount.get(), "No new write should have occurred since the document was skipped."); | ||
| assertEquals(1, skippedCount.get()); | ||
|
|
||
| assertNull(Common.client.newDocumentManager().exists(SOURCE_URI), | ||
| "Nothing should have been written back to the source URI since the write was skipped."); | ||
| assertNotNull(Common.client.newDocumentManager().exists(RELOCATED_URI), | ||
| "The relocated document should still be the only copy of this content."); | ||
| } | ||
|
|
||
| @Test | ||
| void changedContentIsWrittenAfterExternalRelocation() { | ||
| writeDoc(SOURCE_URI, "<doc>original content</doc>"); | ||
| relocateDocument(); | ||
|
|
||
| // Content has changed, so the write should go through - to the source URI, not the relocated one. | ||
| writeDoc(SOURCE_URI, "<doc>modified content</doc>"); | ||
| assertEquals(2, writtenCount.get()); | ||
| assertEquals(0, skippedCount.get()); | ||
|
|
||
| String newContent = Common.client.newTextDocumentManager().read(SOURCE_URI, new StringHandle()).get(); | ||
| assertNotNull(newContent); | ||
| assertTrue(newContent.contains("<doc>modified content</doc>")); | ||
|
|
||
| DocumentMetadataHandle metadata = Common.client.newDocumentManager().readMetadata(SOURCE_URI, | ||
| new DocumentMetadataHandle()); | ||
| assertEquals(SOURCE_URI, metadata.getMetadataValues().get(SOURCE_URI_KEY_NAME), | ||
| "The rewritten document should have the source-URI metadata value stamped again."); | ||
| } | ||
|
|
||
| private void writeDoc(String uri, String content) { | ||
| List<DocumentWriteOperation> ops = new ArrayList<>(); | ||
| ops.add(new DocumentWriteOperationImpl(uri, METADATA, new StringHandle(content))); | ||
| writeDocs(ops); | ||
| } | ||
|
|
||
| /** | ||
| * Simulates a process outside of this filter relocating the document to a new URI while preserving its | ||
| * metadata (in particular, the source-URI metadata value), then removing the original. | ||
| */ | ||
| private void relocateDocument() { | ||
| DocumentMetadataHandle metadata = Common.client.newDocumentManager().readMetadata(SOURCE_URI, | ||
| new DocumentMetadataHandle()); | ||
| String content = Common.client.newTextDocumentManager().read(SOURCE_URI, new StringHandle()).get(); | ||
|
|
||
| Common.client.newTextDocumentManager().write(RELOCATED_URI, metadata, new StringHandle(content)); | ||
| Common.client.newDocumentManager().delete(SOURCE_URI); | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.