Search in sources :

Example 31 with Assembler

use of org.qi4j.bootstrap.Assembler in project qi4j-sdk by Qi4j.

the class AbstractEntityStorePerformanceTest method whenReadEntityWithComplexTypeThenRecordIterationsPerSecond.

@Test
public void whenReadEntityWithComplexTypeThenRecordIterationsPerSecond() throws Exception {
    try {
        Assembler assembler = new Assembler() {

            @Override
            public void assemble(ModuleAssembly module) throws AssemblyException {
                module.entities(ComplexProduct.class);
            }
        };
        createQi4jRuntime(assembler);
        {
            int bulk = 0;
            UnitOfWork uow = module.newUnitOfWork(newUsecase("readEntityWithComplexType PREPARE " + bulk));
            for (int i = 0; i < ITERATIONS; i++) {
                ComplexProduct product = uow.newEntity(ComplexProduct.class, "product" + i);
                product.name().set("Product " + i);
                if (i % 1000 == 0) {
                    uow.complete();
                    bulk++;
                    uow = module.newUnitOfWork(newUsecase("readEntityWithComplexType PREPARE " + bulk));
                }
            }
            uow.complete();
        }
        profile(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                Report report = new Report(storeName);
                int bulk = 0;
                UnitOfWork uow = module.newUnitOfWork(newUsecase("readEntityWithComplexType " + bulk));
                Random rnd = new Random();
                report.start("readEntityWithComplexType");
                String id = rnd.nextInt(ITERATIONS) + "";
                for (int i = 0; i < ITERATIONS; i++) {
                    ComplexProduct product = uow.get(ComplexProduct.class, "product" + id);
                    String name = product.name().get();
                    if (i % 100 == 0) {
                        uow.discard();
                        bulk++;
                        uow = module.newUnitOfWork(newUsecase("readEntityWithComplexType " + bulk));
                    }
                }
                uow.complete();
                report.stop(ITERATIONS);
                writeReport(report);
                return null;
            }
        });
    } finally {
        cleanUp();
    }
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Random(java.util.Random) Assembler(org.qi4j.bootstrap.Assembler) IOException(java.io.IOException) AssemblyException(org.qi4j.bootstrap.AssemblyException) Test(org.junit.Test)

Example 32 with Assembler

use of org.qi4j.bootstrap.Assembler in project qi4j-sdk by Qi4j.

the class AbstractEntityStorePerformanceTest method whenCreateEntityWithComplexTypeThenRecordIterationsPerSecond.

@Test
public void whenCreateEntityWithComplexTypeThenRecordIterationsPerSecond() throws Exception {
    try {
        Assembler assembler = new Assembler() {

            @Override
            public void assemble(ModuleAssembly module) throws AssemblyException {
                module.entities(ComplexProduct.class);
            }
        };
        createQi4jRuntime(assembler);
        profile(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                Report report = new Report(storeName);
                report.start("createEntityWithComplexType");
                for (int i = 0; i < ITERATIONS; i++) {
                    try (UnitOfWork uow = module.newUnitOfWork(newUsecase("createEntityWithComplexType " + i))) {
                        ComplexProduct product = uow.newEntity(ComplexProduct.class);
                        String id = product.identity().get();
                        uow.complete();
                    }
                }
                report.stop(ITERATIONS);
                writeReport(report);
                return null;
            }
        });
    } finally {
        cleanUp();
    }
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Assembler(org.qi4j.bootstrap.Assembler) IOException(java.io.IOException) AssemblyException(org.qi4j.bootstrap.AssemblyException) Test(org.junit.Test)

Example 33 with Assembler

use of org.qi4j.bootstrap.Assembler in project qi4j-sdk by Qi4j.

the class PostgreSQLEntityStorePerformanceTest method createAssembler.

private static Assembler createAssembler() {
    return new Assembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            ModuleAssembly config = module.layer().module("config");
            config.services(MemoryEntityStoreService.class);
            // DataSourceService
            new DBCPDataSourceServiceAssembler().identifiedBy("postgresql-datasource-service").visibleIn(Visibility.module).withConfig(config, Visibility.layer).assemble(module);
            // DataSource
            new DataSourceAssembler().withDataSourceServiceIdentity("postgresql-datasource-service").identifiedBy("postgresql-datasource").withCircuitBreaker().assemble(module);
            // SQL EntityStore
            new PostgreSQLEntityStoreAssembler().withConfig(config, Visibility.layer).assemble(module);
        }
    };
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) DataSourceAssembler(org.qi4j.library.sql.assembly.DataSourceAssembler) DBCPDataSourceServiceAssembler(org.qi4j.library.sql.dbcp.DBCPDataSourceServiceAssembler) DBCPDataSourceServiceAssembler(org.qi4j.library.sql.dbcp.DBCPDataSourceServiceAssembler) PostgreSQLEntityStoreAssembler(org.qi4j.entitystore.sql.assembly.PostgreSQLEntityStoreAssembler) Assembler(org.qi4j.bootstrap.Assembler) DataSourceAssembler(org.qi4j.library.sql.assembly.DataSourceAssembler) PostgreSQLEntityStoreAssembler(org.qi4j.entitystore.sql.assembly.PostgreSQLEntityStoreAssembler)

