Permalink
Browse files

HHH-6618 running hibernate functional test cases on DB matrix

  • Loading branch information...
1 parent 68f7d9b commit e941eca2d55614d8daae991bc299a2ee9cc298ee @stliu stliu committed Aug 30, 2011
Showing 2,989 changed files with 31,999 additions and 29,518 deletions.
View
@@ -229,7 +229,8 @@ subprojects { subProject ->
file("$buildDir/libs"),
file("$buildDir/reports"),
file("$buildDir/test-results"),
- file("$buildDir/tmp")
+ file("$buildDir/tmp"),
+ file("$buildDir/matrix")
] as Set
}
View
@@ -1,3 +1,27 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
apply plugin: 'groovy'
apply plugin: 'idea'
@@ -8,17 +32,18 @@ repositories {
mavenLocal()
mavenRepo name: "jboss", urls: "http://repository.jboss.org/nexus/content/groups/public/"
}
-
+targetCompatibility = "1.6"
+sourceCompatibility = "1.6"
dependencies {
// common
compile gradleApi()
compile localGroovy()
- compile 'org.apache.ant:ant:1.7.0'
- compile 'org.apache.maven:maven-ant-tasks:2.1.0'
+// compile 'org.apache.ant:ant:1.7.0'
+// compile 'org.apache.maven:maven-ant-tasks:2.1.0'
// needed?
- compile 'org.apache.maven.wagon:wagon-http:1.0-beta-6'
+// compile 'org.apache.maven.wagon:wagon-http:1.0-beta-6'
// injection plugin
compile 'javassist:javassist:3.12.0.GA'
@@ -27,4 +52,7 @@ dependencies {
}
ideaModule {
+ downloadSources =true
+ downloadJavadoc= true
+ javaVersion = '1.6'
}
View
@@ -0,0 +1,62 @@
+org.hibernate.gradle.testing.matrix.MatrixTestingPlugin
+
+Goal:
+Run hibernate-core functional test on other DBs besides default H2 easily.
+
+Usage:
+1. Databases configuration
+In the root hibernate-core project, we have a 'databases' directory, this is the default DB profiles location, take it as an example and you can create your db profile easily.
+
+Take a look of the sub-directories of 'databases' to see how each DB profile is defined.
+Each default DB profile has a matrix.gradle, we use this to get jdbc driver from a maven repo.
+but we also accept a 'jbdc' directory which contains jdbc driver directly to replace this matrix.gradle, this is useful for non-opensource jdbc drivers.
+
+And each DB profile also needs a "resources/hibernate.properties", which, as you expected, defines DB connection info and others hibernate properties.
+
+For now, we have 5 default DB profiles, mysql50, mysql51, postgresql82, postgresql83 and postgresql84.
+
+You can create your DB profile under 'hibernate-core/databases', but if you do that, GIT will ask you check in or remove it everytime when you run git command.
+so, you should create a 'databases/${your db profile}' in other place and use system property 'hibernate-matrix-databases' with the full path of your 'databases'.
+Btw, to add a system properties, you can either use '-Dhibernate-matrix-databases' or add it to ${user.home}/.gradle/gradle.properties with a 'systemProp' perfix, like 'systemProp.hibernate-matrix-databases=${your databases directory path}'
+and if this property is given, MatrixTestingPlugin will take profiles defined in there as well as default 'hibernate-core/databases'
+
+MatrixTestingPlugin also has a system property "hibernate-matrix-ignore" which can be use to ignore some DB profiles or all of them, it accepts values like:
+'all' -- ignore all DB profiles, so matrix testing will be ignored.
+'${profile name1},${profile name2},${profile name3}'
+
+2. Gradle Tasks
+
+run './gradlew tasks --all', you will see there is a 'matrix' task and also 'matrix_${profile_name}' tasks against your DB profiles (not ignored).
+
+3. Source Set separation
+All functional tests[1] should go into src/matrix/java
+All unit tests[2] should go into src/test/java
+
+if you run gradle task 'test', tests in src/test/java and src/matrix/java will be ran, and resources of src/test/resource will be used.
+so, "functional tests" defined in 'src/matrix/java' here are also 'unit test' which run on default H2.
+all test results (test and matrix) are in target/test-results.
+
+if you run gradle task 'matrix' (or its sub-task 'matrix_${profile name}), only tests in 'src/matrix/java' will be ran, and hibernate.properties come from your db profile/resources/hibernate.properties.
+
+3. DBAllocation
+
+For users who has access to JBoss QA lab (need redhat vpn), here is an better way to run matrix tests, you don't need to have a DB instance on your side, but you can use DB instance in JBoss QA Lab.
+And the connection info can be queried by DBAllocation automatically.
+This feature is disabled by default, to enable it, you need system property 'hibernate-matrix-dballcoation', it accepts value like: 'all', '${profile name1},${profile name2},${profile name3}'
+
+for example, if you want to run matrix test on postgresql84, default DB profile, you can
+'./gradlew clean test matrix_postgresql84 -Dhibernate-matrix-dballocation=postgresql84'
+
+what does this command do actually?
+1. test
+run 'src/test/java' on default H2, test results in 'target/test-results'
+run 'src/matrix/java' on default H2, test results in 'target/test-results'
+
+2. query postgresql 84 db instance connection info
+3. run 'src/matrix/java' on postgresql 84 with 'databases/postgresql84/matrix.gradle' defined jdbc driver and 'databases/postgresql84/resources/hibernate.properties' and postgresql84 db instance connection info (this info will override those defined in hibernate.properties), test results in 'target/matrix/postgresql84/results'
+
+
+[1] Functional Test in this document means test need to run on DB matrix
+[2] Unit Test in this document means test does not care the underlying DB (H2) or does not need a DB involved.
+* others may have different "functional test"/"unit test" definition :)
+* use 'hibernate-matrix-dballocation-requestee' to define requestee, default is 'hibernate'
@@ -0,0 +1,113 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package hudson.util
+
+/**
+ *
+ * @author mvecera
+ */
+class DBAllocation {
+ private final static String DB_ALLOCATOR_URL = "http://dballocator.mw.lab.eng.bos.redhat.com:8080/Allocator/AllocatorServlet";
+ private dbinstallPath = "dbinstall"
+ private retries = 30
+ private UUID = ""
+ private ant
+ private File dbConfigFile;
+ private String requestee;
+
+ def DBAllocation(dbinstallPath) {
+ this(new AntBuilder(), dbinstallPath)
+ }
+
+ def DBAllocation(ant, dbinstallPath, outPropsFileName = "allocated.db.properties") {
+ this.ant = ant;
+ this.dbinstallPath = dbinstallPath;
+ this.dbConfigFile = new File(dbinstallPath, outPropsFileName);
+ if(System.properties.containsKey("hibernate-matrix-dballocation-requestee"))
+ requestee = System.properties["hibernate-matrix-dballocation-requestee"]
+ else
+ requestee = "hibernate"
+ }
+
+ def getProperties() {
+ def props = new Properties();
+ props.load(new FileInputStream(dbConfigFile));
+ return props;
+ }
+
+ def allocate(label, expiry) {
+ if ( dbConfigFile.exists() ) {
+ dbConfigFile.delete()
+ }
+ def i = 0
+ while ( !(dbConfigFile.exists() && dbConfigFile.length() > 0) ) {
+ if ( i >= retries ) {
+ throw new Exception('Database unavailable')
+ }
+ if ( i > 0 ) {
+ println "Waiting before trying to allocate DB again."
+ Thread.sleep(60000)
+ }
+ println "Allocating DB..."
+ def allocatorUrl = DB_ALLOCATOR_URL + "?operation=alloc&label=$label&requestee=${requestee}&expiry=$expiry"
+ ant.get(src: allocatorUrl, dest: dbConfigFile.absolutePath, ignoreerrors: 'true')
+ i++
+ }
+ def dbProps = getProperties();
+ this.UUID = dbProps['uuid']
+ return this.UUID
+ }
+
+ def release() {
+ release(this.UUID)
+ }
+
+ def release(UUID) {
+ println 'De-allocating DB...'
+ def allocatorUrl = DB_ALLOCATOR_URL + "?operation=dealloc&uuid=$UUID"
+ ant.get(src: allocatorUrl, dest: "/tmp/.tmpfile")
+ }
+
+ def clean() {
+ clean(this.UUID);
+ }
+
+ def clean(UUID) {
+ println 'Cleaning DB...'
+ def allocatorUrl = DB_ALLOCATOR_URL + "?operation=erase&uuid=$UUID"
+ ant.get(src: allocatorUrl, dest: "/tmp/.tmpfile")
+ }
+
+ def reallocate(newExpiry) {
+ reallocate(this.UUID, newExpiry)
+ }
+
+ def reallocate(UUID, newExpiry) {
+ println 'Re-allocating DB...'
+ def allocatorUrl = DB_ALLOCATOR_URL + "?operation=realloc&uuid=$UUID&expiry=$newExpiry"
+ ant.get(src: allocatorUrl, dest: "/tmp/.tmpfile")
+ }
+}
+
@@ -0,0 +1,85 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package hudson.util
+
+import org.gradle.api.logging.Logger
+import org.gradle.api.logging.Logging
+import org.hibernate.gradle.testing.matrix.MatrixNode
+import org.hibernate.gradle.util.FileUtil
+
+/**
+ *
+ * @author Strong Liu
+ */
+public class DBAllocationHelper {
+ private static final Logger log = Logging.getLogger(DBAllocationHelper.class);
+
+ private static final String DRIVER_PROP = "hibernate.connection.driver_class";
+ private static final String URL_PROP = "hibernate.connection.url";
+ private static final String USERNAME_PROP = "hibernate.connection.username";
+ private static final String PASSWORD_PROP = "hibernate.connection.password";
+ //DBAllocator supports the following DBs
+ private static def supportedDB = ["oracle9i", "oracle10g", "oracle11gR1", "oracle11gR2",
+ "postgresql82", "postgresql83", "postgresql84", "mysql50", "mysql51",
+ "db2-91", "db2-97", "mssql2005", "mssql2008R1", "mssql2008R2", "sybase155"];
+
+ public static Map<String, String> getProperties(MatrixNode node) {
+ Map<String, String> map = new HashMap<String, String>();
+ if ( FileUtil.isFile(node.hibernatePropertyFile) ) {
+ Properties hibernateProperties = new Properties();
+ hibernateProperties.load(new FileInputStream(node.hibernatePropertyFile));
+ map.putAll(hibernateProperties);
+ }
+ if ( isDBAllocationEnabled(node.name) ) {
+ log.lifecycle("using DBAllocator to get DB[${node.name}] connection info");
+ try {
+ DBAllocation db = node.DBAllocation
+ db.allocate(node.name, 300);
+ Properties prop = db.properties
+ log.lifecycle("DBAllocating finished for DB[${node.name}], uuid is [${prop['uuid']}]")
+ map[DRIVER_PROP] = prop["db.jdbc_class"]
+ map[URL_PROP] = prop["db.jdbc_url"]
+ map[USERNAME_PROP] = prop["db.username"]
+ map[PASSWORD_PROP] = prop["db.password"]
+ map["uuid"] = prop["uuid"];
+ db.clean();
+ }
+ catch (RuntimeException e) {
+ log.debug("DBAllocating error, ignore", e);
+ }
+ }
+ return map;
+ }
+ /**
+ * use -Dhibernate-matrix-dballocation=all to enable DBAllocation for all matrix node
+ * or
+ * add systemProp.hibernate-matrix-dballocation=all to ${user.home}/.gradle/gradle.properties
+ */
+ public static boolean isDBAllocationEnabled(String name) {
+ if ( !supportedDB.contains(name) ) return false;
+ String value = System.properties["hibernate-matrix-dballocation"]
+ return value != null && (value.contains(name) || value.equals("all"));
+ }
+}
@@ -0,0 +1,57 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.build.gradle.inject;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Steve Ebersole
+ */
+public class Injection {
+ private final String expression;
+ private List<TargetMember> targetMembers = new ArrayList<TargetMember>();
+
+ public Injection(String expression) {
+ this.expression = expression;
+ }
+
+ public String getExpression() {
+ return expression;
+ }
+
+ public void into(String className, String member) {
+ into( new TargetMember( className, member ) );
+ }
+
+ public void into(TargetMember targetMember) {
+ targetMembers.add( targetMember );
+ }
+
+ public Iterable<TargetMember> getTargetMembers() {
+ return targetMembers;
+ }
+
+}
Oops, something went wrong.

0 comments on commit e941eca

Please sign in to comment.