İki oyuncu da Play 2.0'da AKKA aktörlerini kullanıyor. Buna göre, bu iki API'ye karşı test edilen iki test vakası vardır. Ancak, 'oyun testi' yürütülürken, sadece bir test vakası başarılı olur, diğeri başarısız olur. Onları ayrı ayrı çalıştırırsam, başarılı bir şekilde çalışır. Önsezim, ilk testle aktör sisteminin kapatılmış olması. Ancak, Play 2 ve Akka için yeniyim, bu benim tahminim. Bir çözüm var mı?Oyna 2.0 Birden fazla testis mevcut olduğunda Akka sisteminin kapatılması
public class PostA extends Controller {
// master actor for workers
public static ActorRef masterActorA = Akka.system().actorOf(new Props(new UntypedActorFactory() {
public UntypedActor create() {
return new PostAActorMaster(Config.NUMBER_OF_WORKER_ACTOR);
}
}), "PostAActorMaster");
public static Result postA() {
Map<String, String[]> dict = body.asFormUrlEncoded();
String paramField1 = dict.get("paramField1");
String paramField2 = dict.get("paramField2");
ProductInfo pInfo = new ProductInfo(paramField1, paramField2);
ProductMessage pMessage = new ProductMessage(pInfo);
return async(
Akka.asPromise(ask(masterActorA, pMessage, 15000)).map(
new Function<Object, Result>() {
...
}
));
}
public class PostB extends Controller {
// master actor for workers
public static ActorRef masterActorB = Akka.system().actorOf(new Props(new UntypedActorFactory() {
public UntypedActor create() {
return new PostBActorMaster(Config.NUMBER_OF_WORKER_ACTOR);
}
}), "PostBActorMaster");
public static Result postB() {
Map<String, String[]> dict = body.asFormUrlEncoded();
String paramField3 = dict.get("paramField3");
String paramField4 = dict.get("paramField4");
BillInfo bInfo = new BillInfo(paramField3, paramField4);
BillMessage pMessage = new BillMessage(bInfo);
return async(
Akka.asPromise(ask(masterActorB, pMessage, 15000)).map(
new Function<Object, Result>() {
...
}
));
}
Posta'nın AKKA Master ve işçi:
@Test
public void callPostA() {
running(testServer(2222, fakeApplication(inMemoryDatabase())), new Runnable() {
@Override
public void run() {
HttpPost httpPost = new HttpPost("http://localhost:2222/controllera");
....
}
});
}
@Test
public void callPostB() {
running(testServer(2222, fakeApplication(inMemoryDatabase())), new Runnable() {
@Override
public void run() {
HttpPost httpPost = new HttpPost("http://localhost:2222/controllerb");
....
}
});
}
İki kontrolörleri aşağıdaki gibidir
public class PostAActorMaster extends UntypedActor {
private final ActorRef workerRouter;
public PostAActorMaster(final int nrOfWorkers) {
workerRouter = this.getContext().actorOf(new Props(PostAActorMaster.class).withRouter(new RoundRobinRouter(nrOfWorkers)));
}
public void onReceive(Object messageObj) {
try {
if (messageObj instanceof ProductMessage) {
// invoke worker to submit channel messaages
workerRouter.tell(messageObj, getSender());
} else if (messageObj instanceof ProductMessageResult) {
......
getSender().tell("OK");
}
} catch (Exception e) {
......
}
}
}
public class PostAActorWorker extends UntypedActor {
public void onReceive(Object messageObj) throws Exception {
if (messageObj instanceof ProductMessage) {
ProductMessage pMessage = (ProductMessage)messageObj;
ProductInfo pInfo = pMessage.getProductInfo();
log.info(pInfo.getProductId());
ProductMessageResult pr = new ProductMessageResult(pInfo);
PostA.masterActor.tell(pr, getSender());
}
}
}
Yönetilen Nesne:
public class ProductInfo extends Model {
@Id
private String productId;
...
}
Bir çözüm buldunuz mu? 2.2.4 – Isammoc
da aynı sorun var. Ayrıca benzer sorunları gördüm - 2.3 akka spring play2 aktör sistemini kullanarak. – JasonG
[hata] sbt.ForkMain $ ForkError: Dosyada tanımlanmış 'accountServiceController' adıyla fasulye yaratılırken hata oluştu [/Users/admin/Delelopment/src/totes/app/target/scala-2.11/classes/controllers/AccountServiceController.class]: Fasulyenin örneklenmesi başarısız oldu; nested exception org.springframework.beans.BeanInstantiationException: Bean sınıfı [controllers.AccountServiceController] örneği oluşturulamıyor: Constructor istisnayı attı; iç içe istisna java.lang.IllegalStateException: – JasonG