Search in sources :

Example 56 with DualGraph

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);
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) ArrayList(java.util.ArrayList) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 57 with DualGraph

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);
}
Also used : Camera(au.gov.asd.tac.constellation.utilities.camera.Camera) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 58 with DualGraph

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);
}
Also used : QualityControlRule(au.gov.asd.tac.constellation.views.qualitycontrol.rules.QualityControlRule) QualityControlEvent(au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent) ArrayList(java.util.ArrayList) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 59 with DualGraph

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);
}
Also used : QualityControlRule(au.gov.asd.tac.constellation.views.qualitycontrol.rules.QualityControlRule) QualityControlEvent(au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent) ArrayList(java.util.ArrayList) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 60 with DualGraph

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) {
    }
}
Also used : WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Frame(java.awt.Frame) GLVisualProcessor(au.gov.asd.tac.constellation.visual.opengl.renderer.GLVisualProcessor) Blaze(au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.Blaze) ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) DefaultIconProvider(au.gov.asd.tac.constellation.utilities.icon.DefaultIconProvider) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) WindowAdapter(java.awt.event.WindowAdapter) JFXPanel(javafx.embed.swing.JFXPanel) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) Component(java.awt.Component) WindowEvent(java.awt.event.WindowEvent) VisualProcessor(au.gov.asd.tac.constellation.utilities.visual.VisualProcessor) VisualProperty(au.gov.asd.tac.constellation.utilities.visual.VisualProperty) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphChangeListener(au.gov.asd.tac.constellation.graph.monitor.GraphChangeListener) Camera(au.gov.asd.tac.constellation.utilities.camera.Camera) VisualChangeBuilder(au.gov.asd.tac.constellation.utilities.visual.VisualChangeBuilder) VisualManager(au.gov.asd.tac.constellation.utilities.visual.VisualManager) ConnectionMode(au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.ConnectionMode) GraphVisualAccess(au.gov.asd.tac.constellation.graph.visual.framework.GraphVisualAccess) VisualChangeBuilder(au.gov.asd.tac.constellation.utilities.visual.VisualChangeBuilder) GraphVisualAccess(au.gov.asd.tac.constellation.graph.visual.framework.GraphVisualAccess) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) VisualManager(au.gov.asd.tac.constellation.utilities.visual.VisualManager) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GLVisualProcessor(au.gov.asd.tac.constellation.visual.opengl.renderer.GLVisualProcessor) GraphChangeListener(au.gov.asd.tac.constellation.graph.monitor.GraphChangeListener) Blaze(au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.Blaze) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph)

Aggregations

DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)66 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)41 Test (org.testng.annotations.Test)30 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)21 Graph (au.gov.asd.tac.constellation.graph.Graph)19 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)18 ArrayList (java.util.ArrayList)13 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)10 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)10 BeforeMethod (org.testng.annotations.BeforeMethod)9 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)7 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)6 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)5 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)4 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)3 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)3 SchemaFactory (au.gov.asd.tac.constellation.graph.schema.SchemaFactory)3 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)3 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)3 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)3