Skip to content

Commit

Permalink
Move most skips to single file, expand API to handle conditions (#1557)
Browse files Browse the repository at this point in the history
  • Loading branch information
katcharov authored Nov 20, 2024
1 parent 5c8f6b2 commit 90976e4
Show file tree
Hide file tree
Showing 33 changed files with 596 additions and 629 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@
*/
package com.mongodb.kotlin.client.coroutine

import com.mongodb.client.unified.UnifiedCrudTest.doSkips
import java.io.IOException
import java.net.URISyntaxException
import org.junit.jupiter.params.provider.Arguments

internal class UnifiedCrudTest() : UnifiedTest() {

override fun skips(fileDescription: String, testDescription: String) {
doSkips(fileDescription, testDescription)
}

companion object {
@JvmStatic
@Throws(URISyntaxException::class, IOException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@
*/
package com.mongodb.kotlin.client

import com.mongodb.client.unified.UnifiedCrudTest.doSkips
import java.io.IOException
import java.net.URISyntaxException
import org.junit.jupiter.params.provider.Arguments

internal class UnifiedCrudTest() : UnifiedTest() {

override fun skips(fileDescription: String, testDescription: String) {
doSkips(fileDescription, testDescription)
}

companion object {
@JvmStatic
@Throws(URISyntaxException::class, IOException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,89 +16,13 @@

package com.mongodb.reactivestreams.client.unified;

import com.mongodb.lang.Nullable;
import org.bson.BsonArray;
import org.bson.BsonDocument;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.provider.Arguments;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import static com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient.disableSleep;
import static com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient.disableWaitForBatchCursorCreation;
import static com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient.enableSleepAfterCursorOpen;
import static com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient.enableWaitForBatchCursorCreation;
import static org.junit.jupiter.api.Assumptions.assumeFalse;

final class ChangeStreamsTest extends UnifiedReactiveStreamsTest {

private static final List<String> ERROR_REQUIRED_FROM_CHANGE_STREAM_INITIALIZATION_TESTS =
Arrays.asList(
"Test with document comment - pre 4.4"
);

private static final List<String> EVENT_SENSITIVE_TESTS =
Arrays.asList(
"Test that comment is set on getMore",
"Test that comment is not set on getMore - pre 4.4"
);

private static final List<String> TESTS_WITH_EXTRA_EVENTS =
Arrays.asList(
"Test with document comment",
"Test with string comment"
);

private static final List<String> REQUIRES_BATCH_CURSOR_CREATION_WAITING =
Arrays.asList(
"Change Stream should error when an invalid aggregation stage is passed in",
"The watch helper must not throw a custom exception when executed against a single server topology, "
+ "but instead depend on a server error"
);

@Override
protected void skips(final String fileDescription, final String testDescription) {
assumeFalse(ERROR_REQUIRED_FROM_CHANGE_STREAM_INITIALIZATION_TESTS.contains(testDescription));
assumeFalse(EVENT_SENSITIVE_TESTS.contains(testDescription));
assumeFalse(TESTS_WITH_EXTRA_EVENTS.contains(testDescription));
}

@BeforeEach
@Override
public void setUp(@Nullable final String fileDescription,
@Nullable final String testDescription,
final String schemaVersion,
@Nullable final BsonArray runOnRequirements,
final BsonArray entitiesArray,
final BsonArray initialData,
final BsonDocument definition) {
super.setUp(
fileDescription,
testDescription,
schemaVersion,
runOnRequirements,
entitiesArray,
initialData,
definition);
enableSleepAfterCursorOpen(256);
if (REQUIRES_BATCH_CURSOR_CREATION_WAITING.contains(testDescription)) {
enableWaitForBatchCursorCreation();
}
}

@AfterEach
@Override
public void cleanUp() {
super.cleanUp();
disableSleep();
disableWaitForBatchCursorCreation();
}

private static Collection<Arguments> data() throws URISyntaxException, IOException {
return getTestData("unified-test-format/change-streams");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ The Reactive Streams specification prevents us from allowing a subsequent next c
public void shouldPassAllOutcomes(
@Nullable final String fileDescription,
@Nullable final String testDescription,
@Nullable final String directoryName,
final String schemaVersion,
@Nullable final BsonArray runOnRequirements,
final BsonArray entitiesArray,
Expand All @@ -109,6 +110,7 @@ public void shouldPassAllOutcomes(
try {
super.shouldPassAllOutcomes(fileDescription,
testDescription,
directoryName,
schemaVersion,
runOnRequirements,
entitiesArray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@
import java.net.URISyntaxException;
import java.util.Collection;

import static org.junit.jupiter.api.Assumptions.assumeFalse;

final class CollectionManagementTest extends UnifiedReactiveStreamsTest {
@Override
protected void skips(final String fileDescription, final String testDescription) {
assumeFalse(testDescription.equals("modifyCollection to changeStreamPreAndPostImages enabled"));
}

private static Collection<Arguments> data() throws URISyntaxException, IOException {
return getTestData("unified-test-format/collection-management");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,7 @@
import java.net.URISyntaxException;
import java.util.Collection;

import static org.junit.jupiter.api.Assumptions.assumeFalse;

final class CommandLoggingTest extends UnifiedReactiveStreamsTest {
@Override
protected void skips(final String fileDescription, final String testDescription) {
// The driver has a hack where getLastError command is executed as part of the handshake in order to get a connectionId
// even when the hello command response doesn't contain it.
assumeFalse(fileDescription.equals("pre-42-server-connection-id"));
}

private static Collection<Arguments> data() throws URISyntaxException, IOException {
return getTestData("unified-test-format/command-logging");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,7 @@
import java.net.URISyntaxException;
import java.util.Collection;

import static org.junit.jupiter.api.Assumptions.assumeFalse;

final class CommandMonitoringTest extends UnifiedReactiveStreamsTest {
@Override
protected void skips(final String fileDescription, final String testDescription) {
// The driver has a hack where getLastError command is executed as part of the handshake in order to get a connectionId
// even when the hello command response doesn't contain it.
assumeFalse(fileDescription.equals("pre-42-server-connection-id"));
}

private static Collection<Arguments> data() throws URISyntaxException, IOException {
return getTestData("unified-test-format/command-monitoring");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,7 @@
import java.net.URISyntaxException;
import java.util.Collection;

import static org.junit.jupiter.api.Assumptions.assumeFalse;

final class ConnectionPoolLoggingTest extends UnifiedReactiveStreamsTest {
@Override
protected void skips(final String fileDescription, final String testDescription) {
// The implementation of the functionality related to clearing the connection pool before closing the connection
// will be carried out once the specification is finalized and ready.
assumeFalse(testDescription.equals("Connection checkout fails due to error establishing connection"));
}

private static Collection<Arguments> data() throws URISyntaxException, IOException {
return getTestData("unified-test-format/connection-monitoring-and-pooling/logging");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,88 +16,13 @@

package com.mongodb.reactivestreams.client.unified;

import com.mongodb.lang.Nullable;
import org.bson.BsonArray;
import org.bson.BsonDocument;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.provider.Arguments;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import static com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient.disableSleep;
import static com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient.enableSleepAfterCursorClose;
import static com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient.enableSleepAfterCursorOpen;
import static org.junit.jupiter.api.Assumptions.assumeFalse;

final class LoadBalancerTest extends UnifiedReactiveStreamsTest {

private static final List<String> CURSOR_OPEN_TIMING_SENSITIVE_TESTS =
Arrays.asList(
"pinned connections are returned when the cursor is drained",
"only connections for a specific serviceId are closed when pools are cleared",
"pinned connections are returned to the pool when the cursor is closed",
"no connection is pinned if all documents are returned in the initial batch",
"stale errors are ignored",
"a connection can be shared by a transaction and a cursor",
"wait queue timeout errors include cursor statistics");

private static final List<String> CURSOR_CLOSE_TIMING_SENSITIVE_TESTS =
Arrays.asList(
"pinned connections are returned to the pool when the cursor is closed",
"only connections for a specific serviceId are closed when pools are cleared",
"pinned connections are returned after a network error during a killCursors request",
"a connection can be shared by a transaction and a cursor");

@Override
protected void skips(final String fileDescription, final String testDescription) {
// Reactive streams driver can't implement these tests because the underlying cursor is closed on error, which
// breaks assumption in the tests that closing the cursor is something that happens under user control
assumeFalse(testDescription.equals("pinned connections are not returned after an network error during getMore"));
assumeFalse(testDescription.equals("pinned connections are not returned to the pool after a non-network error on getMore"));
// Reactive streams driver can't implement this test because there is no way to tell that a change stream cursor
// that has not yet received any results has even initiated the change stream
assumeFalse(testDescription.equals("change streams pin to a connection"));
}

@Override
@BeforeEach
public void setUp(
@Nullable final String fileDescription,
@Nullable final String testDescription,
final String schemaVersion,
@Nullable final BsonArray runOnRequirements,
final BsonArray entitiesArray,
final BsonArray initialData,
final BsonDocument definition) {
super.setUp(
fileDescription,
testDescription,
schemaVersion,
runOnRequirements,
entitiesArray,
initialData,
definition);
if (CURSOR_OPEN_TIMING_SENSITIVE_TESTS.contains(testDescription)) {
enableSleepAfterCursorOpen(256);
}

if (CURSOR_CLOSE_TIMING_SENSITIVE_TESTS.contains(testDescription)) {
enableSleepAfterCursorClose(256);
}
}

@Override
@AfterEach
public void cleanUp() {
super.cleanUp();
disableSleep();
}

private static Collection<Arguments> data() throws URISyntaxException, IOException {
return getTestData("unified-test-format/load-balancers");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@
import java.net.URISyntaxException;
import java.util.Collection;

import static com.mongodb.client.unified.UnifiedCrudTest.doSkips;

final class UnifiedCrudTest extends UnifiedReactiveStreamsTest {
@Override
protected void skips(final String fileDescription, final String testDescription) {
doSkips(fileDescription, testDescription);
}

private static Collection<Arguments> data() throws URISyntaxException, IOException {
return getTestData("unified-test-format/crud");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,7 @@
import java.net.URISyntaxException;
import java.util.Collection;

import static org.junit.jupiter.api.Assumptions.assumeFalse;

final class UnifiedGridFSTest extends UnifiedReactiveStreamsTest {
@Override
protected void skips(final String fileDescription, final String testDescription) {
// contentType is deprecated in GridFS spec, and 4.x Java driver no longer support it, so skipping this test
assumeFalse(testDescription.equals("upload when contentType is provided"));
// Re-enable when JAVA-4214 is fixed
assumeFalse(testDescription.equals("delete when files entry does not exist and there are orphaned chunks"));
}

private static Collection<Arguments> data() throws URISyntaxException, IOException {
return getTestData("unified-test-format/gridfs");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.gridfs.GridFSBucket;
import com.mongodb.client.unified.UnifiedTest;
import com.mongodb.client.unified.UnifiedTestModifications;
import com.mongodb.client.vault.ClientEncryption;
import com.mongodb.reactivestreams.client.MongoClients;
import com.mongodb.reactivestreams.client.gridfs.GridFSBuckets;
Expand All @@ -31,6 +32,14 @@
import com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient;
import com.mongodb.reactivestreams.client.syncadapter.SyncMongoDatabase;

import static com.mongodb.client.unified.UnifiedTestModifications.Modifier;
import static com.mongodb.client.unified.UnifiedTestModifications.TestDef;
import static com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient.disableSleep;
import static com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient.disableWaitForBatchCursorCreation;
import static com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient.enableSleepAfterCursorClose;
import static com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient.enableSleepAfterCursorOpen;
import static com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient.enableWaitForBatchCursorCreation;

public abstract class UnifiedReactiveStreamsTest extends UnifiedTest {
protected UnifiedReactiveStreamsTest() {
}
Expand All @@ -49,4 +58,40 @@ protected GridFSBucket createGridFSBucket(final MongoDatabase database) {
protected ClientEncryption createClientEncryption(final MongoClient keyVaultClient, final ClientEncryptionSettings clientEncryptionSettings) {
return new SyncClientEncryption(new ClientEncryptionImpl(((SyncMongoClient) keyVaultClient).getWrapped(), clientEncryptionSettings));
}

@Override
protected boolean isReactive() {
return true;
}

@Override
protected void postSetUp(final TestDef testDef) {
super.postSetUp(testDef);
if (testDef.wasAssignedModifier(UnifiedTestModifications.Modifier.IGNORE_EXTRA_EVENTS)) {
ignoreExtraEvents(); // no disable needed
}
if (testDef.wasAssignedModifier(Modifier.SLEEP_AFTER_CURSOR_OPEN)) {
enableSleepAfterCursorOpen(256);
}
if (testDef.wasAssignedModifier(Modifier.SLEEP_AFTER_CURSOR_CLOSE)) {
enableSleepAfterCursorClose(256);
}
if (testDef.wasAssignedModifier(Modifier.WAIT_FOR_BATCH_CURSOR_CREATION)) {
enableWaitForBatchCursorCreation();
}
}

@Override
protected void postCleanUp(final TestDef testDef) {
super.postCleanUp(testDef);
if (testDef.wasAssignedModifier(Modifier.WAIT_FOR_BATCH_CURSOR_CREATION)) {
disableWaitForBatchCursorCreation();
}
if (testDef.wasAssignedModifier(Modifier.SLEEP_AFTER_CURSOR_CLOSE)) {
disableSleep();
}
if (testDef.wasAssignedModifier(Modifier.SLEEP_AFTER_CURSOR_OPEN)) {
disableSleep();
}
}
}
Loading

0 comments on commit 90976e4

Please sign in to comment.