diff --git a/li.strolch.performancetest/src/runtime_postgresql_versioning/config/PrivilegeConfig.xml b/li.strolch.performancetest/src/runtime_postgresql_versioning/config/PrivilegeConfig.xml new file mode 100644 index 000000000..aaf42b2c6 --- /dev/null +++ b/li.strolch.performancetest/src/runtime_postgresql_versioning/config/PrivilegeConfig.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/li.strolch.performancetest/src/runtime_postgresql_versioning/config/PrivilegeRoles.xml b/li.strolch.performancetest/src/runtime_postgresql_versioning/config/PrivilegeRoles.xml new file mode 100644 index 000000000..3a9e8ab07 --- /dev/null +++ b/li.strolch.performancetest/src/runtime_postgresql_versioning/config/PrivilegeRoles.xml @@ -0,0 +1,16 @@ + + + + + li.strolch.agent.impl.StartRealms + + + + + true + + + true + + + diff --git a/li.strolch.performancetest/src/runtime_postgresql_versioning/config/PrivilegeUsers.xml b/li.strolch.performancetest/src/runtime_postgresql_versioning/config/PrivilegeUsers.xml new file mode 100644 index 000000000..ac8f13f5c --- /dev/null +++ b/li.strolch.performancetest/src/runtime_postgresql_versioning/config/PrivilegeUsers.xml @@ -0,0 +1,33 @@ + + + + SYSTEM + + agent + + + + Application + Administrator + ENABLED + en_GB + + AppUser + + + + + + + Application + Administrator + ENABLED + en_GB + + AppUser + + + + + + diff --git a/li.strolch.performancetest/src/runtime_postgresql_versioning/config/StrolchConfiguration.xml b/li.strolch.performancetest/src/runtime_postgresql_versioning/config/StrolchConfiguration.xml new file mode 100644 index 000000000..16357b82c --- /dev/null +++ b/li.strolch.performancetest/src/runtime_postgresql_versioning/config/StrolchConfiguration.xml @@ -0,0 +1,74 @@ + + + + + minimal + + en + true + + + + PrivilegeHandler + li.strolch.runtime.privilege.PrivilegeHandler + li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler + + PrivilegeConfig.xml + + + + RealmHandler + li.strolch.agent.api.RealmHandler + li.strolch.agent.impl.DefaultRealmHandler + PrivilegeHandler + + + transactional, cached + + TRANSACTIONAL + true + true + + CACHED + true + true + + + + PersistenceHandler + li.strolch.persistence.api.PersistenceHandler + li.strolch.persistence.postgresql.PostgreSqlPersistenceHandler + + true + true + + + jdbc:postgresql://localhost/testdb + testuser + test + 1 + + + jdbc:postgresql://localhost/testdb + testuser + test + 1 + + + + ServiceHandler + li.strolch.service.api.ServiceHandler + li.strolch.service.api.DefaultServiceHandler + RealmHandler + PrivilegeHandler + + true + + + + diff --git a/li.strolch.performancetest/src/test/java/li/strolch/performance/PerformancePostgreSqlTest.java b/li.strolch.performancetest/src/test/java/li/strolch/performance/PerformancePostgreSqlTest.java index e4b02a57a..8fbb537eb 100644 --- a/li.strolch.performancetest/src/test/java/li/strolch/performance/PerformancePostgreSqlTest.java +++ b/li.strolch.performancetest/src/test/java/li/strolch/performance/PerformancePostgreSqlTest.java @@ -22,6 +22,7 @@ import java.text.MessageFormat; import org.junit.AfterClass; import org.junit.BeforeClass; +import org.postgresql.Driver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,6 +56,10 @@ public class PerformancePostgreSqlTest extends PerformanceTest { } public static void dropSchema(String dbUrl, String dbUsername, String dbPassword) throws Exception { + + if (!Driver.isRegistered()) + Driver.register(); + Version dbVersion = DbSchemaVersionCheck.getExpectedDbVersion(PostgreSqlPersistenceHandler.SCRIPT_PREFIX, PostgreSqlPersistenceHandler.class); logger.info(MessageFormat.format("Dropping schema for expected version {0}", dbVersion)); @@ -79,7 +84,7 @@ public class PerformancePostgreSqlTest extends PerformanceTest { } @AfterClass - public static void afterClass() { + public static void afterClass() throws Exception { if (runtimeMock != null) runtimeMock.destroyRuntime(); @@ -87,5 +92,8 @@ public class PerformancePostgreSqlTest extends PerformanceTest { if (rootPath.exists()) { FileHelper.deleteFile(rootPath, false); } + + if (Driver.isRegistered()) + Driver.deregister(); } } diff --git a/li.strolch.performancetest/src/test/java/li/strolch/performance/PerformancePostgreVersioningSqlTest.java b/li.strolch.performancetest/src/test/java/li/strolch/performance/PerformancePostgreVersioningSqlTest.java new file mode 100644 index 000000000..4d224cf77 --- /dev/null +++ b/li.strolch.performancetest/src/test/java/li/strolch/performance/PerformancePostgreVersioningSqlTest.java @@ -0,0 +1,99 @@ +/* + * Copyright 2015 Robert von Burg + * + * 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 li.strolch.performance; + +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; +import java.text.MessageFormat; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.postgresql.Driver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import li.strolch.db.DbSchemaVersionCheck; +import li.strolch.persistence.postgresql.PostgreSqlPersistenceHandler; +import li.strolch.testbase.runtime.RuntimeMock; +import li.strolch.utils.Version; +import li.strolch.utils.helper.FileHelper; +import li.strolch.utils.helper.StringHelper; + +/** + * @author Robert von Burg + */ +public class PerformancePostgreVersioningSqlTest extends PerformanceTest { + + public static final String RUNTIME_PATH = "target/runtime_postgresql_test/"; //$NON-NLS-1$ + public static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$ + public static final String CONFIG_SRC = "src/runtime_postgresql_versioning"; //$NON-NLS-1$ + + public static final String DB_URL = "jdbc:postgresql://localhost/testdb"; //$NON-NLS-1$ + public static final String DB_USERNAME = "testuser"; //$NON-NLS-1$ + public static final String DB_PASSWORD = "test"; //$NON-NLS-1$ + + private static final Logger logger = LoggerFactory.getLogger(PerformancePostgreVersioningSqlTest.class); + + protected static RuntimeMock runtimeMock; + + @Override + protected RuntimeMock runtime() { + return runtimeMock; + } + + public static void dropSchema(String dbUrl, String dbUsername, String dbPassword) throws Exception { + + if (!Driver.isRegistered()) + Driver.register(); + + Version dbVersion = DbSchemaVersionCheck.getExpectedDbVersion(PostgreSqlPersistenceHandler.SCRIPT_PREFIX, + PostgreSqlPersistenceHandler.class); + logger.info(MessageFormat.format("Dropping schema for expected version {0}", dbVersion)); + String sql = DbSchemaVersionCheck.getSql(PostgreSqlPersistenceHandler.SCRIPT_PREFIX, + PostgreSqlPersistenceHandler.class, dbVersion, "drop"); //$NON-NLS-1$ + logger.info(StringHelper.NEW_LINE + sql); + try (Connection connection = DriverManager.getConnection(dbUrl, dbUsername, dbPassword)) { + connection.prepareStatement(sql).execute(); + } + } + + @BeforeClass + public static void beforeClass() throws Exception { + + dropSchema(DB_URL, DB_USERNAME, DB_PASSWORD); + + File rootPath = new File(RUNTIME_PATH); + File configSrc = new File(CONFIG_SRC); + runtimeMock = new RuntimeMock(); + runtimeMock.mockRuntime(rootPath, configSrc); + runtimeMock.startContainer(); + } + + @AfterClass + public static void afterClass() throws Exception { + if (runtimeMock != null) + runtimeMock.destroyRuntime(); + + File rootPath = new File(RUNTIME_PATH); + if (rootPath.exists()) { + FileHelper.deleteFile(rootPath, false); + } + + if (Driver.isRegistered()) + Driver.deregister(); + } +}