All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.umlg.sqlg.test.gremlincompile.TestBulkWithin Maven / Gradle / Ivy

There is a newer version: 3.1.0
Show newest version
package org.umlg.sqlg.test.gremlincompile;

import org.apache.commons.lang3.time.StopWatch;
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.umlg.sqlg.structure.SqlgGraph;
import org.umlg.sqlg.test.BaseTest;

import java.beans.PropertyVetoException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * Date: 2015/10/07
 * Time: 7:28 PM
 */
public class TestBulkWithin extends BaseTest {

    @BeforeClass
    public static void beforeClass() throws ClassNotFoundException, IOException, PropertyVetoException {
        BaseTest.beforeClass();
        if (configuration.getString("jdbc.url").contains("postgresql")) {
            configuration.addProperty("distributed", true);
        }
    }

    @Test
    public void testBulkWithin() throws InterruptedException {
        if (this.sqlgGraph.getSqlDialect().supportsBatchMode()) {
            this.sqlgGraph.tx().normalBatchModeOn();
        }
        Vertex god = this.sqlgGraph.addVertex(T.label, "God");
        List uuids = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            String uuid = UUID.randomUUID().toString();
            uuids.add(uuid);
            Vertex person = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", uuid);
            god.addEdge("creator", person);
        }
        this.sqlgGraph.tx().commit();
        testBulkWithin_assert(this.sqlgGraph, uuids);
        if (this.sqlgGraph1 != null) {
            Thread.sleep(SLEEP_TIME);
            testBulkWithin_assert(this.sqlgGraph1, uuids);
        }
    }

    private void testBulkWithin_assert(SqlgGraph sqlgGraph, List uuids) {
        List persons = sqlgGraph.traversal().V().hasLabel("God").out().has("idNumber", P.within(uuids.subList(0, 2).toArray())).toList();
        Assert.assertEquals(2, persons.size());
        persons = sqlgGraph.traversal().V().hasLabel("God").out().has("idNumber", P.within(uuids.toArray())).toList();
        Assert.assertEquals(100, persons.size());
    }

    @Test
    public void testBulkWithinMultipleHasContainers() throws InterruptedException {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        if (this.sqlgGraph.getSqlDialect().supportsBatchMode()) {
            this.sqlgGraph.tx().normalBatchModeOn();
        }
        Vertex god = this.sqlgGraph.addVertex(T.label, "God");
        Vertex person1 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 1, "name", "pete");
        god.addEdge("creator", person1);
        Vertex person2 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 2, "name", "pete");
        god.addEdge("creator", person2);
        Vertex person3 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 3, "name", "john");
        god.addEdge("creator", person3);
        Vertex person4 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 4, "name", "pete");
        god.addEdge("creator", person4);
        Vertex person5 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 5, "name", "pete");
        god.addEdge("creator", person5);
        Vertex person6 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 6, "name", "pete");
        god.addEdge("creator", person6);
        Vertex person7 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 7, "name", "pete");
        god.addEdge("creator", person7);
        Vertex person8 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 8, "name", "pete");
        god.addEdge("creator", person8);
        Vertex person9 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 9, "name", "pete");
        god.addEdge("creator", person9);
        Vertex person10 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 10, "name", "pete");
        god.addEdge("creator", person10);

        this.sqlgGraph.tx().commit();
        stopWatch.stop();
        System.out.println(stopWatch.toString());
        stopWatch.reset();
        stopWatch.start();
        testBulkWithinMultipleHasContrainers_assert(this.sqlgGraph);
        if (this.sqlgGraph1 != null) {
            Thread.sleep(SLEEP_TIME);
            testBulkWithinMultipleHasContrainers_assert(this.sqlgGraph);
        }
        stopWatch.stop();
        System.out.println(stopWatch.toString());
    }

    private void testBulkWithinMultipleHasContrainers_assert(SqlgGraph sqlgGraph) {
        List persons = sqlgGraph.traversal().V()
                .hasLabel("God")
                .out()
                .has("name", "pete")
                .has("idNumber", P.within(1,2,3))
                .toList();
        Assert.assertEquals(2, persons.size());
    }

    @Test
    public void testBulkWithinVertexCompileStep() throws InterruptedException {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        if (this.sqlgGraph.getSqlDialect().supportsBatchMode()) {
            this.sqlgGraph.tx().normalBatchModeOn();
        }
        Vertex god = this.sqlgGraph.addVertex(T.label, "God");
        List uuids = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            String uuid = UUID.randomUUID().toString();
            uuids.add(uuid);
            Vertex person = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", uuid);
            god.addEdge("creator", person);
        }
        this.sqlgGraph.tx().commit();
        stopWatch.stop();
        System.out.println(stopWatch.toString());
        stopWatch.reset();
        stopWatch.start();
        testBulkWithinVertexCompileStep_assert(this.sqlgGraph, god, uuids);
        if (this.sqlgGraph1 != null) {
            Thread.sleep(SLEEP_TIME);
            testBulkWithinVertexCompileStep_assert(this.sqlgGraph1, god, uuids);
        }
        stopWatch.stop();
        System.out.println(stopWatch.toString());

    }

    private void testBulkWithinVertexCompileStep_assert(SqlgGraph sqlgGraph, Vertex god, List uuids) {
        List persons = sqlgGraph.traversal().V(god.id()).out().has("idNumber", P.within(uuids.subList(0, 2).toArray())).toList();
        Assert.assertEquals(2, persons.size());
        persons = sqlgGraph.traversal().V().hasLabel("God").out().has("idNumber", P.within(uuids.toArray())).toList();
        Assert.assertEquals(100, persons.size());
    }

    @Test
    public void testBulkWithinWithPercentageInJoinProperties() throws InterruptedException {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        if (this.sqlgGraph.getSqlDialect().supportsBatchMode()) {
            this.sqlgGraph.tx().normalBatchModeOn();
        }
        Vertex god = this.sqlgGraph.addVertex(T.label, "God");
        List uuids = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            String uuid = UUID.randomUUID().toString();
            uuids.add("\"BLRNC5->CXC4030052~%%%~FAJ1211373~%%%~2015-07-19~%%%~9999-12-31~%%%~Enabled~%%%~Licensed~%%%~Improved~%%%~compressed~%%%~mode~%%%~handling.~%%%~Restricted:~%%%~\"\"Partial.~%%%~Feature~%%%~is~%%%~restricted~%%%~in~%%%~RNC~%%%~W12B~%%%~SW.~%%%~RNC~%%%~W13.0.1.1~%%%~or~%%%~later~%%%~SW~%%%~is~%%%~required~%%%~in~%%%~order~%%%~to~%%%~run~%%%~this~%%%~feature.~%%%~For~%%%~RBS~%%%~W12.1.2.2/~%%%~W13.0.0.0~%%%~or~%%%~later~%%%~is~%%%~required.~%%%~OSS-RC~%%%~12.2~%%%~or~%%%~later~%%%~is~%%%~required.\"\".~%%%~GA:~%%%~W13A\"" + uuid);
            Vertex person = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", "\"BLRNC5->CXC4030052~%%%~FAJ1211373~%%%~2015-07-19~%%%~9999-12-31~%%%~Enabled~%%%~Licensed~%%%~Improved~%%%~compressed~%%%~mode~%%%~handling.~%%%~Restricted:~%%%~\"\"Partial.~%%%~Feature~%%%~is~%%%~restricted~%%%~in~%%%~RNC~%%%~W12B~%%%~SW.~%%%~RNC~%%%~W13.0.1.1~%%%~or~%%%~later~%%%~SW~%%%~is~%%%~required~%%%~in~%%%~order~%%%~to~%%%~run~%%%~this~%%%~feature.~%%%~For~%%%~RBS~%%%~W12.1.2.2/~%%%~W13.0.0.0~%%%~or~%%%~later~%%%~is~%%%~required.~%%%~OSS-RC~%%%~12.2~%%%~or~%%%~later~%%%~is~%%%~required.\"\".~%%%~GA:~%%%~W13A\"" + uuid);
            god.addEdge("creator", person);
        }
        this.sqlgGraph.tx().commit();
        stopWatch.stop();
        System.out.println(stopWatch.toString());
        stopWatch.reset();
        stopWatch.start();
        testBulkWithinWithPercentageInJoinProperties_assert(this.sqlgGraph, uuids);
        if (this.sqlgGraph1 != null) {
            Thread.sleep(SLEEP_TIME);
            testBulkWithinWithPercentageInJoinProperties_assert(this.sqlgGraph1, uuids);
        }
        stopWatch.stop();
        System.out.println(stopWatch.toString());
    }

    private void testBulkWithinWithPercentageInJoinProperties_assert(SqlgGraph sqlgGraph, List uuids) {
        List persons = sqlgGraph.traversal().V().hasLabel("God").out().has("idNumber", P.within(uuids.subList(0, 2).toArray())).toList();
        Assert.assertEquals(2, persons.size());
        persons = this.sqlgGraph.traversal().V().hasLabel("God").out().has("idNumber", P.within(uuids.toArray())).toList();
        Assert.assertEquals(100, persons.size());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy