Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix using limit=0 and details=on to get only the count of elements #1492 #3994

Merged
merged 25 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
da0256c
Fix issue #1492
Anjali-NEC Nov 9, 2021
28d9007
Updated
Anjali-NEC Nov 10, 2021
aade17a
Merge branch 'master' into issue1492
Anjali-NEC Nov 11, 2021
9dd6330
Updated
Anjali-NEC Nov 11, 2021
bd8fd20
Merge branch 'issue1492' of https://github.com/Anjali-NEC/fiware-orio…
Anjali-NEC Nov 11, 2021
f4d0cbd
Added test file
Anjali-NEC Nov 11, 2021
8879a39
Updated as per comment
Anjali-NEC Nov 12, 2021
8877986
Merge branch 'master' into issue1492
Anjali-NEC Nov 18, 2021
cf68c96
Updated code as per comment
Anjali-NEC Nov 18, 2021
a5e89be
Merge branch 'issue1492' of https://github.com/Anjali-NEC/fiware-orio…
Anjali-NEC Nov 18, 2021
7d6160f
Update getEntities.cpp
Anjali-NEC Nov 18, 2021
397baaf
Merge remote-tracking branch 'upstream/master' into issue1492
Anjali-NEC Nov 30, 2021
64cf793
Updated code and test case
Anjali-NEC Nov 30, 2021
38b7bf4
Merge branch 'issue1492' of https://github.com/Anjali-NEC/fiware-orio…
Anjali-NEC Nov 30, 2021
8a03332
Updated code
Anjali-NEC Nov 30, 2021
18c7f89
Merge branch 'master' into issue1492
Anjali-NEC Jan 24, 2022
67ea727
Updated as per comment
Anjali-NEC Jan 24, 2022
6fe85e9
Merge branch 'issue1492' of https://github.com/Anjali-NEC/fiware-orio…
Anjali-NEC Jan 24, 2022
4caae7d
Merge branch 'master' into issue1492
Anjali-NEC Mar 4, 2022
9a54cb8
Merge remote-tracking branch 'upstream/master' into issue1492
invalid-email-address Mar 4, 2022
397ae9e
Modify code as per comment
invalid-email-address Mar 4, 2022
d978465
Merge branch 'issue1492' of https://github.com/Anjali-NEC/fiware-orio…
invalid-email-address Mar 4, 2022
ff2b225
Updated code
invalid-email-address Mar 7, 2022
30d7c01
Merge branch 'master' into issue1492
Anjali-NEC Mar 21, 2022
e779cb2
Merge branch 'master' into issue1492
Anjali-NEC Mar 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Fix: Using limit=0 and options=count to get only the count of elements (#1492)
- Add: maxFailsLimit subscription field, so subscription is automatically passed to inactive after that number of failed notification attemps (#3541)
- Add: failsCounter subscription field, to count the number of consecutive notificaitons fails (#3541)
- Fix: throttling misbehaviour after subscription update when csubs cache is in use (#3981)
Expand Down
4 changes: 1 addition & 3 deletions src/lib/rest/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ static int uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* ckey, c
}
else if (limit == 0)
{
OrionError error(SccBadRequest, std::string("Bad pagination limit: /") + value + "/ [a value of ZERO is unacceptable]");
ciP->httpStatusCode = error.code;
ciP->answer = error.smartRender(ciP->apiVersion);
ciP->httpStatusCode = SccOk;
return MHD_YES;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ Date: REGEX(.*)


+++++ 3. URI param 'limit' == 0
HTTP/1.1 400 Bad Request
Content-Length: 135
HTTP/1.1 200 OK
Content-Length: 86
Content-Type: application/json
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Date: REGEX(.*)

{
"orionError": {
"errorCode": {
"code": "400",
"details": "Bad pagination limit: /000000/ [a value of ZERO is unacceptable]",
"details": "JSON Parse Error",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"JSON Parse Error" doesn't seem to be a right message in this case, as actually the request in step 3 doesn't have any payload...

In fact, a OK response seems to be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"JSON Parse Error" doesn't seem to be a right message in this case, as actually the request in step 3 doesn't have any payload...

In fact, a OK response seems to be better.

In step 3 everything is OK but it shows "JSON Parse Error". I didn't find reason for this error. Could you please suggest what modification should be done in this test case?

Copy link
Member

@fgalan fgalan Nov 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that the response in this case should be the same you get when do a /v1/queryContext operation without any matching result. You can test yourself using this curl:

curl -vvv localhost:1026/v1/queryContext -H 'content-type: application/json' -d @- <<EOF
{
    "entities": [
        {
            "type": "foo",
            "isPattern": "false",
            "id": "bar"
        }
    ]
}
EOF

You should get something like this:

< HTTP/1.1 200 OK
< Connection: Keep-Alive
< Content-Length: 70
< Content-Type: application/json
< Fiware-Correlator: aaee0e26-4621-11ec-9ae3-000c29583ca5
< Date: Mon, 15 Nov 2021 14:38:15 GMT
< 
* Connection #0 to host localhost left intact
{"errorCode":{"code":"404","reasonPhrase":"No context element found"}}

The expectation in the step should resemble that. The reason behind the "JSON Parser Error" in this case should be analyzed.

"reasonPhrase": "Bad Request"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright 2021 Telefonica Investigacion y Desarrollo, S.A.U
#
# This file is part of Orion Context Broker.
#
# Orion Context Broker is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Orion Context Broker is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/.
#
# For those usages not covered by this license please contact with
# iot_support at tid dot es

# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh

--NAME--
using_limit=0_and_options=count_to_get_only_the_count_of_elements

--SHELL-INIT--
dbInit CB
brokerStart CB

--SHELL--

#
# 01. GET /v2/entities with 'limit' == 0 and options=count
# 02. GET /v2/entities with 'limit' == 0
#

echo "01. GET /v2/entities with 'limit' == 0 and options=count"
echo "========================================================"
orionCurl --url "/v2/entities?limit=0&options=count"
echo
echo



echo "02. GET /v2/entities with 'limit' == 0"
echo "======================================"
orionCurl --url "/v2/entities?limit=0"
echo
echo



--REGEXPECT--
01. GET /v2/entities with 'limit' == 0 and options=count
========================================================
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json
Fiware-Total-Count: 0
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Date: REGEX(.*)

[]


02. GET /v2/entities with 'limit' == 0
======================================
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Date: REGEX(.*)

[]


--TEARDOWN--
brokerStop CB
dbDrop CB