Skip to content

Commit

Permalink
fixed tests for mysql, cleaned up configuration, switched to annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Mar 6, 2018
1 parent d517a43 commit a763f04
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 152 deletions.
3 changes: 2 additions & 1 deletion repo/repo-sql-impl-test/sql-procedures/mysql.sql
Expand Up @@ -38,7 +38,6 @@ DETERMINISTIC
DELETE FROM m_assignment_reference;
DELETE FROM m_assignment_policy_situation;
DELETE FROM m_assignment;
DELETE FROM m_exclusion;
DELETE FROM m_connector_target_system;
DELETE FROM m_connector;
DELETE FROM m_connector_host;
Expand Down Expand Up @@ -74,6 +73,8 @@ DETERMINISTIC
DELETE FROM m_form;
DELETE FROM m_case;
DELETE FROM m_function_library;
DELETE FROM m_ext_item;
DELETE FROM m_object_subtype;
DELETE FROM m_object;

RETURN run;
Expand Down
Expand Up @@ -105,7 +105,9 @@ public void test100UpdateGivenNameAndActivation() throws Exception {
queryCountInterceptor.startCounter();
repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result);

AssertJUnit.assertEquals(4, queryCountInterceptor.getQueryCount());
if (baseHelper.getConfiguration().isUsingH2()) {
AssertJUnit.assertEquals(4, queryCountInterceptor.getQueryCount());
}

