use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class DualGraphFlushTester method main.
public static void main(String[] args) throws InterruptedException {
StoreGraph g = new StoreGraph();
Graph dg = new DualGraph(g, true);
dg.setUndoManager(new UndoRedo.Manager());
WritableGraph wg = dg.getWritableGraph("sdfgsdfg", true);
final int x = VisualConcept.VertexAttribute.X.ensure(wg);
final int y = VisualConcept.VertexAttribute.Y.ensure(wg);
final int z = VisualConcept.VertexAttribute.Z.ensure(wg);
final int id = VisualConcept.VertexAttribute.IDENTIFIER.ensure(wg);
for (int i = 0; i < 1000; i++) {
final int vxId = wg.addVertex();
wg.setFloatValue(x, vxId, i);
wg.setFloatValue(y, vxId, i);
wg.setFloatValue(z, vxId, i);
wg.setStringValue(id, vxId, String.valueOf(i));
}
wg.commit();
final float[] coordSums = new float[1000];
GraphChangeListener gcl = (GraphChangeEvent event) -> {
ReadableGraph rg = dg.getReadableGraph();
try {
for (int i = 0; i < 1000; i++) {
final int vxId = rg.getVertex(i);
coordSums[i] = rg.getFloatValue(x, vxId) + rg.getFloatValue(y, vxId) + rg.getFloatValue(z, vxId);
}
} finally {
rg.release();
}
};
dg.addGraphChangeListener(gcl);
long time = System.currentTimeMillis();
wg = dg.getWritableGraph("test", false);
for (int i = 0; i < 100000; i++) {
for (int j = 0; j < 1000; j++) {
final int vxId = wg.getVertex(j);
wg.setFloatValue(x, vxId, wg.getFloatValue(x, vxId) + 1);
wg.setFloatValue(y, vxId, wg.getFloatValue(y, vxId) + 2);
wg.setFloatValue(z, vxId, wg.getFloatValue(z, vxId) + 3);
}
wg = wg.flush(false);
}
wg.commit();
LOGGER.log(Level.INFO, "took: {0}", (System.currentTimeMillis() - time));
Thread.sleep(3000);
LOGGER.log(Level.INFO, "{0}", Arrays.toString(coordSums));
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class AutosaveGraphPluginNGTest method setUpMethod.
@BeforeMethod
public void setUpMethod() throws Exception {
final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
graph = new DualGraph(schema);
WritableGraph wg = graph.getWritableGraph("Autosave", true);
try {
attrX = VisualConcept.VertexAttribute.X.ensure(wg);
attrY = VisualConcept.VertexAttribute.Y.ensure(wg);
attrZ = VisualConcept.VertexAttribute.Z.ensure(wg);
vAttrId = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
tAttrId = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
vxId1 = wg.addVertex();
wg.setFloatValue(attrX, vxId1, 1.0f);
wg.setFloatValue(attrY, vxId1, 1.0f);
wg.setBooleanValue(vAttrId, vxId1, false);
vxId2 = wg.addVertex();
wg.setFloatValue(attrX, vxId2, 5.0f);
wg.setFloatValue(attrY, vxId2, 1.0f);
wg.setBooleanValue(vAttrId, vxId2, true);
vxId3 = wg.addVertex();
wg.setFloatValue(attrX, vxId3, 1.0f);
wg.setFloatValue(attrY, vxId3, 5.0f);
wg.setBooleanValue(vAttrId, vxId3, false);
vxId4 = wg.addVertex();
wg.setFloatValue(attrX, vxId4, 5.0f);
wg.setFloatValue(attrY, vxId4, 5.0f);
wg.setBooleanValue(vAttrId, vxId4, false);
vxId5 = wg.addVertex();
wg.setFloatValue(attrX, vxId5, 10.0f);
wg.setFloatValue(attrY, vxId5, 10.0f);
wg.setBooleanValue(vAttrId, vxId5, true);
vxId6 = wg.addVertex();
wg.setFloatValue(attrX, vxId6, 15.0f);
wg.setFloatValue(attrY, vxId6, 15.0f);
vxId7 = wg.addVertex();
wg.setFloatValue(attrX, vxId7, 100.0f);
wg.setFloatValue(attrY, vxId7, 100.0f);
txId1 = wg.addTransaction(vxId1, vxId2, false);
txId2 = wg.addTransaction(vxId1, vxId3, false);
txId3 = wg.addTransaction(vxId2, vxId4, true);
txId4 = wg.addTransaction(vxId4, vxId2, true);
txId5 = wg.addTransaction(vxId5, vxId6, false);
} finally {
wg.commit();
}
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class QualityControlStateUpdaterNGTest method testReadSelectedNodesWithRules.
@Test
public void testReadSelectedNodesWithRules() throws Exception {
System.out.println("read Selected Nodes With Rules");
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 two vertices
vxId1 = wg.addVertex();
vxId2 = wg.addVertex();
// Add one transaction between the two vertices
txId1 = wg.addTransaction(vxId1, vxId2, false);
wg.setFloatValue(attrX, vxId1, 1.0f);
wg.setFloatValue(attrY, vxId1, 1.0f);
wg.setBooleanValue(vSelectedAttrId, vxId1, false);
wg.setFloatValue(attrX, vxId2, 2.0f);
wg.setFloatValue(attrY, vxId2, 2.0f);
wg.setBooleanValue(vSelectedAttrId, vxId1, true);
// Add vertex IDENTIFIER attribute and label each vertice.
vxIdentifierAttrId = VisualConcept.VertexAttribute.IDENTIFIER.ensure(wg);
wg.setStringValue(vxIdentifierAttrId, vxId1, "Vertex1");
wg.setStringValue(vxIdentifierAttrId, vxId2, "Vertex2");
// Add vertex TYPE attribute and set each type to unknown
typeAttrId = AnalyticConcept.VertexAttribute.TYPE.ensure(wg);
wg.setObjectValue(typeAttrId, vxId1, SchemaVertexType.unknownType());
wg.setObjectValue(typeAttrId, vxId2, SchemaVertexType.unknownType());
} finally {
wg.commit();
}
// Expected rules
final List<QualityControlRule> expectedRegisteredRules = new ArrayList<>(Lookup.getDefault().lookupAll(QualityControlRule.class));
// generate list of vertex ids
final List<Integer> vertexIds = new ArrayList<>();
vertexIds.add(0);
vertexIds.add(1);
// Check rules against vertex ids
for (final QualityControlRule rule : expectedRegisteredRules) {
rule.executeRule(graph.getReadableGraph(), vertexIds);
}
final List<QualityControlEvent> expectedQualityControlEvents = new ArrayList<>();
expectedQualityControlEvents.add(new QualityControlEvent(0, "Vertex1", SchemaVertexType.unknownType(), 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();
// Loop all events and check equality for each item specifically. Testing equality of the list was taken literally.
assertEquals(qualityControlEvents.size(), expectedQualityControlEvents.size());
int i = 0;
for (QualityControlEvent event : expectedQualityControlEvents) {
if (qualityControlEvents.size() >= i) {
assertEquals(qualityControlEvents.get(i).getReasons(), event.getReasons());
assertEquals(qualityControlEvents.get(i).getQuality(), event.getQuality());
assertEquals(qualityControlEvents.get(i).getVertex(), event.getVertex());
assertEquals(qualityControlEvents.get(i).getRules(), event.getRules());
assertEquals(qualityControlEvents.get(i).getType(), event.getType());
}
i++;
}
// check equality of the rules
assertEquals(registeredRules, expectedRegisteredRules);
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class PreferentialAttachmentGraphBuilderPluginNGTest method testUpdateParameters.
/**
* Test of updateParameters method, of class PreferentialAttachmentGraphBuilderPlugin.
*/
@Test
public void testUpdateParameters() {
System.out.println("updateParameters");
final PreferentialAttachmentGraphBuilderPlugin instance = new PreferentialAttachmentGraphBuilderPlugin();
final PluginParameters params = instance.createParameters();
final PluginParameter<MultiChoiceParameterValue> nAttribute = (PluginParameter<MultiChoiceParameterValue>) params.getParameters().get(NODE_TYPES_PARAMETER_ID);
final PluginParameter<MultiChoiceParameterValue> tAttribute = (PluginParameter<MultiChoiceParameterValue>) params.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
assertTrue(MultiChoiceParameterType.getOptions(nAttribute).isEmpty());
assertTrue(MultiChoiceParameterType.getOptions(tAttribute).isEmpty());
instance.updateParameters(new DualGraph(graph.getSchema(), graph), params);
assertEquals(MultiChoiceParameterType.getOptions(nAttribute).size(), 27);
assertEquals(MultiChoiceParameterType.getChoices(nAttribute).size(), 1);
assertEquals(MultiChoiceParameterType.getOptions(tAttribute).size(), 9);
assertEquals(MultiChoiceParameterType.getChoices(tAttribute).size(), 1);
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class SmallWorldGraphBuilderPluginNGTest method testUpdateParameters.
/**
* Test of updateParameters method, of class SmallWorldGraphBuilderPlugin.
*/
@Test
public void testUpdateParameters() {
System.out.println("updateParameters");
final SmallWorldGraphBuilderPlugin instance = new SmallWorldGraphBuilderPlugin();
final PluginParameters params = instance.createParameters();
final PluginParameter<MultiChoiceParameterValue> nAttribute = (PluginParameter<MultiChoiceParameterValue>) params.getParameters().get(NODE_TYPES_PARAMETER_ID);
final PluginParameter<MultiChoiceParameterValue> tAttribute = (PluginParameter<MultiChoiceParameterValue>) params.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
assertTrue(MultiChoiceParameterType.getOptions(nAttribute).isEmpty());
assertTrue(MultiChoiceParameterType.getOptions(tAttribute).isEmpty());
instance.updateParameters(new DualGraph(graph.getSchema(), graph), params);
assertEquals(MultiChoiceParameterType.getOptions(nAttribute).size(), 27);
assertEquals(MultiChoiceParameterType.getChoices(nAttribute).size(), 1);
assertEquals(MultiChoiceParameterType.getOptions(tAttribute).size(), 9);
assertEquals(MultiChoiceParameterType.getChoices(tAttribute).size(), 1);
}
Aggregations