Search in sources :

Example 21 with WritableGraph

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

Example 22 with WritableGraph

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

Example 23 with WritableGraph

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

Example 24 with WritableGraph

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

Example 25 with WritableGraph

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) {
    }
}
Also used : 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