Microsoft

Local Testing using Gremlin on Azure Cosmos DB Emulator

Web API Using Azure

I was recently tasked with setting up a local database instance for testing a web application. The application uses a Gremlin graph database hosted on Azure Cosmos DB. The solution we decided on was using the Azure Cosmos DB Emulator with data populated by a script. Due to the low usage of Gremlin, there does not exist much documentation supporting this. Therefore, after finishing the scripts and setup, I decided to share my newfound knowledge with everybody.

First, you need to download and install the Azure Cosmos DB Emulator. Then, download the Gremlin console sdk and place the unzipped folder in C:/sdk.

Then, run this command in your console:
C:\”Program Files”\”Azure Cosmos DB Emulator”\CosmosDB.Emulator.exe /EnableGremlinEndpoint

This will start the emulator. When your browser window opens, create a new container and database. When finished, paste the following in C:\sdk\apache-tinkerpop-gremlin-console-3.4.3\conf\remote-localcompute.yaml:

hosts: [localhost]
port: 8901
username: /dbs/{database}/colls/{collection}
password:C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
connectionPool: {
enableSsl: false}
serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0,
config: { serializeResultToString: true }}

Now, run the following command from C:\sdk\apache-tinkerpop-gremlin-console-3.4.3:

Microsoft - The Essential Guide to Microsoft Teams End-User Engagement
The Essential Guide to Microsoft Teams End-User Engagement

We take you through 10 best practices, considerations, and suggestions that can enrich your Microsoft Teams deployment and ensure both end-user adoption and engagement.

Get the Guide

bin\gremlin.bat

This will open the Gremlin console in your console window. To start a data-populating script, run ‘. {location of your script}’ An example script looks like:

:remote connect tinkerpop.server conf/remote-localcompute.yaml
:remote console
g.E().drop()
g.V().drop()
g.addV(‘Location’).property(‘Name’, ‘Atlanta’).property(‘_partitionKey’, ‘v1’)
g.addV(‘Person’).property(‘Name’, ‘Josh Kostal’).property(‘_partitionKey’, ‘v1’)

This will connect to your local database, drop all existing edges and vertices, and add two new vertices. Now, you are able to run your tests. When these are finished, run:

C:\”Program Files”\”Azure Cosmos DB Emulator”\CosmosDB.Emulator.exe /Shutdown

This will spin down the emulator.

Finally, here are working examples of my scripts:

gremlin-connect.bat
start C:\”Program Files”\”Azure Cosmos DB Emulator”\CosmosDB.Emulator.exe /EnableGremlinEndpoint
cd /d C:\sdk\apache-tinkerpop-gremlin-console-3.4.3
start cmd /k call bin\gremlin.bat
ECHO When finished testing, press any key. This will shutdown the local database
PAUSE
C:\”Program Files”\”Azure Cosmos DB Emulator”\CosmosDB.Emulator.exe /Shutdown

load-data.txt
:remote connect tinkerpop.server conf/remote-localcompute.yaml
:remote console
g.E().drop()
g.V().drop()
g.addV(‘Location’).property(‘Name’, ‘Atlanta’).property(‘_partitionKey’, ‘v1’)
g.addV(‘Person’).property(‘Name’, ‘Josh Kostal’).property(‘_partitionKey’, ‘v1’)

I hope this helps, feel free to reach out to me if you have any questions! My email is josh.kostal@perficient.com.

About the Author

I am a recent college graduate who moved from Omaha to Atlanta to work at Perficient, where I started in May 2019. I enjoy working on APIs and microservices using .NET or Ruby on Rails, with an emphasis on security.

More from this Author

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to the Weekly Blog Digest:

Sign Up