Query "Is There a way to use titandb to do unit test without connecting to remote titandb server"

405 views
Skip to first unread message

Sunil S

unread,
Jun 10, 2016, 3:33:42 PM6/10/16
to Aurelius
I stumbled on this query "Is There a way to use titandb APIs to do unit test without connecting to remote titandb server using greamlin driver; means "can I use titandb API along with my java code to perform these opeartions like 'CRUD operation' without connecting to actual titanDB(on remote host/local host) via gremlin driver, " I am wondering how to achieve the same. 

Seth Rife

unread,
Jun 10, 2016, 4:52:02 PM6/10/16
to Aurelius

Dylan Millikin

unread,
Jun 11, 2016, 12:02:26 AM6/11/16
to Aurelius
I think Sunil wants to completely get rid of the network overhead (and starting a server at all). So using the in memory storage is probably only half the solution. 

Sunil, if the code you want to test currently makes use of the java gremlin driver, ie : 
Cluster cluster = Cluster.open();
Client client = cluster.connect();
ResultSet results = client.submit("g.V()");
Then one possibility would be to mock the Cluster and Client classes to alter the the behavior of submit() and have it apply the gremlin queries directly to the graph. This however requires for you to be using proper dependency injection so that you can use the real gremlin driver by default but switch to your custom one for testing.
Maybe Stephen has a better idea here?

I still think it would be easier to make a proper integration test setup that automatically starts whatever service you require (servers). At least this way you can test any application behaviors against a real Gremlin server configuration and avoid missing some potential bugs in your test cases.

Stephen Mallette

unread,
Jun 11, 2016, 6:27:05 AM6/11/16
to Aurelius
I guess if i were to mock (now 100% sure how easy this is as there are a bunch of internal classes that might get in the way - not sure), I would try to back the mock by GremlinGroovyScriptEngine. That way, i could bind a "g" and a "graph" and whatever else I would have in Gremlin Server and then have my scripts execute in full locally in the script engine without needing to ship to gremlin server.  Starting Gremlin Server in a test is pretty easy and provided you don't tear it up and down between tests, the tests can execute quite quickly, so you really just need to figure out how to potentially clear the graph between tests. RemoteGraph in 3.2.0-incubating introduces some interesting ideas in this area too, because you could potentially swap out RemoteGraph for another specific Graph implementation which could then run embedded.

--
You received this message because you are subscribed to the Google Groups "Aurelius" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraph...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aureliusgraphs/5adb22d1-4e4f-4221-a49c-21afbe1db96e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sunil S

unread,
Jun 13, 2016, 3:25:53 PM6/13/16
to Aurelius
Hi stephen,

I unable to understand your point, can you list-out step what are you explaining with coding snippets.
It's hard to visualize.

Sunil S

unread,
Jun 13, 2016, 3:29:41 PM6/13/16
to Aurelius
Hi Dylan,

I am actually using it in same way
 private static ConnectionFactory instance = null;
    private String address = "xxx.xxx.xxx.xxx"; /* Default address */
    private int port = 8182; /* Default port */
    private Cluster cluster = null;
    private Client client = null;

    /**
     * Constructor for the titan graph connection. The constructor cannot be called directly.
     *
     */
    private ConnectionFactory() {
    }

    /**
     * Get an instance of the Connection factory. If an instance already exist, the existing one is passed
     * back to the caller. If class instance does not exist, a new one is crated.
     *
     * @return ConnectionFactory instance
     */

    public static ConnectionFactory getInstance() {
        if(instance == null) {
            instance = new ConnectionFactory();
            instance.openConnection();
        }
        return instance;
    }


    /**
     * Opens the connection to the graph database.
     *
     */
    public void openConnection() {

        GryoMessageSerializerV1d0 serializerClass = null;
        Cluster.Builder clusterBuilder = null;
        Map<String, Object> configMap = null;

        /* This is required so that the result vertex can be serialized to string */
        serializerClass = new GryoMessageSerializerV1d0();
        configMap = new HashMap<String, Object>();
        configMap.put("serializeResultToString", "true");
        serializerClass.configure(configMap, null);

        /* Build cluster configuration */
        clusterBuilder = Cluster.build(address);
        clusterBuilder.port(port);
        clusterBuilder.serializer(serializerClass);


        /* create a cluster instance */
        cluster = clusterBuilder.create();
        client = cluster.connect();

I hope now you have the idea of my code.

Stephen Mallette

unread,
Jun 14, 2016, 10:24:40 AM6/14/16
to Aurelius
As I look at the code now, I guess you can't easily mock Cluster/Client very easily, so that idea might not work very well. I guess your best option is to develop an abstraction around Client so that you can build your own mock and use that in your tests. I still would consider just starting Gremlin Server as Dylan said and testing the stack all the way through, but that's your call.

--
You received this message because you are subscribed to the Google Groups "Aurelius" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraph...@googlegroups.com.

Mustafa Sohail

unread,
Sep 24, 2017, 12:02:31 PM9/24/17
to Aurelius
Is there a way to start a gremlin server from your test code instead of from the terminal? It would be easier this way if someone later were to work on my code and could just run the test script instead of having to start the server separately.
Reply all
Reply to author
Forward
0 new messages