Unit testing with JanusGraph

260 views
Skip to first unread message

Suny

unread,
Sep 7, 2017, 10:22:37 AM9/7/17
to JanusGraph users
Hi,

I am using janusgraph with cassandra as backend for my application. If i want to write a unit test to verify saving/retrieving of data, is mocking the only way ? 

Can i use in-memory database for unit testing and cassandra for the real application data on same janusgraph instance ? Or do i need separate JG instances ?

Thanks

Vladyslav Kosulin

unread,
Sep 7, 2017, 10:54:36 AM9/7/17
to JanusGraph users
For unit testing you should use mocks otherwise this is not unit testing.
For functional testing I use TinkerGraph as much faster and less resource hungry backend. Janus in-memory should be fine, also, but I have not tried it.
I would use cassandra backend only for regression and acceptance testing.
But my app is dealing with multiple backends and my domain model is based on interfaces and all my business logic is backend agnostic.

Vladyslav Kosulin

unread,
Sep 7, 2017, 10:56:44 AM9/7/17
to JanusGraph users
Oh, and I would always use separate JG instance for testing if it is possible.

Robert Dale

unread,
Sep 7, 2017, 11:09:58 AM9/7/17
to Vladyslav Kosulin, JanusGraph users
The in-memory database was built for testing - http://docs.janusgraph.org/latest/inmemorystorage.html#_ideal_use_case_2

If it's only the data access layer (e.g. gremlin queries) being tested, I would still call that unit testing.

Robert Dale

On Thu, Sep 7, 2017 at 10:56 AM, Vladyslav Kosulin <vkos...@gmail.com> wrote:
Oh, and I would always use separate JG instance for testing if it is possible.

--
You received this message because you are subscribed to the Google Groups "JanusGraph users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to janusgraph-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/janusgraph-users/32f079e5-37c3-4ffd-a5b9-933ec47ef26e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Suny

unread,
Sep 7, 2017, 11:24:54 AM9/7/17
to JanusGraph users
Thanks for you response. So I should use 2 instances of JG - One with in-memory backed to perform unit testing and other with cassandra to run functional use cases ?

Vladyslav Kosulin

unread,
Sep 7, 2017, 1:59:46 PM9/7/17
to JanusGraph users
Suny, in the original post you wrote about "in-memory database for unit testing and cassandra for the real application data on same janusgraph instance".
I assumed you mean same JG instance for both testing and production which I would strongly object about.

But even speaking about separation of JG instances for in-memory unit testing and for (acceptance/regression) testing with real backend - yes, I would keep them separate. JG itself is very cheap to run, and such setup will allow you to have testing environment as closely matching production as possible while using another env for development including changes to JG config and upgrades.

Suny

unread,
Sep 7, 2017, 2:18:03 PM9/7/17
to JanusGraph users
Thanks.

I startup JG instance in my local and use this code to connect to it 

GryoMapper.Builder builder = GryoMapper.build().addRegistry(JanusGraphIoRegistry.getInstance());

cluster = Cluster.build().serializer(new GryoMessageSerializerV1d0(builder)).addContactPoint(serverUrl).create();

client = cluster.connect();


where serverUrl is localhost:8081. This instance has cassandra configured as backend.


Now if i want to run a unit test against in-memory db, Should i run another instance of JG on different port and connect to it from application ?

Reply all
Reply to author
Forward
0 new messages