Skip to content

Commit 7fa05cd

Browse files
authored
Handle dropIndex behavior change (#1785)
JAVA-5941
1 parent f0da98d commit 7fa05cd

File tree

4 files changed

+100
-3
lines changed

4 files changed

+100
-3
lines changed

driver-core/src/test/functional/com/mongodb/internal/operation/DropIndexOperationSpecification.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import spock.lang.Unroll
3131

3232
import static com.mongodb.ClusterFixture.getBinding
3333
import static com.mongodb.ClusterFixture.isDiscoverableReplicaSet
34+
import static com.mongodb.ClusterFixture.serverVersionAtLeast
3435

3536
class DropIndexOperationSpecification extends OperationFunctionalSpecification {
3637

@@ -45,6 +46,7 @@ class DropIndexOperationSpecification extends OperationFunctionalSpecification {
4546
async << [true, false]
4647
}
4748

49+
@IgnoreIf({ serverVersionAtLeast(8, 3) })
4850
def 'should error when dropping non-existent index on existing collection'() {
4951
given:
5052
getCollectionHelper().insertDocuments(new DocumentCodec(), new Document('documentThat', 'forces creation of the Collection'))

driver-legacy/src/main/com/mongodb/DBCollection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ public OperationExecutor getExecutor() {
18901890
* key name and type must be specified.
18911891
*
18921892
* @param index the specification of the index to drop
1893-
* @throws MongoException if the index does not exist
1893+
* @throws MongoException if the index does not exist and the server version is less than 8.3
18941894
* @mongodb.driver.manual core/indexes/ Indexes
18951895
*/
18961896
public void dropIndex(final DBObject index) {
@@ -1906,7 +1906,7 @@ public void dropIndex(final DBObject index) {
19061906
* Drops the index with the given name from this collection.
19071907
*
19081908
* @param indexName name of index to drop
1909-
* @throws MongoException if the index does not exist
1909+
* @throws MongoException if the index does not exist and the server version is less than 8.3
19101910
* @mongodb.driver.manual core/indexes/ Indexes
19111911
*/
19121912
public void dropIndex(final String indexName) {
@@ -1930,7 +1930,7 @@ public void dropIndexes() {
19301930
* Drops the index with the given name from this collection. This method is exactly the same as {@code dropIndex(indexName)}.
19311931
*
19321932
* @param indexName name of index to drop
1933-
* @throws MongoException if the index does not exist
1933+
* @throws MongoException if the index does not exist and the server version is less than 8.3
19341934
* @mongodb.driver.manual core/indexes/ Indexes
19351935
*/
19361936
public void dropIndexes(final String indexName) {

driver-legacy/src/test/functional/com/mongodb/DBCollectionFunctionalSpecification.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import spock.lang.IgnoreIf
3131
import spock.lang.Unroll
3232

3333
import static com.mongodb.ClusterFixture.isDiscoverableReplicaSet
34+
import static com.mongodb.ClusterFixture.serverVersionAtLeast
3435
import static org.hamcrest.Matchers.contains
3536
import static org.hamcrest.Matchers.containsInAnyOrder
3637
import static spock.util.matcher.HamcrestSupport.that
@@ -163,6 +164,7 @@ class DBCollectionFunctionalSpecification extends FunctionalSpecification {
163164
collection.dropIndex('indexOnCollectionThatDoesNotExist')
164165
}
165166

167+
@IgnoreIf({ serverVersionAtLeast(8, 3) })
166168
def 'drop index should error if index does not exist'() {
167169
given:
168170
collection.createIndex(new BasicDBObject('x', 1))
@@ -175,6 +177,7 @@ class DBCollectionFunctionalSpecification extends FunctionalSpecification {
175177
exception.getErrorMessage().contains('index not found')
176178
}
177179

180+
@IgnoreIf({ serverVersionAtLeast(8, 3) })
178181
def 'should throw Exception if dropping an index with an incorrect type'() {
179182
given:
180183
BasicDBObject index = new BasicDBObject('x', 1)

driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTestModifications.java

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,98 @@ public static void applyCustomizations(final TestDef def) {
8080
.test("client-side-operations-timeout", "WaitQueueTimeoutError does not clear the pool",
8181
"WaitQueueTimeoutError does not clear the pool");
8282

83+
def.skipJira("https://jira.mongodb.org/browse/JAVA-5491")
84+
.testContains("client-side-operations-timeout", "dropIndex")
85+
.when(() -> !serverVersionLessThan(8, 3))
86+
.test("client-side-operations-timeout", "operations ignore deprecated timeout options if timeoutMS is set",
87+
"socketTimeoutMS is ignored if timeoutMS is set - dropIndex on collection")
88+
.test("client-side-operations-timeout", "operations ignore deprecated timeout options if timeoutMS is set",
89+
"wTimeoutMS is ignored if timeoutMS is set - dropIndex on collection")
90+
.test("client-side-operations-timeout", "operations ignore deprecated timeout options if timeoutMS is set",
91+
"maxTimeMS is ignored if timeoutMS is set - dropIndex on collection")
92+
.test("client-side-operations-timeout", "operations ignore deprecated timeout options if timeoutMS is set",
93+
"socketTimeoutMS is ignored if timeoutMS is set - dropIndexes on collection")
94+
.test("client-side-operations-timeout", "operations ignore deprecated timeout options if timeoutMS is set",
95+
"wTimeoutMS is ignored if timeoutMS is set - dropIndexes on collection")
96+
.test("client-side-operations-timeout", "operations ignore deprecated timeout options if timeoutMS is set",
97+
"maxTimeMS is ignored if timeoutMS is set - dropIndexes on collection")
98+
.test("client-side-operations-timeout", "timeoutMS can be overridden for a MongoDatabase",
99+
"timeoutMS can be configured on a MongoDatabase - dropIndex on collection")
100+
.test("client-side-operations-timeout", "timeoutMS can be overridden for a MongoDatabase",
101+
"timeoutMS can be set to 0 on a MongoDatabase - dropIndex on collection")
102+
.test("client-side-operations-timeout", "timeoutMS can be overridden for a MongoDatabase",
103+
"timeoutMS can be configured on a MongoDatabase - dropIndexes on collection")
104+
.test("client-side-operations-timeout", "timeoutMS can be overridden for a MongoDatabase",
105+
"timeoutMS can be set to 0 on a MongoDatabase - dropIndexes on collection")
106+
.test("client-side-operations-timeout", "timeoutMS can be overridden for a MongoCollection",
107+
"timeoutMS can be configured on a MongoCollection - dropIndex on collection")
108+
.test("client-side-operations-timeout", "timeoutMS can be overridden for a MongoCollection",
109+
"timeoutMS can be set to 0 on a MongoCollection - dropIndex on collection")
110+
.test("client-side-operations-timeout", "timeoutMS can be overridden for a MongoCollection",
111+
"timeoutMS can be configured on a MongoCollection - dropIndexes on collection")
112+
.test("client-side-operations-timeout", "timeoutMS can be overridden for a MongoCollection",
113+
"timeoutMS can be set to 0 on a MongoCollection - dropIndexes on collection")
114+
.test("client-side-operations-timeout", "timeoutMS can be overridden for an operation",
115+
"timeoutMS can be configured for an operation - dropIndex on collection")
116+
.test("client-side-operations-timeout", "timeoutMS can be overridden for an operation",
117+
"timeoutMS can be set to 0 for an operation - dropIndex on collection")
118+
.test("client-side-operations-timeout", "timeoutMS can be overridden for an operation",
119+
"timeoutMS can be configured for an operation - dropIndexes on collection")
120+
.test("client-side-operations-timeout", "timeoutMS can be overridden for an operation",
121+
"timeoutMS can be set to 0 for an operation - dropIndexes on collection")
122+
.test("client-side-operations-timeout", "timeoutMS can be configured on a MongoClient",
123+
"timeoutMS can be configured on a MongoClient - dropIndex on collection")
124+
.test("client-side-operations-timeout", "timeoutMS can be configured on a MongoClient",
125+
"timeoutMS can be set to 0 on a MongoClient - dropIndex on collection")
126+
.test("client-side-operations-timeout", "timeoutMS can be configured on a MongoClient",
127+
"timeoutMS can be configured on a MongoClient - dropIndexes on collection")
128+
.test("client-side-operations-timeout", "timeoutMS can be configured on a MongoClient",
129+
"timeoutMS can be set to 0 on a MongoClient - dropIndexes on collection")
130+
.test("client-side-operations-timeout", "operations ignore deprecated timeout options if timeoutMS is set",
131+
"socketTimeoutMS is ignored if timeoutMS is set - dropIndex on collection")
132+
.test("client-side-operations-timeout", "operations ignore deprecated timeout options if timeoutMS is set",
133+
"wTimeoutMS is ignored if timeoutMS is set - dropIndex on collection")
134+
.test("client-side-operations-timeout", "operations ignore deprecated timeout options if timeoutMS is set",
135+
"maxTimeMS is ignored if timeoutMS is set - dropIndex on collection")
136+
.test("client-side-operations-timeout", "operations ignore deprecated timeout options if timeoutMS is set",
137+
"socketTimeoutMS is ignored if timeoutMS is set - dropIndexes on collection")
138+
.test("client-side-operations-timeout", "operations ignore deprecated timeout options if timeoutMS is set",
139+
"wTimeoutMS is ignored if timeoutMS is set - dropIndexes on collection")
140+
.test("client-side-operations-timeout", "operations ignore deprecated timeout options if timeoutMS is set",
141+
"maxTimeMS is ignored if timeoutMS is set - dropIndexes on collection")
142+
.test("client-side-operations-timeout", "timeoutMS can be overridden for a MongoDatabase",
143+
"timeoutMS can be configured on a MongoDatabase - dropIndex on collection")
144+
.test("client-side-operations-timeout", "timeoutMS can be overridden for a MongoDatabase",
145+
"timeoutMS can be set to 0 on a MongoDatabase - dropIndex on collection")
146+
.test("client-side-operations-timeout", "timeoutMS can be overridden for a MongoDatabase",
147+
"timeoutMS can be configured on a MongoDatabase - dropIndexes on collection")
148+
.test("client-side-operations-timeout", "timeoutMS can be overridden for a MongoDatabase",
149+
"timeoutMS can be set to 0 on a MongoDatabase - dropIndexes on collection")
150+
.test("client-side-operations-timeout", "timeoutMS can be overridden for a MongoCollection",
151+
"timeoutMS can be configured on a MongoCollection - dropIndex on collection")
152+
.test("client-side-operations-timeout", "timeoutMS can be overridden for a MongoCollection",
153+
"timeoutMS can be set to 0 on a MongoCollection - dropIndex on collection")
154+
.test("client-side-operations-timeout", "timeoutMS can be overridden for a MongoCollection",
155+
"timeoutMS can be configured on a MongoCollection - dropIndexes on collection")
156+
.test("client-side-operations-timeout", "timeoutMS can be overridden for a MongoCollection",
157+
"timeoutMS can be set to 0 on a MongoCollection - dropIndexes on collection")
158+
.test("client-side-operations-timeout", "timeoutMS can be overridden for an operation",
159+
"timeoutMS can be configured for an operation - dropIndex on collection")
160+
.test("client-side-operations-timeout", "timeoutMS can be overridden for an operation",
161+
"timeoutMS can be set to 0 for an operation - dropIndex on collection")
162+
.test("client-side-operations-timeout", "timeoutMS can be overridden for an operation",
163+
"timeoutMS can be configured for an operation - dropIndexes on collection")
164+
.test("client-side-operations-timeout", "timeoutMS can be overridden for an operation",
165+
"timeoutMS can be set to 0 for an operation - dropIndexes on collection")
166+
.test("client-side-operations-timeout", "timeoutMS can be configured on a MongoClient",
167+
"timeoutMS can be configured on a MongoClient - dropIndex on collection")
168+
.test("client-side-operations-timeout", "timeoutMS can be configured on a MongoClient",
169+
"timeoutMS can be set to 0 on a MongoClient - dropIndex on collection")
170+
.test("client-side-operations-timeout", "timeoutMS can be configured on a MongoClient",
171+
"timeoutMS can be configured on a MongoClient - dropIndexes on collection")
172+
.test("client-side-operations-timeout", "timeoutMS can be configured on a MongoClient",
173+
"timeoutMS can be set to 0 on a MongoClient - dropIndexes on collection");
174+
83175
// TODO-JAVA-5712
84176

85177
// collection-management

0 commit comments

Comments
 (0)