Search in sources :

Example 26 with WritableGraph

use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.

the class NestedLockingNGTest method unmodifiedCommitControlTest.

@Test
public void unmodifiedCommitControlTest() {
    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 and immediately commit
        final WritableGraph wg3 = g.getWritableGraph("3", true);
        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)

Example 27 with WritableGraph

use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.

the class PrimaryKeyUnitNGTest method rollbackTest.

@Test
public void rollbackTest() {
    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(transaction2, tName, "transaction");
                transaction3 = wg.addTransaction(source, destination, true);
                wg.setStringValue(transaction3, tName, "transaction");
            } finally {
                wg.commit();
            }
        } catch (DuplicateKeyException ex) {
        }
        wg = graph.getWritableGraph("Add Unique Transaction", true);
        try {
            transaction2 = wg.addTransaction(source, destination, true);
            wg.setStringValue(transaction2, tName, "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 28 with WritableGraph

use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.

the class ModCountNGTest method setLongValueModCounts.

/**
 * Tests that the mod counts on the two graphs in a DualGraph match after a
 * long value is set on a graph with a single vertex.
 */
@Test
public void setLongValueModCounts() {
    final DualGraph g = new DualGraph(null);
    try {
        long modCount;
        WritableGraph wg = g.getWritableGraph("", true);
        int attribute, vertex;
        final long value = 1, defaultValue = 0;
        try {
            vertex = wg.addVertex();
            attribute = wg.addAttribute(GraphElementType.VERTEX, LongAttributeDescription.ATTRIBUTE_NAME, "name", "description", defaultValue, null);
            modCount = wg.getGlobalModificationCounter();
        } finally {
            wg.commit();
        }
        wg = g.getWritableGraph("", true);
        try {
            assertEquals(defaultValue, wg.getLongValue(attribute, vertex));
            assertEquals(modCount, wg.getGlobalModificationCounter());
        } finally {
            wg.commit();
        }
        wg = g.getWritableGraph("", true);
        try {
            wg.setLongValue(attribute, vertex, value);
            modCount = wg.getGlobalModificationCounter();
        } finally {
            wg.commit();
        }
        wg = g.getWritableGraph("", true);
        try {
            assertEquals(value, wg.getLongValue(attribute, vertex));
            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 29 with WritableGraph

use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.

the class ModCountNGTest method setTransactionDestinationModCounts.

/**
 * Tests that the mod counts on the two graphs in a DualGraph match after a
 * transactions is added between two vertices and then its destination
 * vertex is set to a third vertex.
 */
@Test
public void setTransactionDestinationModCounts() {
    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.setTransactionDestinationVertex(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), vertex0);
            assertEquals(wg.getTransactionDestinationVertex(trans), vertex2);
            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 30 with WritableGraph

use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.

the class ModCountNGTest method setIntegerValueModCounts.

/**
 * Tests that the mod counts on the two graphs in a DualGraph match after an
 * integer value is set on a graph with a single vertex.
 */
@Test
public void setIntegerValueModCounts() {
    final DualGraph g = new DualGraph(null);
    try {
        long modCount;
        WritableGraph wg = g.getWritableGraph("", true);
        int attribute, vertex;
        final int value = 1, defaultValue = 0;
        try {
            vertex = wg.addVertex();
            attribute = wg.addAttribute(GraphElementType.VERTEX, IntegerAttributeDescription.ATTRIBUTE_NAME, "name", "description", defaultValue, null);
            modCount = wg.getGlobalModificationCounter();
        } finally {
            wg.commit();
        }
        wg = g.getWritableGraph("", true);
        try {
            assertEquals(defaultValue, wg.getIntValue(attribute, vertex));
            assertEquals(modCount, wg.getGlobalModificationCounter());
        } finally {
            wg.commit();
        }
        wg = g.getWritableGraph("", true);
        try {
            wg.setIntValue(attribute, vertex, value);
            modCount = wg.getGlobalModificationCounter();
        } finally {
            wg.commit();
        }
        wg = g.getWritableGraph("", true);
        try {
            assertEquals(value, wg.getIntValue(attribute, vertex));
            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)

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