Skip to content

Commit 3231890

Browse files
committed
GridFS fix default chunk size
JAVA-2028
1 parent cd84425 commit 3231890

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

driver/src/main/com/mongodb/client/gridfs/GridFSBucketImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ final class GridFSBucketImpl implements GridFSBucket {
6565
GridFSBucketImpl(final MongoDatabase database, final String bucketName) {
6666
this.database = notNull("database", database);
6767
this.bucketName = notNull("bucketName", bucketName);
68-
this.chunkSizeBytes = 255;
68+
this.chunkSizeBytes = 255 * 1024;
6969
this.writeConcern = database.getWriteConcern();
7070
this.readPreference = database.getReadPreference();
7171
this.codecRegistry = getCodecRegistry();

driver/src/test/functional/com/mongodb/client/gridfs/GridFSBucketSmokeTestSpecification.groovy

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class GridFSBucketSmokeTestSpecification extends FunctionalSpecification {
3636
protected MongoCollection<Document> filesCollection;
3737
protected MongoCollection<Document> chunksCollection;
3838
protected GridFSBucket gridFSBucket;
39+
def singleChunkString = 'GridFS'
40+
def multiChunkString = singleChunkString.padLeft(1024 * 255 * 5)
3941

4042
def setup() {
4143
mongoDatabase = getMongoClient().getDatabase(getDefaultDatabaseName())
@@ -56,6 +58,7 @@ class GridFSBucketSmokeTestSpecification extends FunctionalSpecification {
5658
@Unroll
5759
def 'should round trip a #description'() {
5860
given:
61+
def content = multiChunk ? multiChunkString : singleChunkString
5962
def contentBytes = content as byte[]
6063
def expectedLength = contentBytes.length as Long
6164
def expectedMD5 = MessageDigest.getInstance('MD5').digest(contentBytes).encodeHex().toString()
@@ -100,16 +103,16 @@ class GridFSBucketSmokeTestSpecification extends FunctionalSpecification {
100103
gridFSContentBytes == contentBytes
101104

102105
where:
103-
description | content | chunkCount | direct
104-
'a small file directly' | 'Hello GridFS' | 1 | true
105-
'a small file to stream' | 'Hello GridFS' | 1 | false
106-
'a large file directly' | 'qwerty' * 1024 | 25 | true
107-
'a large file to stream' | 'qwerty' * 1024 | 25 | false
106+
description | multiChunk | chunkCount | direct
107+
'a small file directly' | false | 1 | true
108+
'a small file to stream' | false | 1 | false
109+
'a large file directly' | true | 5 | true
110+
'a large file to stream' | true | 5 | false
108111
}
109112

110113
def 'should round trip with a batchSize of 1'() {
111114
given:
112-
def content = 'qwerty' * 1024
115+
def content = multiChunkString
113116
def contentBytes = content as byte[]
114117
def expectedLength = contentBytes.length as Long
115118
def expectedMD5 = MessageDigest.getInstance('MD5').digest(contentBytes).encodeHex().toString()
@@ -121,7 +124,7 @@ class GridFSBucketSmokeTestSpecification extends FunctionalSpecification {
121124

122125
then:
123126
filesCollection.count() == 1
124-
chunksCollection.count() == 25
127+
chunksCollection.count() == 5
125128

126129
when:
127130
def file = filesCollection.find().first()

driver/src/test/unit/com/mongodb/client/gridfs/GridFSBucketSpecification.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ class GridFSBucketSpecification extends Specification {
105105

106106
def 'should get defaults from MongoDatabase'() {
107107
given:
108-
def defaultChunkSize = 255
108+
def defaultChunkSizeBytes = 255 * 1024
109109
def database = new MongoDatabaseImpl('test', fromProviders(new DocumentCodecProvider()), secondary(), WriteConcern.ACKNOWLEDGED,
110110
new TestOperationExecutor([]))
111111

112112
when:
113113
def gridFSBucket = new GridFSBucketImpl(database)
114114

115115
then:
116-
gridFSBucket.getChunkSizeBytes() == defaultChunkSize
116+
gridFSBucket.getChunkSizeBytes() == defaultChunkSizeBytes
117117
gridFSBucket.getReadPreference() == database.getReadPreference()
118118
gridFSBucket.getWriteConcern() == database.getWriteConcern()
119119
}

0 commit comments

Comments
 (0)