Search in sources :

Example 81 with WritableGraph

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) {
    }
}
Also used : WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 82 with WritableGraph

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);
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) DuplicateKeyException(au.gov.asd.tac.constellation.graph.DuplicateKeyException) Test(org.testng.annotations.Test)

Example 83 with WritableGraph

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);
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) DuplicateKeyException(au.gov.asd.tac.constellation.graph.DuplicateKeyException) Test(org.testng.annotations.Test)

Example 84 with WritableGraph

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);
}
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 85 with WritableGraph

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);
}
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)

Aggregations

WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)116 Test (org.testng.annotations.Test)77 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)39 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)37 Graph (au.gov.asd.tac.constellation.graph.Graph)20 ArrayList (java.util.ArrayList)14 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)9 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)8 CompositeNodeState (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState)8 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)6 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)6 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)6 Attribute (au.gov.asd.tac.constellation.graph.Attribute)5 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)5 CopyToNewGraphPlugin (au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin)5 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)4 DuplicateKeyException (au.gov.asd.tac.constellation.graph.DuplicateKeyException)3 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)3