couchbase / CouchbaseMock

A Java mock for Couchbase
Apache License 2.0
64 stars 42 forks source link

Wrong Subdoc Error returned on counter underflow #38

Closed daschl closed 5 years ago

daschl commented 6 years ago

When a counter underflow is triggered, the real server responds with SUBDOC_DELTA_RANGE while the mock responds with SUBDOC_VALUE_CANTINSERT.

Here is the test case from core-io that triggers it:

    @Test
    public void shouldReturnDeltaRangeOnCounterDeltaUnderflow() {
        String path = "counter";
        long prepareUnderflow = -1L;
        long delta = Long.MIN_VALUE;

        //first request will bring the value to -1
        SubCounterRequest request = new SubCounterRequest(testSubKey, path, prepareUnderflow, bucket());
        SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single();
        ReferenceCountUtil.releaseLater(response.content());
        String result = response.content().toString(CharsetUtil.UTF_8);

        assertEquals("-1", result);

        //second request will underflow
        request = new SubCounterRequest(testSubKey, path, delta, bucket());
        response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single();
        ReferenceCountUtil.releaseLater(response.content());
        result = response.content().toString(CharsetUtil.UTF_8);

        assertEquals(result, 0, result.length());
        assertEquals(ResponseStatus.SUBDOC_DELTA_RANGE, response.status());
    }
avsej commented 5 years ago

Fixed in http://review.couchbase.org/c/101590/