use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class NestedLockingNGTest method modifiedRollbackControlTest.
@Test
public void modifiedRollbackControlTest() {
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 rollback
final WritableGraph wg3 = g.getWritableGraph("3", true);
final long modCount = wg3.getGlobalModificationCounter();
wg3.addVertex();
wg3.rollBack();
// Check that the modcount prior to modifying 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) {
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class PrimaryKeyUnitNGTest method nestedRollbackTest.
@Test
public void nestedRollbackTest() {
try {
Graph graph = new DualGraph(null);
int vName, tName;
int source, destination;
int transaction1, transaction2, transaction3;
WritableGraph wg = graph.getWritableGraph("Set Up Graph", true);
try {
vName = wg.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "name", "name", null, null);
tName = wg.addAttribute(GraphElementType.TRANSACTION, StringAttributeDescription.ATTRIBUTE_NAME, "name", "name", null, null);
wg.setPrimaryKey(GraphElementType.VERTEX, vName);
wg.setPrimaryKey(GraphElementType.TRANSACTION, tName);
source = wg.addVertex();
wg.setStringValue(vName, source, "Source");
destination = wg.addVertex();
wg.setStringValue(vName, destination, "Destination");
transaction1 = wg.addTransaction(source, destination, true);
wg.setStringValue(tName, transaction1, "transaction");
} finally {
wg.commit();
}
try {
wg = graph.getWritableGraph("Add Duplicate Transactions", true);
try {
transaction2 = wg.addTransaction(source, destination, true);
wg.setStringValue(tName, transaction2, "transaction");
transaction3 = wg.addTransaction(source, destination, true);
wg.setStringValue(tName, transaction3, "transaction");
WritableGraph wg2 = graph.getWritableGraph("Not doing anything wrong", true);
try {
} finally {
wg2.commit();
}
} finally {
wg.commit();
}
} catch (DuplicateKeyException ex) {
ex.printStackTrace();
}
wg = graph.getWritableGraph("Add Unique Transaction", true);
try {
transaction2 = wg.addTransaction(source, destination, true);
wg.setStringValue(tName, transaction2, "transaction2");
} finally {
wg.commit();
}
ReadableGraph rg = graph.getReadableGraph();
try {
assert rg.getTransactionCount() == 2;
} finally {
rg.release();
}
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class PrimaryKeyUnitNGTest method primaryKeyUpdateTest.
@Test
public void primaryKeyUpdateTest() {
try {
Graph graph = new DualGraph(null);
int a1 = 0, a2 = 0, v1 = 0, v2 = 0;
WritableGraph wg = graph.getWritableGraph("Primary Key Test", true);
try {
a1 = wg.addAttribute(GraphElementType.VERTEX, BooleanAttributeDescription.ATTRIBUTE_NAME, "a", null, null, null);
a2 = wg.addAttribute(GraphElementType.VERTEX, BooleanAttributeDescription.ATTRIBUTE_NAME, "b", null, null, null);
wg.setPrimaryKey(GraphElementType.VERTEX, a1, a2);
v1 = wg.addVertex();
} finally {
wg.commit();
}
try {
wg = graph.getWritableGraph("Primary Key Test", true);
try {
wg.setBooleanValue(a1, v1, true);
v2 = wg.addVertex();
wg.setBooleanValue(a1, v2, true);
// wg.setBooleanValue(a2, v2, true);
} finally {
wg.commit();
}
} catch (Exception e) {
}
ReadableGraph rg = graph.getReadableGraph();
try {
assert rg.getBooleanValue(a1, v1) == false;
} finally {
rg.release();
}
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class TestListener method testGraphChangedWithGraph.
// Test commented out as TopComponent launches GUI panels which don't execute in the test environment
@Test
public void testGraphChangedWithGraph() throws Exception {
QualityControlAutoVetter.destroyInstance();
QualityControlAutoVetter instance = QualityControlAutoVetter.getInstance();
assertNull(instance.getCurrentGraph());
assertEquals(instance.getlastGlobalModCount(), (long) 0);
// Open a new graph
graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
// Add camera attribute
final WritableGraph wg = graph.getWritableGraph("TEST", true);
try {
final int cameraAttrId = VisualConcept.GraphAttribute.CAMERA.ensure(wg);
// Change camera attribute
final Camera camera = new Camera();
camera.setVisibilityLow(0.67f);
wg.setObjectValue(cameraAttrId, 0, camera);
} finally {
wg.commit();
}
try {
// Sleep until after pluginExecution thread has returned
Thread.sleep(1000);
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
}
// Set the current graph
instance.newActiveGraph(graph);
QualityControlAutoVetter.getInstance().graphChanged(null);
assertNotEquals(instance.getlastGlobalModCount(), (long) 0);
assertNotEquals(instance.getlastCameraModCount(), (long) 0);
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class QualityControlStateUpdaterNGTest method testReadNoNodesNoAttributes.
@Test
public void testReadNoNodesNoAttributes() throws Exception {
System.out.println("read No Nodes");
graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
WritableGraph wg = graph.getWritableGraph("Add Elements", true);
try {
// Add X,Y,Z vertex attributes
attrX = VisualConcept.VertexAttribute.X.ensure(wg);
attrY = VisualConcept.VertexAttribute.Y.ensure(wg);
attrZ = VisualConcept.VertexAttribute.Z.ensure(wg);
} finally {
wg.commit();
}
// Expected rules and events
final List<QualityControlEvent> expectedQualityControlEvents = new ArrayList<>();
final List<QualityControlRule> expectedRegisteredRules = new ArrayList<>();
final List<QualityControlRule> uExpectedRegisteredRules = Collections.unmodifiableList(expectedRegisteredRules);
// Call update state to trigger checking of rules
PluginExecution.withPlugin(new QualityControlStateUpdater()).executeNow(graph);
// get the state and events
final QualityControlState state = QualityControlAutoVetter.getInstance().getQualityControlState();
final List<QualityControlEvent> qualityControlEvents = state.getQualityControlEvents();
final List<QualityControlRule> registeredRules = state.getRegisteredRules();
// check equality of the events and rules
assertEquals(qualityControlEvents, expectedQualityControlEvents);
assertEquals(registeredRules, uExpectedRegisteredRules);
}
Aggregations