2012-07-15 14:12:03 +02:00
|
|
|
package docs.camel;
|
2012-07-23 01:36:12 +02:00
|
|
|
//#CamelActivation
|
|
|
|
|
import akka.actor.ActorRef;
|
|
|
|
|
import akka.actor.ActorSystem;
|
|
|
|
|
import akka.actor.Props;
|
|
|
|
|
import akka.camel.Camel;
|
|
|
|
|
import akka.camel.CamelExtension;
|
|
|
|
|
import akka.camel.javaapi.UntypedConsumerActor;
|
2013-05-02 17:12:36 +02:00
|
|
|
import akka.testkit.JavaTestKit;
|
|
|
|
|
import akka.testkit.TestKit;
|
2012-09-03 12:08:46 +02:00
|
|
|
import akka.util.Timeout;
|
2012-07-23 15:49:19 +02:00
|
|
|
import scala.concurrent.Future;
|
2012-10-15 16:18:52 +02:00
|
|
|
import scala.concurrent.duration.Duration;
|
2012-07-23 01:36:12 +02:00
|
|
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
|
|
|
|
//#CamelActivation
|
2012-07-15 14:12:03 +02:00
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
public class ActivationTestBase {
|
|
|
|
|
|
2013-04-14 22:56:41 +02:00
|
|
|
@SuppressWarnings("unused")
|
2012-07-15 14:12:03 +02:00
|
|
|
@Test
|
|
|
|
|
public void testActivation() {
|
|
|
|
|
//#CamelActivation
|
2012-07-23 01:36:12 +02:00
|
|
|
|
|
|
|
|
// ..
|
2012-07-15 14:12:03 +02:00
|
|
|
ActorSystem system = ActorSystem.create("some-system");
|
2013-04-14 22:56:41 +02:00
|
|
|
Props props = Props.create(MyConsumer.class);
|
2012-07-15 14:12:03 +02:00
|
|
|
ActorRef producer = system.actorOf(props,"myproducer");
|
|
|
|
|
Camel camel = CamelExtension.get(system);
|
|
|
|
|
// get a future reference to the activation of the endpoint of the Consumer Actor
|
2012-09-03 12:08:46 +02:00
|
|
|
Timeout timeout = new Timeout(Duration.create(10, SECONDS));
|
2012-10-01 20:35:19 +02:00
|
|
|
Future<ActorRef> activationFuture = camel.activationFutureFor(producer,
|
|
|
|
|
timeout, system.dispatcher());
|
2012-07-15 14:12:03 +02:00
|
|
|
//#CamelActivation
|
|
|
|
|
//#CamelDeactivation
|
2012-07-23 01:36:12 +02:00
|
|
|
// ..
|
2012-07-15 14:12:03 +02:00
|
|
|
system.stop(producer);
|
|
|
|
|
// get a future reference to the deactivation of the endpoint of the Consumer Actor
|
2012-10-01 20:35:19 +02:00
|
|
|
Future<ActorRef> deactivationFuture = camel.deactivationFutureFor(producer,
|
|
|
|
|
timeout, system.dispatcher());
|
2012-07-15 14:12:03 +02:00
|
|
|
//#CamelDeactivation
|
2013-05-02 17:12:36 +02:00
|
|
|
JavaTestKit.shutdownActorSystem(system);
|
2012-07-15 14:12:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class MyConsumer extends UntypedConsumerActor {
|
|
|
|
|
public String getEndpointUri() {
|
|
|
|
|
return "direct:test";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onReceive(Object message) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|