当前位置: 首页>>代码示例>>Java>>正文


Java ExceptionUtils类代码示例

本文整理汇总了Java中org.springframework.cloud.sleuth.util.ExceptionUtils的典型用法代码示例。如果您正苦于以下问题:Java ExceptionUtils类的具体用法?Java ExceptionUtils怎么用?Java ExceptionUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ExceptionUtils类属于org.springframework.cloud.sleuth.util包,在下文中一共展示了ExceptionUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testShouldAddSpanForPrepatedStatementExecuteUpdate

import org.springframework.cloud.sleuth.util.ExceptionUtils; //导入依赖的package包/类
@Test
public void testShouldAddSpanForPrepatedStatementExecuteUpdate() throws Exception {
    Connection connection = dataSource.getConnection();
    connection.prepareStatement("UPDATE INFORMATION_SCHEMA.TABLES SET table_Name = '' WHERE 0 = 1").executeUpdate();
    connection.close();

    assertThat(ExceptionUtils.getLastException()).isNull();

    assertThat(spanReporter.getSpans()).hasSize(2);
    Span connectionSpan = spanReporter.getSpans().get(0);
    Span statementSpan = spanReporter.getSpans().get(1);
    assertThat(connectionSpan.getName()).isEqualTo("jdbc:/dataSource/connection");
    assertThat(statementSpan.getName()).isEqualTo("jdbc:/dataSource/query");
    assertThat(statementSpan.tags()).containsEntry(SleuthListenerAutoConfiguration.SPAN_SQL_QUERY_TAG_NAME, "UPDATE INFORMATION_SCHEMA.TABLES SET table_Name = '' WHERE 0 = 1");
    assertThat(statementSpan.tags()).containsEntry(SleuthListenerAutoConfiguration.SPAN_ROW_COUNT_TAG_NAME, "0");
}
 
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:17,代码来源:TracingJdbcEventListenerTests.java

示例2: testShouldAddSpanForStatementExecuteUpdate

import org.springframework.cloud.sleuth.util.ExceptionUtils; //导入依赖的package包/类
@Test
public void testShouldAddSpanForStatementExecuteUpdate() throws Exception {
    Connection connection = dataSource.getConnection();
    connection.createStatement().executeUpdate("UPDATE INFORMATION_SCHEMA.TABLES SET table_Name = '' WHERE 0 = 1");
    connection.close();

    assertThat(ExceptionUtils.getLastException()).isNull();

    assertThat(spanReporter.getSpans()).hasSize(2);
    Span connectionSpan = spanReporter.getSpans().get(0);
    Span statementSpan = spanReporter.getSpans().get(1);
    assertThat(connectionSpan.getName()).isEqualTo("jdbc:/dataSource/connection");
    assertThat(statementSpan.getName()).isEqualTo("jdbc:/dataSource/query");
    assertThat(statementSpan.tags()).containsEntry(SleuthListenerAutoConfiguration.SPAN_SQL_QUERY_TAG_NAME, "UPDATE INFORMATION_SCHEMA.TABLES SET table_Name = '' WHERE 0 = 1");
    assertThat(statementSpan.tags()).containsEntry(SleuthListenerAutoConfiguration.SPAN_ROW_COUNT_TAG_NAME, "0");
}
 
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:17,代码来源:TracingJdbcEventListenerTests.java

示例3: testShouldAddSpanForPreparedStatementExecuteQueryIncludingTimeToCloseResultSet

import org.springframework.cloud.sleuth.util.ExceptionUtils; //导入依赖的package包/类
@Test
public void testShouldAddSpanForPreparedStatementExecuteQueryIncludingTimeToCloseResultSet() throws Exception {
    Connection connection = dataSource.getConnection();
    ResultSet resultSet = connection.prepareStatement("SELECT NOW()").executeQuery();
    resultSet.next();
    resultSet.next();
    resultSet.close();
    connection.close();

    assertThat(ExceptionUtils.getLastException()).isNull();

    assertThat(spanReporter.getSpans()).hasSize(3);
    Span connectionSpan = spanReporter.getSpans().get(0);
    Span resultSetSpan = spanReporter.getSpans().get(1);
    Span statementSpan = spanReporter.getSpans().get(2);
    assertThat(connectionSpan.getName()).isEqualTo("jdbc:/dataSource/connection");
    assertThat(statementSpan.getName()).isEqualTo("jdbc:/dataSource/query");
    assertThat(resultSetSpan.getName()).isEqualTo("jdbc:/dataSource/fetch");
    assertThat(statementSpan.tags()).containsEntry(SleuthListenerAutoConfiguration.SPAN_SQL_QUERY_TAG_NAME, "SELECT NOW()");
    assertThat(resultSetSpan.tags()).containsEntry(SleuthListenerAutoConfiguration.SPAN_ROW_COUNT_TAG_NAME, "1");
}
 
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:22,代码来源:TracingJdbcEventListenerTests.java

