Last active
January 2, 2016 01:09
-
-
Save martin-spa/8228489 to your computer and use it in GitHub Desktop.
OrientDB Blueprints test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//// to run the test you need Spring and Guava (for Iterables) | |
//// | |
//// classes (at the bottom results) | |
//// | |
///// first class | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import com.tinkerpop.blueprints.Parameter; | |
import com.tinkerpop.blueprints.Vertex; | |
import com.tinkerpop.blueprints.impls.orient.OrientGraph; | |
/** | |
* @author Martin Spasovski (@moondowner) | |
*/ | |
@Configuration | |
public class OrientDBConfig { | |
@Bean(destroyMethod = "shutdown") | |
public OrientGraph orientGraph() { | |
OrientGraph graph = new OrientGraph("local:new-test"); | |
// http://www.tinkerpop.com/docs/wikidocs/blueprints/2.4.0/Graph-Indices.html | |
graph.createKeyIndex("origId", Vertex.class, new Parameter<>("type", | |
"UNIQUE")); | |
graph.setSaveOriginalIds(true); | |
return graph; | |
} | |
} | |
///// second class | |
import java.util.UUID; | |
import javax.annotation.Resource; | |
import org.junit.Assert; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.test.context.ContextConfiguration; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
import com.google.common.collect.Iterables; | |
import com.tinkerpop.blueprints.Vertex; | |
import com.tinkerpop.blueprints.impls.orient.OrientGraph; | |
/** | |
* @author Martin Spasovski (@moondowner) | |
*/ | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@ContextConfiguration(classes = { OrientDBConfig.class }) | |
public class OrientDBHasTest { | |
@Resource | |
private OrientGraph orientGraph; | |
@Test | |
public void testHas() { | |
String uuid = UUID.randomUUID().toString(); | |
Vertex vertex = orientGraph.addVertex(uuid); | |
vertex.setProperty("SomeOtherKey", ""); | |
vertex.setProperty("SomeThirdKey", ""); | |
Vertex vertex2 = orientGraph.addVertex(UUID.randomUUID().toString()); | |
vertex2.setProperty("SomeOtherKey", ""); | |
vertex2.setProperty("SomeThirdKey", ""); | |
Vertex vertex3 = orientGraph.addVertex(UUID.randomUUID().toString()); | |
vertex3.setProperty("SomeOtherKey", ""); | |
vertex3.setProperty("SomeThirdKey", ""); | |
Vertex vertex4 = orientGraph.addVertex(UUID.randomUUID().toString()); | |
vertex4.setProperty("SomeOtherKey", ""); | |
vertex4.setProperty("SomeThirdKey", ""); | |
Vertex vertex5 = orientGraph.addVertex(UUID.randomUUID().toString()); | |
vertex5.setProperty("SomeOtherKey", ""); | |
vertex5.setProperty("SomeThirdKey", ""); | |
orientGraph.commit(); | |
Iterable<Vertex> vertexes = orientGraph.getVertices("origId", uuid); | |
Iterable<Vertex> vertexes2 = orientGraph.query().has("origId", uuid) | |
.vertices(); | |
Iterable<Vertex> vertexes3 = orientGraph.query().has("SomeOtherKey") | |
.has("origId", uuid).vertices(); | |
System.out.println("Vertexes size: " + Iterables.size(vertexes)); | |
System.out.println("Vertexes2 size: " + Iterables.size(vertexes2)); | |
System.out.println("Vertexes3 size: " + Iterables.size(vertexes3)); | |
Assert.assertNotNull(vertexes); | |
Assert.assertNotNull(vertexes2); | |
Assert.assertNotNull(vertexes3); | |
Assert.assertEquals(Iterables.size(vertexes), Iterables.size(vertexes2)); | |
Assert.assertEquals(Iterables.size(vertexes), Iterables.size(vertexes3)); | |
} | |
} | |
/// | |
/// Results | |
/// | |
/// after first run is OK | |
Vertexes size: 1 | |
Vertexes2 size: 1 | |
Vertexes3 size: 1 | |
/// after second run (and more) is NOK | |
Vertexes size: 1 | |
Vertexes2 size: 0 | |
Vertexes3 size: 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment