AbstractActorWithDiscardOldStash() { actorCell = (ActorCell) getContext(); if (!(actorCell.mailbox().messageQueue() instanceof DequeBasedMessageQueueSemantics)) { throw new IllegalArgumentException(MessageFormat .format("DequeBasedMailbox required, got: {0}", actorCell.mailbox().getClass().getSimpleName())); } mailbox = (DequeBasedMessageQueueSemantics) actorCell.mailbox().messageQueue(); capacity = getContext().system() .mailboxes() .stashCapacity(getContext().props().dispatcher(), getContext().props().mailbox()); theStash = new Vector<>(capacity); }
AbstractActorWithDiscardOldStash() { actorCell = (ActorCell) getContext(); if (!(actorCell.mailbox().messageQueue() instanceof DequeBasedMessageQueueSemantics)) { throw new IllegalArgumentException(MessageFormat .format("DequeBasedMailbox required, got: {0}", actorCell.mailbox().getClass().getSimpleName())); } mailbox = (DequeBasedMessageQueueSemantics) actorCell.mailbox().messageQueue(); capacity = getContext().system() .mailboxes() .stashCapacity(getContext().props().dispatcher(), getContext().props().mailbox()); theStash = new Vector<>(capacity); }
@Test public void shouldSendMsgToDeadLetterWhenQueueIsFull() { final TestKit mockReceiver = new TestKit(actorSystem); actorSystem.eventStream().subscribe(mockReceiver.testActor(), DeadLetter.class); final FiniteDuration twentySeconds = new FiniteDuration(20, TimeUnit.SECONDS); ActorRef pingPongActor = actorSystem.actorOf(PingPongActor.props(lock).withMailbox(config.getMailBoxName()), "pingpongactor"); actorSystem.mailboxes().settings(); lock.lock(); try { //queue capacity = 10 //need to send 12 messages; 1 message is dequeued and actor waits on lock, //2nd to 11th messages are put on the queue //12th message is sent to dead letter. for (int i = 0; i < 12; i++) { pingPongActor.tell("ping", mockReceiver.testActor()); } mockReceiver.expectMsgClass(twentySeconds, DeadLetter.class); } finally { lock.unlock(); } mockReceiver.receiveN(11, twentySeconds); }