-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for new repo in integration tests, first test passes
Similar to old repo, there is TestSqaleRepositoryBeanConfig, which also takes care of DB cleanup that is required for integration tests. Config XML file for StartupConfiguration in Spring test XML config can be overridden like: -Dtest.config.file=test-config-new-repo.xml
- Loading branch information
Showing
5 changed files
with
194 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...t/src/main/java/com/evolveum/midpoint/repo/sql/testing/TestSqaleRepositoryBeanConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright (C) 2010-2021 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
package com.evolveum.midpoint.repo.sql.testing; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import net.ttddyy.dsproxy.listener.ChainListener; | ||
import net.ttddyy.dsproxy.support.ProxyConfigSpringXmlSupport; | ||
import net.ttddyy.dsproxy.support.ProxyDataSource; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | ||
import org.springframework.context.annotation.*; | ||
|
||
import com.evolveum.midpoint.repo.api.SqlPerformanceMonitorsCollection; | ||
import com.evolveum.midpoint.repo.sqale.SqaleRepoContext; | ||
import com.evolveum.midpoint.repo.sqale.SqaleRepositoryBeanConfig; | ||
import com.evolveum.midpoint.repo.sqale.SqaleRepositoryService; | ||
import com.evolveum.midpoint.repo.sqlbase.JdbcSession; | ||
import com.evolveum.midpoint.util.logging.Trace; | ||
import com.evolveum.midpoint.util.logging.TraceManager; | ||
|
||
/** | ||
* Test configuration for new repository, adding test query listener and database cleanup. | ||
*/ | ||
@Configuration | ||
@ConditionalOnExpression("#{midpointConfiguration.keyMatches(" | ||
+ "'midpoint.repository.repositoryServiceFactoryClass'," | ||
+ " '(?i)com\\.evolveum\\.midpoint\\.repo\\.sqale\\..*', '(?i)s[qc]ale')" | ||
+ "|| midpointConfiguration.keyMatches(" | ||
+ "'midpoint.repository.type'," | ||
+ " '(?i)com\\.evolveum\\.midpoint\\.repo\\.sqale\\..*', '(?i)s[qc]ale')" | ||
+ "}") | ||
@ComponentScan | ||
@Import(SqaleRepositoryBeanConfig.class) | ||
public class TestSqaleRepositoryBeanConfig { | ||
|
||
private static final Trace LOGGER = TraceManager.getTrace(TestSqaleRepositoryBeanConfig.class); | ||
|
||
@Bean | ||
public TestQueryListener testQueryListener() { | ||
return new TestQueryListener(); | ||
} | ||
|
||
/** Proxied data source used to collect SQL statements. */ | ||
@Primary | ||
@Bean | ||
public DataSource proxiedTestDataSource( | ||
DataSource dataSource, | ||
TestQueryListener testQueryListener) { | ||
ChainListener chainListener = new ChainListener(); | ||
chainListener.addListener(testQueryListener); | ||
|
||
ProxyConfigSpringXmlSupport proxyConfigSupport = new ProxyConfigSpringXmlSupport(); | ||
proxyConfigSupport.setDataSourceName("my-ds"); | ||
proxyConfigSupport.setQueryListener(chainListener); | ||
|
||
ProxyDataSource bean = new ProxyDataSource(); | ||
bean.setDataSource(dataSource); | ||
bean.setProxyConfig(proxyConfigSupport.create()); | ||
return bean; | ||
} | ||
|
||
@Primary | ||
@Bean | ||
public SqaleRepositoryService repositoryService( | ||
SqaleRepoContext sqlRepoContext, | ||
SqlPerformanceMonitorsCollection sqlPerformanceMonitorsCollection) { | ||
clearDatabase(sqlRepoContext); | ||
|
||
return new SqaleRepositoryService( | ||
sqlRepoContext, | ||
sqlPerformanceMonitorsCollection); | ||
} | ||
|
||
/** | ||
* Taken from `SqaleRepoBaseTest#clearDatabase()` - this is the new repo version of | ||
* TestSqlRepositoryBeanPostProcessor. | ||
*/ | ||
public void clearDatabase(SqaleRepoContext sqlRepoContext) { | ||
LOGGER.info("Postprocessing session factory - removing everything from database if necessary."); | ||
try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startTransaction()) { | ||
// object delete cascades to sub-rows of the "object aggregate" | ||
|
||
jdbcSession.executeStatement("TRUNCATE m_object CASCADE;"); | ||
// truncate does not run ON DELETE trigger, many refs/container tables are not cleaned | ||
jdbcSession.executeStatement("TRUNCATE m_object_oid CASCADE;"); | ||
// but after truncating m_object_oid it cleans all the tables | ||
|
||
/* | ||
Truncates are much faster than this delete probably because it works row by row: | ||
long count = jdbcSession.newDelete(QObjectMapping.INSTANCE.defaultAlias()).execute(); | ||
display("Deleted " + count + " objects from DB"); | ||
*/ | ||
jdbcSession.commit(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
repo/repo-test-util/src/main/resources/test-config-new-repo.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
~ Copyright (C) 2010-2021 Evolveum and contributors | ||
~ | ||
~ This work is dual-licensed under the Apache License 2.0 | ||
~ and European Union Public License. See LICENSE file for details. | ||
--> | ||
<configuration> | ||
<midpoint> | ||
<global> | ||
<extensionDir>./src/test/resources/schema</extensionDir> | ||
</global> | ||
<repository> | ||
<type>sqale</type> | ||
|
||
<!-- | ||
Use this Vagrantbox to run this: | ||
https://github.com/virgo47/midpoint-vagrantboxes/tree/master/vagrant-midpoint-db-pg-new-repo | ||
Then connect to it with the info below and execute pgnew-repo.sql file to initialize the DB. | ||
--> | ||
<database>postgresql</database> | ||
<jdbcUrl>jdbc:postgresql://192.168.56.33:5432/midtest</jdbcUrl> | ||
<jdbcUsername>midtest</jdbcUsername> | ||
<jdbcPassword>password</jdbcPassword> | ||
|
||
<performanceStatisticsLevel>10</performanceStatisticsLevel> | ||
<performanceStatisticsFile>./target/performance.log</performanceStatisticsFile> | ||
</repository> | ||
<workflow> | ||
<enabled>true</enabled> | ||
</workflow> | ||
<audit> | ||
<auditService> | ||
<auditServiceFactoryClass>com.evolveum.midpoint.audit.impl.LoggerAuditServiceFactory</auditServiceFactoryClass> | ||
</auditService> | ||
<!-- TODO audit not supported for new repo yet | ||
<auditService> | ||
<auditServiceFactoryClass>com.evolveum.midpoint.repo.sql.SqlAuditServiceFactory</auditServiceFactoryClass> | ||
<!– Needed for model-intest where these properties are used. –> | ||
<customColumn> | ||
<columnName>foo</columnName> | ||
<eventRecordPropertyName>foo</eventRecordPropertyName> | ||
</customColumn> | ||
<customColumn> | ||
<columnName>ship</columnName> | ||
<eventRecordPropertyName>ship</eventRecordPropertyName> | ||
</customColumn> | ||
</auditService> | ||
--> | ||
<auditService> | ||
<auditServiceFactoryClass>com.evolveum.midpoint.test.DummyAuditServiceFactory</auditServiceFactoryClass> | ||
</auditService> | ||
</audit> | ||
<taskManager> | ||
<jdbcJobStore>false</jdbcJobStore> | ||
<waitingTasksCheckInterval>5</waitingTasksCheckInterval> | ||
<testMode>true</testMode> | ||
<useThreadInterrupt>whenNecessary</useThreadInterrupt> <!-- needed for task manager tests --> | ||
<threads>50</threads> <!-- some performance tests use this --> | ||
</taskManager> | ||
<icf> | ||
<scanClasspath>true</scanClasspath> | ||
<scanDirectory>${midpoint.home}/icf-connectors</scanDirectory> | ||
</icf> | ||
<keystore> | ||
<keyStorePath>${midpoint.home}/keystore.jceks</keyStorePath> | ||
<keyStorePassword>changeit</keyStorePassword> | ||
<encryptionKeyAlias>default</encryptionKeyAlias> | ||
</keystore> | ||
<constants> | ||
<useless>xUSEless</useless> | ||
<drink>rum</drink> | ||
<blabla>Bla bla bla</blabla> | ||
<baseDn>dc=example,dc=com</baseDn> | ||
<passwordClear>secret</passwordClear> | ||
<adBaseDn>DC=ad,DC=evolveum,DC=com</adBaseDn> | ||
<adUsersDn>CN=Users,DC=ad,DC=evolveum,DC=com</adUsersDn> | ||
<ad2012BaseDn>DC=ad2012,DC=lab,DC=evolveum,DC=com</ad2012BaseDn> | ||
<ad2012UsersDn>CN=Users,DC=ad2012,DC=lab,DC=evolveum,DC=com</ad2012UsersDn> | ||
</constants> | ||
</midpoint> | ||
</configuration> |