• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ContextedRuntimeException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: issueCommand

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
protected static void issueCommand(String[] commandArray, String errorMessage,
		Pair<String, Object>[] errorContextValues) {
	String commandStr = StringUtils.join(commandArray, ' ');

	logger.info("Docker command: {}", commandStr);
	try {
		Process docker = createProcess(commandArray);
		waitForThrowingException(docker, commandStr);
	} catch (Exception e) {
		ContextedRuntimeException cEx = new DockerProcessAPIException(errorMessage, e)
				.addContextValue("commandStr", commandStr);
		if (errorContextValues != null) {
			for (Pair<String, Object> pair : errorContextValues) {
				cEx.addContextValue(pair.getKey(), pair.getValue());
			}
		}
		throw cEx;
	}
}
 
开发者ID:BreakTheMonolith,项目名称:DockerProcessAPI,代码行数:20,代码来源:CommandUtils.java


示例2: testCheckException

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
@Test
public void testCheckException() throws Exception {
	TestCassandraHealthCheck testCassandraHealthCheck = new TestCassandraHealthCheck(TEST_SERVER);
	testCassandraHealthCheck.cluster = testCluster;
	FieldUtils.writeField(testCassandraHealthCheck, "logger", loggerMock, true);
	Mockito.when(session.execute(Matchers.anyString())).thenThrow(new RuntimeException("crap"));
	Result result = testCassandraHealthCheck.check();

	Assert.assertFalse(result.isHealthy());
	Mockito.verify(session).close();
	Mockito.verify(session).execute(Matchers.anyString());
	Assert.assertEquals(1, testCluster.nbrTimesCloseCalled);

	ArgumentCaptor<ContextedRuntimeException> exCaptor = ArgumentCaptor.forClass(ContextedRuntimeException.class);
	Mockito.verify(loggerMock).error(Matchers.anyString(), exCaptor.capture());
	Assert.assertEquals(3, exCaptor.getValue().getContextLabels().size());
	Assert.assertEquals(result.getError(), exCaptor.getValue());
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:19,代码来源:CassandraHealthCheckTest.java


示例3: check

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
@Override
protected Result check() throws Exception {
	Connection conn = null;
	Statement stmt = null;
	ResultSet rSet = null;
	try {
		conn = dataSource.getConnection();
		stmt = conn.createStatement();
		rSet = stmt.executeQuery(testSqlText);
		safeClose(rSet);
	} catch (Exception e) {
		Exception wrappedException = new ContextedRuntimeException(e).addContextValue("datasource", dataSource);
		logger.error("Healthcheck Failure", wrappedException);
		return Result.unhealthy(wrappedException);

	} finally {
		safeClose(stmt);
		safeClose(conn);
	}
	return Result.healthy();
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:22,代码来源:DataSourceHealthCheck.java


示例4: testCheckInvalidDatabase

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
@Test
public void testCheckInvalidDatabase() throws Exception {
	TestMongoDbHealthCheck healthCheck = setTpcheckMocks();
	Mockito.when(commandResult.get(Matchers.anyString())).thenReturn(Integer.valueOf(0));
	Result result = healthCheck.check();

	Mockito.verify(loggerMock).debug("connectionUrl={} databaseList={} stats={}", TEST_CONNECT_URL, "",
			"commandResult");
	Mockito.verify(mongoClientMock).close();
	Assert.assertFalse(result.isHealthy());

	ArgumentCaptor<ContextedRuntimeException> exCaptor = ArgumentCaptor.forClass(ContextedRuntimeException.class);
	Mockito.verify(loggerMock).error(Matchers.anyString(), exCaptor.capture());
	Assert.assertEquals(4, exCaptor.getValue().getContextLabels().size());
	Assert.assertEquals("Database has nothing in it.", exCaptor.getValue().getCause().getMessage());
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:17,代码来源:MongoDbHealthCheckTest.java


示例5: check

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
@Override
protected Result check() throws Exception {
	Connection conn = null;
	Channel channel = null;

	try {
		conn = connectionFactory.newConnection();
		channel = conn.createChannel();
		channel.queueDeclarePassive(queueName);
		return Result.healthy();
	} catch (Exception e) {
		Exception wrappedException = new ContextedRuntimeException(e).addContextValue("queueName", queueName)
				.addContextValue("connectionFactory", ToStringBuilder.reflectionToString(connectionFactory));
		logger.error("Healthcheck Failure", wrappedException);
		return Result.unhealthy(wrappedException);
	} finally {
		closeChannel(channel);
		closeConnection(conn);
	}
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:21,代码来源:RabbitMQHealthCheck.java


示例6: closeChannel

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
private void closeChannel(Channel channel) throws IOException, TimeoutException {
	try {
		if (channel != null && channel.isOpen()) {
			channel.close();
		}
	} catch (Exception e) {
		logger.warn("RabbitMQ channel erred on close",
				new ContextedRuntimeException(e)
						.addContextValue("queueName", queueName)
						.addContextValue("connectionFactory",
						ToStringBuilder.reflectionToString(connectionFactory)));
	}
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:14,代码来源:RabbitMQHealthCheck.java


示例7: setUp

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	connectionFactory = new ConnectionFactory();
	// connectionFactory.setUri("amqp://guest:[email protected]:" +
	// RABBITMQ_OUTSIDE_PORT + "/");
	connectionFactory.setHost("localhost");
	connectionFactory.setPort(6000);
	connectionFactory.setUsername("guest");
	connectionFactory.setPassword("guest");
	connectionFactory.setVirtualHost("/");

	Connection conn = null;
	Channel channel = null;

	try {
		conn = connectionFactory.newConnection();
		channel = conn.createChannel();
		channel.queueDeclare(TEST_QUEUE, false, false, false, null);
		channel.exchangeDeclare(TEST_QUEUE, "direct");
		channel.queueBind(TEST_QUEUE, TEST_QUEUE, TEST_QUEUE);
	} catch (Exception e) {
		throw new ContextedRuntimeException(e).addContextValue("queueName", TEST_QUEUE)
				.addContextValue("connectionFactory", ToStringBuilder.reflectionToString(connectionFactory));

	}
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:27,代码来源:RabbitMQHealthCheckTestIntegration.java


示例8: loadIntoForm

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
/**
 * @throws RuntimeException if course does not exist or if the courseForm is null
 */
public void loadIntoForm(CourseConfigurationForm courseForm, long courseId) {
    Validate.notNull(courseForm, "courseForm must not be null");

    List<AttendanceSection> sections = sectionRepository.findByCanvasCourseId(courseId);
    if(CollectionUtils.isEmpty(sections)){
        RuntimeException e = new RuntimeException("Cannot load data into courseForm for non-existent sections for this course");
        throw new ContextedRuntimeException(e).addContextValue("courseId", courseId);
    }

    AttendanceAssignment attendanceAssignment = assignmentRepository.findByAttendanceSection(sections.get(0));
    if(attendanceAssignment == null) {
        attendanceAssignment = new AttendanceAssignment();
    }

    courseForm.setAssignmentName(StringUtils.defaultIfEmpty(attendanceAssignment.getAssignmentName(), "Attendance"));
    courseForm.setAssignmentPoints(StringUtils.defaultIfEmpty(attendanceAssignment.getAssignmentPoints(), "100"));
    //default to full points for present or excused
    courseForm.setPresentPoints(StringUtils.defaultIfEmpty(attendanceAssignment.getPresentPoints(), courseForm.getAssignmentPoints()));
    courseForm.setExcusedPoints(StringUtils.defaultIfEmpty(attendanceAssignment.getExcusedPoints(), courseForm.getAssignmentPoints()));
    courseForm.setTardyPoints(StringUtils.defaultIfEmpty(attendanceAssignment.getTardyPoints(), "0"));
    courseForm.setAbsentPoints(StringUtils.defaultIfEmpty(attendanceAssignment.getAbsentPoints(), "0"));
    courseForm.setGradingOn(attendanceAssignment.getGradingOn());
}
 
开发者ID:kstateome,项目名称:lti-attendance,代码行数:27,代码来源:AttendanceSectionService.java


示例9: loadIntoForm

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
/**
 * @throws RuntimeException if course does not exist or if the courseForm is null
 */
public void loadIntoForm(CourseConfigurationForm courseForm, long courseId) {
    Validate.notNull(courseForm, "courseForm must not be null");
    
    AttendanceCourse attendanceCourse = attendanceCourseRepository.findByCanvasCourseId(courseId);
    
    if(attendanceCourse == null) {
        RuntimeException e = new IllegalArgumentException("Cannot load data into courseForm for non-existent course");
        throw new ContextedRuntimeException(e).addContextValue("courseId", courseId);
    }

    courseForm.setTotalClassMinutes(attendanceCourse.getTotalMinutes());
    courseForm.setDefaultMinutesPerSession(attendanceCourse.getDefaultMinutesPerSession());
    courseForm.setSimpleAttendance(attendanceCourse.getAttendanceType().equals(AttendanceType.SIMPLE));
    courseForm.setShowNotesToStudents(attendanceCourse.getShowNotesToStudents());
}
 
开发者ID:kstateome,项目名称:lti-attendance,代码行数:19,代码来源:AttendanceCourseService.java


示例10: createMakeupForm

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
/**
 * @throws IllegalArgumentException when a student cannot be found in the database for the given studentId
 */
public MakeupForm createMakeupForm(long studentId, long sectionId, boolean addEmptyEntry) {
    AttendanceStudent student = attendanceStudentRepository.findByStudentId(new Long(studentId));
    if(student == null) {
        RuntimeException e = new IllegalArgumentException("student does not exist in the database");
        throw new ContextedRuntimeException(e).addContextValue("studentId", studentId);
    }
    
    List<Makeup> makeups = makeupRepository.findByAttendanceStudentOrderByDateOfClassAsc(student);
    if (addEmptyEntry) {
        makeups.add(new Makeup());
    }

    MakeupForm makeupForm = new MakeupForm();
    makeupForm.setEntriesFromMakeEntities(makeups);
    makeupForm.setSectionId(sectionId);
    makeupForm.setStudentId(studentId);

    return makeupForm;
}
 
开发者ID:kstateome,项目名称:lti-attendance,代码行数:23,代码来源:MakeupService.java


示例11: check

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
@Override
protected Result check() throws Exception {
	try {
		return localCheck();
	} catch (Exception e) {
		Exception wrappedException = new ContextedRuntimeException(e).addContextValue("checkUrl", checkUrl)
				.addContextValue("requestTimeoutMillis", requestTimeoutMillis).addContextValue("headerMap",
						(headerMap == null) ? headerMap : Arrays.toString(headerMap.entrySet().toArray()));
		logger.error("Healthcheck Failure", wrappedException);
		return Result.unhealthy(wrappedException);
	}
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:13,代码来源:HttpHealthCheck.java


示例12: testCheckUrlNonExistent

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
@Test
public void testCheckUrlNonExistent() throws Exception {
	makeCheck3Args(TEST_URL, TEST_TIMEOUT, TEST_HEADERS);
	FieldUtils.writeField(healthCheck3Args, "checkUrl", "invalidUrl", true);

	HealthCheck.Result result = healthCheck3Args.check();
	// System.out.println(result.getMessage());

	Mockito.verify(loggerMock).error(Matchers.anyString(), Matchers.any(ContextedRuntimeException.class));
	Assert.assertTrue(result.getMessage().contains("invalidUrl"));
	Assert.assertTrue(result.getMessage().contains("10"));
	Assert.assertTrue(result.getMessage().contains("headerMap=[]"));
	Assert.assertFalse(result.isHealthy());
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:15,代码来源:HttpHealthCheckTest.java


示例13: testCloseClusterQuietlyClusterException

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
@Test
public void testCloseClusterQuietlyClusterException() throws Exception {
	testCluster.exceptionToThrow = new RuntimeException("crap");
	MethodUtils.invokeMethod(healthCheck, true, "closeClusterQuietly", testCluster);
	Assert.assertEquals(1, testCluster.nbrTimesCloseCalled);

	ArgumentCaptor<ContextedRuntimeException> exCaptor = ArgumentCaptor.forClass(ContextedRuntimeException.class);
	Mockito.verify(loggerMock).warn(Matchers.anyString(), exCaptor.capture());
	Assert.assertEquals(3, exCaptor.getValue().getContextLabels().size());
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:11,代码来源:CassandraHealthCheckTest.java


示例14: testCloseSessionQuietlyException

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
@Test
public void testCloseSessionQuietlyException() throws Exception {
	Mockito.doThrow(new RuntimeException("crap")).when(session).close();
	MethodUtils.invokeMethod(healthCheck, true, "closeSessionQuietly", session);
	Mockito.verify(session).close();

	ArgumentCaptor<ContextedRuntimeException> exCaptor = ArgumentCaptor.forClass(ContextedRuntimeException.class);
	Mockito.verify(loggerMock).warn(Matchers.anyString(), exCaptor.capture());
	Assert.assertEquals(3, exCaptor.getValue().getContextLabels().size());
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:11,代码来源:CassandraHealthCheckTest.java


示例15: safeClose

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
private void safeClose(AutoCloseable statement) {
	try {
		if (statement != null) {
			statement.close();
		}
	} catch (Exception e) {
		logger.warn("JDBC Statement erred on close",
				new ContextedRuntimeException(e).addContextValue("datasource", dataSource));
	}
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:11,代码来源:DataSourceHealthCheck.java


示例16: checkQueryExecutionFailure

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
@Test
public void checkQueryExecutionFailure() throws Exception {

	Mockito.when(dataSourceMock.getConnection()).thenReturn(connectionMock);
	Mockito.when(connectionMock.createStatement()).thenReturn(statementMock);
	Mockito.when(statementMock.executeQuery(TEST_QUERY)).thenThrow(TEST_EXCEPTION);

	Result result = healthCheck.check();
	Assert.assertTrue(!result.isHealthy());
	Assert.assertEquals(TEST_EXCEPTION, result.getError().getCause());

	Mockito.verify(loggerMock).error(Matchers.anyString(), Matchers.any(ContextedRuntimeException.class));
	Mockito.verify(connectionMock).close();
	Mockito.verify(statementMock).close();
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:16,代码来源:DataSourceHealthCheckTest.java


示例17: checkCloseFailure

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
@Test
public void checkCloseFailure() throws Exception {
	mockSetup();
	Mockito.doThrow(TEST_EXCEPTION).when(connectionMock).close();

	Result result = healthCheck.check();
	Assert.assertTrue(result.isHealthy());

	Mockito.verify(loggerMock).warn(Matchers.anyString(), Matchers.any(ContextedRuntimeException.class));
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:11,代码来源:DataSourceHealthCheckTest.java


示例18: check

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
@Override
protected Result check() throws Exception {
	MongoClient mongoClient = null;
	String databaseList = null;
	String databaseStats = null;

	try {
		mongoClient = createMongoClient();
		MongoIterable<String> dbList = mongoClient.listDatabaseNames();
		databaseList = StringUtils.join(dbList, ',');

		CommandResult resultSet = mongoClient.getDB(databaseName).getStats();
		databaseStats = resultSet.toString();
		logger.debug("connectionUrl={} databaseList={} stats={}", connectionUrl, databaseList, databaseStats);

		Integer nbrCollections = (Integer) resultSet.get("collections");
		if (nbrCollections == 0) {
			throw new RuntimeException("Database has nothing in it.");
		}
	} catch (Exception e) {
		ContextedRuntimeException wrappedException = wrapException(e);
		wrappedException.addContextValue("databaseList", databaseList);
		wrappedException.addContextValue("databaseStats", databaseStats);

		logger.error("MongoDB Healthcheck Failure", wrappedException);
		return Result.unhealthy(wrappedException);
	} finally {
		closeQuietly(mongoClient);
	}

	return Result.healthy();
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:33,代码来源:MongoDbHealthCheck.java


示例19: testCloseQuietlyExcepting

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
@Test
public void testCloseQuietlyExcepting() throws Exception {
	TestMongoClient mongoClient = new TestMongoClient();
	mongoClient.exceptionToThrow = TEST_EXCEPTION;
	MethodUtils.invokeMethod(healthCheck, true, "closeQuietly", mongoClient);

	ArgumentCaptor<ContextedRuntimeException> exCaptor = ArgumentCaptor.forClass(ContextedRuntimeException.class);
	Mockito.verify(loggerMock).warn(Matchers.anyString(), exCaptor.capture());
	Assert.assertEquals(2, exCaptor.getValue().getContextLabels().size());
	Assert.assertEquals(mongoClient.exceptionToThrow, exCaptor.getValue().getCause());
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:12,代码来源:MongoDbHealthCheckTest.java


示例20: testWrapException

import org.apache.commons.lang3.exception.ContextedRuntimeException; //导入依赖的package包/类
@Test
public void testWrapException() throws Exception {
	ContextedRuntimeException wrapped = (ContextedRuntimeException) MethodUtils.invokeMethod(healthCheck, true,
			"wrapException", TEST_EXCEPTION);
	Assert.assertEquals(TEST_EXCEPTION, wrapped.getCause());
	Assert.assertEquals(2, wrapped.getContextEntries().size());
	Assert.assertEquals(TEST_CONNECT_URL, wrapped.getContextValues("connectionUrl").get(0));
	Assert.assertEquals(TEST_DATABASE, wrapped.getContextValues("databaseName").get(0));
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:10,代码来源:MongoDbHealthCheckTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DCEndPosTree类代码示例发布时间:2022-05-22
下一篇:
Java ClientData类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap