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


Java ContextedRuntimeException类代码示例

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


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


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