示例4: testShouldAddSpanForStatementAndResultSet

import org.springframework.cloud.sleuth.util.ExceptionUtils; //导入依赖的package包/类
@Test
public void testShouldAddSpanForStatementAndResultSet() throws Exception {
    Connection connection = dataSource.getConnection();
    ResultSet resultSet = connection.createStatement().executeQuery("SELECT NOW()");
    resultSet.next();
    Thread.sleep(200L);
    resultSet.close();
    connection.close();

    assertThat(ExceptionUtils.getLastException()).isNull();

    assertThat(spanReporter.getSpans()).hasSize(3);
    Span connectionSpan = spanReporter.getSpans().get(0);
    Span resultSetSpan = spanReporter.getSpans().get(1);
    Span statementSpan = spanReporter.getSpans().get(2);
    assertThat(connectionSpan.getName()).isEqualTo("jdbc:/dataSource/connection");
    assertThat(statementSpan.getName()).isEqualTo("jdbc:/dataSource/query");
    assertThat(resultSetSpan.getName()).isEqualTo("jdbc:/dataSource/fetch");
    assertThat(statementSpan.tags()).containsEntry(SleuthListenerAutoConfiguration.SPAN_SQL_QUERY_TAG_NAME, "SELECT NOW()");
    assertThat(resultSetSpan.tags()).containsEntry(SleuthListenerAutoConfiguration.SPAN_ROW_COUNT_TAG_NAME, "1");
}
 
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:22,代码来源:TracingJdbcEventListenerTests.java

示例5: testShouldNotFailWhenStatementIsClosedWihoutResultSet

import org.springframework.cloud.sleuth.util.ExceptionUtils; //导入依赖的package包/类
@Test
public void testShouldNotFailWhenStatementIsClosedWihoutResultSet() throws Exception {
    Connection connection = dataSource.getConnection();
    Statement statement = connection.createStatement();
    ResultSet resultSet = statement.executeQuery("SELECT NOW()");
    resultSet.next();
    statement.close();
    connection.close();

    assertThat(ExceptionUtils.getLastException()).isNull();

    assertThat(spanReporter.getSpans()).hasSize(3);
    Span connectionSpan = spanReporter.getSpans().get(0);
    Span resultSetSpan = spanReporter.getSpans().get(1);
    Span statementSpan = spanReporter.getSpans().get(2);
    assertThat(connectionSpan.getName()).isEqualTo("jdbc:/dataSource/connection");
    assertThat(statementSpan.getName()).isEqualTo("jdbc:/dataSource/query");
    assertThat(resultSetSpan.getName()).isEqualTo("jdbc:/dataSource/fetch");
    assertThat(statementSpan.tags()).containsEntry(SleuthListenerAutoConfiguration.SPAN_SQL_QUERY_TAG_NAME, "SELECT NOW()");
}
 
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:21,代码来源:TracingJdbcEventListenerTests.java

示例6: testShouldNotFailWhenConnectionIsClosedWihoutResultSet

import org.springframework.cloud.sleuth.util.ExceptionUtils; //导入依赖的package包/类
@Test
public void testShouldNotFailWhenConnectionIsClosedWihoutResultSet() throws Exception {
    Connection connection = dataSource.getConnection();
    Statement statement = connection.createStatement();
    ResultSet resultSet = statement.executeQuery("SELECT NOW()");
    resultSet.next();
    connection.close();

    assertThat(ExceptionUtils.getLastException()).isNull();

    assertThat(spanReporter.getSpans()).hasSize(3);
    Span connectionSpan = spanReporter.getSpans().get(0);
    Span resultSetSpan = spanReporter.getSpans().get(1);
    Span statementSpan = spanReporter.getSpans().get(2);
    assertThat(connectionSpan.getName()).isEqualTo("jdbc:/dataSource/connection");
    assertThat(statementSpan.getName()).isEqualTo("jdbc:/dataSource/query");
    assertThat(resultSetSpan.getName()).isEqualTo("jdbc:/dataSource/fetch");
    assertThat(statementSpan.tags()).containsEntry(SleuthListenerAutoConfiguration.SPAN_SQL_QUERY_TAG_NAME, "SELECT NOW()");
}
 
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:20,代码来源:TracingJdbcEventListenerTests.java

示例7: testShouldNotFailWhenResultSetNextWasNotCalled

