-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
b134aab
commit 3f4c6e1
Showing
3 changed files
with
94 additions
and
2 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
77 changes: 77 additions & 0 deletions
77
src/test/java/io/opentracing/contrib/jdbc/JdbcTracingUtilsTest.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,77 @@ | ||
/* | ||
* Copyright 2017-2020 The OpenTracing Authors | ||
* | ||
* 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 io.opentracing.contrib.jdbc; | ||
|
||
import io.opentracing.mock.MockSpan; | ||
import io.opentracing.mock.MockTracer; | ||
import io.opentracing.util.GlobalTracerTestUtil; | ||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.Statement; | ||
import java.util.List; | ||
|
||
import static io.opentracing.contrib.jdbc.TestUtil.checkNoEmptyTags; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class JdbcTracingUtilsTest { | ||
|
||
private static final MockTracer mockTracer = new MockTracer(); | ||
|
||
@BeforeClass | ||
public static void init() { | ||
GlobalTracerTestUtil.setGlobalTracerUnconditionally(mockTracer); | ||
} | ||
|
||
@Before | ||
public void before() { | ||
mockTracer.reset(); | ||
} | ||
|
||
@AfterClass | ||
public static void afterClass() { | ||
TracingDriver.setTraceEnabled(true); | ||
} | ||
|
||
@Test | ||
public void buildSpanWithTracedEnabled() throws Exception { | ||
TracingDriver.setInterceptorMode(false); | ||
TracingDriver.setTraceEnabled(true); | ||
try (Connection connection = DriverManager.getConnection("jdbc:tracing:h2:mem:jdbc")) { | ||
Statement statement = connection.createStatement(); | ||
statement.executeUpdate("CREATE TABLE employer (id INTEGER)"); | ||
} | ||
|
||
List<MockSpan> spans = mockTracer.finishedSpans(); | ||
assertEquals(2, spans.size()); | ||
checkNoEmptyTags(spans); | ||
} | ||
|
||
@Test | ||
public void buildSpanWithoutTraceEnabled() throws Exception { | ||
TracingDriver.setInterceptorMode(false); | ||
TracingDriver.setTraceEnabled(false); | ||
try (Connection connection = DriverManager.getConnection("jdbc:tracing:h2:mem:jdbc")) { | ||
Statement statement = connection.createStatement(); | ||
statement.executeUpdate("CREATE TABLE employer (id INTEGER)"); | ||
} | ||
|
||
assertTrue(mockTracer.finishedSpans().isEmpty()); | ||
} | ||
} |