http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/jdbm/JdbmEntityStorePerformanceTest.java ---------------------------------------------------------------------- diff --git a/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/jdbm/JdbmEntityStorePerformanceTest.java b/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/jdbm/JdbmEntityStorePerformanceTest.java new file mode 100644 index 0000000..047ffef --- /dev/null +++ b/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/jdbm/JdbmEntityStorePerformanceTest.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.polygene.test.performance.entitystore.jdbm; + +import java.io.File; +import org.apache.derby.iapi.services.io.FileUtil; +import org.apache.polygene.api.common.Visibility; +import org.apache.polygene.bootstrap.Assembler; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.cache.ehcache.EhCacheConfiguration; +import org.apache.polygene.cache.ehcache.EhCachePoolService; +import org.apache.polygene.entitystore.jdbm.JdbmConfiguration; +import org.apache.polygene.entitystore.jdbm.assembly.JdbmEntityStoreAssembler; +import org.apache.polygene.test.EntityTestAssembler; +import org.apache.polygene.test.performance.entitystore.AbstractEntityStorePerformanceTest; +import org.apache.polygene.valueserialization.orgjson.OrgJsonValueSerializationAssembler; + +/** + * Performance test for JdbmEntityStoreComposite + */ +public class JdbmEntityStorePerformanceTest + extends AbstractEntityStorePerformanceTest +{ + public JdbmEntityStorePerformanceTest() + { + super( "JdbmEntityStore", createAssembler() ); + } + + private static Assembler createAssembler() + { + return new Assembler() + { + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + new JdbmEntityStoreAssembler().assemble( module ); + new OrgJsonValueSerializationAssembler().assemble( module ); + ModuleAssembly configModule = module.layer().module( "Config" ); + configModule.entities( JdbmConfiguration.class ).visibleIn( Visibility.layer ); + new EntityTestAssembler().assemble( configModule ); + + module.services( EhCachePoolService.class ); + configModule.entities( EhCacheConfiguration.class ).visibleIn( Visibility.layer ); + } + }; + } + + @Override + public void cleanUp() + throws Exception + { + super.cleanUp(); + FileUtil.removeDirectory( new File( "build/tmp/jdbm" ) ); + } +}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/memory/MemoryEntityStorePerformanceTest.java ---------------------------------------------------------------------- diff --git a/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/memory/MemoryEntityStorePerformanceTest.java b/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/memory/MemoryEntityStorePerformanceTest.java new file mode 100644 index 0000000..bd664e1 --- /dev/null +++ b/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/memory/MemoryEntityStorePerformanceTest.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.polygene.test.performance.entitystore.memory; + +import org.apache.polygene.api.mixin.Mixins; +import org.apache.polygene.bootstrap.Assembler; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.entitystore.memory.assembly.MemoryEntityStoreAssembler; +import org.apache.polygene.entitystore.memory.MemoryEntityStoreService; +import org.apache.polygene.spi.entitystore.helpers.MapEntityStoreMixin; +import org.apache.polygene.test.performance.entitystore.AbstractEntityStorePerformanceTest; +import org.apache.polygene.valueserialization.orgjson.OrgJsonValueSerializationAssembler; + +public class MemoryEntityStorePerformanceTest + extends AbstractEntityStorePerformanceTest +{ + + public MemoryEntityStorePerformanceTest() + { + super( "MemoryEntityStore", createAssembler() ); + } + + private static Assembler createAssembler() + { + return new Assembler() + { + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + new MemoryEntityStoreAssembler().assemble( module ); + new OrgJsonValueSerializationAssembler().assemble( module ); + } + }; + } + + // Alternate variant that uses the standard MapEntityStore + @Mixins( MapEntityStoreMixin.class ) + interface MemoryEntityStoreService2 + extends MemoryEntityStoreService + { + } + +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/DerbySQLEntityStorePerformanceTest.java ---------------------------------------------------------------------- diff --git a/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/DerbySQLEntityStorePerformanceTest.java b/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/DerbySQLEntityStorePerformanceTest.java new file mode 100644 index 0000000..d1ea720 --- /dev/null +++ b/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/DerbySQLEntityStorePerformanceTest.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.polygene.test.performance.entitystore.sql; + +import java.sql.Connection; +import java.sql.Statement; +import javax.sql.DataSource; +import org.apache.polygene.api.common.Visibility; +import org.apache.polygene.api.unitofwork.UnitOfWork; +import org.apache.polygene.api.usecase.UsecaseBuilder; +import org.apache.polygene.bootstrap.Assembler; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.entitystore.sql.assembly.DerbySQLEntityStoreAssembler; +import org.apache.polygene.entitystore.sql.internal.SQLs; +import org.apache.polygene.library.sql.assembly.DataSourceAssembler; +import org.apache.polygene.library.sql.common.SQLConfiguration; +import org.apache.polygene.library.sql.common.SQLUtil; +import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler; +import org.apache.polygene.test.EntityTestAssembler; +import org.apache.polygene.test.performance.entitystore.AbstractEntityStorePerformanceTest; +import org.apache.polygene.valueserialization.orgjson.OrgJsonValueSerializationAssembler; + +/** + * Performance test for DerbySQLEntityStore. + */ +public class DerbySQLEntityStorePerformanceTest + extends AbstractEntityStorePerformanceTest +{ + + public DerbySQLEntityStorePerformanceTest() + { + super( "DerbySQLEntityStore", createAssembler() ); + } + + private static Assembler createAssembler() + { + return new Assembler() + { + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + ModuleAssembly config = module.layer().module( "config" ); + new EntityTestAssembler().assemble( config ); + + new OrgJsonValueSerializationAssembler().assemble( module ); + + // DataSourceService + new DBCPDataSourceServiceAssembler(). + identifiedBy( "derby-datasource-service" ). + visibleIn( Visibility.module ). + withConfig( config, Visibility.layer ). + assemble( module ); + + // DataSource + new DataSourceAssembler(). + withDataSourceServiceIdentity( "derby-datasource-service" ). + identifiedBy( "derby-datasource" ). + withCircuitBreaker(). + assemble( module ); + + // SQL EntityStore + new DerbySQLEntityStoreAssembler(). + withConfig( config, Visibility.layer ). + assemble( module ); + } + }; + } + + @Override + protected void cleanUp() + throws Exception + { + if( uowf == null ) + { + return; + } + UnitOfWork uow = this.uowf.newUnitOfWork( UsecaseBuilder.newUsecase( + "Delete " + getClass().getSimpleName() + " test data" ) ); + try + { + SQLConfiguration config = uow.get( SQLConfiguration.class, + DerbySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY ); + Connection connection = serviceFinder.findService( DataSource.class ).get().getConnection(); + 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(); + super.cleanUp(); + } + } + +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/PostgreSQLEntityStorePerformanceTest.java ---------------------------------------------------------------------- diff --git a/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/PostgreSQLEntityStorePerformanceTest.java b/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/PostgreSQLEntityStorePerformanceTest.java new file mode 100644 index 0000000..e0c2bcc --- /dev/null +++ b/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/PostgreSQLEntityStorePerformanceTest.java @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.polygene.test.performance.entitystore.sql; + +import java.sql.Connection; +import java.sql.Statement; +import org.junit.Ignore; +import org.apache.polygene.api.common.Visibility; +import org.apache.polygene.api.structure.Application; +import org.apache.polygene.api.structure.Module; +import org.apache.polygene.api.unitofwork.UnitOfWork; +import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; +import org.apache.polygene.bootstrap.ApplicationAssemblerAdapter; +import org.apache.polygene.bootstrap.Assembler; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.Energy4Java; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.entitystore.memory.MemoryEntityStoreService; +import org.apache.polygene.entitystore.sql.assembly.PostgreSQLEntityStoreAssembler; +import org.apache.polygene.entitystore.sql.internal.SQLs; +import org.apache.polygene.library.sql.assembly.DataSourceAssembler; +import org.apache.polygene.library.sql.common.SQLConfiguration; +import org.apache.polygene.library.sql.common.SQLUtil; +import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler; +import org.apache.polygene.test.performance.entitystore.AbstractEntityStorePerformanceTest; + +/** + * Performance test for PostgreSQLEntityStore. + * <p> + * WARN This test is deactivated on purpose, please do not commit it activated. + * </p> + * <p> + * To run it see PostgreSQLEntityStoreTest. + * </p> + */ +@Ignore( "WARN Tearing down this test is broken!" ) +public class PostgreSQLEntityStorePerformanceTest + extends AbstractEntityStorePerformanceTest +{ + + public PostgreSQLEntityStorePerformanceTest() + { + super( "PostgreSQLEntityStore", 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 ); + } + + }; + } + + @Override + protected void cleanUp() + throws Exception + { + try + { + super.cleanUp(); + } + finally + { + + Energy4Java polygene = new Energy4Java(); + Assembler[][][] assemblers = new Assembler[][][] + { + { + { + createAssembler() + } + } + }; + Application application = polygene.newApplication( new ApplicationAssemblerAdapter( assemblers ) + { + } ); + application.activate(); + + Module moduleInstance = application.findModule( "Layer 1", "config" ); + UnitOfWorkFactory uowf = moduleInstance.unitOfWorkFactory(); + UnitOfWork uow = uowf.newUnitOfWork(); + try + { + SQLConfiguration config = uow.get( SQLConfiguration.class, + PostgreSQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY ); + // TODO fix AbstractEntityStorePerformanceTest to extend from AbstractPolygeneTest + Connection connection = null; // SQLUtil.getConnection( this.serviceLocator ); + 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(); + } + } + } + +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/tests/performance/src/perf/java/org/apache/polygene/test/performance/indexing/rdf/QueryPerformanceTest.java ---------------------------------------------------------------------- diff --git a/tests/performance/src/perf/java/org/apache/polygene/test/performance/indexing/rdf/QueryPerformanceTest.java b/tests/performance/src/perf/java/org/apache/polygene/test/performance/indexing/rdf/QueryPerformanceTest.java new file mode 100644 index 0000000..a8e54ee --- /dev/null +++ b/tests/performance/src/perf/java/org/apache/polygene/test/performance/indexing/rdf/QueryPerformanceTest.java @@ -0,0 +1,399 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.polygene.test.performance.indexing.rdf; + +import java.io.File; +import org.apache.derby.iapi.services.io.FileUtil; +import org.apache.polygene.api.query.QueryBuilderFactory; +import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.apache.polygene.api.common.Visibility; +import org.apache.polygene.api.entity.EntityBuilder; +import org.apache.polygene.api.entity.EntityComposite; +import org.apache.polygene.api.injection.scope.Structure; +import org.apache.polygene.api.mixin.Mixins; +import org.apache.polygene.api.property.Property; +import org.apache.polygene.api.query.Query; +import org.apache.polygene.api.query.QueryBuilder; +import org.apache.polygene.api.service.ServiceComposite; +import org.apache.polygene.api.service.ServiceReference; +import org.apache.polygene.api.structure.Application; +import org.apache.polygene.api.structure.Module; +import org.apache.polygene.api.unitofwork.UnitOfWork; +import org.apache.polygene.api.unitofwork.UnitOfWorkCompletionException; +import org.apache.polygene.bootstrap.ApplicationAssembler; +import org.apache.polygene.bootstrap.ApplicationAssembly; +import org.apache.polygene.bootstrap.ApplicationAssemblyFactory; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.Energy4Java; +import org.apache.polygene.bootstrap.LayerAssembly; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.entitystore.memory.assembly.MemoryEntityStoreAssembler; +import org.apache.polygene.index.rdf.assembly.RdfNativeSesameStoreAssembler; +import org.apache.polygene.index.rdf.indexing.RdfIndexingService; +import org.apache.polygene.index.rdf.query.SesameExpressions; +import org.apache.polygene.library.rdf.repository.NativeConfiguration; +import org.apache.polygene.test.EntityTestAssembler; +import org.apache.polygene.valueserialization.orgjson.OrgJsonValueSerializationAssembler; + +import static org.apache.polygene.api.query.QueryExpressions.eq; +import static org.apache.polygene.api.query.QueryExpressions.templateFor; + +@SuppressWarnings( "ResultOfMethodCallIgnored" ) +public class QueryPerformanceTest + implements ApplicationAssembler +{ + private static final int NUMBER_OF_ENTITIES = 100000; + private static final String LAYER_INFRASTRUCTURE = "LAYER_INFRASTRUCTURE"; + private static final String MODULE_PERSISTENCE = "MODULE_PERSISTENCE"; + private static final String LAYER_CONFIGURATION = "CONFIGURATION"; + private static final String LAYER_DOMAIN = "LAYER_DOMAIN"; + private static final String MODULE_DOMAIN = "MODULE_DOMAIN"; + private static final String MODULE_CONFIG = "MODULE_CONFIG"; + + private Application application; + private Module module; + private UnitOfWorkFactory uowf; + private static final String QUERY1 = "PREFIX ns0: <urn:polygene:type:org.apache.polygene.api.identity.HasIdentity#> \n" + + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + + "PREFIX ns1: <urn:polygene:type:org.apache.polygene.test.performance.indexing.rdf.QueryPerformanceTest-Lead#> \n" + + "SELECT ?entityType ?reference\n" + + "WHERE {\n" + + "?entityType rdfs:subClassOf <urn:polygene:type:org.apache.polygene.test.performance.indexing.rdf.QueryPerformanceTest-Lead>. \n" + + "?entity rdf:type ?entityType. \n" + + "?entity ns0:reference ?reference. \n" + + "?entity ns1:name \"Lead64532\". \n" + + "}"; + private static final String QUERY2 = "PREFIX ns0: <urn:polygene:type:org.apache.polygene.api.identity.HasIdentity#> \n" + + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + + "PREFIX ns1: <urn:polygene:type:org.apache.polygene.test.performance.indexing.rdf.QueryPerformanceTest-Lead#> \n" + + "SELECT ?entityType ?reference\n" + + "WHERE {\n" + + "?entityType rdfs:subClassOf <urn:polygene:type:org.apache.polygene.test.performance.indexing.rdf.QueryPerformanceTest-Lead>. \n" + + "?entity rdf:type ?entityType. \n" + + "?entity ns0:reference ?reference. \n" + + "?entity ns1:name \"Lead98276\". \n" + + "}"; + private static final String QUERY3 = "PREFIX ns0: <urn:polygene:type:org.apache.polygene.api.identity.HasIdentity#> \n" + + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + + "PREFIX ns1: <urn:polygene:type:org.apache.polygene.test.performance.indexing.rdf.QueryPerformanceTest-Lead#> \n" + + "SELECT ?entityType ?reference\n" + + "WHERE {\n" + + "?entityType rdfs:subClassOf <urn:polygene:type:org.apache.polygene.test.performance.indexing.rdf.QueryPerformanceTest-Lead>. \n" + + "?entity rdf:type ?entityType. \n" + + "?entity ns0:reference ?reference. \n" + + "?entity ns1:name \"Lead2\". \n" + + "}"; + private static final String QUERY4 = "PREFIX ns0: <urn:polygene:type:org.apache.polygene.api.identity.HasIdentity#> \n" + + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + + "PREFIX ns1: <urn:polygene:type:org.apache.polygene.test.performance.indexing.rdf.QueryPerformanceTest-Lead#> \n" + + "SELECT ?entityType ?reference\n" + + "WHERE {\n" + + "?entityType rdfs:subClassOf <urn:polygene:type:org.apache.polygene.test.performance.indexing.rdf.QueryPerformanceTest-Lead>. \n" + + "?entity rdf:type ?entityType. \n" + + "?entity ns0:reference ?reference. \n" + + "?entity ns1:name \"Lead14332\". \n" + + "}"; + private static final String QUERY5 = "PREFIX ns0: <urn:polygene:type:org.apache.polygene.api.identity.HasIdentity#> \n" + + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + + "PREFIX ns1: <urn:polygene:type:org.apache.polygene.test.performance.indexing.rdf.QueryPerformanceTest-Lead#> \n" + + "SELECT ?entityType ?reference\n" + + "WHERE {\n" + + "?entityType rdfs:subClassOf <urn:polygene:type:org.apache.polygene.test.performance.indexing.rdf.QueryPerformanceTest-Lead>. \n" + + "?entity rdf:type ?entityType. \n" + + "?entity ns0:reference ?reference. \n" + + "?entity ns1:name \"Lead632\". \n" + + "}"; + private File indexingDataDir; + + @Before + public void setup() + throws Exception + { + Energy4Java polygene = new Energy4Java(); + application = polygene.newApplication( this ); + module = application.findModule( LAYER_DOMAIN, MODULE_DOMAIN ); + application.activate(); + indexingDataDir = module.findService( RdfIndexingService.class ).get().dataDir(); + uowf = module.unitOfWorkFactory(); + } + + @After + public void tearDown() + throws Exception + { + try + { + if( application != null ) + { + System.out.println( "Shutting Down test." ); + application.passivate(); + } + } + finally + { + FileUtil.removeDirectory( indexingDataDir ); + } + } + + @Override + public ApplicationAssembly assemble( ApplicationAssemblyFactory applicationFactory ) + throws AssemblyException + { + ApplicationAssembly applicationAssembly = applicationFactory.newApplicationAssembly(); + LayerAssembly infra = createInfrastructureLayer( applicationAssembly ); + LayerAssembly domain = createDomainLayer( applicationAssembly ); + LayerAssembly config = createConfigurationLayer( applicationAssembly ); + infra.uses( config ); + domain.uses( infra ); + return applicationAssembly; + } + + @Test + public void testIndexingFluentQueries() + throws Exception + { + LeadRepository leadRepo = populateEntityStore(); + measureFluentQuery( leadRepo, "Lead64531" ); + measureFluentQuery( leadRepo, "Lead98275" ); + measureFluentQuery( leadRepo, "Lead3" ); + measureFluentQuery( leadRepo, "Lead14331" ); + measureFluentQuery( leadRepo, "Lead631" ); + } + + @Test + public void testIndexingNamedQueries() + throws Exception + { + LeadRepository leadRepo = populateEntityStore(); + measureNamedQuery( leadRepo, QUERY1 ); + measureNamedQuery( leadRepo, QUERY2 ); + measureNamedQuery( leadRepo, QUERY3 ); + measureNamedQuery( leadRepo, QUERY4 ); + measureNamedQuery( leadRepo, QUERY5 ); + } + + private LeadRepository populateEntityStore() + throws UnitOfWorkCompletionException + { + UnitOfWork uow = uowf.newUnitOfWork(); + try + { + LeadRepository leadRepo = module.findService( LeadRepositoryService.class ).get(); + if( leadRepo.findByName( "Lead99999" ) == null ) + { + ServiceReference<LeadEntityFactoryService> leadFactoryRef = module.findService( LeadEntityFactoryService.class ); + LeadEntityFactory leadFactory = leadFactoryRef.get(); + long start, end; + start = System.currentTimeMillis(); + for( int i = 1; i < NUMBER_OF_ENTITIES; i++ ) + { + if( ( i % 10000 ) == 0 ) + { + System.out.print( "\r" + i ); + uow.complete(); + uow = uowf.newUnitOfWork(); + } + leadFactory.create( "Lead" + i ); + } + System.out.println(); + uow.complete(); + end = System.currentTimeMillis(); + System.out.println( "Population time: " + ( end - start ) ); + } + return leadRepo; + } + finally + { + if( uow != null && uow.isOpen() ) + { + uow.discard(); + } + } + } + + private void measureFluentQuery( LeadRepository leadRepo, String nameOfEntity ) + throws Exception + { + long start; + long end; + try( UnitOfWork uow = uowf.newUnitOfWork() ) + { + start = System.currentTimeMillis(); + Lead lead = leadRepo.findByName( nameOfEntity ); + end = System.currentTimeMillis(); + if( lead == null ) + { + Assert.fail( "Entity was not found or more than one entity was found." ); + return; + } + System.out.println( "Lead: " + lead ); + System.out.println( "Retrieval time of " + lead.name().get() + " by name: " + ( end - start ) ); + uow.complete(); + } + } + + private void measureNamedQuery( LeadRepository leadRepo, String queryName ) + throws Exception + { + long start; + long end; + try( UnitOfWork uow = uowf.newUnitOfWork() ) + { + start = System.currentTimeMillis(); + Lead lead = leadRepo.findByFixedQuery( queryName ); + end = System.currentTimeMillis(); + if( lead == null ) + { + Assert.fail( "Entity was not found or more than one entity was found." ); + return; + } + System.out.println( "Lead: " + lead ); + System.out.println( "Retrieval time of " + lead.name().get() + " by name: " + ( end - start ) ); + uow.complete(); + } + } + + private LayerAssembly createDomainLayer( ApplicationAssembly applicationAssembly ) + throws AssemblyException + { + LayerAssembly domainLayer = applicationAssembly.layer( LAYER_DOMAIN ); + ModuleAssembly domainModule = domainLayer.module( MODULE_DOMAIN ); + domainModule.addServices( LeadRepositoryService.class ); + domainModule.addServices( LeadEntityFactoryService.class ); + domainModule.entities( LeadEntity.class ); + return domainLayer; + } + + private LayerAssembly createInfrastructureLayer( ApplicationAssembly applicationAssembly ) + throws AssemblyException + { + LayerAssembly infrastructureLayer = applicationAssembly.layer( LAYER_INFRASTRUCTURE ); + + // Persistence module + ModuleAssembly persistenceModule = infrastructureLayer.module( MODULE_PERSISTENCE ); + + // Indexing + new RdfNativeSesameStoreAssembler().assemble( persistenceModule ); + + // Entity store + new OrgJsonValueSerializationAssembler().assemble( persistenceModule ); + new MemoryEntityStoreAssembler().visibleIn( Visibility.application ).assemble( persistenceModule ); + + return infrastructureLayer; + } + + private LayerAssembly createConfigurationLayer( ApplicationAssembly applicationAssembly ) + throws AssemblyException + { + LayerAssembly layer = applicationAssembly.layer( LAYER_CONFIGURATION ); + ModuleAssembly configModule = layer.module( MODULE_CONFIG ); + configModule.entities( NativeConfiguration.class ).visibleIn( Visibility.application ); + new EntityTestAssembler().assemble( configModule ); + return layer; + } + + public interface Lead + { + Property<String> name(); + } + + public interface LeadEntity + extends Lead, EntityComposite + { + } + + @Mixins( LeadEntityFactoryMixin.class ) + public interface LeadEntityFactoryService + extends LeadEntityFactory, ServiceComposite + { + } + + public interface LeadEntityFactory + { + Lead create( String name ); + } + + public static class LeadEntityFactoryMixin + implements LeadEntityFactory + { + @Structure + private UnitOfWorkFactory uowf; + + @Override + public Lead create( String name ) + { + UnitOfWork uow = uowf.currentUnitOfWork(); + EntityBuilder<LeadEntity> builder = uow.newEntityBuilder( LeadEntity.class ); + Lead prototype = builder.instanceFor( LeadEntity.class ); + prototype.name().set( name ); + return builder.newInstance(); + } + } + + public interface LeadRepository + { + Lead findByFixedQuery( String name ); + + Lead findByName( String name ); + } + + @Mixins( LeadRepositoryMixin.class ) + public interface LeadRepositoryService + extends LeadRepository, ServiceComposite + { + } + + public static class LeadRepositoryMixin + implements LeadRepository + { + @Structure + private QueryBuilderFactory qbf; + + @Structure + private UnitOfWorkFactory uowf; + + @Override + public Lead findByFixedQuery( String queryString ) + { + UnitOfWork uow = uowf.currentUnitOfWork(); + Query<Lead> query = uow.newQuery( qbf.newQueryBuilder( Lead.class ).where( SesameExpressions.sparql( queryString ) ) ); + return query.find(); + } + + @Override + public Lead findByName( String name ) + { + UnitOfWork uow = uowf.currentUnitOfWork(); + QueryBuilder<Lead> builder = qbf.newQueryBuilder( Lead.class ); + Lead template = templateFor( Lead.class ); + + Query<Lead> query = uow.newQuery( builder.where( eq( template.name(), name ) ) ); + return query.find(); + } + } + +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/composite/CompositeCreationPerformanceTest.java ---------------------------------------------------------------------- diff --git a/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/composite/CompositeCreationPerformanceTest.java b/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/composite/CompositeCreationPerformanceTest.java new file mode 100644 index 0000000..449ecf4 --- /dev/null +++ b/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/composite/CompositeCreationPerformanceTest.java @@ -0,0 +1,287 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.polygene.test.performance.runtime.composite; + +import org.apache.polygene.api.activation.ActivationException; +import org.apache.polygene.api.composite.TransientBuilderFactory; +import org.apache.polygene.api.composite.TransientComposite; +import org.apache.polygene.api.object.ObjectFactory; +import org.apache.polygene.api.value.ValueBuilderFactory; +import org.apache.polygene.api.value.ValueComposite; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.bootstrap.SingletonAssembler; +import org.junit.Test; + +/** + * Tests performance of new composite creation. + */ +public class CompositeCreationPerformanceTest +{ + @Test + public void newInstanceForRegisteredCompositePerformance() + throws ActivationException, AssemblyException, InterruptedException + { + SingletonAssembler assembler = new SingletonAssembler() + { + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + module.transients( AnyComposite.class ); + module.objects( AnyObject.class ); + module.values( AnyValue.class ); + } + }; + int warmups = 10; + int runs = 20; + long waitBeforeRun = 1000; + long waitBetweenRuns = 500; + long timeForJavaObject = 0; + { + // Warmup + for( int i = 0; i < warmups; i++ ) + { + testJavaObjectCreationPerformance( false ); + } + Thread.sleep( waitBeforeRun ); + // Run + for( int i = 0; i < runs; i++ ) + { + timeForJavaObject += testJavaObjectCreationPerformance( true ); + Thread.sleep( waitBetweenRuns ); + } + timeForJavaObject = timeForJavaObject / runs; + } + long timeForTransientComposite = 0; + { + TransientBuilderFactory module = assembler.module(); + // Warmup + for( int i = 0; i < warmups; i++ ) + { + testCompositeCreationPerformance( module, false ); + } + Thread.sleep( waitBeforeRun ); + // Run + for( int i = 0; i < runs; i++ ) + { + timeForTransientComposite += testCompositeCreationPerformance( module, true ); + Thread.sleep( waitBetweenRuns ); + } + timeForTransientComposite = timeForTransientComposite / runs; + } + long timeForManagedObject = 0; + { + ObjectFactory objectFactory = assembler.module(); + // Warmup + for( int i = 0; i < warmups; i++ ) + { + testObjectCreationPerformance( objectFactory, false ); + } + Thread.sleep( waitBeforeRun ); + // Run + for( int i = 0; i < runs; i++ ) + { + timeForManagedObject += testObjectCreationPerformance( objectFactory, true ); + Thread.sleep( waitBetweenRuns ); + } + timeForManagedObject = timeForManagedObject / runs; + } + long timeForValueComposite = 0; + { + ValueBuilderFactory valueBuilderFactory = assembler.module(); + // Warmup + for( int i = 0; i < warmups; i++ ) + { + testValueCreationPerformance( valueBuilderFactory, false ); + } + Thread.sleep( waitBeforeRun ); + // Run + for( int i = 0; i < runs; i++ ) + { + timeForValueComposite += testValueCreationPerformance( valueBuilderFactory, true ); + Thread.sleep( waitBetweenRuns ); + } + timeForValueComposite = timeForValueComposite / runs; + } + + long timeForTransientCompositeBuilder = 0; + { + TransientBuilderFactory module = assembler.module(); + // Warmup + for( int i = 0; i < warmups; i++ ) + { + testCompositeCreationWithBuilderPerformance( module, false ); + } + Thread.sleep( waitBeforeRun ); + // Run + for( int i = 0; i < runs; i++ ) + { + timeForTransientCompositeBuilder += testCompositeCreationWithBuilderPerformance( module, true ); + Thread.sleep( waitBetweenRuns ); + } + timeForTransientCompositeBuilder = timeForTransientCompositeBuilder / runs; + } + long timeForValueCompositeBuilder = 0; + { + ValueBuilderFactory valueBuilderFactory = assembler.module(); + // Warmup + for( int i = 0; i < warmups; i++ ) + { + testValueCreationWithBuilderPerformance( valueBuilderFactory, false ); + } + Thread.sleep( waitBeforeRun ); + // Run + for( int i = 0; i < runs; i++ ) + { + timeForValueCompositeBuilder += testValueCreationWithBuilderPerformance( valueBuilderFactory, true ); + Thread.sleep( waitBetweenRuns ); + } + timeForValueCompositeBuilder = timeForValueCompositeBuilder / runs; + } + + System.out.println( "----" ); + System.out.println( "Transient: " + ( timeForTransientComposite / timeForJavaObject ) + "x" ); + System.out.println( "TransientBuilder: " + ( timeForTransientCompositeBuilder / timeForJavaObject ) + "x" ); + System.out.println( "Value: " + ( timeForValueComposite / timeForJavaObject ) + "x" ); + System.out.println( "ValueBuilder: " + ( timeForValueCompositeBuilder / timeForJavaObject ) + "x" ); + System.out.println( "Object: " + ( timeForManagedObject / timeForJavaObject ) + "x" ); + } + + private long testCompositeCreationPerformance( TransientBuilderFactory module, boolean run ) + { + long start = System.currentTimeMillis(); + int iter = 1000000; + for( int i = 0; i < iter; i++ ) + { + module.newTransient( AnyComposite.class ); + } + + long end = System.currentTimeMillis(); + long time = 1000000L * ( end - start ) / iter; + if( run ) + { + System.out.println( "Composite Creation Time:" + time + " nanoseconds per composite" ); + } + return time; + } + + private long testCompositeCreationWithBuilderPerformance( TransientBuilderFactory module, boolean run ) + { + long start = System.currentTimeMillis(); + int iter = 1000000; + for( int i = 0; i < iter; i++ ) + { + module.newTransientBuilder( AnyComposite.class ).newInstance(); + } + + long end = System.currentTimeMillis(); + long time = 1000000L * ( end - start ) / iter; + if( run ) + { + System.out.println( "Composite (builder) Creation Time:" + time + " nanoseconds per composite" ); + } + return time; + } + + private long testValueCreationPerformance( ValueBuilderFactory valueBuilderFactory, boolean run ) + { + long start = System.currentTimeMillis(); + int iter = 1000000; + for( int i = 0; i < iter; i++ ) + { + valueBuilderFactory.newValue( AnyValue.class ); + } + + long end = System.currentTimeMillis(); + long time = 1000000L * ( end - start ) / iter; + if( run ) + { + System.out.println( "Value Creation Time:" + time + " nanoseconds per composite" ); + } + return time; + } + + private long testValueCreationWithBuilderPerformance( ValueBuilderFactory valueBuilderFactory, boolean run ) + { + long start = System.currentTimeMillis(); + int iter = 1000000; + for( int i = 0; i < iter; i++ ) + { + valueBuilderFactory.newValueBuilder( AnyValue.class ).newInstance(); + } + + long end = System.currentTimeMillis(); + long time = 1000000L * ( end - start ) / iter; + if( run ) + { + System.out.println( "Value (builder) Creation Time:" + time + " nanoseconds per composite" ); + } + return time; + } + + private long testObjectCreationPerformance( ObjectFactory objectFactory, boolean run ) + { + long start = System.currentTimeMillis(); + int iter = 1000000; + for( int i = 0; i < iter; i++ ) + { + objectFactory.newObject( AnyObject.class ); + } + + long end = System.currentTimeMillis(); + long time = 1000000L * ( end - start ) / iter; + if( run ) + { + System.out.println( "Polygene Object Creation Time:" + time + " nanoseconds per object" ); + } + return time; + } + + private long testJavaObjectCreationPerformance( boolean run ) + { + long start = System.currentTimeMillis(); + int iter = 1000000; + for( int i = 0; i < iter; i++ ) + { + new AnyObject(); + } + + long end = System.currentTimeMillis(); + long time = 1000000L * ( end - start ) / iter; + if( run ) + { + System.out.println( "Java Object Creation Time:" + time + " nanoseconds per object" ); + } + return time; + } + + public interface AnyComposite + extends TransientComposite + { + } + + public interface AnyValue + extends ValueComposite + { + } + + public static class AnyObject + { + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/composite/InvocationPerformanceTest.java ---------------------------------------------------------------------- diff --git a/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/composite/InvocationPerformanceTest.java b/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/composite/InvocationPerformanceTest.java new file mode 100644 index 0000000..c63e33a --- /dev/null +++ b/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/composite/InvocationPerformanceTest.java @@ -0,0 +1,204 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.polygene.test.performance.runtime.composite; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.text.NumberFormat; +import org.junit.Test; +import org.apache.polygene.api.composite.TransientBuilder; +import org.apache.polygene.api.composite.TransientComposite; +import org.apache.polygene.api.concern.ConcernOf; +import org.apache.polygene.api.concern.Concerns; +import org.apache.polygene.api.mixin.Mixins; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.test.AbstractPolygeneTest; + +/** + * Invocation performance test. + * <p> + * Don't forget to add VM value "-server" before running this test! + * </p> + * <p> + * These tests are very sensitive to warmup of JVM, hence the duplication. Often the first round + * is only for getting the code jitted, and the second round is what you want to look at. + * </p> + */ +public class InvocationPerformanceTest + extends AbstractPolygeneTest +{ + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + module.transients( SimpleComposite.class ); + module.transients( SimpleWithTypedConcernComposite.class ); + module.transients( SimpleWithGenericConcernComposite.class ); + } + + @Test + public void testInvokeMixin() + { + // Create instance + TransientBuilder<SimpleComposite> builder = transientBuilderFactory.newTransientBuilder( SimpleComposite.class ); + Simple simple = builder.newInstance(); + + for( int i = 0; i < 60000; i++ ) + { + simple.test(); + } + + int rounds = 10; + for( int i = 0; i < rounds; i++ ) + { + System.gc(); + performanceCheck( simple ); + } + } + + @Test + public void testInvokeMixinWithTypedConcern() + { + // Create instance + Simple simple = transientBuilderFactory.newTransient( SimpleWithTypedConcernComposite.class ); + + for( int i = 0; i < 60000; i++ ) + { + simple.test(); + } + + int rounds = 3; + for( int i = 0; i < rounds; i++ ) + { + performanceCheck( simple ); + } + } + + @Test + public void testInvokeMixinWithGenericConcern() + { + // Create instance + Simple simple = transientBuilderFactory.newTransient( SimpleWithGenericConcernComposite.class ); + + for( int i = 0; i < 60000; i++ ) + { + simple.test(); + } + + int rounds = 3; + for( int i = 0; i < rounds; i++ ) + { + performanceCheck( simple ); + } + } + + @Test + public void testInvokeMixin2() + { + testInvokeMixin(); + } + + @Test + public void testInvokeMixinWithTypedConcern2() + { + testInvokeMixinWithTypedConcern(); + } + + @Test + public void testInvokeMixinWithGenericConcern2() + { + testInvokeMixinWithGenericConcern(); + } + + private void performanceCheck( Simple simple ) + { + long count = 10000000L; + + long start = System.currentTimeMillis(); + for( long i = 0; i < count; i++ ) + { + simple.test(); + } + long end = System.currentTimeMillis(); + long time = end - start; + long callsPerSecond = ( count / time ) * 1000; + System.out.println( "Calls per second: " + NumberFormat.getIntegerInstance().format( callsPerSecond ) ); + } + + @Mixins( SimpleMixin.class ) + @Concerns( SimpleTypedConcern.class ) + public interface SimpleWithTypedConcernComposite + extends Simple, TransientComposite + { + } + + @Mixins( SimpleMixin.class ) + @Concerns( SimpleGenericConcern.class ) + public interface SimpleWithGenericConcernComposite + extends Simple, TransientComposite + { + } + + @Mixins( SimpleMixin.class ) + public interface SimpleComposite + extends Simple, TransientComposite + { + } + + public interface Simple + { + public void test(); + } + + public static class SimpleMixin + implements Simple + { + long count = 0; + + @Override + public void test() + { + count++; // Do nothing + } + } + + public static class SimpleTypedConcern + extends ConcernOf<Simple> + implements Simple + { + @Override + public void test() + { + next.test(); + } + } + + public static class SimpleGenericConcern + extends ConcernOf<InvocationHandler> + implements InvocationHandler + { + @Override + public Object invoke( Object o, Method method, Object[] objects ) + throws Throwable + { + return next.invoke( o, method, objects ); + } + } + +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/composite/PropertyMixinInvocationPerformanceTest.java ---------------------------------------------------------------------- diff --git a/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/composite/PropertyMixinInvocationPerformanceTest.java b/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/composite/PropertyMixinInvocationPerformanceTest.java new file mode 100644 index 0000000..7508fe2 --- /dev/null +++ b/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/composite/PropertyMixinInvocationPerformanceTest.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.polygene.test.performance.runtime.composite; + +import java.text.NumberFormat; +import java.util.Locale; +import org.junit.Test; +import org.apache.polygene.api.common.Optional; +import org.apache.polygene.api.composite.TransientBuilder; +import org.apache.polygene.api.composite.TransientComposite; +import org.apache.polygene.api.injection.scope.State; +import org.apache.polygene.api.mixin.Mixins; +import org.apache.polygene.api.property.Property; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.test.AbstractPolygeneTest; + +/** + * PropertyMixin invocation performance test. + * <p> + * Don't forget to add VM value "-server" before running this test! + * </p> + */ +public class PropertyMixinInvocationPerformanceTest + extends AbstractPolygeneTest +{ + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + module.transients( SimpleComposite.class ); + module.transients( SimpleComposite2.class ); + } + + @Test + public void testNewInstance() + { + { + TransientBuilder<SimpleComposite> builder = transientBuilderFactory.newTransientBuilder( SimpleComposite.class ); + SimpleComposite simple = builder.newInstance(); + + int rounds = 1; + for( int i = 0; i < rounds; i++ ) + { + performanceCheck( simple ); + } + } + + { + TransientBuilder<SimpleComposite> builder = transientBuilderFactory.newTransientBuilder( SimpleComposite.class ); + SimpleComposite simple = builder.newInstance(); + + int rounds = 1; + for( int i = 0; i < rounds; i++ ) + { + performanceCheck( simple ); + } + } + } + + private void performanceCheck( SimpleComposite simple ) + { + long count = 10000000L; + + { + long start = System.currentTimeMillis(); + for( long i = 0; i < count; i++ ) + { + simple.test(); + } + long end = System.currentTimeMillis(); + long time = end - start; + long callsPerSecond = ( count / time ) * 1000; + System.out.println( "Accesses per second: " + + NumberFormat.getIntegerInstance( Locale.US ).format( callsPerSecond ) ); + } + + { + long start = System.currentTimeMillis(); + for( long i = 0; i < count; i++ ) + { + simple.test().get(); + } + long end = System.currentTimeMillis(); + long time = end - start; + long callsPerSecond = ( count / time ) * 1000; + System.out.println( "Gets per second: " + + NumberFormat.getIntegerInstance( Locale.US ).format( callsPerSecond ) ); + } + } + + public interface SimpleComposite + extends TransientComposite + { + @Optional + Property<String> test(); + } + + @Mixins( SimpleMixin.class ) + public interface SimpleComposite2 + extends SimpleComposite + { + } + + public abstract static class SimpleMixin + implements SimpleComposite2 + { + @State + Property<String> test; + + @Override + public Property<String> test() + { + return test; + } + } + +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/object/ObjectCreationPerformanceTest.java ---------------------------------------------------------------------- diff --git a/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/object/ObjectCreationPerformanceTest.java b/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/object/ObjectCreationPerformanceTest.java new file mode 100644 index 0000000..b995770 --- /dev/null +++ b/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/object/ObjectCreationPerformanceTest.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.polygene.test.performance.runtime.object; + +import org.junit.Test; +import org.apache.polygene.api.activation.ActivationException; +import org.apache.polygene.api.object.ObjectFactory; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.bootstrap.SingletonAssembler; + +/** + * Tests performance of new object creation. + */ +public class ObjectCreationPerformanceTest +{ + + @Test + public void newInstanceForRegisteredObjectPerformance() + throws ActivationException, AssemblyException + { + SingletonAssembler assembler = new SingletonAssembler() + { + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + module.objects( AnyObject.class ); + } + }; + ObjectFactory objectFactory = assembler.module(); + for( int i = 0; i < 10; i++ ) + { + testPerformance( objectFactory ); + } + } + + private void testPerformance( ObjectFactory objectFactory ) + { + long start = System.currentTimeMillis(); + int iter = 1000000; + for( int i = 0; i < iter; i++ ) + { + objectFactory.newObject( AnyObject.class ); + } + + long end = System.currentTimeMillis(); + System.out.println( end - start ); + } + + public static final class AnyObject + { + } + +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/service/ServiceInvocationPerformanceTest.java ---------------------------------------------------------------------- diff --git a/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/service/ServiceInvocationPerformanceTest.java b/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/service/ServiceInvocationPerformanceTest.java new file mode 100644 index 0000000..c599f6e --- /dev/null +++ b/tests/performance/src/perf/java/org/apache/polygene/test/performance/runtime/service/ServiceInvocationPerformanceTest.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.polygene.test.performance.runtime.service; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.text.NumberFormat; +import junit.framework.TestCase; +import org.apache.polygene.api.injection.scope.Service; +import org.apache.polygene.api.mixin.Mixins; +import org.apache.polygene.api.service.ServiceComposite; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.bootstrap.SingletonAssembler; + +public class ServiceInvocationPerformanceTest + extends TestCase +{ + @Service + ServiceInvocationPerformanceTest.MyService service; + + public void testInjectService() + throws Exception + { + SingletonAssembler assembly = new SingletonAssembler() + { + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + module.services( ServiceInvocationPerformanceTest.MyServiceComposite.class ); + module.objects( ServiceInvocationPerformanceTest.class ); + } + }; + + assembly.module().injectTo( this ); + + // Warmup + for( int i = 0; i < 60000; i++ ) + { + service.test(); + } + + int rounds = 5; + for( int i = 0; i < rounds; i++ ) + { + performanceCheck( service ); + } + } + + private void performanceCheck( MyService simple ) + { + long count = 10000000L; + + long start = System.currentTimeMillis(); + for( long i = 0; i < count; i++ ) + { + simple.test(); + } + long end = System.currentTimeMillis(); + long time = end - start; + long callsPerSecond = ( count / time ) * 1000; + System.out.println( "Calls per second: " + NumberFormat.getIntegerInstance().format( callsPerSecond ) ); + } + + @Mixins( NoopMixin.class ) + public static interface MyServiceComposite + extends ServiceInvocationPerformanceTest.MyService, ServiceComposite + { + } + + public static interface MyService + { + void test(); + } + + public static class MyServiceMixin + implements ServiceInvocationPerformanceTest.MyService + { + @Override + public void test() + { + } + } + + public final static class NoopMixin + implements InvocationHandler + { + @Override + public Object invoke( Object object, Method method, Object[] objects ) + throws Throwable + { + return null; + } + } + +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/tests/performance/src/perf/java/org/apache/zest/test/performance/entitystore/jdbm/JdbmEntityStorePerformanceTest.java ---------------------------------------------------------------------- diff --git a/tests/performance/src/perf/java/org/apache/zest/test/performance/entitystore/jdbm/JdbmEntityStorePerformanceTest.java b/tests/performance/src/perf/java/org/apache/zest/test/performance/entitystore/jdbm/JdbmEntityStorePerformanceTest.java deleted file mode 100644 index 047ffef..0000000 --- a/tests/performance/src/perf/java/org/apache/zest/test/performance/entitystore/jdbm/JdbmEntityStorePerformanceTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.polygene.test.performance.entitystore.jdbm; - -import java.io.File; -import org.apache.derby.iapi.services.io.FileUtil; -import org.apache.polygene.api.common.Visibility; -import org.apache.polygene.bootstrap.Assembler; -import org.apache.polygene.bootstrap.AssemblyException; -import org.apache.polygene.bootstrap.ModuleAssembly; -import org.apache.polygene.cache.ehcache.EhCacheConfiguration; -import org.apache.polygene.cache.ehcache.EhCachePoolService; -import org.apache.polygene.entitystore.jdbm.JdbmConfiguration; -import org.apache.polygene.entitystore.jdbm.assembly.JdbmEntityStoreAssembler; -import org.apache.polygene.test.EntityTestAssembler; -import org.apache.polygene.test.performance.entitystore.AbstractEntityStorePerformanceTest; -import org.apache.polygene.valueserialization.orgjson.OrgJsonValueSerializationAssembler; - -/** - * Performance test for JdbmEntityStoreComposite - */ -public class JdbmEntityStorePerformanceTest - extends AbstractEntityStorePerformanceTest -{ - public JdbmEntityStorePerformanceTest() - { - super( "JdbmEntityStore", createAssembler() ); - } - - private static Assembler createAssembler() - { - return new Assembler() - { - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - new JdbmEntityStoreAssembler().assemble( module ); - new OrgJsonValueSerializationAssembler().assemble( module ); - ModuleAssembly configModule = module.layer().module( "Config" ); - configModule.entities( JdbmConfiguration.class ).visibleIn( Visibility.layer ); - new EntityTestAssembler().assemble( configModule ); - - module.services( EhCachePoolService.class ); - configModule.entities( EhCacheConfiguration.class ).visibleIn( Visibility.layer ); - } - }; - } - - @Override - public void cleanUp() - throws Exception - { - super.cleanUp(); - FileUtil.removeDirectory( new File( "build/tmp/jdbm" ) ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/tests/performance/src/perf/java/org/apache/zest/test/performance/entitystore/memory/MemoryEntityStorePerformanceTest.java ---------------------------------------------------------------------- diff --git a/tests/performance/src/perf/java/org/apache/zest/test/performance/entitystore/memory/MemoryEntityStorePerformanceTest.java b/tests/performance/src/perf/java/org/apache/zest/test/performance/entitystore/memory/MemoryEntityStorePerformanceTest.java deleted file mode 100644 index bd664e1..0000000 --- a/tests/performance/src/perf/java/org/apache/zest/test/performance/entitystore/memory/MemoryEntityStorePerformanceTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.polygene.test.performance.entitystore.memory; - -import org.apache.polygene.api.mixin.Mixins; -import org.apache.polygene.bootstrap.Assembler; -import org.apache.polygene.bootstrap.AssemblyException; -import org.apache.polygene.bootstrap.ModuleAssembly; -import org.apache.polygene.entitystore.memory.assembly.MemoryEntityStoreAssembler; -import org.apache.polygene.entitystore.memory.MemoryEntityStoreService; -import org.apache.polygene.spi.entitystore.helpers.MapEntityStoreMixin; -import org.apache.polygene.test.performance.entitystore.AbstractEntityStorePerformanceTest; -import org.apache.polygene.valueserialization.orgjson.OrgJsonValueSerializationAssembler; - -public class MemoryEntityStorePerformanceTest - extends AbstractEntityStorePerformanceTest -{ - - public MemoryEntityStorePerformanceTest() - { - super( "MemoryEntityStore", createAssembler() ); - } - - private static Assembler createAssembler() - { - return new Assembler() - { - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - new MemoryEntityStoreAssembler().assemble( module ); - new OrgJsonValueSerializationAssembler().assemble( module ); - } - }; - } - - // Alternate variant that uses the standard MapEntityStore - @Mixins( MapEntityStoreMixin.class ) - interface MemoryEntityStoreService2 - extends MemoryEntityStoreService - { - } - -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/tests/performance/src/perf/java/org/apache/zest/test/performance/entitystore/sql/DerbySQLEntityStorePerformanceTest.java ---------------------------------------------------------------------- diff --git a/tests/performance/src/perf/java/org/apache/zest/test/performance/entitystore/sql/DerbySQLEntityStorePerformanceTest.java b/tests/performance/src/perf/java/org/apache/zest/test/performance/entitystore/sql/DerbySQLEntityStorePerformanceTest.java deleted file mode 100644 index d1ea720..0000000 --- a/tests/performance/src/perf/java/org/apache/zest/test/performance/entitystore/sql/DerbySQLEntityStorePerformanceTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.polygene.test.performance.entitystore.sql; - -import java.sql.Connection; -import java.sql.Statement; -import javax.sql.DataSource; -import org.apache.polygene.api.common.Visibility; -import org.apache.polygene.api.unitofwork.UnitOfWork; -import org.apache.polygene.api.usecase.UsecaseBuilder; -import org.apache.polygene.bootstrap.Assembler; -import org.apache.polygene.bootstrap.AssemblyException; -import org.apache.polygene.bootstrap.ModuleAssembly; -import org.apache.polygene.entitystore.sql.assembly.DerbySQLEntityStoreAssembler; -import org.apache.polygene.entitystore.sql.internal.SQLs; -import org.apache.polygene.library.sql.assembly.DataSourceAssembler; -import org.apache.polygene.library.sql.common.SQLConfiguration; -import org.apache.polygene.library.sql.common.SQLUtil; -import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler; -import org.apache.polygene.test.EntityTestAssembler; -import org.apache.polygene.test.performance.entitystore.AbstractEntityStorePerformanceTest; -import org.apache.polygene.valueserialization.orgjson.OrgJsonValueSerializationAssembler; - -/** - * Performance test for DerbySQLEntityStore. - */ -public class DerbySQLEntityStorePerformanceTest - extends AbstractEntityStorePerformanceTest -{ - - public DerbySQLEntityStorePerformanceTest() - { - super( "DerbySQLEntityStore", createAssembler() ); - } - - private static Assembler createAssembler() - { - return new Assembler() - { - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - ModuleAssembly config = module.layer().module( "config" ); - new EntityTestAssembler().assemble( config ); - - new OrgJsonValueSerializationAssembler().assemble( module ); - - // DataSourceService - new DBCPDataSourceServiceAssembler(). - identifiedBy( "derby-datasource-service" ). - visibleIn( Visibility.module ). - withConfig( config, Visibility.layer ). - assemble( module ); - - // DataSource - new DataSourceAssembler(). - withDataSourceServiceIdentity( "derby-datasource-service" ). - identifiedBy( "derby-datasource" ). - withCircuitBreaker(). - assemble( module ); - - // SQL EntityStore - new DerbySQLEntityStoreAssembler(). - withConfig( config, Visibility.layer ). - assemble( module ); - } - }; - } - - @Override - protected void cleanUp() - throws Exception - { - if( uowf == null ) - { - return; - } - UnitOfWork uow = this.uowf.newUnitOfWork( UsecaseBuilder.newUsecase( - "Delete " + getClass().getSimpleName() + " test data" ) ); - try - { - SQLConfiguration config = uow.get( SQLConfiguration.class, - DerbySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY ); - Connection connection = serviceFinder.findService( DataSource.class ).get().getConnection(); - 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(); - super.cleanUp(); - } - } - -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/tests/performance/src/perf/java/org/apache/zest/test/performance/entitystore/sql/PostgreSQLEntityStorePerformanceTest.java ---------------------------------------------------------------------- diff --git a/tests/performance/src/perf/java/org/apache/zest/test/performance/entitystore/sql/PostgreSQLEntityStorePerformanceTest.java b/tests/performance/src/perf/java/org/apache/zest/test/performance/entitystore/sql/PostgreSQLEntityStorePerformanceTest.java deleted file mode 100644 index e0c2bcc..0000000 --- a/tests/performance/src/perf/java/org/apache/zest/test/performance/entitystore/sql/PostgreSQLEntityStorePerformanceTest.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.polygene.test.performance.entitystore.sql; - -import java.sql.Connection; -import java.sql.Statement; -import org.junit.Ignore; -import org.apache.polygene.api.common.Visibility; -import org.apache.polygene.api.structure.Application; -import org.apache.polygene.api.structure.Module; -import org.apache.polygene.api.unitofwork.UnitOfWork; -import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; -import org.apache.polygene.bootstrap.ApplicationAssemblerAdapter; -import org.apache.polygene.bootstrap.Assembler; -import org.apache.polygene.bootstrap.AssemblyException; -import org.apache.polygene.bootstrap.Energy4Java; -import org.apache.polygene.bootstrap.ModuleAssembly; -import org.apache.polygene.entitystore.memory.MemoryEntityStoreService; -import org.apache.polygene.entitystore.sql.assembly.PostgreSQLEntityStoreAssembler; -import org.apache.polygene.entitystore.sql.internal.SQLs; -import org.apache.polygene.library.sql.assembly.DataSourceAssembler; -import org.apache.polygene.library.sql.common.SQLConfiguration; -import org.apache.polygene.library.sql.common.SQLUtil; -import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler; -import org.apache.polygene.test.performance.entitystore.AbstractEntityStorePerformanceTest; - -/** - * Performance test for PostgreSQLEntityStore. - * <p> - * WARN This test is deactivated on purpose, please do not commit it activated. - * </p> - * <p> - * To run it see PostgreSQLEntityStoreTest. - * </p> - */ -@Ignore( "WARN Tearing down this test is broken!" ) -public class PostgreSQLEntityStorePerformanceTest - extends AbstractEntityStorePerformanceTest -{ - - public PostgreSQLEntityStorePerformanceTest() - { - super( "PostgreSQLEntityStore", 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 ); - } - - }; - } - - @Override - protected void cleanUp() - throws Exception - { - try - { - super.cleanUp(); - } - finally - { - - Energy4Java polygene = new Energy4Java(); - Assembler[][][] assemblers = new Assembler[][][] - { - { - { - createAssembler() - } - } - }; - Application application = polygene.newApplication( new ApplicationAssemblerAdapter( assemblers ) - { - } ); - application.activate(); - - Module moduleInstance = application.findModule( "Layer 1", "config" ); - UnitOfWorkFactory uowf = moduleInstance.unitOfWorkFactory(); - UnitOfWork uow = uowf.newUnitOfWork(); - try - { - SQLConfiguration config = uow.get( SQLConfiguration.class, - PostgreSQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY ); - // TODO fix AbstractEntityStorePerformanceTest to extend from AbstractPolygeneTest - Connection connection = null; // SQLUtil.getConnection( this.serviceLocator ); - 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(); - } - } - } - -}
