Skip to content

Commit

Permalink
Issue orientechnologies#3456 new tests were added.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii0lomakin committed Jan 26, 2015
1 parent be092cf commit 2d074e8
Showing 1 changed file with 139 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,85 +13,167 @@
* @since 1/30/14
*/
public class EdgeIndexingTest {
@Test
public void testOutLinksUniqueness() {
final String url = "memory:" + this.getClass().getSimpleName();
OrientGraph graph = new OrientGraph(url);
graph.drop();

graph = new OrientGraph(url);
/**
* Test that "in_vertex" has edges to only single "out_vertex" but we may have several edges to single "out_vertex".
*/
@Test
public void testOutLinksUniqueness() {
final String url = "memory:" + this.getClass().getSimpleName();
OrientGraph graph = new OrientGraph(url);
graph.drop();

graph = new OrientGraph(url);
graph.setUseLightweightEdges(true);
graph.createEdgeType("link");
graph.setAutoStartTx(false);
graph.createEdgeType("link");
graph.setAutoStartTx(false);

OClass outVertexType = graph.createVertexType("IndexedOutVertex");
outVertexType.createProperty("out_link", OType.LINKBAG);
outVertexType.createIndex("uniqueLinkIndex", "unique", "out_link");

graph.setAutoStartTx(true);

Vertex vertexOutOne = graph.addVertex("class:IndexedOutVertex");

Vertex vertexInOne = graph.addVertex(null);
Vertex vertexInTwo = graph.addVertex(null);

vertexOutOne.addEdge("link", vertexInOne);
vertexOutOne.addEdge("link", vertexInTwo);
graph.commit();

OClass outVertexType = graph.createVertexType("IndexedOutVertex");
outVertexType.createProperty("out_link", OType.LINKBAG);
outVertexType.createIndex("uniqueLinkIndex", "unique", "out_link");
Vertex vertexOutTwo = graph.addVertex("class:IndexedOutVertex");
vertexOutTwo.addEdge("link", vertexInTwo);

try {
graph.commit();

// in vertex can be linked by only one out vertex.
Assert.fail();
} catch (ORecordDuplicatedException e) {
}

graph.drop();
}

/**
* Test that "in_vertex" has edges to only single "out_vertex" but we may have several edges to single "out_vertex".
*/
@Test
public void testOutLinksUniquenessTwo() {
final String url = "memory:" + this.getClass().getSimpleName();
OrientGraph graph = new OrientGraph(url);
graph.drop();

graph = new OrientGraph(url);
graph.setUseLightweightEdges(true);
graph.createEdgeType("link");
graph.setAutoStartTx(false);

graph.setAutoStartTx(true);
OClass outVertexType = graph.createVertexType("IndexedOutVertex");
outVertexType.createProperty("out_link", OType.LINKBAG);
outVertexType.createIndex("uniqueLinkIndex", "unique", "out_link");

graph.setAutoStartTx(true);

Vertex vertexOutOne = graph.addVertex("class:IndexedOutVertex");

Vertex vertexInOne = graph.addVertex(null);
Vertex vertexInTwo = graph.addVertex(null);

vertexOutOne.addEdge("link", vertexInOne);
vertexOutOne.addEdge("link", vertexInTwo);

Vertex vertexOutTwo = graph.addVertex("class:IndexedOutVertex");
vertexOutTwo.addEdge("link", vertexInTwo);

try {
graph.commit();

// in vertex can be linked by only one out vertex.
Assert.fail();
} catch (ORecordDuplicatedException e) {
}

graph.drop();
}

/**
* Test that "out_vertex" has edges to only single "in_vertex" but we may have several edges to single "in_vertex".
*/
@Test
public void testOutLinksUniquenessThree() {
final String url = "memory:" + this.getClass().getSimpleName();

OrientGraph graph = new OrientGraph(url, "admin", "admin", false);
graph.drop();

graph = new OrientGraph(url, "admin", "admin", false);
graph.setUseLightweightEdges(true);

Vertex vertexOutOne = graph.addVertex("class:IndexedOutVertex");
graph.createEdgeType("link");

Vertex vertexInOne = graph.addVertex(null);
Vertex vertexInTwo = graph.addVertex(null);
OClass inVertexType = graph.createVertexType("IndexedInVertex");
inVertexType.createProperty("in_link", OType.LINKBAG);
inVertexType.createIndex("uniqueLinkIndex", "unique", "in_link");

vertexOutOne.addEdge("link", vertexInOne);
vertexOutOne.addEdge("link", vertexInTwo);
graph.commit();
graph.setAutoStartTx(true);

Vertex vertexOutTwo = graph.addVertex("class:IndexedOutVertex");
vertexOutTwo.addEdge("link", vertexInTwo);
Vertex vertexOutOne = graph.addVertex(null);

try {
graph.commit();
Vertex vertexInOne = graph.addVertex("class:IndexedInVertex");
Vertex vertexInTwo = graph.addVertex("class:IndexedInVertex");

//in vertex can be linked by only one out vertex.
Assert.fail();
} catch (ORecordDuplicatedException e) {
}
vertexOutOne.addEdge("link", vertexInOne);
vertexOutOne.addEdge("link", vertexInTwo);

graph.drop();
}
try {
graph.commit();
Assert.fail();
// in vertex can be linked by only one out vertex.
} catch (ORecordDuplicatedException e) {
}

@Test
public void testOutLinksUniquenessTwo() {
final String url = "memory:" + this.getClass().getSimpleName();
OrientGraph graph = new OrientGraph(url);
graph.drop();
graph.drop();
}

graph = new OrientGraph(url);
graph.setUseLightweightEdges(true);
graph.createEdgeType("link");
graph.setAutoStartTx(false);
/**
* Test that "out_vertex" has singe and only single edge to "in_vertex". This only possible if edges are not lightweight edges.
*/
@Test
public void testOutLinksUniquenessFour() {
final String url = "memory:" + this.getClass().getSimpleName();

OClass outVertexType = graph.createVertexType("IndexedOutVertex");
outVertexType.createProperty("out_link", OType.LINKBAG);
outVertexType.createIndex("uniqueLinkIndex", "unique", "out_link");
OrientGraph graph = new OrientGraph(url, "admin", "admin", false);
graph.drop();

graph.setAutoStartTx(true);
graph = new OrientGraph(url, "admin", "admin", false);

OClass edgeType = graph.createEdgeType("link");

Vertex vertexOutOne = graph.addVertex("class:IndexedOutVertex");
edgeType.createProperty("in", OType.LINK);
edgeType.createProperty("out", OType.LINK);
edgeType.createIndex("uniqueLinkIndex", "unique", "in", "out");

Vertex vertexInOne = graph.addVertex(null);
Vertex vertexInTwo = graph.addVertex(null);
graph.setAutoStartTx(true);

vertexOutOne.addEdge("link", vertexInOne);
vertexOutOne.addEdge("link", vertexInTwo);
Vertex vertexOutOne = graph.addVertex(null);

Vertex vertexOutTwo = graph.addVertex("class:IndexedOutVertex");
vertexOutTwo.addEdge("link", vertexInTwo);
Vertex vertexInOne = graph.addVertex(null);
Vertex vertexInTwo = graph.addVertex(null);

try {
graph.commit();
vertexOutOne.addEdge("link", vertexInOne);
vertexOutOne.addEdge("link", vertexInTwo);
vertexOutOne.addEdge("link", vertexInOne);

//in vertex can be linked by only one out vertex.
Assert.fail();
} catch (ORecordDuplicatedException e) {
int i = 1;
}
try {
graph.commit();
Assert.fail();
// in vertex can be linked by only one out vertex.
} catch (ORecordDuplicatedException e) {
}

graph.drop();
}
graph.drop();
}
}

0 comments on commit 2d074e8

Please sign in to comment.