use of org.structr.core.entity.GenericNode in project structr by structr.
the class BasicTest method test05CheckRelationshipEntities.
/**
* Create a node for each configured entity class and check the type
*/
@Test
public void test05CheckRelationshipEntities() {
try (final Tx tx = app.tx()) {
List<Class> entityList = null;
try {
entityList = getClasses("org.structr.core.entity");
} catch (IOException | ClassNotFoundException ex) {
logger.error("Unable to get list of entity classes", ex);
}
assertTrue(entityList.contains(AbstractRelationship.class));
assertTrue(entityList.contains(GenericRelationship.class));
for (Class entityClass : entityList) {
// Class entityClass = entity.getValue();
if (AbstractRelationship.class.isAssignableFrom(entityClass)) {
String type = entityClass.getSimpleName();
logger.info("Creating relationship of type {}", type);
List<GenericNode> nodes = createTestNodes(GenericNode.class, 2);
final NodeInterface startNode = nodes.get(0);
final NodeInterface endNode = nodes.get(1);
final RelationshipType relType = RelType.IS_AT;
NodeHasLocation rel = app.create(startNode, endNode, NodeHasLocation.class);
assertTrue(rel != null);
assertTrue(rel.getType().equals(relType.name()));
}
}
tx.success();
} catch (Throwable ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.GenericNode in project structr by structr.
the class PerformanceTest method testPerformanceOfRelationshipCreation.
/**
* Tests basic throughput of relationship creation operations
*
* Note that this is just a very rought test as performance is heavily
* depending on hardware and setup (cache parameters etc.)
*
* The assumed rate is low so if this test fails, there may be issues
* with the test setup.
*
* If the test passes, one can expect structr to create relationship with typical performance.
*/
@Test
public void testPerformanceOfRelationshipCreation() {
try {
int expected = 1000;
final App app = StructrApp.getInstance(setup());
final List<GenericNode> nodes = new ArrayList<>(createNodes(app, GenericNode.class, expected + 1));
List<NodeHasLocation> rels = new LinkedList<>();
long t0 = System.nanoTime();
try (final Tx tx = app.tx()) {
for (int i = 0; i < expected; i++) {
final GenericNode n1 = nodes.get(i);
final GenericNode n2 = nodes.get(i + 1);
rels.add(app.create(n1, n2, NodeHasLocation.class));
}
tx.success();
}
long t1 = System.nanoTime();
assertEquals("Invalid relationship creation result", expected, rels.size());
DecimalFormat decimalFormat = new DecimalFormat("0.000000000", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
Double time = (t1 - t0) / 1000000000.0;
Double rate = expected / ((t1 - t0) / 1000000000.0);
logger.info("Created {} relationships in {} seconds ({} per s)", new Object[] { expected, decimalFormat.format(time), decimalFormat.format(rate) });
assertTrue(rate > 50);
} catch (FrameworkException ex) {
ex.printStackTrace();
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.GenericNode in project structr by structr.
the class StructrMessagingEngineModuleTest method createTestRelationships.
protected <T extends Relation> List<T> createTestRelationships(final Class<T> relType, final int number) throws FrameworkException {
List<GenericNode> nodes = createTestNodes(GenericNode.class, 2);
final NodeInterface startNode = nodes.get(0);
final NodeInterface endNode = nodes.get(1);
try (final Tx tx = app.tx()) {
List<T> rels = new LinkedList<>();
for (int i = 0; i < number; i++) {
rels.add((T) app.create(startNode, endNode, relType));
}
tx.success();
return rels;
}
}
use of org.structr.core.entity.GenericNode in project structr by structr.
the class StructrPaymentModuleTest method createTestRelationships.
protected <T extends Relation> List<T> createTestRelationships(final Class<T> relType, final int number) throws FrameworkException {
List<GenericNode> nodes = createTestNodes(GenericNode.class, 2);
final NodeInterface startNode = nodes.get(0);
final NodeInterface endNode = nodes.get(1);
try (final Tx tx = app.tx()) {
List<T> rels = new LinkedList<>();
for (int i = 0; i < number; i++) {
rels.add((T) app.create(startNode, endNode, relType));
}
tx.success();
return rels;
}
}
Aggregations