Skip to content

Commit

Permalink
Merge pull request #14 from opentracing-contrib/coverage
Browse files Browse the repository at this point in the history
add test coverage
  • Loading branch information
malafeev committed Jun 4, 2018
2 parents 0d33b3d + d6b2944 commit 1cd8a4a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ branches:
except:
- /^[0-9]/

after_success:
- mvn jacoco:report coveralls:report

env:
global:
# Ex. travis encrypt BINTRAY_USER=your_github_account
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status][ci-img]][ci] [![Released Version][maven-img]][maven]
[![Build Status][ci-img]][ci] [![Coverage Status][cov-img]][cov] [![Released Version][maven-img]][maven]

# OpenTracing JDBC Instrumentation
OpenTracing instrumentation for JDBC.
Expand Down Expand Up @@ -84,5 +84,7 @@ E.g. `Class.forName("com.mysql.jdbc.Driver");`

[ci-img]: https://travis-ci.org/opentracing-contrib/java-jdbc.svg?branch=master
[ci]: https://travis-ci.org/opentracing-contrib/java-jdbc
[cov-img]: https://coveralls.io/repos/github/opentracing-contrib/java-jdbc/badge.svg?branch=master
[cov]: https://coveralls.io/github/opentracing-contrib/java-jdbc?branch=master
[maven-img]: https://img.shields.io/maven-central/v/io.opentracing.contrib/opentracing-jdbc.svg
[maven]: http://search.maven.org/#search%7Cga%7C1%7Cio.opentracing.contrib%20opentracing-jdbc
25 changes: 24 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-jdbc</artifactId>
Expand Down Expand Up @@ -60,6 +62,8 @@
<project.build.resourceEncoding>UTF-8</project.build.resourceEncoding>

<opentracing.version>0.31.0</opentracing.version>
<coveralls-maven-plugin.version>4.3.0</coveralls-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.1</jacoco-maven-plugin.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -174,6 +178,7 @@
<exclude>mvnw</exclude>
<exclude>mvnw.cmd</exclude>
<exclude>.mvn/wrapper/maven-wrapper.properties</exclude>
<exclude>.coveralls.yml</exclude>
</excludes>
</configuration>
<executions>
Expand All @@ -185,6 +190,24 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>${coveralls-maven-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
9 changes: 6 additions & 3 deletions src/test/java/io/opentracing/contrib/jdbc/HibernateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ public void hibernate_with_parent_and_active_span_only() {

@Test
public void hibernate_with_ignored_statement() {
SessionFactory sessionFactory = createSessionFactory(false, Arrays.asList("insert into Employee (id) values (?)"));
SessionFactory sessionFactory = createSessionFactory(false,
Arrays.asList("insert into Employee (id) values (?)"));
Session session = sessionFactory.openSession();

Employee employee = new Employee();
Expand Down Expand Up @@ -264,14 +265,16 @@ private SessionFactory createSessionFactory(boolean traceWithActiveSpanOnly) {
return createSessionFactory(traceWithActiveSpanOnly, new ArrayList<String>());
}

private SessionFactory createSessionFactory(boolean traceWithActiveSpanOnly, List<String> ignored) {
private SessionFactory createSessionFactory(boolean traceWithActiveSpanOnly,
List<String> ignored) {
String ignoredForTrace = TestUtil.buildIgnoredString(ignored);
Configuration configuration = new Configuration();
configuration.addAnnotatedClass(Employee.class);
configuration.setProperty("hibernate.connection.driver_class",
"io.opentracing.contrib.jdbc.TracingDriver");
configuration.setProperty("hibernate.connection.url",
"jdbc:tracing:h2:mem:hibernate?" + ignoredForTrace + "traceWithActiveSpanOnly=" + traceWithActiveSpanOnly);
"jdbc:tracing:h2:mem:hibernate?" + ignoredForTrace + "traceWithActiveSpanOnly="
+ traceWithActiveSpanOnly);
configuration.setProperty("hibernate.connection.username", "sa");
configuration.setProperty("hibernate.connection.password", "");
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
Expand Down
9 changes: 3 additions & 6 deletions src/test/java/io/opentracing/contrib/jdbc/SpringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.dbcp2.BasicDataSource;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -169,8 +166,8 @@ public void spring_with_parent_and_active_span_only() throws Exception {
@Test
public void spring_with_ignored_statement() throws Exception {
BasicDataSource dataSource = getDataSource(false, Arrays.asList(
"CREATE TABLE ignored (id INTEGER, TEST VARCHAR)",
"INSERT INTO ignored (id, \\\"TEST\\\") VALUES (1, 'value')"
"CREATE TABLE ignored (id INTEGER, TEST VARCHAR)",
"INSERT INTO ignored (id, \\\"TEST\\\") VALUES (1, 'value')"
));

JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
Expand All @@ -196,7 +193,7 @@ private BasicDataSource getDataSource(boolean traceWithActiveSpanOnly, List<Stri
dataSource.setDriverClassName("io.opentracing.contrib.jdbc.TracingDriver");
dataSource
.setUrl("jdbc:tracing:h2:mem:spring?" + ignoreForTracing +
"traceWithActiveSpanOnly=" + traceWithActiveSpanOnly);
"traceWithActiveSpanOnly=" + traceWithActiveSpanOnly);
dataSource.setUsername("sa");
dataSource.setPassword("");
return dataSource;
Expand Down

0 comments on commit 1cd8a4a

Please sign in to comment.