@Test
  public void MinionsSpawnAt30SecondsInterval() throws Exception {
    int tickPerSecond = 10;
    Engine engine = new Engine();
    Nexus nexus = new Nexus(engine);
    SummonerRiftNexusBehavior behavior = new SummonerRiftNexusBehavior(engine, nexus);
    nexus.setBehavior(behavior);
    engine.addActor(nexus);

    Actor spectator = Mockito.mock(Actor.class);
    engine.addActor(spectator);
    engine.start();

    engine.enqueue(new TickEvent(LocalTime.parse("00:01:30"), tickPerSecond));
    Mockito.verify(spectator, Mockito.timeout(100).times(1))
        .onEvent(Matchers.isA(MinionWaveSpawnEvent.class));

    engine.enqueue(new TickEvent(LocalTime.parse("00:01:40"), tickPerSecond));
    Mockito.verify(spectator, Mockito.timeout(100).times(1))
        .onEvent(Matchers.isA(MinionWaveSpawnEvent.class));

    engine.enqueue(new TickEvent(LocalTime.parse("00:01:50"), tickPerSecond));
    Mockito.verify(spectator, Mockito.timeout(100).times(1))
        .onEvent(Matchers.isA(MinionWaveSpawnEvent.class));

    engine.enqueue(new TickEvent(LocalTime.parse("00:02:00"), tickPerSecond));
    Mockito.verify(spectator, Mockito.timeout(100).times(2))
        .onEvent(Matchers.isA(MinionWaveSpawnEvent.class));
  }
  @Test
  public void testAbortJobCalledAfterKillingTasks() throws IOException {
    Configuration conf = new Configuration();
    conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
    conf.set(MRJobConfig.MR_AM_COMMITTER_CANCEL_TIMEOUT_MS, "1000");
    InlineDispatcher dispatcher = new InlineDispatcher();
    dispatcher.init(conf);
    dispatcher.start();
    OutputCommitter committer = Mockito.mock(OutputCommitter.class);
    CommitterEventHandler commitHandler = createCommitterEventHandler(dispatcher, committer);
    commitHandler.init(conf);
    commitHandler.start();
    JobImpl job = createRunningStubbedJob(conf, dispatcher, 2, null);

    // Fail one task. This should land the JobImpl in the FAIL_WAIT state
    job.handle(
        new JobTaskEvent(MRBuilderUtils.newTaskId(job.getID(), 1, TaskType.MAP), TaskState.FAILED));
    // Verify abort job hasn't been called
    Mockito.verify(committer, Mockito.never())
        .abortJob((JobContext) Mockito.any(), (State) Mockito.any());
    assertJobState(job, JobStateInternal.FAIL_WAIT);

    // Verify abortJob is called once and the job failed
    Mockito.verify(committer, Mockito.timeout(2000).times(1))
        .abortJob((JobContext) Mockito.any(), (State) Mockito.any());
    assertJobState(job, JobStateInternal.FAILED);

    dispatcher.stop();
  }
  @Test(timeout = 10000)
  public void testFailAbortDoesntHang() throws IOException {
    Configuration conf = new Configuration();
    conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
    conf.set(MRJobConfig.MR_AM_COMMITTER_CANCEL_TIMEOUT_MS, "1000");

    DrainDispatcher dispatcher = new DrainDispatcher();
    dispatcher.init(conf);
    dispatcher.start();
    OutputCommitter committer = Mockito.mock(OutputCommitter.class);
    CommitterEventHandler commitHandler = createCommitterEventHandler(dispatcher, committer);
    commitHandler.init(conf);
    commitHandler.start();
    // Job has only 1 mapper task. No reducers
    conf.setInt(MRJobConfig.NUM_REDUCES, 0);
    conf.setInt(MRJobConfig.MAP_MAX_ATTEMPTS, 1);
    JobImpl job = createRunningStubbedJob(conf, dispatcher, 1, null);

    // Fail / finish all the tasks. This should land the JobImpl directly in the
    // FAIL_ABORT state
    for (Task t : job.tasks.values()) {
      TaskImpl task = (TaskImpl) t;
      task.handle(new TaskEvent(task.getID(), TaskEventType.T_SCHEDULE));
      for (TaskAttempt ta : task.getAttempts().values()) {
        task.handle(new TaskTAttemptEvent(ta.getID(), TaskEventType.T_ATTEMPT_FAILED));
      }
    }
    assertJobState(job, JobStateInternal.FAIL_ABORT);

    dispatcher.await();
    // Verify abortJob is called once and the job failed
    Mockito.verify(committer, Mockito.timeout(2000).times(1))
        .abortJob((JobContext) Mockito.any(), (State) Mockito.any());
    assertJobState(job, JobStateInternal.FAILED);

    dispatcher.stop();
  }
Example #4
0
  @Test
  public void testProcessMessage() throws Exception {
    log.info("starting testProcessMessage ... ");

    MockPacketProcessor pp =
        new MockPacketProcessor(
            new PacketProcessor() {

              @Override
              public void processPacket(SmppRequest packet, ResponseSender responseSender) {
                if (packet.getCommandId() == SmppPacket.SUBMIT_SM) {
                  responseSender.send(Response.OK.withMessageId("12000"));
                  return;
                }

                responseSender.send(Response.OK);
              }
            });
    server.setPacketProcessor(pp);

    MessageStore messageStore = Mockito.mock(MessageStore.class);

    Message m = new Message();
    m.setProperty("to", "3002175604");
    m.setProperty("from", "3542");

    Mockito.when(messageStore.list(Mockito.any(MessageCriteria.class)))
        .thenReturn(Collections.singletonList(m));

    SmppConfiguration configuration = new SmppConfiguration();
    configuration.setHost("localhost");
    configuration.setPort(SERVER_PORT);
    configuration.setSystemId("test");
    configuration.setPassword("test");
    configuration.setDataCoding(3);

    SmppConnector connector = new SmppConnector(configuration);
    injectResource(new MockProcessorContext(), connector);
    injectResource(messageStore, connector);
    connector.doStart();
    waitUntilStatus(connector, DEFAULT_TIMEOUT, Status.OK);

    try {
      Message message = new Message();
      message.setProperty("to", "3002175604");
      message.setProperty("from", "3542");
      message.setProperty("text", "This is the test with ñ");

      connector.process(message);

      Assert.assertNotNull(message.getReference());

      Mockito.verify(messageStore, Mockito.timeout(1000)).saveOrUpdate(Mockito.any(Message.class));

      List<SmppPacket> packets = pp.getPackets(1, DEFAULT_TIMEOUT);
      Assert.assertNotNull(packets);
      Assert.assertEquals(packets.size(), 1);

      SubmitSm submitSM = (SubmitSm) packets.get(0);
      Assert.assertNotNull(submitSM);
      Assert.assertEquals(submitSM.getDestAddress().getAddress(), "3002175604");
      Assert.assertEquals(submitSM.getSourceAddress().getAddress(), "3542");
      Assert.assertEquals(submitSM.getDataCoding(), 3);

      Assert.assertEquals(submitSM.getShortMessage(), "This is the test with ñ");
    } finally {
      connector.doStop();
    }
  }