import org.springframework.cloud.sleuth.util.ExceptionUtils; //导入依赖的package包/类
@Test
public void testShouldNotFailWhenResultSetNextWasNotCalled() throws Exception {
    Connection connection = dataSource.getConnection();
    Statement statement = connection.createStatement();
    ResultSet resultSet = statement.executeQuery("SELECT NOW()");
    resultSet.close();
    statement.close();
    connection.close();

    assertThat(ExceptionUtils.getLastException()).isNull();

    assertThat(spanReporter.getSpans()).hasSize(3);
    Span connectionSpan = spanReporter.getSpans().get(0);
    Span resultSetSpan = spanReporter.getSpans().get(1);
    Span statementSpan = spanReporter.getSpans().get(2);
    assertThat(connectionSpan.getName()).isEqualTo("jdbc:/dataSource/connection");
    assertThat(statementSpan.getName()).isEqualTo("jdbc:/dataSource/query");
    assertThat(resultSetSpan.getName()).isEqualTo("jdbc:/dataSource/fetch");
    assertThat(statementSpan.tags()).containsEntry(SleuthListenerAutoConfiguration.SPAN_SQL_QUERY_TAG_NAME, "SELECT NOW()");
}
 
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:21,代码来源:TracingJdbcEventListenerTests.java

示例8: testShouldAddSpanForPreparedStatementExecuteUpdate

import org.springframework.cloud.sleuth.util.ExceptionUtils; //导入依赖的package包/类
@Test
public void testShouldAddSpanForPreparedStatementExecuteUpdate() throws Exception {
    Connection connection = dataSource.getConnection();
    connection.prepareStatement("UPDATE INFORMATION_SCHEMA.TABLES SET table_Name = '' WHERE 0 = 1").executeUpdate();
    connection.close();

    assertThat(ExceptionUtils.getLastException()).isNull();

    assertThat(spanReporter.getSpans()).hasSize(2);
    Span connectionSpan = spanReporter.getSpans().get(0);
    Span statementSpan = spanReporter.getSpans().get(1);
    assertThat(connectionSpan.getName()).isEqualTo("jdbc:/dataSource/connection");
    assertThat(statementSpan.getName()).isEqualTo("jdbc:/dataSource/query");
    assertThat(statementSpan.tags()).containsEntry(SleuthListenerAutoConfiguration.SPAN_SQL_QUERY_TAG_NAME, "UPDATE INFORMATION_SCHEMA.TABLES SET table_Name = '' WHERE 0 = 1");
    assertThat(statementSpan.tags()).containsEntry(SleuthListenerAutoConfiguration.SPAN_ROW_COUNT_TAG_NAME, "0");
}
 
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:17,代码来源:TracingQueryExecutionListenerTests.java

示例9: testShouldAddSpanForPreparedStatementExecuteQueryIncludingTimeToCloseResultSet

import org.springframework.cloud.sleuth.util.ExceptionUtils; //导入依赖的package包/类
@Test
public void testShouldAddSpanForPreparedStatementExecuteQueryIncludingTimeToCloseResultSet() throws Exception {
    Connection connection = dataSource.getConnection();
    ResultSet resultSet = connection.prepareStatement("SELECT NOW()").executeQuery();
    Thread.sleep(200L);
    resultSet.close();
    connection.close();

    assertThat(ExceptionUtils.getLastException()).isNull();

    assertThat(spanReporter.getSpans()).hasSize(2);
    Span connectionSpan = spanReporter.getSpans().get(0);
    Span statementSpan = spanReporter.getSpans().get(1);
    assertThat(connectionSpan.getName()).isEqualTo("jdbc:/dataSource/connection");
    assertThat(statementSpan.getName()).isEqualTo("jdbc:/dataSource/query");
    assertThat(statementSpan.tags()).containsEntry(SleuthListenerAutoConfiguration.SPAN_SQL_QUERY_TAG_NAME, "SELECT NOW()");
}
 
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:18,代码来源:TracingQueryExecutionListenerTests.java

示例10: detach