Example 34 with Assembler

use of org.qi4j.bootstrap.Assembler in project qi4j-sdk by Qi4j.

the class PostgreSQLEntityStorePerformanceTest method cleanUp.

@Override
protected void cleanUp() throws Exception {
    try {
        super.cleanUp();
    } finally {
        Energy4Java qi4j = new Energy4Java();
        Assembler[][][] assemblers = new Assembler[][][] { { { createAssembler() } } };
        Application application = qi4j.newApplication(new ApplicationAssemblerAdapter(assemblers) {
        });
        application.activate();
        Module moduleInstance = application.findModule("Layer 1", "config");
        UnitOfWorkFactory uowf = moduleInstance;
        UnitOfWork uow = uowf.newUnitOfWork();
        try {
            SQLConfiguration config = uow.get(SQLConfiguration.class, PostgreSQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY);
            // TODO fix AbstractEntityStorePerformanceTest to extend from AbstractQi4jTest
            // SQLUtil.getConnection( this.serviceLocator );
            Connection connection = null;
            String schemaName = config.schemaName().get();
            if (schemaName == null) {
                schemaName = SQLs.DEFAULT_SCHEMA_NAME;
            }
            Statement stmt = null;
            try {
                stmt = connection.createStatement();
                stmt.execute(String.format("DELETE FROM %s." + SQLs.TABLE_NAME, schemaName));
                connection.commit();
            } finally {
                SQLUtil.closeQuietly(stmt);
            }
        } finally {
            uow.discard();
        }
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Statement(java.sql.Statement) Connection(java.sql.Connection) Energy4Java(org.qi4j.bootstrap.Energy4Java) UnitOfWorkFactory(org.qi4j.api.unitofwork.UnitOfWorkFactory) SQLConfiguration(org.qi4j.library.sql.common.SQLConfiguration) DBCPDataSourceServiceAssembler(org.qi4j.library.sql.dbcp.DBCPDataSourceServiceAssembler) PostgreSQLEntityStoreAssembler(org.qi4j.entitystore.sql.assembly.PostgreSQLEntityStoreAssembler) Assembler(org.qi4j.bootstrap.Assembler) DataSourceAssembler(org.qi4j.library.sql.assembly.DataSourceAssembler) Module(org.qi4j.api.structure.Module) Application(org.qi4j.api.structure.Application) ApplicationAssemblerAdapter(org.qi4j.bootstrap.ApplicationAssemblerAdapter)

Aggregations

Assembler (org.qi4j.bootstrap.Assembler)34 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)23 Energy4Java (org.qi4j.bootstrap.Energy4Java)19 Test (org.junit.Test)17 ApplicationAssemblerAdapter (org.qi4j.bootstrap.ApplicationAssemblerAdapter)17 Application (org.qi4j.api.structure.Application)13 AssemblyException (org.qi4j.bootstrap.AssemblyException)10 EntityTestAssembler (org.qi4j.test.EntityTestAssembler)9 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)8 IOException (java.io.IOException)6 Before (org.junit.Before)6 Module (org.qi4j.api.structure.Module)5 ApplicationAssembler (org.qi4j.bootstrap.ApplicationAssembler)4 OrgJsonValueSerializationAssembler (org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler)4 ApplicationAssembly (org.qi4j.bootstrap.ApplicationAssembly)3 ApplicationAssemblyFactory (org.qi4j.bootstrap.ApplicationAssemblyFactory)3 DataSourceAssembler (org.qi4j.library.sql.assembly.DataSourceAssembler)3 DBCPDataSourceServiceAssembler (org.qi4j.library.sql.dbcp.DBCPDataSourceServiceAssembler)3 PostgreSQLEntityStoreAssembler (org.qi4j.entitystore.sql.assembly.PostgreSQLEntityStoreAssembler)2 Connection (java.sql.Connection)1