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();
}
}
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();
}
}
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);
}
};
}
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();
}
}
}
Aggregations