@@ -115,26 +115,26 @@ public void testCountAndHint() {
115
115
116
116
c .createIndex (new BasicDBObject ("i" , 1 ));
117
117
118
- assertEquals (1 , c .find (new BasicDBObject ("i" , 1 )).hint ( "_id_" ).count ());
119
- assertEquals (2 , c .find ().hint ( "_id_" ).count ());
118
+ assertEquals (1 , c .find (new BasicDBObject ("i" , 1 )).hint ("_id_" ).count ());
119
+ assertEquals (2 , c .find ().hint ("_id_" ).count ());
120
120
121
121
if (serverIsAtLeastVersion (2.6 )) {
122
122
try {
123
- c .find (new BasicDBObject ("i" , 1 )).hint ( "BAD HINT" ).count ();
123
+ c .find (new BasicDBObject ("i" , 1 )).hint ("BAD HINT" ).count ();
124
124
fail ("Show have thrown" );
125
125
} catch (MongoException e ) {
126
126
// good
127
127
}
128
128
} else {
129
- assertEquals (1 , c .find (new BasicDBObject ("i" , 1 )).hint ( "BAD HINT" ).count ());
129
+ assertEquals (1 , c .find (new BasicDBObject ("i" , 1 )).hint ("BAD HINT" ).count ());
130
130
}
131
131
132
132
c .createIndex (new BasicDBObject ("x" , 1 ), new BasicDBObject ("sparse" , true ));
133
133
134
134
if (serverIsAtLeastVersion (2.6 )) {
135
- assertEquals (0 , c .find (new BasicDBObject ("i" , 1 )).hint ( "x_1" ).count ());
135
+ assertEquals (0 , c .find (new BasicDBObject ("i" , 1 )).hint ("x_1" ).count ());
136
136
} else {
137
- assertEquals (1 , c .find (new BasicDBObject ("i" , 1 )).hint ( "x_1" ).count ());
137
+ assertEquals (1 , c .find (new BasicDBObject ("i" , 1 )).hint ("x_1" ).count ());
138
138
}
139
139
if (serverIsAtLeastVersion (3.3 )) {
140
140
assertEquals (0 , collection .find ().hint ("x_1" ).count ()); // see https://jira.mongodb.org/browse/SERVER-22041
@@ -225,8 +225,8 @@ public void testTailable() {
225
225
DBObject secondDBObject = new BasicDBObject ("x" , 2 );
226
226
227
227
final DBCursor cur = c .find ()
228
- .sort (new BasicDBObject ("$natural" , 1 ))
229
- .addOption (Bytes .QUERYOPTION_TAILABLE );
228
+ .sort (new BasicDBObject ("$natural" , 1 ))
229
+ .addOption (Bytes .QUERYOPTION_TAILABLE );
230
230
c .save (firstDBObject , WriteConcern .SAFE );
231
231
232
232
assertEquals (firstDBObject , cur .tryNext ());
@@ -257,8 +257,8 @@ public void testTailableImplicitAwaitOnHasNext() throws ExecutionException, Time
257
257
}
258
258
259
259
final DBCursor cur = c .find ()
260
- .sort (new BasicDBObject ("$natural" , 1 ))
261
- .addOption (Bytes .QUERYOPTION_TAILABLE );
260
+ .sort (new BasicDBObject ("$natural" , 1 ))
261
+ .addOption (Bytes .QUERYOPTION_TAILABLE );
262
262
263
263
final CountDownLatch latch = new CountDownLatch (1 );
264
264
Callable <Integer > callable = new Callable <Integer >() {
@@ -300,8 +300,8 @@ public void testTailableImplicitAwaitOnNext() throws ExecutionException, Timeout
300
300
}
301
301
302
302
final DBCursor cur = c .find ()
303
- .sort (new BasicDBObject ("$natural" , 1 ))
304
- .addOption (Bytes .QUERYOPTION_TAILABLE );
303
+ .sort (new BasicDBObject ("$natural" , 1 ))
304
+ .addOption (Bytes .QUERYOPTION_TAILABLE );
305
305
306
306
final CountDownLatch latch = new CountDownLatch (1 );
307
307
Callable <Integer > callable = new Callable <Integer >() {
@@ -340,8 +340,8 @@ public void shouldSupportTryNextOnTailableCursors() {
340
340
341
341
c .save (new BasicDBObject ("x" , 1 ), WriteConcern .SAFE );
342
342
DBCursor cur = c .find ()
343
- .sort (new BasicDBObject ("$natural" , 1 ))
344
- .addOption (Bytes .QUERYOPTION_TAILABLE );
343
+ .sort (new BasicDBObject ("$natural" , 1 ))
344
+ .addOption (Bytes .QUERYOPTION_TAILABLE );
345
345
346
346
try {
347
347
cur .tryNext ();
@@ -350,67 +350,54 @@ public void shouldSupportTryNextOnTailableCursors() {
350
350
}
351
351
}
352
352
353
- @ Test (expected = IllegalArgumentException .class )
353
+ @ Test (expected = IllegalArgumentException .class )
354
354
public void shouldThrowExceptionOnTryNextForNonTailableCursors () {
355
355
DBCollection c = getDatabase ().getCollection ("tail1" );
356
356
c .drop ();
357
357
getDatabase ().createCollection ("tail1" , new BasicDBObject ("capped" , true ).append ("size" , 10000 ));
358
358
359
359
c .save (new BasicDBObject ("x" , 1 ), WriteConcern .SAFE );
360
360
DBCursor cur = c .find ()
361
- .sort (new BasicDBObject ("$natural" , 1 ))
362
- .addOption (Bytes .QUERYOPTION_AWAITDATA );
361
+ .sort (new BasicDBObject ("$natural" , 1 ))
362
+ .addOption (Bytes .QUERYOPTION_AWAITDATA );
363
363
364
364
cur .tryNext ();
365
365
}
366
366
367
367
@ Test
368
368
public void testBig () {
369
- DBCollection c = collection ;
370
- String bigString ;
371
- {
372
- StringBuilder buf = new StringBuilder (16000 );
373
- for (int i = 0 ; i < 16000 ; i ++) {
374
- buf .append ("x" );
375
- }
376
- bigString = buf .toString ();
369
+ StringBuilder buf = new StringBuilder (16000 );
370
+ for (int i = 0 ; i < 16000 ; i ++) {
371
+ buf .append ("x" );
377
372
}
373
+ String bigString = buf .toString ();
378
374
379
375
int numToInsert = (15 * 1024 * 1024 ) / bigString .length ();
376
+ assert numToInsert > 800 ;
380
377
381
378
for (int i = 0 ; i < numToInsert ; i ++) {
382
- c . save ( BasicDBObjectBuilder . start (). add ( "x" , i ).add ("s" , bigString ). get ( ));
379
+ collection . insert ( new BasicDBObject ( "x" , i ).append ("s" , bigString ));
383
380
}
384
381
385
- assert (800 < numToInsert );
386
-
387
- assertEquals (numToInsert , c .find ().count ());
388
- assertEquals (numToInsert , c .find ().toArray ().size ());
389
- assertEquals (numToInsert , c .find ().limit (800 ).count ());
390
- assertEquals (800 , c .find ().limit (800 ).toArray ().size ());
391
-
392
- // negative limit works like negative batch size, for legacy reason
393
- int x = c .find ().limit (-800 ).toArray ().size ();
394
- if (serverIsAtLeastVersion (3.3 )) {
395
- assertEquals (800 , x ); // MongoDB 3.4 creates a 12MB OP_REPLY that fits all 800 documents
396
- } else {
397
- assertTrue (x < 800 ); // Previous versions cut off the OP_REPLY at 4MB
398
- }
382
+ assertEquals (numToInsert , collection .find ().count ());
383
+ assertEquals (numToInsert , collection .find ().toArray ().size ());
384
+ assertEquals (numToInsert , collection .find ().limit (800 ).count ());
385
+ assertEquals (800 , collection .find ().limit (800 ).toArray ().size ());
399
386
400
- DBCursor a = c .find ();
387
+ DBCursor a = collection .find ();
401
388
assertEquals (numToInsert , a .itcount ());
402
389
403
- DBCursor b = c .find ().batchSize (10 );
390
+ DBCursor b = collection .find ().batchSize (10 );
404
391
assertEquals (numToInsert , b .itcount ());
405
392
assertEquals (10 , b .getSizes ().get (0 ).intValue ());
406
393
407
394
assertTrue (a .numGetMores () < b .numGetMores ());
408
395
409
- assertEquals (numToInsert , c .find ().batchSize (2 ).itcount ());
410
- assertEquals (numToInsert , c .find ().batchSize (1 ).itcount ());
396
+ assertEquals (numToInsert , collection .find ().batchSize (2 ).itcount ());
397
+ assertEquals (numToInsert , collection .find ().batchSize (1 ).itcount ());
411
398
412
- assertEquals (numToInsert , _count (c .find (null , null ).skip (0 ).batchSize (5 )));
413
- assertEquals (5 , _count (c .find (null , null ).skip (0 ).batchSize (-5 )));
399
+ assertEquals (numToInsert , _count (collection .find (null , null ).skip (0 ).batchSize (5 )));
400
+ assertEquals (5 , _count (collection .find (null , null ).skip (0 ).batchSize (-5 )));
414
401
}
415
402
416
403
@ SuppressWarnings ("unchecked" )
@@ -680,7 +667,7 @@ public void testHasFinalizer() throws UnknownHostException {
680
667
Mongo m ;
681
668
if (getMongoClientURI ().getCredentials () != null ) {
682
669
m = new MongoClient (new ServerAddress (getMongoClientURI ().getHosts ().get (0 )), asList (getMongoClientURI ().getCredentials ()),
683
- mongoOptions );
670
+ mongoOptions );
684
671
} else {
685
672
m = new MongoClient (new ServerAddress (getMongoClientURI ().getHosts ().get (0 )), mongoOptions );
686
673
}
@@ -716,7 +703,7 @@ public void testMaxTimeForIterator() {
716
703
public void testMaxTimeDuringGetMore () {
717
704
assumeFalse (isSharded (getMongoClient ()));
718
705
checkServerVersion (2.5 );
719
- for (int i = 0 ; i < 20 ; i ++) {
706
+ for (int i = 0 ; i < 20 ; i ++) {
720
707
collection .insert (new BasicDBObject ("x" , 1 ));
721
708
}
722
709
@@ -727,7 +714,7 @@ public void testMaxTimeDuringGetMore() {
727
714
728
715
enableMaxTimeFailPoint ();
729
716
try {
730
- while (cursor .hasNext ()) {
717
+ while (cursor .hasNext ()) {
731
718
cursor .next ();
732
719
}
733
720
fail ("Show have thrown" );
@@ -835,46 +822,46 @@ private void insertData() {
835
822
public void testMaxScan () {
836
823
insertData ();
837
824
countResults (new DBCursor (collection , new BasicDBObject (), new BasicDBObject (), ReadPreference .primary ())
838
- .addSpecial ("$maxScan" , 4 ), 4 );
825
+ .addSpecial ("$maxScan" , 4 ), 4 );
839
826
countResults (new DBCursor (collection , new BasicDBObject (), new BasicDBObject (), ReadPreference .primary ()).maxScan (4 ), 4 );
840
827
}
841
828
842
829
@ Test
843
830
public void testMax () {
844
831
insertData ();
845
832
countResults (new DBCursor (collection , new BasicDBObject (), new BasicDBObject (), ReadPreference .primary ())
846
- .addSpecial ("$max" , new BasicDBObject ("x" , 4 )), 4 );
833
+ .addSpecial ("$max" , new BasicDBObject ("x" , 4 )), 4 );
847
834
countResults (new DBCursor (collection , new BasicDBObject (), new BasicDBObject (), ReadPreference .primary ())
848
- .max (new BasicDBObject ("x" , 4 )), 4 );
835
+ .max (new BasicDBObject ("x" , 4 )), 4 );
849
836
}
850
837
851
838
@ Test
852
839
public void testMin () {
853
840
insertData ();
854
841
countResults (new DBCursor (collection , new BasicDBObject (), new BasicDBObject (), ReadPreference .primary ())
855
- .addSpecial ("$min" , new BasicDBObject ("x" , 4 )), 6 );
842
+ .addSpecial ("$min" , new BasicDBObject ("x" , 4 )), 6 );
856
843
countResults (new DBCursor (collection , new BasicDBObject (), new BasicDBObject (), ReadPreference .primary ())
857
- .min (new BasicDBObject ("x" , 4 )), 6 );
844
+ .min (new BasicDBObject ("x" , 4 )), 6 );
858
845
}
859
846
860
847
@ Test
861
848
public void testReturnKey () {
862
849
DBCursor cursor = new DBCursor (collection , new BasicDBObject (), new BasicDBObject (), ReadPreference .primary ())
863
- .addSpecial ("$returnKey" , true );
850
+ .addSpecial ("$returnKey" , true );
864
851
try {
865
852
while (cursor .hasNext ()) {
866
853
Assert .assertNull (cursor .next ()
867
- .get ("_id" ));
854
+ .get ("_id" ));
868
855
}
869
856
} finally {
870
857
cursor .close ();
871
858
}
872
859
cursor = new DBCursor (collection , new BasicDBObject (), new BasicDBObject (), ReadPreference .primary ())
873
- .returnKey ();
860
+ .returnKey ();
874
861
try {
875
862
while (cursor .hasNext ()) {
876
863
Assert .assertNull (cursor .next ()
877
- .get ("_id" ));
864
+ .get ("_id" ));
878
865
}
879
866
} finally {
880
867
cursor .close ();
@@ -884,7 +871,7 @@ public void testReturnKey() {
884
871
@ Test
885
872
public void testShowDiskLoc () {
886
873
DBCursor cursor = new DBCursor (collection , new BasicDBObject (), new BasicDBObject (), ReadPreference .primary ())
887
- .addSpecial ("$showDiskLoc" , true );
874
+ .addSpecial ("$showDiskLoc" , true );
888
875
try {
889
876
while (cursor .hasNext ()) {
890
877
DBObject next = cursor .next ();
@@ -894,7 +881,7 @@ public void testShowDiskLoc() {
894
881
cursor .close ();
895
882
}
896
883
cursor = new DBCursor (collection , new BasicDBObject (), new BasicDBObject (), ReadPreference .primary ())
897
- .showDiskLoc ();
884
+ .showDiskLoc ();
898
885
try {
899
886
while (cursor .hasNext ()) {
900
887
DBObject next = cursor .next ();
@@ -908,8 +895,8 @@ public void testShowDiskLoc() {
908
895
@ Test (expected = MongoException .class )
909
896
public void testSnapshotWithHint () {
910
897
DBCursor cursor = new DBCursor (collection , new BasicDBObject (), new BasicDBObject (), ReadPreference .primary ())
911
- .hint ("x" )
912
- .addSpecial ("$snapshot" , true );
898
+ .hint ("x" )
899
+ .addSpecial ("$snapshot" , true );
913
900
try {
914
901
while (cursor .hasNext ()) {
915
902
cursor .next ();
@@ -922,8 +909,8 @@ public void testSnapshotWithHint() {
922
909
@ Test (expected = MongoException .class )
923
910
public void testSnapshotWithSort () {
924
911
DBCursor cursor = new DBCursor (collection , new BasicDBObject (), new BasicDBObject (), ReadPreference .primary ())
925
- .sort (new BasicDBObject ("x" , 1 ))
926
- .addSpecial ("$snapshot" , true );
912
+ .sort (new BasicDBObject ("x" , 1 ))
913
+ .addSpecial ("$snapshot" , true );
927
914
try {
928
915
while (cursor .hasNext ()) {
929
916
cursor .next ();
@@ -946,7 +933,7 @@ private void countResults(final DBCursor cursor, final int expected) {
946
933
@ Test
947
934
public void testComment () {
948
935
DBCursor cursor = new DBCursor (collection , new BasicDBObject (), new BasicDBObject (), ReadPreference .primary ())
949
- .addSpecial ("$comment" , "test comment" );
936
+ .addSpecial ("$comment" , "test comment" );
950
937
while (cursor .hasNext ()) {
951
938
cursor .next ();
952
939
}
@@ -956,7 +943,7 @@ public void testComment() {
956
943
@ Test
957
944
public void testBatchSizeTracking () {
958
945
DBCursor cursor = new DBCursor (collection , new BasicDBObject (), new BasicDBObject (), ReadPreference .primary ())
959
- .batchSize (2 );
946
+ .batchSize (2 );
960
947
961
948
assertFalse (cursor .isBatchSizeTrackingDisabled ());
962
949
assertFalse (cursor .copy ().isBatchSizeTrackingDisabled ());
@@ -977,7 +964,7 @@ public void testBatchSizeTracking() {
977
964
@ Test
978
965
public void testDisabledBatchSizeTracking () {
979
966
DBCursor cursor = new DBCursor (collection , new BasicDBObject (), new BasicDBObject (), ReadPreference .primary ())
980
- .disableBatchSizeTracking ().batchSize (1 );
967
+ .disableBatchSizeTracking ().batchSize (1 );
981
968
assertTrue (cursor .isBatchSizeTrackingDisabled ());
982
969
assertTrue (cursor .copy ().isBatchSizeTrackingDisabled ());
983
970
0 commit comments