use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class ModCountNGTest method addDeleteTransactionModCounts.
/**
* Tests that the mod counts on the two graphs in a DualGraph match after
* two transactions are added and then one is removed between a pair of
* vertices.
*/
@Test
public void addDeleteTransactionModCounts() {
final DualGraph g = new DualGraph(null);
try {
long modCount;
WritableGraph wg = g.getWritableGraph("", true);
int vertex0, vertex1;
int trans0, trans1;
try {
vertex0 = wg.addVertex();
vertex1 = wg.addVertex();
trans0 = wg.addTransaction(vertex0, vertex1, true);
trans1 = wg.addTransaction(vertex0, vertex1, true);
modCount = wg.getGlobalModificationCounter();
} finally {
wg.commit();
}
wg = g.getWritableGraph("", true);
try {
assertEquals(wg.getVertexCount(), 2);
assertEquals(wg.getTransactionCount(), 2);
assertEquals(modCount, wg.getGlobalModificationCounter());
} finally {
wg.commit();
}
wg = g.getWritableGraph("", true);
try {
wg.removeTransaction(trans1);
modCount = wg.getGlobalModificationCounter();
} finally {
wg.commit();
}
wg = g.getWritableGraph("", true);
try {
assertEquals(wg.getVertexCount(), 2);
assertEquals(wg.getTransactionCount(), 1);
assertEquals(modCount, wg.getGlobalModificationCounter());
} finally {
wg.commit();
}
} catch (InterruptedException ex) {
assertTrue(ex.toString(), false);
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class ModCountNGTest method setTransactionSourceModCounts.
/**
* Tests that the mod counts on the two graphs in a DualGraph match after a
* transactions is added between two vertices and then its source vertex is
* set to a third vertex.
*/
@Test
public void setTransactionSourceModCounts() {
final DualGraph g = new DualGraph(null);
try {
long modCount;
WritableGraph wg = g.getWritableGraph("", true);
int vertex0, vertex1, vertex2;
int trans;
try {
vertex0 = wg.addVertex();
vertex1 = wg.addVertex();
vertex2 = wg.addVertex();
trans = wg.addTransaction(vertex0, vertex1, true);
modCount = wg.getGlobalModificationCounter();
} finally {
wg.commit();
}
wg = g.getWritableGraph("", true);
try {
assertEquals(wg.getVertexCount(), 3);
assertEquals(wg.getTransactionCount(), 1);
assertEquals(wg.getTransactionSourceVertex(trans), vertex0);
assertEquals(wg.getTransactionDestinationVertex(trans), vertex1);
assertEquals(modCount, wg.getGlobalModificationCounter());
} finally {
wg.commit();
}
wg = g.getWritableGraph("", true);
try {
wg.setTransactionSourceVertex(trans, vertex2);
modCount = wg.getGlobalModificationCounter();
} finally {
wg.commit();
}
wg = g.getWritableGraph("", true);
try {
assertEquals(wg.getVertexCount(), 3);
assertEquals(wg.getTransactionCount(), 1);
assertEquals(wg.getTransactionSourceVertex(trans), vertex2);
assertEquals(wg.getTransactionDestinationVertex(trans), vertex1);
assertEquals(modCount, wg.getGlobalModificationCounter());
} finally {
wg.commit();
}
} catch (InterruptedException ex) {
assertTrue(ex.toString(), false);
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class ModCountNGTest method clearAttributeValueModCounts.
/**
* Tests that the mod counts on the two graphs in a DualGraph match after a
* vertex attribute is added and then its value is cleared for a single
* vertex.
*/
@Test
public void clearAttributeValueModCounts() {
final DualGraph g = new DualGraph(null);
try {
long modCount;
WritableGraph wg = g.getWritableGraph("", true);
int attribute;
try {
wg.addVertex();
attribute = wg.addAttribute(GraphElementType.VERTEX, IntegerAttributeDescription.ATTRIBUTE_NAME, "name", "description", null, null);
modCount = wg.getGlobalModificationCounter();
} finally {
wg.commit();
}
wg = g.getWritableGraph("", true);
try {
assertEquals(1, wg.getVertexCount());
assertEquals(1, wg.getAttributeCount(GraphElementType.VERTEX));
assertEquals(0, wg.getIntValue(attribute, 0));
assertEquals(modCount, wg.getGlobalModificationCounter());
} finally {
wg.commit();
}
wg = g.getWritableGraph("", true);
try {
wg.clearValue(attribute, 0);
modCount = wg.getGlobalModificationCounter();
} finally {
wg.commit();
}
wg = g.getWritableGraph("", true);
try {
assertEquals(1, wg.getVertexCount());
assertEquals(1, wg.getAttributeCount(GraphElementType.VERTEX));
assertEquals(0, wg.getIntValue(attribute, 0));
assertEquals(modCount, wg.getGlobalModificationCounter());
} finally {
wg.commit();
}
} catch (InterruptedException ex) {
assertTrue(ex.toString(), false);
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class ModCountNGTest method addMergeDeletePrimaryKeyModCounts.
/**
* Tests that the mod counts on the two graphs in a DualGraph match after a
* vertex attribute is added, this is set as the primary key, and then the
* primary key is removed. This is performed on a graph with a two vertices
* so the setting of the primary key should cause merging to occur. As a
* result, we need to crate a dual graph using the bare schema so that a
* merger is available. We also need to explicitly performing the merging
* ourselves; if we let the commit perform it then the mod count on the
* locked target will be altered by the commit method itself.
*
* TODO: One should be able to set the GraphElementMerger on a
* StoreGraph/GraphWriteMethods, as a graph should not have to have a schema
* in order to perform any sort of merging.
*/
@Test
public void addMergeDeletePrimaryKeyModCounts() {
final DualGraph g = new DualGraph(new BareSchemaFactory().createSchema());
try {
long modCount;
WritableGraph wg = g.getWritableGraph("", true);
int attribute;
try {
wg.addVertex();
wg.addVertex();
attribute = wg.addAttribute(GraphElementType.VERTEX, IntegerAttributeDescription.ATTRIBUTE_NAME, "name", "description", null, null);
wg.setPrimaryKey(GraphElementType.VERTEX, attribute);
wg.validateKey(GraphElementType.VERTEX, true);
modCount = wg.getGlobalModificationCounter();
} finally {
wg.commit();
}
wg = g.getWritableGraph("", true);
try {
assertEquals(1, wg.getVertexCount());
assertEquals(1, wg.getAttributeCount(GraphElementType.VERTEX));
assertEquals(1, wg.getPrimaryKey(GraphElementType.VERTEX).length);
assertEquals(modCount, wg.getGlobalModificationCounter());
} finally {
wg.commit();
}
wg = g.getWritableGraph("", true);
try {
wg.setPrimaryKey(GraphElementType.VERTEX);
modCount = wg.getGlobalModificationCounter();
} finally {
wg.commit();
}
wg = g.getWritableGraph("", true);
try {
assertEquals(1, wg.getVertexCount());
assertEquals(1, wg.getAttributeCount(GraphElementType.VERTEX));
assertEquals(0, wg.getPrimaryKey(GraphElementType.VERTEX).length);
assertEquals(modCount, wg.getGlobalModificationCounter());
} finally {
wg.commit();
}
} catch (InterruptedException ex) {
assertTrue(ex.toString(), false);
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class NestedLockingNGTest method modifiedCommitControlTest.
@Test
public void modifiedCommitControlTest() {
final DualGraph g = new DualGraph(null);
try {
// Get the first write lock, modify the graph, then commit
final WritableGraph wg2 = g.getWritableGraph("2", true);
wg2.addVertex();
wg2.commit();
// Get the second write lock, modify the graph, then commit
final WritableGraph wg3 = g.getWritableGraph("3", true);
wg3.addVertex();
final long modCount = wg3.getGlobalModificationCounter();
wg3.commit();
// Check that the modcount prior to commiting the second write lock is the same as the current modcount in a new lock.
final WritableGraph wg4 = g.getWritableGraph("4", true);
assertEquals(modCount, wg4.getGlobalModificationCounter());
wg4.commit();
} catch (InterruptedException ex) {
}
}
Aggregations