import org.springframework.cloud.sleuth.util.ExceptionUtils; //导入依赖的package包/类
@Override
public Span detach(Span span) {
	if (span == null) {
		return null;
	}
	Span cur = SpanContextHolder.getCurrentSpan();
	if (!span.equals(cur)) {
		ExceptionUtils.warn("Tried to detach trace span but "
				+ "it is not the current span: " + span
				+ ". You may have forgotten to close or detach " + cur);
	}
	else {
		SpanContextHolder.removeCurrentSpan();
	}
	return span.getSavedSpan();
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:17,代码来源:DefaultTracer.java

示例11: shouldCloseSpanUponException

import org.springframework.cloud.sleuth.util.ExceptionUtils; //导入依赖的package包/类
private void shouldCloseSpanUponException(ResponseEntityProvider provider)
		throws IOException {
	Span span = this.tracer.createSpan("new trace");

	try {
		provider.get(this);
		Assert.fail("should throw an exception");
	}
	catch (RuntimeException e) {
	}

	assertThat(ExceptionUtils.getLastException(), is(nullValue()));

	SleuthAssertions.then(this.tracer.getCurrentSpan()).isEqualTo(span);
	this.tracer.close(span);
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:17,代码来源:WebClientDiscoveryExceptionTests.java

示例12: shouldCloseSpanUponException

import org.springframework.cloud.sleuth.util.ExceptionUtils; //导入依赖的package包/类
@Test
@Parameters
public void shouldCloseSpanUponException(ResponseEntityProvider provider)
		throws IOException {
	Span span = this.tracer.createSpan("new trace");

	try {
		provider.get(this);
		Assert.fail("should throw an exception");
	}
	catch (RuntimeException e) {
		// SleuthAssertions.then(e).hasRootCauseInstanceOf(IOException.class);
	}

	assertThat(ExceptionUtils.getLastException(), is(nullValue()));

	SleuthAssertions.then(this.tracer.getCurrentSpan()).isEqualTo(span);
	this.tracer.close(span);
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:20,代码来源:WebClientExceptionTests.java

示例13: detach

import org.springframework.cloud.sleuth.util.ExceptionUtils; //导入依赖的package包/类
@Override
public Span detach(Span span) {
	if (span == null) {
		return null;
	}
	Span cur = SpanContextHolder.getCurrentSpan();
	if (cur == null) {
		if (log.isTraceEnabled()) {
			log.trace("Span in the context is null so something has already detached the span. Won't do anything about it");
		}
		return null;
	}
	if (!span.equals(cur)) {
		ExceptionUtils.warn("Tried to detach trace span but "
				+ "it is not the current span: " + span
				+ ". You may have forgotten to close or detach " + cur);
	}
	else {
		SpanContextHolder.removeCurrentSpan();
	}
	return span.getSavedSpan();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:23,代码来源:DefaultTracer.java

示例14: should_add_a_custom_tag_to_the_span_created_in_controller

import org.springframework.cloud.sleuth.util.ExceptionUtils; //导入依赖的package包/类
@Test
public void should_add_a_custom_tag_to_the_span_created_in_controller() throws Exception {
	Long expectedTraceId = new Random().nextLong();

	MvcResult mvcResult = whenSentDeferredWithTraceId(expectedTraceId);
	this.mockMvc.perform(asyncDispatch(mvcResult))
			.andExpect(status().isOk()).andReturn();

	Optional<Span> taggedSpan = this.spanAccumulator.getSpans().stream()
			.filter(span -> span.tags().containsKey("tag")).findFirst();
	then(taggedSpan.isPresent()).isTrue();
	then(taggedSpan.get()).hasATag("tag", "value");
	then(taggedSpan.get()).hasATag("mvc.controller.method", "deferredMethod");
	then(taggedSpan.get()).hasATag("mvc.controller.class", "TestController");
	then(ExceptionUtils.getLastException()).isNull();
	then(new ListOfSpans(this.spanAccumulator.getSpans())).hasServerSideSpansInProperOrder();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:18,代码来源:TraceFilterIntegrationTests.java

示例15: should_not_create_a_span_for_error_controller

import org.springframework.cloud.sleuth.util.ExceptionUtils; //导入依赖的package包/类
@Test
public void should_not_create_a_span_for_error_controller() {
	this.restTemplate.getForObject("http://localhost:" + port() + "/", String.class);

	then(this.tracer.getCurrentSpan()).isNull();
	then(new ListOfSpans(this.accumulator.getSpans()))
			.doesNotHaveASpanWithName("error")
			.hasASpanWithTagEqualTo("http.status_code", "500");
	then(ExceptionUtils.getLastException()).isNull();
	then(new ListOfSpans(this.accumulator.getSpans()))
			.hasASpanWithTagEqualTo(Span.SPAN_ERROR_TAG_NAME,
					"Request processing failed; nested exception is java.lang.RuntimeException: Throwing exception")
			.hasRpcLogsInProperOrder();
	// issue#714
	Span span = this.accumulator.getSpans().get(0);
	String hex = Span.idToHex(span.getTraceId());
	String[] split = capture.toString().split("\n");
	List<String> list = Arrays.stream(split).filter(s -> s.contains(
			"Uncaught exception thrown"))
			.filter(s -> s.contains(hex + "," + hex + ",true]"))
			.collect(Collectors.toList());
	then(list).isNotEmpty();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:24,代码来源:TraceFilterWebIntegrationTests.java


注:本文中的org.springframework.cloud.sleuth.util.ExceptionUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。