How to test VMware GemFire function input and output in JSON through Swagger UI
search cancel

How to test VMware GemFire function input and output in JSON through Swagger UI

book

Article ID: 294341

calendar_today

Updated On:

Products

VMware Tanzu Gemfire

Issue/Introduction

If a VMware GemFire use-case has the requirement to write the function, which will be consumed through REST and receive a JSON object as the response, the examples mentioned in the VMware GemFire documentation might not be sufficient.

Since Swagger UI is an effective way to visualize the test, this knowledge article shows a process with detailed steps on how to test VMware GemFire function input and output in JSON through Swagger UI.

Environment

Product Version: 9.7

Resolution

1. Launch one locator and couple of servers through gfsh script: 
start locator --name=locator1 --port=9551

start server --name=server1 --hostname-for-clients=localhost --server-bind-address=localhost --server-port=8581 --J=-Dgemfire.start-dev-rest-api=true --J=-Dgemfire.http-service-port=8571 --J=-Dgemfire.http-service-bind-address=localhost --classpath=/path/to/conf:/path/to/lib/* --cache-xml-file=/path/to/lib/cache.xml

start server --name=server2 --hostname-for-clients=localhost --server-bind-address=localhost --server-port=8582 --J=-Dgemfire.start-dev-rest-api=true --J=-Dgemfire.http-service-port=8572 --J=-Dgemfire.http-service-bind-address=localhost --classpath=/path/to/conf:/path/to/lib/* --cache-xml-file=/path/to/lib/cache.xml
2. Deploy the attached “functions-1.0.v1.jar”:
deploy --jars=functions-1.0.v1.jar
3. Launch swagger by going to the following URL:
http://localhost:8581/geode/swagger-ui.html
4. Click on region : region CRUD operations to list all the available endpoints for accessing regions. 

5. Make entry to be retrieved in the next step. Go "POST /v1/{region}" to create the following entry:
json body - {"Name1":"John"}
key - person1
onRegion - SampleCache_Test
6. Retrieve the value using deployed function. Go to POST /v1/functions/{functionId}execute function with the following input:
json body - {"@type":"String","@value":"person1"}
functionId -ReadSampleCacheDataForKeyFunction
onRegion - SampleCache_Test
7. The response will be as follows:
[
  "{\n  \"Name1\" : \"John\"\n}",
  null
]
The entry with be retrieved in this way.
Note: If the test is carried out on multiple VMs and servers, redundant copies will also be returned. Null’s will be returned from those nodes not containing the copies.