use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class CompareGraphPluginNGTest method testCreateComparisonGraphWithAddedTransactionInReverse.
/**
* Test of createComparisonGraph method, of class CompareGraphPlugin.
*
* @throws java.lang.Exception
*/
@Test
public void testCreateComparisonGraphWithAddedTransactionInReverse() throws Exception {
int vx0, vx1, tx0, tx1;
int labelAttribute, uniqueIdAttribute;
final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
final StoreGraph originalGraph = new StoreGraph(schema);
labelAttribute = VisualConcept.VertexAttribute.LABEL.ensure(originalGraph);
uniqueIdAttribute = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(originalGraph);
originalGraph.setPrimaryKey(GraphElementType.VERTEX, labelAttribute);
originalGraph.setPrimaryKey(GraphElementType.TRANSACTION, uniqueIdAttribute);
vx0 = originalGraph.addVertex();
vx1 = originalGraph.addVertex();
tx0 = originalGraph.addTransaction(vx0, vx1, true);
originalGraph.setStringValue(labelAttribute, vx0, "vx0");
originalGraph.setStringValue(labelAttribute, vx1, "vx1");
originalGraph.setStringValue(uniqueIdAttribute, tx0, "1");
final StoreGraph compareGraph = new StoreGraph(schema);
labelAttribute = VisualConcept.VertexAttribute.LABEL.ensure(compareGraph);
uniqueIdAttribute = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(compareGraph);
compareGraph.setPrimaryKey(GraphElementType.VERTEX, labelAttribute);
compareGraph.setPrimaryKey(GraphElementType.TRANSACTION, uniqueIdAttribute);
vx0 = compareGraph.addVertex();
vx1 = compareGraph.addVertex();
tx0 = compareGraph.addTransaction(vx1, vx0, true);
compareGraph.setStringValue(labelAttribute, vx0, "vx0");
compareGraph.setStringValue(labelAttribute, vx1, "vx1");
originalGraph.setStringValue(uniqueIdAttribute, tx0, "2");
final GraphRecordStore originalAll = GraphRecordStoreUtilities.getAll(originalGraph, false, true);
final GraphRecordStore compareAll = GraphRecordStoreUtilities.getAll(compareGraph, false, true);
final Set<String> vertexPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(originalGraph, GraphElementType.VERTEX);
final Set<String> transactionPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(originalGraph, GraphElementType.TRANSACTION);
final List<String> ignoreVertexAttributes = new ArrayList<>();
final List<String> ignoreTransactionAttributes = new ArrayList<>();
ignoreVertexAttributes.add("[id]");
ignoreTransactionAttributes.add("[id]");
final CompareGraphPlugin instance = new CompareGraphPlugin();
final GraphRecordStore changes = instance.compareGraphs("", originalAll, compareAll, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, ADDED_COLOUR, REMOVED_COLOUR, CHANGED_COLOUR, UNCHANGED_COLOUR);
final boolean initializeWithSchema = true;
final boolean completeWithSchema = false;
final Graph finalGraph = instance.createComparisonGraph(new DualGraph(originalGraph, true), changes);
System.out.println("changes ==>\n" + changes.toStringVerbose());
final ReadableGraph rg = finalGraph.getReadableGraph();
try {
assertEquals(rg.getVertexCount(), 2);
assertEquals(rg.getTransactionCount(), 2);
vx0 = rg.getVertex(0);
vx1 = rg.getVertex(1);
tx0 = rg.getTransaction(0);
tx1 = rg.getTransaction(1);
labelAttribute = rg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.LABEL.getName());
assertEquals(rg.getStringValue(labelAttribute, vx0), "vx0");
assertEquals(rg.getStringValue(labelAttribute, vx1), "vx1");
assertEquals(rg.getTransactionSourceVertex(tx0), vx0);
assertEquals(rg.getTransactionSourceVertex(tx1), vx1);
} finally {
rg.release();
}
SaveGraphUtilities.saveGraphToTemporaryDirectory(originalGraph, "originalGraph");
SaveGraphUtilities.saveGraphToTemporaryDirectory(compareGraph, "compareGraph");
SaveGraphUtilities.saveGraphToTemporaryDirectory(finalGraph, "testCreateComparisonGraphWithAddedTransactionInReverse", true);
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph 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.locking.DualGraph 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);
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class QualityControlStateUpdaterNGTest method testReadNoNodes.
@Test
public void testReadNoNodes() 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);
// Add vertex and transaction SELECTED attributes
vSelectedAttrId = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
tSelectedAttrId = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
// Add vertex IDENTIFIER attribute and label each vertice.
vxIdentifierAttrId = VisualConcept.VertexAttribute.IDENTIFIER.ensure(wg);
// Add vertex TYPE attribute and set each type to unknown
typeAttrId = AnalyticConcept.VertexAttribute.TYPE.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);
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class GLVisualProcessorGraphTester method main.
public static void main(String[] args) {
final GLVisualProcessorDemo demo = new GLVisualProcessorDemo();
final StoreGraph graph = createGraph();
final Graph dualGraph = new DualGraph(graph, false);
final GraphVisualAccess access = new GraphVisualAccess(dualGraph);
final GLVisualProcessor processor = new GLVisualProcessor();
final VisualManager visualManager = new VisualManager(access, processor);
processor.startVisualising(visualManager);
demo.runDemo(processor, visualManager);
final GraphChangeListener gct = (event) -> visualManager.updateFromIndigenousChanges();
gct.graphChanged(null);
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
}
try {
WritableGraph wg = dualGraph.getWritableGraph("linkmode", false);
try {
final int connectionModeAttr = VisualConcept.GraphAttribute.CONNECTION_MODE.ensure(wg);
wg.setObjectValue(connectionModeAttr, 0, ConnectionMode.LINK);
} finally {
wg.commit();
}
} catch (InterruptedException ex) {
}
gct.graphChanged(null);
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
}
try {
WritableGraph wg = dualGraph.getWritableGraph("transmode", false);
try {
final int connectionModeAttr = VisualConcept.GraphAttribute.CONNECTION_MODE.ensure(wg);
wg.setObjectValue(connectionModeAttr, 0, ConnectionMode.TRANSACTION);
} finally {
wg.commit();
}
} catch (InterruptedException ex) {
}
gct.graphChanged(null);
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
}
final int[] changed = new int[] { 0, 1 };
try {
WritableGraph wg = dualGraph.getWritableGraph("blazin", false);
try {
final int blazeAttr = VisualConcept.VertexAttribute.BLAZE.ensure(wg);
for (int i = 0; i < 10000; i++) {
try {
Thread.sleep(1);
} catch (InterruptedException ex) {
}
wg.setObjectValue(blazeAttr, 0, new Blaze(((Blaze) wg.getObjectValue(blazeAttr, 0)).getAngle() + 1, ConstellationColor.BLUE));
wg = wg.flush(false);
visualManager.addSingleChangeOperation(new VisualChangeBuilder(VisualProperty.VERTEX_BLAZE_ANGLE).forItems(changed).build());
}
} finally {
wg.commit();
}
} catch (InterruptedException ex) {
}
}
Aggregations