Search in sources :

Example 1 with BulkDeleteCommand

use of org.structr.core.graph.BulkDeleteCommand 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);
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) BulkDeleteCommand(org.structr.core.graph.BulkDeleteCommand) DecimalFormat(java.text.DecimalFormat) GraphObject(org.structr.core.GraphObject) LinkedList(java.util.LinkedList) Iterator(java.util.Iterator) TestOne(org.structr.web.entity.TestOne) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Aggregations

DecimalFormat (java.text.DecimalFormat)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1 FrameworkException (org.structr.common.error.FrameworkException)1 GraphObject (org.structr.core.GraphObject)1 App (org.structr.core.app.App)1 StructrApp (org.structr.core.app.StructrApp)1 BulkDeleteCommand (org.structr.core.graph.BulkDeleteCommand)1 Tx (org.structr.core.graph.Tx)1 StructrUiTest (org.structr.web.StructrUiTest)1 TestOne (org.structr.web.entity.TestOne)1