Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests with hibernate 5 and 6 #2182

Merged
merged 3 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply from: "$rootDir/gradle/instrumentation.gradle"
apply plugin: 'org.unbroken-dome.test-sets'

muzzle {
pass {
Expand All @@ -9,8 +10,23 @@ muzzle {
}
}

testSets {
version5Test {
dirName = 'test'
}
version6Test {
dirName = 'test'
}

latestDepTest {
dirName = 'test'
}
}

test.dependsOn version5Test, version6Test

dependencies {
library group: 'org.hibernate', name: 'hibernate-core', version: '4.3.0.Final'
implementation group: 'org.hibernate', name: 'hibernate-core', version: '4.3.0.Final'

implementation project(':instrumentation:hibernate:hibernate-common:javaagent')

Expand All @@ -19,15 +35,25 @@ dependencies {
testInstrumentation project(':instrumentation:hibernate:hibernate-3.3:javaagent')
testInstrumentation project(':instrumentation:hibernate:hibernate-4.0:javaagent')

testLibrary group: 'org.hibernate', name: 'hibernate-entitymanager', version: '4.3.0.Final'
testImplementation group: 'org.hibernate', name: 'hibernate-entitymanager', version: '4.3.0.Final'
testImplementation group: 'org.hsqldb', name: 'hsqldb', version: '2.0.0'
//First version to work with Java 14
testLibrary group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.8.0.RELEASE'
testImplementation group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.8.0.RELEASE'

version5TestImplementation group: 'org.hibernate', name: 'hibernate-core', version: '5.0.0.Final'
version5TestImplementation group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.0.0.Final'
version5TestImplementation group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.3.0.RELEASE'

version6TestImplementation group: 'org.hibernate', name: 'hibernate-core', version: '6.0.0.Alpha6'
version6TestImplementation group: 'org.hibernate', name: 'hibernate-entitymanager', version: '6.0.0.Alpha6'
version6TestImplementation group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.3.0.RELEASE'

// TODO(anuraaga): Investigate why these tests don't pass on 5 or 6
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/1042
latestDepTestLibrary group: 'org.hibernate', name: 'hibernate-core', version: '4.+'
latestDepTestLibrary group: 'org.hibernate', name: 'hibernate-entitymanager', version: '4.+'
testImplementation group: 'javax.activation', name: 'javax.activation-api', version: '1.2.0'
testImplementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
testImplementation group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.3'

latestDepTestLibrary group: 'org.springframework.data', name: 'spring-data-jpa', version: '(,2.4.0)'
// hibernate 6 is alpha so use 5 as latest version
latestDepTestImplementation group: 'org.hibernate', name: 'hibernate-core', version: '5.+'
latestDepTestImplementation group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.+'
latestDepTestImplementation group: 'org.springframework.data', name: 'spring-data-jpa', version: '(2.4.0,)'
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.hibernate.SessionFactory
import org.hibernate.cfg.Configuration
import org.hibernate.exception.SQLGrammarException
import org.hibernate.procedure.ProcedureCall
import org.junit.Assume
import spock.lang.Shared

class ProcedureCallTest extends AgentInstrumentationSpecification {
Expand Down Expand Up @@ -55,14 +56,24 @@ class ProcedureCallTest extends AgentInstrumentationSpecification {
}
}

def callProcedure(ProcedureCall call) {
try {
call.getOutputs()
} catch (Exception exception) {
// ignore failures on hibernate 6 where this functionality has not been implemented yet
Assume.assumeFalse("org.hibernate.NotYetImplementedFor6Exception" == exception.getClass().getName())
throw exception
}
}

def "test ProcedureCall"() {
setup:

Session session = sessionFactory.openSession()
session.beginTransaction()

ProcedureCall call = session.createStoredProcedureCall("TEST_PROC")
call.getOutputs()
callProcedure(call)

session.getTransaction().commit()
session.close()
Expand Down Expand Up @@ -114,10 +125,11 @@ class ProcedureCallTest extends AgentInstrumentationSpecification {
session.beginTransaction()

ProcedureCall call = session.createStoredProcedureCall("TEST_PROC")
call.registerParameter("nonexistent", Long, ParameterMode.IN)
call.getParameterRegistration("nonexistent").bindValue(420L)
def parameterRegistration = call.registerParameter("nonexistent", Long, ParameterMode.IN)
Assume.assumeTrue(parameterRegistration.metaClass.getMetaMethod("bindValue", Object) != null)
parameterRegistration.bindValue(420L)
try {
call.getOutputs()
callProcedure(call)
} catch (Exception e) {
// We expected this.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.DB_SYSTEM.key}" "hsqldb"
"${SemanticAttributes.DB_NAME.key}" "test"
"${SemanticAttributes.DB_USER.key}" "sa"
"${SemanticAttributes.DB_STATEMENT.key}" "select customer0_.id as id1_0_, customer0_.firstName as firstNam2_0_, customer0_.lastName as lastName3_0_ from Customer customer0_"
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^\.]+)\.id([^\,]*), ([^\.]+)\.firstName([^\,]*), ([^\.]+)\.lastName(.*)from Customer(.*)/
"${SemanticAttributes.DB_CONNECTION_STRING.key}" "hsqldb:mem:"
}
}
Expand Down Expand Up @@ -104,7 +104,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.DB_SYSTEM.key}" "hsqldb"
"${SemanticAttributes.DB_NAME.key}" "test"
"${SemanticAttributes.DB_USER.key}" "sa"
"${SemanticAttributes.DB_STATEMENT.key}" "select customer0_.id as id1_0_0_, customer0_.firstName as firstNam2_0_0_, customer0_.lastName as lastName3_0_0_ from Customer customer0_ where customer0_.id=?"
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^\.]+)\.id([^\,]*), ([^\.]+)\.firstName([^\,]*), ([^\.]+)\.lastName (.*)from Customer (.*)where ([^\.]+)\.id( ?)=( ?)\?/
"${SemanticAttributes.DB_CONNECTION_STRING.key}" "hsqldb:mem:"
}
}
Expand Down Expand Up @@ -140,7 +140,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.DB_SYSTEM.key}" "hsqldb"
"${SemanticAttributes.DB_NAME.key}" "test"
"${SemanticAttributes.DB_USER.key}" "sa"
"${SemanticAttributes.DB_STATEMENT.key}" "select customer0_.id as id1_0_, customer0_.firstName as firstNam2_0_, customer0_.lastName as lastName3_0_ from Customer customer0_ where customer0_.lastName=?"
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^\.]+)\.id([^\,]*), ([^\.]+)\.firstName([^\,]*), ([^\.]+)\.lastName (.*)from Customer (.*)(where ([^\.]+)\.lastName( ?)=( ?)\?|)/
"${SemanticAttributes.DB_CONNECTION_STRING.key}" "hsqldb:mem:"
}
}
Expand All @@ -161,7 +161,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.DB_SYSTEM.key}" "hsqldb"
"${SemanticAttributes.DB_NAME.key}" "test"
"${SemanticAttributes.DB_USER.key}" "sa"
"${SemanticAttributes.DB_STATEMENT.key}" "select customer0_.id as id1_0_0_, customer0_.firstName as firstNam2_0_0_, customer0_.lastName as lastName3_0_0_ from Customer customer0_ where customer0_.id=?"
"${SemanticAttributes.DB_STATEMENT.key}" ~/select ([^\.]+)\.id([^\,]*), ([^\.]+)\.firstName([^\,]*), ([^\.]+)\.lastName (.*)from Customer (.*)where ([^\.]+)\.id( ?)=( ?)\?/
"${SemanticAttributes.DB_CONNECTION_STRING.key}" "hsqldb:mem:"
}
}
Expand Down