Skip to content
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
Expand Up @@ -28,24 +28,67 @@ dependencies {
testImplementation("com.sun.xml.bind:jaxb-impl:2.2.11")
testImplementation("javax.activation:activation:1.1.1")
testImplementation("org.hsqldb:hsqldb:2.0.0")
testImplementation("org.springframework.data:spring-data-jpa:3.0.0")
testLibrary("org.springframework.data:spring-data-jpa:3.0.0")
}

otelJava {
minJavaVersionSupported.set(JavaVersion.VERSION_11)
}

val latestDepTest = findProperty("testLatestDeps") as Boolean

testing {
suites {
val hibernate6Test by registering(JvmTestSuite::class) {
dependencies {
implementation("com.h2database:h2:1.4.197")
implementation("org.hsqldb:hsqldb:2.0.0")
if (latestDepTest) {
implementation("org.hibernate:hibernate-core:6.+")
} else {
implementation("org.hibernate:hibernate-core:6.0.0.Final")
}
}
}

val hibernate7Test by registering(JvmTestSuite::class) {
dependencies {
implementation("com.h2database:h2:1.4.197")
implementation("org.hsqldb:hsqldb:2.0.0")
if (latestDepTest) {
implementation("org.hibernate:hibernate-core:7.+")
} else {
implementation("org.hibernate:hibernate-core:7.0.0.Final")
}
}
}
}
}

tasks {
withType<Test>().configureEach {
// TODO run tests both with and without experimental span attributes
jvmArgs("-Dotel.instrumentation.hibernate.experimental-span-attributes=true")
}

named("compileHibernate7TestJava", JavaCompile::class).configure {
options.release.set(17)
}
val testJavaVersion =
gradle.startParameter.projectProperties.get("testJavaVersion")?.let(JavaVersion::toVersion)
?: JavaVersion.current()
if (!testJavaVersion.isCompatibleWith(JavaVersion.VERSION_17)) {
named("hibernate7Test", Test::class).configure {
enabled = false
}
}

val testStableSemconv by registering(Test::class) {
jvmArgs("-Dotel.semconv-stability.opt-in=database")
}

check {
dependsOn(testStableSemconv)
dependsOn(testing.suites)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.hibernate.v6_0;

import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.RegisterExtension;

abstract class AbstractHibernateTest {
protected static SessionFactory sessionFactory;
protected static List<Value> prepopulated;

@RegisterExtension
protected static final InstrumentationExtension testing = AgentInstrumentationExtension.create();

@BeforeAll
protected static void setup() {
sessionFactory = new Configuration().configure().buildSessionFactory();
// Pre-populate the DB, so delete/update can be tested.
Session writer = sessionFactory.openSession();
writer.beginTransaction();
prepopulated = new ArrayList<>();
for (int i = 0; i < 5; i++) {
prepopulated.add(new Value("Hello :) " + i));
writer.persist(prepopulated.get(i));
}
writer.getTransaction().commit();
writer.close();
}

@AfterAll
protected static void cleanup() {
if (sessionFactory != null) {
sessionFactory.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

public class ProcedureCallTest {
class ProcedureCallTest {
protected static SessionFactory sessionFactory;
protected static List<Value> prepopulated;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import org.junit.jupiter.params.provider.MethodSource;

@SuppressWarnings("deprecation") // testing instrumentation of deprecated class
public class SessionTest extends AbstractHibernateTest {
class SessionTest extends AbstractHibernateTest {
@ParameterizedTest(name = "{index}: {0}")
@MethodSource("provideHibernateActionParameters")
void testHibernateAction(Parameter parameter) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.hibernate.v6_0;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NamedQuery;

@Entity
@Table
@NamedQuery(name = "TestNamedQuery", query = "from Value")
public class Value {

private Long id;
private String name;

public Value() {}

public Value(String name) {
this.name = name;
}

@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String title) {
name = title;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

<!-- Use in-memory DB for testing -->
<property name="connection.driver_class">org.h2.Driver</property>
<property name="connection.url">jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE</property>
<property name="connection.username">sa</property>
<property name="connection.password"/>
<property name="dialect">org.hibernate.dialect.H2Dialect</property>

<property name="connection.pool_size">3</property>
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<property name="show_sql">true</property>

<!-- Reset the DB each test -->
<property name="hbm2ddl.auto">create</property>

<!-- Objects -->
<mapping class="io.opentelemetry.javaagent.instrumentation.hibernate.v6_0.Value"/>

</session-factory>

</hibernate-configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.hibernate.v7_0;

import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.RegisterExtension;

abstract class AbstractHibernateTest {
protected static SessionFactory sessionFactory;
protected static List<Value> prepopulated;

@RegisterExtension
protected static final InstrumentationExtension testing = AgentInstrumentationExtension.create();

@BeforeAll
protected static void setup() {
sessionFactory = new Configuration().configure().buildSessionFactory();
// Pre-populate the DB, so delete/update can be tested.
Session writer = sessionFactory.openSession();
writer.beginTransaction();
prepopulated = new ArrayList<>();
for (int i = 0; i < 5; i++) {
prepopulated.add(new Value("Hello :) " + i));
writer.persist(prepopulated.get(i));
}
writer.getTransaction().commit();
writer.close();
}

@AfterAll
protected static void cleanup() {
if (sessionFactory != null) {
sessionFactory.close();
}
}
}
Loading
Loading