use of org.structr.web.entity.TestOne in project structr by structr.
the class PerformanceTest method testPerformanceOfNodeDeletion.
@Test
public void testPerformanceOfNodeDeletion() {
final App app = StructrApp.getInstance(setup());
final List<TestOne> nodes = new LinkedList<>();
final int number = 1000;
try {
try (final Tx tx = app.tx()) {
nodes.addAll(createNodes(app, TestOne.class, number));
tx.success();
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
// start measuring
final long t0 = System.currentTimeMillis();
try {
final BulkDeleteCommand cmd = app.command(BulkDeleteCommand.class);
try (final Tx tx = app.tx()) {
final Iterator<GraphObject> iterator = (Iterator) nodes.iterator();
cmd.bulkDelete(iterator);
tx.success();
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
final long t1 = System.currentTimeMillis();
DecimalFormat decimalFormat = new DecimalFormat("0.000000000", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
Double time = (t1 - t0) / 1000.0;
Double rate = number / ((t1 - t0) / 1000.0);
logger.info("Deleted {} nodes in {} seconds ({} per s)", number, decimalFormat.format(time), decimalFormat.format(rate));
assertTrue("Deletion rate of nodes too low, expected > 100, was " + rate, rate > 50);
}
use of org.structr.web.entity.TestOne in project structr by structr.
the class RenderContextTest method testAnyAllAndNoneFunctions1.
@Test
public void testAnyAllAndNoneFunctions1() {
final ActionContext ctx = new ActionContext(securityContext, null);
Principal user = null;
TestOne test = null;
try (final Tx tx = app.tx()) {
user = app.create(User.class, "user1");
test = app.create(TestOne.class, "test1");
app.create(Group.class, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "group1"), new NodeAttribute<>(StructrApp.key(Group.class, "members"), Arrays.asList(new Principal[] { user })));
final Group group2 = app.create(Group.class, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "group2"), new NodeAttribute<>(StructrApp.key(Group.class, "members"), Arrays.asList(new Principal[] { user })));
app.create(Group.class, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "group3"), new NodeAttribute<>(StructrApp.key(Group.class, "members"), Arrays.asList(new Principal[] { user })));
test.setProperty(AbstractNode.owner, group2);
tx.success();
} catch (FrameworkException ex) {
logger.warn("", ex);
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
ctx.setConstant("user", user);
ctx.setConstant("test", test);
assertEquals("Invalid any() result", "true", Scripting.replaceVariables(ctx, null, "${any(user.groups, is_allowed(data, test, 'read'))}"));
assertEquals("Invalid all() result", "false", Scripting.replaceVariables(ctx, null, "${all(user.groups, is_allowed(data, test, 'read'))}"));
assertEquals("Invalid none() result", "false", Scripting.replaceVariables(ctx, null, "${none(user.groups, is_allowed(data, test, 'read'))}"));
tx.success();
} catch (FrameworkException ex) {
logger.warn("", ex);
fail("Unexpected exception");
}
}
use of org.structr.web.entity.TestOne in project structr by structr.
the class PerformanceTest method testReadPerformance.
/**
* Tests basic throughput of reading node properties.
*
* 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 read nodes with typical performance.
*/
@Test
public void testReadPerformance() {
try {
final App app = StructrApp.getInstance(setup());
int number = 1000;
int loop = 1000;
createNodes(app, TestOne.class, number);
long t0 = System.nanoTime();
for (int i = 0; i < loop; i++) {
try (final Tx tx = app.tx()) {
final List<TestOne> res = app.nodeQuery(TestOne.class).getAsList();
for (final TestOne t : res) {
final String name = t.getProperty(AbstractNode.name);
}
tx.success();
}
}
long t1 = System.nanoTime();
DecimalFormat decimalFormat = new DecimalFormat("0.000000000", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
double time = (t1 - t0) / 1000000000.0;
double rate = number * loop / ((t1 - t0) / 1000000000.0);
logger.info("Read {}x {} nodes in {} seconds ({} per s)", new Object[] { loop, number, decimalFormat.format(time), decimalFormat.format(rate) });
assertTrue("Invalid read performance result", rate > 50000);
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.web.entity.TestOne in project structr by structr.
the class PerformanceTest method testPerformanceOfNodeCreation.
/**
* Tests basic throughput of node 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 nodes with typical performance.
*/
@Test
public void testPerformanceOfNodeCreation() {
final List<TestOne> nodes = new LinkedList<>();
final long number = 1000;
// start measuring
final long t0 = System.currentTimeMillis();
final App app = StructrApp.getInstance(setup());
try {
try (final Tx tx = app.tx()) {
final long t1 = System.currentTimeMillis();
for (int i = 0; i < number; i++) {
nodes.add(app.create(TestOne.class, new NodeAttribute(TestOne.name, "TestOne" + i), new NodeAttribute(TestOne.aDate, new Date()), new NodeAttribute(TestOne.aDouble, 1.234), new NodeAttribute(TestOne.aLong, 12345L), new NodeAttribute(TestOne.anInt, 123)));
}
final long t2 = System.currentTimeMillis();
System.out.println((t2 - t1) + " ms");
tx.success();
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
final long t1 = System.currentTimeMillis();
assertTrue(nodes.size() == number);
DecimalFormat decimalFormat = new DecimalFormat("0.000000000", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
Double time = (t1 - t0) / 1000.0;
Double rate = number / ((t1 - t0) / 1000.0);
logger.info("Created {} nodes in {} seconds ({} per s)", number, decimalFormat.format(time), decimalFormat.format(rate));
assertTrue("Creation rate of nodes too low, expected > 100, was " + rate, rate > 50);
}
use of org.structr.web.entity.TestOne in project structr by structr.
the class UiScriptingTest method testScripting.
@Test
public void testScripting() {
NodeInterface detailsDataObject = null;
Page page = null;
DOMNode html = null;
DOMNode head = null;
DOMNode body = null;
DOMNode title = null;
DOMNode div = null;
DOMNode p = null;
DOMNode text = null;
try (final Tx tx = app.tx()) {
detailsDataObject = app.create(TestOne.class, "TestOne");
page = Page.createNewPage(securityContext, "testpage");
page.setProperties(page.getSecurityContext(), new PropertyMap(Page.visibleToPublicUsers, true));
assertTrue(page != null);
assertTrue(page instanceof Page);
html = (DOMNode) page.createElement("html");
head = (DOMNode) page.createElement("head");
body = (DOMNode) page.createElement("body");
title = (DOMNode) page.createElement("title");
div = (DOMNode) page.createElement("div");
p = (DOMNode) page.createElement("p");
text = (DOMNode) page.createTextNode("x");
// add HTML element to page
page.appendChild(html);
// add HEAD and BODY elements to HTML
html.appendChild(head);
html.appendChild(body);
// add TITLE element to HEAD
head.appendChild(title);
body.appendChild(div);
div.appendChild(p);
final PropertyMap changedProperties = new PropertyMap();
changedProperties.put(StructrApp.key(DOMElement.class, "restQuery"), "/divs");
changedProperties.put(StructrApp.key(DOMElement.class, "dataKey"), "div");
p.setProperties(p.getSecurityContext(), changedProperties);
p.appendChild(text);
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
final RenderContext ctx = new RenderContext(securityContext, new RequestMockUp(), new ResponseMockUp(), RenderContext.EditMode.NONE);
ctx.setDetailsDataObject(detailsDataObject);
ctx.setPage(page);
test(p, text, "${{ return Structr.get('div').id}}", "<p>" + div.getUuid() + "</p>", ctx);
test(p, text, "${{ return Structr.get('page').id}}", "<p>" + page.getUuid() + "</p>", ctx);
test(p, text, "${{ return Structr.get('parent').id}}", "<p>" + p.getUuid() + "</p>", ctx);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
}
Aggregations