Session session = factory.openSession();
try {
Expand Down Expand Up @@ -138,7 +140,9 @@ public void test115DeleteActivation() throws Exception {
queryCountInterceptor.startCounter();
repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result);

AssertJUnit.assertEquals(3, queryCountInterceptor.getQueryCount());
if (baseHelper.getConfiguration().isUsingH2()) {
AssertJUnit.assertEquals(3, queryCountInterceptor.getQueryCount());
}

Session session = factory.openSession();
try {
Expand All @@ -151,7 +155,7 @@ public void test115DeleteActivation() throws Exception {
}

@Test
public void test110ReplaceExtensionProperty() throws Exception {
public void test110ReplaceNonIndexedExtensionProperty() throws Exception {
OperationResult result = new OperationResult("test110ReplaceExtensionProperty");

ObjectDelta delta = ObjectDelta.createEmptyModifyDelta(UserType.class, userOid, prismContext);
Expand All @@ -160,7 +164,9 @@ public void test110ReplaceExtensionProperty() throws Exception {
queryCountInterceptor.startCounter();
repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result);

AssertJUnit.assertEquals(2, queryCountInterceptor.getQueryCount());
if (baseHelper.getConfiguration().isUsingH2()) {
AssertJUnit.assertEquals(3, queryCountInterceptor.getQueryCount());
}

Session session = factory.openSession();
try {
Expand Down Expand Up @@ -210,7 +216,9 @@ public void test120AddExtensionProperty() throws Exception {
queryCountInterceptor.startCounter();
repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result);

AssertJUnit.assertEquals(6, queryCountInterceptor.getQueryCount());
if (baseHelper.getConfiguration().isUsingH2()) {
AssertJUnit.assertEquals(6, queryCountInterceptor.getQueryCount());
}

Session session = factory.openSession();
try {
Expand Down Expand Up @@ -247,7 +255,9 @@ public void test140AddDeleteAssignment() throws Exception {
// todo this should be only 7 queries, these two aren't expected:
// select createappr0_.owner_id as owner_id1_14_0_, createappr0_.owner_owner_oid as owner_ow2_14_0_, createappr0_.reference_type as referenc3_14_0_, createappr0_.relation as relation4_14_0_, createappr0_.targetOid as targetOi5_14_0_, createappr0_.owner_id as owner_id1_14_1_, createappr0_.owner_owner_oid as owner_ow2_14_1_, createappr0_.reference_type as referenc3_14_1_, createappr0_.relation as relation4_14_1_, createappr0_.targetOid as targetOi5_14_1_, createappr0_.targetType as targetTy6_14_1_ from m_assignment_reference createappr0_ where ( createappr0_.reference_type= 0) and createappr0_.owner_id=? and createappr0_.owner_owner_oid=?
// select modifyappr0_.owner_id as owner_id1_14_0_, modifyappr0_.owner_owner_oid as owner_ow2_14_0_, modifyappr0_.reference_type as referenc3_14_0_, modifyappr0_.relation as relation4_14_0_, modifyappr0_.targetOid as targetOi5_14_0_, modifyappr0_.owner_id as owner_id1_14_1_, modifyappr0_.owner_owner_oid as owner_ow2_14_1_, modifyappr0_.reference_type as referenc3_14_1_, modifyappr0_.relation as relation4_14_1_, modifyappr0_.targetOid as targetOi5_14_1_, modifyappr0_.targetType as targetTy6_14_1_ from m_assignment_reference modifyappr0_ where ( modifyappr0_.reference_type= 1) and modifyappr0_.owner_id=? and modifyappr0_.owner_owner_oid=?
AssertJUnit.assertEquals(9, queryCountInterceptor.getQueryCount());
if (baseHelper.getConfiguration().isUsingH2()) {
AssertJUnit.assertEquals(9, queryCountInterceptor.getQueryCount());
}

Session session = factory.openSession();
try {
Expand Down Expand Up @@ -284,7 +294,9 @@ public void test145AddActivationToAssignment() throws Exception {
queryCountInterceptor.startCounter();
repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result);

AssertJUnit.assertEquals(4, queryCountInterceptor.getQueryCount());
if (baseHelper.getConfiguration().isUsingH2()) {
AssertJUnit.assertEquals(4, queryCountInterceptor.getQueryCount());
}

Session session = factory.openSession();
try {
Expand Down Expand Up @@ -317,7 +329,9 @@ public void test150AddDeleteLinkRef() throws Exception {
queryCountInterceptor.startCounter();
repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result);

AssertJUnit.assertEquals(5, queryCountInterceptor.getQueryCount());
if (baseHelper.getConfiguration().isUsingH2()) {
AssertJUnit.assertEquals(5, queryCountInterceptor.getQueryCount());
}

Session session = factory.openSession();
try {
Expand Down Expand Up @@ -345,7 +359,9 @@ public void test160AddDeleteParentRef() throws Exception {
queryCountInterceptor.startCounter();
repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result);

AssertJUnit.assertEquals(5, queryCountInterceptor.getQueryCount());
if (baseHelper.getConfiguration().isUsingH2()) {
AssertJUnit.assertEquals(5, queryCountInterceptor.getQueryCount());
}

Session session = factory.openSession();
try {
Expand Down Expand Up @@ -403,7 +419,9 @@ public void test170ModifyEmployeeTypeAndMetadataCreateChannel() throws Exception
queryCountInterceptor.startCounter();
repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result);

AssertJUnit.assertEquals(4, queryCountInterceptor.getQueryCount());
if (baseHelper.getConfiguration().isUsingH2()) {
AssertJUnit.assertEquals(4, queryCountInterceptor.getQueryCount());
}

Session session = factory.openSession();
RUser u = session.get(RUser.class, userOid);
Expand All @@ -427,7 +445,9 @@ public void test180ModifyMetadataChannel() throws Exception {
queryCountInterceptor.startCounter();
repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result);

AssertJUnit.assertEquals(4, queryCountInterceptor.getQueryCount());
if (baseHelper.getConfiguration().isUsingH2()) {
AssertJUnit.assertEquals(4, queryCountInterceptor.getQueryCount());
}

Session session = factory.openSession();
RUser u = session.get(RUser.class, userOid);
Expand Down
Expand Up @@ -40,7 +40,7 @@ It fakes JNDI context with simple H2 file DataSource.


<bean id="sampleJNDIDataSourceFromConfig" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close"
lazy-init="false">
lazy-init="true">
<property name="driverClassName" value="#{testSqlRepositoryFactory.sqlConfiguration.driverClassName}"/>
<property name="jdbcUrl" value="#{testSqlRepositoryFactory.sqlConfiguration.jdbcUrl}"/>
<property name="username" value="#{testSqlRepositoryFactory.sqlConfiguration.jdbcUsername}"/>
Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.apache.commons.lang.StringUtils;
import org.springframework.jndi.JndiObjectFactoryBean;

import javax.annotation.PreDestroy;
import javax.naming.NamingException;
import javax.sql.DataSource;
import java.io.Closeable;
Expand Down Expand Up @@ -77,7 +78,7 @@ private DataSource createJNDIDataSource() throws IllegalArgumentException, Namin
return (DataSource) factory.getObject();
}

public HikariConfig createConfig() {
private HikariConfig createConfig() {
HikariConfig config = new HikariConfig();

config.setDriverClassName(configuration.getDriverClassName());
Expand All @@ -90,6 +91,8 @@ public HikariConfig createConfig() {
config.setMinimumIdle(configuration.getMinPoolSize());
config.setMaximumPoolSize(configuration.getMaxPoolSize());

// config.setAutoCommit(false);

TransactionIsolation ti = configuration.getTransactionIsolation();
if (ti != null) {
config.setTransactionIsolation("TRANSACTION_" + ti.name());
Expand All @@ -99,18 +102,18 @@ public HikariConfig createConfig() {
// config.setConnectionTesterClassName(MidPointConnectionTester.class.getName());

if (configuration.isUsingMySqlCompatible()) {
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");

config.addDataSourceProperty("useServerPrepStmts", "true");
config.addDataSourceProperty("useLocalSessionState", "true");
config.addDataSourceProperty("useLocalTransactionState", "true");
config.addDataSourceProperty("rewriteBatchedStatements", "true");
config.addDataSourceProperty("cacheResultSetMetadata", "true");
config.addDataSourceProperty("cacheServerConfiguration", "true");
config.addDataSourceProperty("elideSetAutoCommits", "true");
config.addDataSourceProperty("maintainTimeStats", "false");
// config.addDataSourceProperty("cachePrepStmts", "true");
// config.addDataSourceProperty("prepStmtCacheSize", "250");
// config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
//
// config.addDataSourceProperty("useServerPrepStmts", "true");
// config.addDataSourceProperty("useLocalSessionState", "true");
// config.addDataSourceProperty("useLocalTransactionState", "true");
// config.addDataSourceProperty("rewriteBatchedStatements", "true");
// config.addDataSourceProperty("cacheResultSetMetadata", "true");
// config.addDataSourceProperty("cacheServerConfiguration", "true");
// config.addDataSourceProperty("elideSetAutoCommits", "true");
// config.addDataSourceProperty("maintainTimeStats", "false");
}

return config;
Expand All @@ -122,6 +125,7 @@ private DataSource createDataSourceInternal() {
return new HikariDataSource(config);
}

@PreDestroy
public void destroy() throws IOException {
if (dataSource instanceof Closeable) {
((Closeable) dataSource).close();
Expand Down
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2010-2018 Evolveum
*
* Licensed 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 com.evolveum.midpoint.repo.sql;

import com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException;
import com.evolveum.midpoint.repo.sql.util.EntityStateInterceptor;
import com.evolveum.midpoint.repo.sql.util.MidPointImplicitNamingStrategy;
import com.evolveum.midpoint.repo.sql.util.MidPointPhysicalNamingStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;

import java.util.Properties;

/**
* Created by Viliam Repan (lazyman).
*/
@Configuration
public class SqlRepositoryBeanConfig {

@Autowired
private SqlRepositoryFactory sqlRepositoryFactory;

@Bean
public DataSourceFactory dataSourceFactory() {
DataSourceFactory df = new DataSourceFactory();
df.setConfiguration(sqlRepositoryFactory.getSqlConfiguration());

return df;
}

@Bean
public MidPointImplicitNamingStrategy midPointImplicitNamingStrategy() {
return new MidPointImplicitNamingStrategy();
}

@Bean
public MidPointPhysicalNamingStrategy midPointPhysicalNamingStrategy() {
return new MidPointPhysicalNamingStrategy();
}

@Bean
public EntityStateInterceptor entityStateInterceptor() {
return new EntityStateInterceptor();
}

@Bean
public LocalSessionFactoryBean sessionFactory() throws RepositoryServiceFactoryException {
LocalSessionFactoryBean bean = new LocalSessionFactoryBean();

DataSourceFactory dataSourceFactory = dataSourceFactory();
SqlRepositoryConfiguration configuration = sqlRepositoryFactory.getSqlConfiguration();

bean.setDataSource(dataSourceFactory.createDataSource());

Properties hibernateProperties = new Properties();
hibernateProperties.setProperty("hibernate.dialect", configuration.getHibernateDialect());
hibernateProperties.setProperty("hibernate.hbm2ddl.auto", configuration.getHibernateHbm2ddl());
hibernateProperties.setProperty("hibernate.id.new_generator_mappings", "true");
hibernateProperties.setProperty("hibernate.jdbc.batch_size", "20");
hibernateProperties.setProperty("javax.persistence.validation.mode", "none");
hibernateProperties.setProperty("hibernate.transaction.coordinator_class", "jdbc");
hibernateProperties.setProperty("hibernate.hql.bulk_id_strategy", "org.hibernate.hql.spi.id.inline.InlineIdsOrClauseBulkIdStrategy");

bean.setHibernateProperties(hibernateProperties);
bean.setImplicitNamingStrategy(midPointImplicitNamingStrategy());
bean.setPhysicalNamingStrategy(midPointPhysicalNamingStrategy());
bean.setAnnotatedPackages("com.evolveum.midpoint.repo.sql.type");
bean.setPackagesToScan(
"com.evolveum.midpoint.repo.sql.data.common",
"com.evolveum.midpoint.repo.sql.data.common.any",
"com.evolveum.midpoint.repo.sql.data.common.container",
"com.evolveum.midpoint.repo.sql.data.common.embedded",
"com.evolveum.midpoint.repo.sql.data.common.enums",
"com.evolveum.midpoint.repo.sql.data.common.id",
"com.evolveum.midpoint.repo.sql.data.common.other",
"com.evolveum.midpoint.repo.sql.data.common.type",
"com.evolveum.midpoint.repo.sql.data.audit");
bean.setEntityInterceptor(entityStateInterceptor());

return bean;
}

@Bean
public HibernateTransactionManager transactionManager() throws RepositoryServiceFactoryException {
HibernateTransactionManager htm = new HibernateTransactionManager();
htm.setSessionFactory(sessionFactory().getObject());

return htm;
}
}

This file was deleted.

0 comments on commit a763f04

Please sign in to comment.