[ 
https://issues.apache.org/jira/browse/OAK-12114?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18061652#comment-18061652
 ] 

Rishabh Daim commented on OAK-12114:
------------------------------------

More on the BSON Wired Size vs Storage Size:

{quote}What the method creates

  char[] chars = new char[1024 * 1024];  // 1M chars
  Arrays.fill(chars, '0');                // all identical: "00000000..."
  String content = new String(chars);

  BSON Wire Size vs Storage Size

  These are two separate things:

  1. BSON Wire Size (~1MB)

  The '0' character is ASCII (1 byte in UTF-8), so the string is exactly ~1MB 
as BSON on the wire. This is what matters for the 
BsonMaximumSizeExceededException — the 16MB limit is enforced on the 
uncompressed BSON
   payload before it reaches MongoDB.

  2. Storage Size (near zero)

  MongoDB's WiredTiger engine (default since 3.x) uses Snappy compression on 
disk. A string of 1 million identical characters is maximally compressible — 
Snappy would reduce it to just a few bytes using run-length
  encoding.{quote}

> MongoDBExceptionTest uses payloads that compress well
> -----------------------------------------------------
>
>                 Key: OAK-12114
>                 URL: https://issues.apache.org/jira/browse/OAK-12114
>             Project: Jackrabbit Oak
>          Issue Type: Bug
>          Components: mongomk
>            Reporter: Julian Reschke
>            Priority: Major
>             Fix For: 2.0.0
>
>
> ...containing only zeros, thus defeating the purpose of testing large 
> payloads.
> (actually, not testing it at all)
> With this change:
> {code}
> diff --git 
> a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java
>  
> b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java
> index d6e7cb264e..934af36627 100644
> --- 
> a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java
> +++ 
> b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java
> @@ -36,7 +36,6 @@ import org.junit.Test;
>  import org.slf4j.event.Level;
>  import java.util.ArrayList;
> -import java.util.Arrays;
>  import java.util.List;
>  import static java.util.Collections.singletonList;
> @@ -333,9 +332,5 @@ public class MongoDBExceptionTest {
>      // RED ALERT: OAK-12114
>      private String create1MBContent() {
> -        char[] chars = new char[1024 * 1024];
> -        Arrays.fill(chars, '0');
> -        String content = new String(chars);
> -        return content;
> -    }
> +        return  RandomStringUtils.secure().next(1024 * 1024);    }
>  }
> {code}
> we get
> {code}
> ERROR] Failures:
> [ERROR]   MongoDBExceptionTest.createOrUpdate16MBDoc:156
> Expected: a string containing "Document to upsert is larger than 16777216"
>      but: was "Document size of 37633707 is larger than maximum of 16793600. 
> [/foo]"
> [ERROR]   MongoDBExceptionTest.findAndUpdate16MBDoc:304
> Expected: a string containing "Resulting document after update is larger than 
> 16777216"
>      but: was "Payload document size is larger than maximum of 16793600. 
> [/foo]"
> [ERROR]   MongoDBExceptionTest.multiCreateOrUpdate16MBDoc:263
> Expected: a string containing "Resulting document after update is larger than 
> 16777216"
>      but: was "Payload document size is larger than maximum of 16793600. 
> [/test]"
> [ERROR]   MongoDBExceptionTest.update16MBDoc:231
> Expected: a string containing "Resulting document after update is larger than 
> 16777216"
>      but: was "Payload document size is larger than maximum of 16793600. 
> [/foo]"
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to