0 Replies Latest reply on Oct 24, 2016 9:25 AM by xtrezz

    Arquillian spring extension javaconfig is initializing context for each test

    xtrezz

      I am trying to test some rest interfaces using Arquillian. I have a class

       

      @RunWith(Arquillian.class)
      @SpringAnnotationConfiguration(classes = PersistenceTestConfig.class)
      public class RestTest{...}

       

      In this clas i have a deployment method and several tests for now. The deployment is shared for all tests but context is initialized for each test.

      I have tried with this @ContextLifeCycle(ContextLifeCycleMode.TEST_CASE) annotation on test class but i'm facing the same issue.

      How can i configure arquillian to use same context for all tests ?

       

      This happens all the time(each test):

       

      2016-10-19 15:18:46 INFO  [anonymousUser] [127.0.0.1] AnnotationConfigApplicationContext:982 - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@3c8d5c05: startup date [Wed Oct 19 15:18:46 EEST 2016]; root of context hierarchy
      2016-10-19 15:18:46 INFO  [anonymousUser] [127.0.0.1] LocalContainerEntityManagerFactoryBean:551 - Closing JPA EntityManagerFactory for persistence unit 'persistenceUnit'
      2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] AnnotationConfigApplicationContext:581 - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2c0a0685: startup date [Wed Oct 19 15:18:47 EEST 2016]; root of context hierarchy
      2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] AutowiredAnnotationBeanPostProcessor:155 - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
      2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] PostProcessorRegistrationDelegate$BeanPostProcessorChecker:328 - Bean 'persistenceTestConfig' of type [class de.awinta.licensing.server.core.config.PersistenceTestConfig] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
      2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] AbstractJPAConfig:114 - [PERSISTENCE CONFIG] - Initialize Spring Bean: exceptionTranslation
      2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] AbstractJPAConfig:89 - [PERSISTENCE CONFIG] - Initialize Spring Bean: entityManagerFactory
      2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] AbstractJPAConfig:61 - [PERSISTENCE CONFIG] - Initialize Spring Bean: dataSource
      2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] LocalContainerEntityManagerFactoryBean:334 - Building JPA container EntityManagerFactory for persistence unit 'persistenceUnit'
      2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] LogHelper:46 - HHH000204: Processing PersistenceUnitInfo [
        name
      : persistenceUnit
        
      ...]
      2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] AbstractPoolBackedDataSource:522 - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 10, acquireRetryAttempts -> 10, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 3000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge7xl9j1paaqpcnkbsaf|1cb8ec46, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> org.h2.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge7xl9j1paaqpcnkbsaf|1cb8ec46, idleConnectionTestPeriod -> 3000, initialPoolSize -> 3, jdbcUrl -> jdbc:h2:mem:arquillian, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 100, maxStatements -> 1000, maxStatementsPerConnection -> 0, minPoolSize -> 10, numHelperThreads -> 3, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
      2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] Dialect:145 - HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
      2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] LobCreatorBuilder:123 - HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
      2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] ASTQueryTranslatorFactory:47 - HHH000397: Using ASTQueryTranslatorFactory
      2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] SchemaUpdate:207 - HHH000228: Running hbm2ddl schema update
      2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] SchemaUpdate:218 - HHH000102: Fetching database metadata
      2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] SchemaUpdate:230 - HHH000396: Updating schema
      2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] TableMetadata:65 - HHH000261: Table found: ARQUILLIAN.PUBLIC.LS_DB_UPDATE
      2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] TableMetadata:66 - HHH000037: Columns: [id, last_modified_time, update_file, run_date, created_time]

       

      On arquillian website i found this:

       

      Previous versions had one common drawback, each test were running using a separate instance of Spring’s ApplicationContext. Although the ApplicationContext were destroyed and all of its resources were freed after the test execution, this brought additional overhead for each test. From now on the developer has the control whether he want to create only a single context per test case or to have each test run with a new “clean” context, which in some situation might be handy. By default the context will be created only once, but it can easly be changed by adding the @ContextLifeCycle annotation to the test case.

       

      What am i doing wrong ?

       

      Thabk you