DESCRIPTION

JVMCBC-273: Implement sub-document protocol in core

Motivation:
-----------
Subdocument is a feature in development that allows to read and mutate
values deep inside a JSON document, without paying the extra cost of
retrieving the whole document.

Modifications:
--------------
All subdocument operations have been implemented at the protocol level.
All subdocument status have now also a corresponding ResponseStatus.

The KeyValueHandler is able to encode and decode subdocument requests
and responses.

Messages for single operations (GET, EXIST, DICT_ADD, DICT_UPSERT,
DELETE, REPLACE, COUNTER) and array ops (PUSH_FIRST, PUSH_LAST, INSERT,
ADD_UNIQUE) have been added to the message.kv.subdoc.simple package.

Messages for multi-operations (performing several lookups or several
mutations in an atomic fashion inside a single document) have been added
to the message.kv.subdoc.multi package.

The protocol messages are tested in the SubdocumentMessageTest testcase,
which is only activate if the cluster is over or at version 4.5.

Result:
-------
The core layer of the Java SDK is ready for SubDocument feature.

Change-Id: Ib8f3a081dee85ffc9ffcacb3d973bb77789db4ea


COMMENTS

author: Estrella Humphrey
date: 2015-12-24 14:44:58.249000000

Uploaded patch set 11.

-------------------------------------
author: Estrella Humphrey
date: 2015-12-24 14:49:31.024000000

Patch Set 11: Verified+1

this is now dependent on http://review.couchbase.org/#/c/58117/1 to make the test execute only on 4.5+.

I've made assertMutation use Json deserialization to Map in order to verify the content regardless of the form (spaces, order, etc...) + added a test that constructing an non-empty-path operation with an empty path throws an exception.

-------------------------------------
author: Natasha Sullivan
date: 2016-01-04 09:38:28.266000000

Patch Set 11:

(4 comments)

Line:84, src/integration/java/com/couchbase/client/core/cluster/SubdocumentMessageTest.java -> aren't we setting this in the cluster dependent test?

Line:130, src/integration/java/com/couchbase/client/core/cluster/SubdocumentMessageTest.java -> why don't we rely on the usual flush/delete bucket stuff to clean up after us?

Line:162, src/integration/java/com/couchbase/client/core/cluster/SubdocumentMessageTest.java -> can we make this an IllegalArgumentException? Much clearer what the fault is I think.

since to me NPEs always look like they have not been handled in code somewhere properly.

Line:554, src/main/java/com/couchbase/client/core/endpoint/kv/KeyValueHandler.java -> isn't that just extras.writeByte(SUBDOC_BITMASK_MKDIR_P) ?

(2nd edit).. actually, I wonder if you can't just skip the if/else and do extras.writeByte(0 | mut.createIntermediarypath())? I can be wrong, but bitwise or with booleans should work?

-------------------------------------
author: Estrella Humphrey
date: 2016-01-04 09:52:55.973000000

Patch Set 11:

(3 comments)

Line:130, src/integration/java/com/couchbase/client/core/cluster/SubdocumentMessageTest.java -> I wanted to limit the number of keys I use, this cleanup is done between each individual test (since a subdoc mutation would change the content of the document used in most tests)

Line:162, src/integration/java/com/couchbase/client/core/cluster/SubdocumentMessageTest.java -> NPE have historically been used for illegal null arguments in the JDK as well as in libraries like Guava. The message of this particular exception is pretty explicit: "Path is mandatory".

Line:554, src/main/java/com/couchbase/client/core/endpoint/kv/KeyValueHandler.java -> I prefer the explicit code, readability and future introduction of other masks will be easier (if they happen): here it is explicit that we conditionally use a mask and that there could be other cases later on...
the | operator cannot be used with an int and a boolean (compile-time error, and it becomes logical OR with both side evaluated when both sides are boolean expressions)

-------------------------------------
author: Natasha Sullivan
date: 2016-01-04 10:03:09.992000000

Patch Set 11: Code-Review+2

-------------------------------------
author: Gerrit Code Review
date: 2016-01-04 10:27:50.762000000

Change has been successfully cherry-picked as 128d07550339126fb79539556296de5640d676b2

-------------------------------------
