Skip to content
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 @@ -7,6 +7,7 @@
import com.marklogic.client.io.marker.ContentHandle;
import com.marklogic.client.query.*;

import java.io.Closeable;
import java.util.Iterator;

/**
Expand All @@ -33,7 +34,15 @@
* dataMovementManager.release();
*}</pre>
*/
public interface DataMovementManager {
public interface DataMovementManager extends Closeable {

/**
* @since 8.1.0
*/
default void close() {
release();
}

/** Calls release() on all host-specific DatabaseClient instances (but not on
* the DatabaseClient instance used to create this DataMovementManager
* instance).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
package com.marklogic.client.test;

import com.marklogic.client.DatabaseClient;
import com.marklogic.junit5.AbstractMarkLogicTest;

/**
* Intended to be the base class for all future client API tests, as it properly prepares the database by deleting
* documents from previous test runs that were not created as part of deploying the test app.
*/
public abstract class AbstractClientTest extends AbstractMarkLogicTest {

@Override
protected final DatabaseClient getDatabaseClient() {
return Common.newServerAdminClient();
}

@Override
protected final String getJavascriptForDeletingDocumentsBeforeTestRuns() {
return """
declareUpdate();
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

The excluded collections 'test-data' and 'temporal-collection' should be documented to explain why they are preserved during test cleanup, as this filtering logic is critical for test data management.

Suggested change
declareUpdate();
declareUpdate();
// Preserve documents in the 'test-data' and 'temporal-collection' collections because they are
// created as part of deploying the test application (including temporal configuration) and must
// persist across test runs.

Copilot uses AI. Check for mistakes.
cts.uris('', [], cts.notQuery(cts.collectionQuery(['test-data', 'temporal-collection'])))
.toArray().forEach(item => xdmp.documentDelete(item))
""";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
package com.marklogic.client.test.datamovement;

import com.marklogic.client.DatabaseClient;
import com.marklogic.client.datamovement.DataMovementManager;
import com.marklogic.client.datamovement.WriteBatcher;
import com.marklogic.client.io.DocumentMetadataHandle;
import com.marklogic.client.io.StringHandle;
import com.marklogic.client.test.AbstractClientTest;
import com.marklogic.client.test.Common;
import org.junit.jupiter.api.Test;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;

import static org.junit.jupiter.api.Assertions.assertEquals;

class IncrementalWriteTest extends AbstractClientTest {

private static final DocumentMetadataHandle METADATA = new DocumentMetadataHandle()
.withCollections("incremental-test")
.withPermission("rest-reader", DocumentMetadataHandle.Capability.READ, DocumentMetadataHandle.Capability.UPDATE);

@Test
void test() {
AtomicInteger writtenCount = new AtomicInteger();

try (DatabaseClient client = Common.newClient()) {
WriteBatcherTemplate template = new WriteBatcherTemplate(client);

template.runWriteJob(writeBatcher -> writeBatcher
.withThreadCount(1)
.withBatchSize(10)
.onBatchSuccess(batch -> writtenCount.addAndGet(batch.getItems().length)),

writeBatcher -> {
for (int i = 1; i <= 20; i++) {
String uri = "/incremental/test/doc-" + i + ".xml";
String content = "<doc><docNum>" + i + "</docNum><text>This is document number " + i + "</text></doc>";
writeBatcher.add(uri, METADATA, new StringHandle(content));
}
}
);
}

assertEquals(20, writtenCount.get());
}

// Experimenting with a template that gets rid of some annoying DMSDK boilerplate.
private record WriteBatcherTemplate(DatabaseClient databaseClient) {

public void runWriteJob(Consumer<WriteBatcher> writeBatcherConfigurer, Consumer<WriteBatcher> writeBatcherUser) {
try (DataMovementManager dmm = databaseClient.newDataMovementManager()) {
WriteBatcher writeBatcher = dmm.newWriteBatcher();
writeBatcherConfigurer.accept(writeBatcher);

dmm.startJob(writeBatcher);

writeBatcherUser.accept(writeBatcher);
writeBatcher.awaitCompletion();

dmm.stopJob(writeBatcher);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.marklogic.client.row.RawPlanDefinition;
import com.marklogic.client.row.RowManager;
import com.marklogic.client.row.RowRecord;
import com.marklogic.client.test.AbstractClientTest;
import com.marklogic.client.test.Common;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -32,7 +33,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;


public abstract class AbstractOpticUpdateTest {
public abstract class AbstractOpticUpdateTest extends AbstractClientTest {

private final static String XML_PREAMBLE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

Expand All @@ -42,10 +43,6 @@ public abstract class AbstractOpticUpdateTest {

@BeforeEach
public void setup() {
// Subclasses of this test are expected to only write URIs starting with /acme/ (which is used so that test
// URIs show up near the top when exploring the database in qconsole), so delete all of them before running the
// test to ensure a document doesn't already exist.
Common.deleteUrisWithPattern("/acme/*");
Common.client = Common.newClientBuilder().withUsername("writer-no-default-permissions").build();
rowManager = Common.client.newRowManager().withUpdate(true);
op = rowManager.newPlanBuilder();
Expand Down