use of org.apache.camel.CamelExecutionException in project camel by apache.
the class SimpleScheduledRoutePolicyTest method testScheduledSuspendAndResumeRoutePolicy.
@Test
public void testScheduledSuspendAndResumeRoutePolicy() throws Exception {
MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);
success.expectedMessageCount(1);
context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
context.addRoutes(new RouteBuilder() {
public void configure() {
SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
long suspendTime = System.currentTimeMillis() + 1000L;
policy.setRouteSuspendDate(new Date(suspendTime));
policy.setRouteSuspendRepeatCount(0);
policy.setRouteSuspendRepeatInterval(3000);
long resumeTime = System.currentTimeMillis() + 4000L;
policy.setRouteResumeDate(new Date(resumeTime));
policy.setRouteResumeRepeatCount(1);
policy.setRouteResumeRepeatInterval(3000);
from("direct:start").routeId("test").routePolicy(policy).to("mock:success");
}
});
context.start();
Thread.sleep(1000);
try {
template.sendBody("direct:start", "Ready or not, Here, I come");
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
LOG.debug("Consumer successfully suspended");
}
Thread.sleep(4000);
template.sendBody("direct:start", "Ready or not, Here, I come");
context.getComponent("quartz2", QuartzComponent.class).stop();
success.assertIsSatisfied();
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class SimpleScheduledRoutePolicyTest method testScheduledStopRoutePolicy.
@Test
public void testScheduledStopRoutePolicy() throws Exception {
context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
context.addRoutes(new RouteBuilder() {
public void configure() {
SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
long startTime = System.currentTimeMillis() + 3000;
policy.setRouteStopDate(new Date(startTime));
policy.setRouteStopRepeatCount(1);
policy.setRouteStopRepeatInterval(3000);
from("direct:start").routeId("test").routePolicy(policy).to("mock:unreachable");
}
});
context.start();
Thread.sleep(4000);
assertTrue(context.getRouteStatus("test") == ServiceStatus.Stopped);
boolean consumerStopped = false;
try {
template.sendBody("direct:start", "Ready or not, Here, I come");
} catch (CamelExecutionException e) {
consumerStopped = true;
}
assertTrue(consumerStopped);
context.getComponent("quartz2", QuartzComponent.class).stop();
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class RabbitMQInOutIntTest method partiallySerializeTest.
@Test
public void partiallySerializeTest() throws InterruptedException, IOException {
TestPartiallySerializableObject foo = new TestPartiallySerializableObject();
foo.setName("foobar");
try {
TestPartiallySerializableObject reply = template.requestBodyAndHeader("direct:rabbitMQ", foo, RabbitMQConstants.EXCHANGE_NAME, EXCHANGE, TestPartiallySerializableObject.class);
} catch (CamelExecutionException e) {
// expected
}
// Make sure we didn't crash the one Consumer thread
String reply2 = template.requestBodyAndHeader("direct:rabbitMQ", "partiallySerializeTest1", RabbitMQConstants.EXCHANGE_NAME, EXCHANGE, String.class);
assertEquals("partiallySerializeTest1 response", reply2);
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class RestApiIntegrationTest method testRetryFailure.
@Test
public void testRetryFailure() throws Exception {
final SalesforceComponent sf = context().getComponent("salesforce", SalesforceComponent.class);
final String accessToken = sf.getSession().getAccessToken();
final SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setSslContext(new SSLContextParameters().createSSLContext(context));
final HttpClient httpClient = new HttpClient(sslContextFactory);
httpClient.setConnectTimeout(60000);
httpClient.start();
final String uri = sf.getLoginConfig().getLoginUrl() + "/services/oauth2/revoke?token=" + accessToken;
final Request logoutGet = httpClient.newRequest(uri).method(HttpMethod.GET).timeout(1, TimeUnit.MINUTES);
final ContentResponse response = logoutGet.send();
assertEquals(HttpStatus.OK_200, response.getStatus());
// set component config to bad password to cause relogin attempts to fail
final String password = sf.getLoginConfig().getPassword();
sf.getLoginConfig().setPassword("bad_password");
try {
testGetGlobalObjects();
fail("Expected CamelExecutionException!");
} catch (final CamelExecutionException e) {
if (e.getCause() instanceof SalesforceException) {
final SalesforceException cause = (SalesforceException) e.getCause();
assertEquals("Expected 400 on authentication retry failure", HttpStatus.BAD_REQUEST_400, cause.getStatusCode());
} else {
fail("Expected SalesforceException!");
}
} finally {
// reset password and retries to allow other tests to pass
sf.getLoginConfig().setPassword(password);
}
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class BeanNoTypeConvertionPossibleWhenHeaderTest method testBeanHeaderNoTypeConvertionPossibleFail.
public void testBeanHeaderNoTypeConvertionPossibleFail() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(0);
// we send in a bar string as header which cannot be converted to a number so it should fail
try {
template.requestBodyAndHeader("direct:start", "Hello World", "foo", 555);
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
ParameterBindingException pbe = assertIsInstanceOf(ParameterBindingException.class, e.getCause());
assertEquals(1, pbe.getIndex());
assertTrue(pbe.getMethod().getName().contains("hello"));
assertEquals(555, pbe.getParameterValue());
NoTypeConversionAvailableException ntae = assertIsInstanceOf(NoTypeConversionAvailableException.class, e.getCause().getCause());
assertEquals(Integer.class, ntae.getFromType());
assertEquals(Document.class, ntae.getToType());
assertEquals(555, ntae.getValue());
assertNotNull(ntae.getMessage());
}
assertMockEndpointsSatisfied();
}
Aggregations