-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NH-93561: add test for hibernate v4 and update v6 test
- Loading branch information
1 parent
076e015
commit 590f48a
Showing
10 changed files
with
288 additions
and
55 deletions.
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
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
65 changes: 65 additions & 0 deletions
65
...te-4.0/src/test/java/com/solarwinds/opentelemetry/instrumentation/hibernate/v4_0/Dev.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,65 @@ | ||
/* | ||
* © SolarWinds Worldwide, LLC. All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
|
||
/* | ||
* © SolarWinds Worldwide, LLC. All rights reserved. | ||
* | ||
* 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 com.solarwinds.opentelemetry.instrumentation.hibernate.v4_0; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import org.hibernate.annotations.GenericGenerator; | ||
|
||
@Entity(name = "devs") | ||
public class Dev { | ||
|
||
@Id | ||
@GeneratedValue(generator = "increment") | ||
@GenericGenerator(name = "increment", strategy = "increment") | ||
private Long id; | ||
|
||
private String name; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...om/solarwinds/opentelemetry/instrumentation/hibernate/v4_0/LoaderInstrumentationTest.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,84 @@ | ||
/* | ||
* © SolarWinds Worldwide, LLC. All rights reserved. | ||
* | ||
* 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 com.solarwinds.opentelemetry.instrumentation.hibernate.v4_0; | ||
|
||
import io.opentelemetry.api.trace.SpanKind; | ||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; | ||
import org.hibernate.Session; | ||
import org.hibernate.SessionFactory; | ||
import org.hibernate.Transaction; | ||
import org.hibernate.cfg.Configuration; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class LoaderInstrumentationTest { | ||
@RegisterExtension | ||
public static AgentInstrumentationExtension testing = AgentInstrumentationExtension.create(); | ||
|
||
private SessionFactory sessionFactory; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
Configuration configuration = new Configuration(); | ||
configuration | ||
.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect") | ||
.setProperty("hibernate.connection.driver_class", "org.h2.Driver") | ||
.setProperty("hibernate.connection.url", "jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1") | ||
.setProperty("hibernate.connection.username", "sa") | ||
.setProperty("hibernate.connection.password", "") | ||
.setProperty("hibernate.hbm2ddl.auto", "create") | ||
.setProperty("hibernate.show_sql", "true"); | ||
|
||
sessionFactory = configuration.addAnnotatedClass(Dev.class).buildSessionFactory(); | ||
|
||
Session session = sessionFactory.openSession(); | ||
Transaction transaction = session.beginTransaction(); | ||
|
||
Dev dev = new Dev(); | ||
dev.setName("cleverchuk"); | ||
|
||
session.persist(dev); | ||
transaction.commit(); | ||
session.close(); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
sessionFactory.close(); | ||
} | ||
|
||
@Test | ||
void verifyDbContextInjectionSpanIsCreated() { | ||
testing.runWithSpan( | ||
"root", | ||
() -> { | ||
Session session = sessionFactory.openSession(); | ||
session.createQuery("SELECT name FROM devs").list(); | ||
session.close(); | ||
}); | ||
testing.waitAndAssertTraces( | ||
trace -> | ||
trace.hasSpansSatisfyingExactly( | ||
span -> span.hasName("root").hasKind(SpanKind.INTERNAL), | ||
span -> span.hasName("sw.hibernate.context").hasKind(SpanKind.INTERNAL))); | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...te-6.0/src/test/java/com/solarwinds/opentelemetry/instrumentation/hibernate/v6_0/Dev.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,65 @@ | ||
/* | ||
* © SolarWinds Worldwide, LLC. All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
|
||
/* | ||
* © SolarWinds Worldwide, LLC. All rights reserved. | ||
* | ||
* 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 com.solarwinds.opentelemetry.instrumentation.hibernate.v6_0; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import org.hibernate.annotations.GenericGenerator; | ||
|
||
@Entity(name = "devs") | ||
public class Dev { | ||
|
||
@Id | ||
@GeneratedValue(generator = "increment") | ||
@GenericGenerator(name = "increment", strategy = "increment") | ||
private Long id; | ||
|
||
private String name; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
Oops, something went wrong.