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