Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add default test, document properties
- Loading branch information
1 parent
0d9abc0
commit bdbf55a
Showing
5 changed files
with
109 additions
and
3 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
91 changes: 91 additions & 0 deletions
91
...est/java/io/opentracing/contrib/spring/cloud/jdbc/jdbc/JdbcWithActiveSpanDefaultTest.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,91 @@ | ||
/** | ||
* Copyright 2017-2018 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.spring.cloud.jdbc.jdbc; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import io.opentracing.Scope; | ||
import io.opentracing.contrib.spring.cloud.jdbc.MockTracingConfiguration; | ||
import io.opentracing.mock.MockSpan; | ||
import io.opentracing.mock.MockTracer; | ||
import io.opentracing.tag.Tags; | ||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
import java.util.Optional; | ||
import javax.sql.DataSource; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
/** | ||
* Test behaviour when withActiveSpanOnly is set | ||
* @author Will Penington | ||
*/ | ||
@SpringBootTest(classes = {MockTracingConfiguration.class}) | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
public class JdbcWithActiveSpanDefaultTest { | ||
|
||
@Autowired | ||
MockTracer tracer; | ||
|
||
@Autowired | ||
DataSource dataSource; | ||
|
||
@Autowired | ||
JdbcTemplate jdbcTemplate; | ||
|
||
@Before | ||
public void before() { | ||
tracer.reset(); | ||
} | ||
|
||
/** | ||
* Make sure that a span is created when an active span exists. | ||
*/ | ||
@Test | ||
public void spanJoinsActiveSpan() throws SQLException { | ||
try (Scope ignored = tracer.buildSpan("parent").startActive(true)) { | ||
assertTrue(dataSource.getConnection().prepareStatement("select 1").execute()); | ||
assertEquals(1, tracer.finishedSpans().size()); | ||
} | ||
|
||
assertEquals(2, tracer.finishedSpans().size()); | ||
|
||
Optional<MockSpan> jdbcSpan = tracer | ||
.finishedSpans() | ||
.stream() | ||
.filter((s) -> "java-jdbc".equals(s.tags().get(Tags.COMPONENT.getKey()))) | ||
.findFirst(); | ||
|
||
assertTrue(jdbcSpan.isPresent()); | ||
} | ||
|
||
/** | ||
* Make sure a new span is created when there is no active parent span. | ||
*/ | ||
@Test | ||
public void spanIsCreatedForPreparedStatement() throws SQLException { | ||
PreparedStatement pstmt = dataSource.getConnection().prepareStatement("select 1"); | ||
assertTrue(pstmt.execute()); | ||
assertEquals(1, tracer.finishedSpans().size()); | ||
} | ||
|
||
} |
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