Search in sources :

Example 1 with ListJobIdsRequest

use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobIdsRequest in project mantis by Netflix.

the class JobClusterTest method testListJobIdsForCluster.

@Test
public void testListJobIdsForCluster() throws InvalidJobException {
    TestKit probe = new TestKit(system);
    String clusterName = "testListJobsForCluster";
    MantisScheduler schedulerMock = mock(MantisScheduler.class);
    MantisJobStore jobStoreMock = mock(MantisJobStore.class);
    final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName);
    ActorRef jobClusterActor = system.actorOf(props(clusterName, jobStoreMock, schedulerMock, eventPublisher));
    jobClusterActor.tell(new JobClusterProto.InitializeJobClusterRequest(fakeJobCluster, user, probe.getRef()), probe.getRef());
    JobClusterProto.InitializeJobClusterResponse createResp = probe.expectMsgClass(JobClusterProto.InitializeJobClusterResponse.class);
    assertEquals(SUCCESS, createResp.responseCode);
    final JobDefinition jobDefn1 = createJob(clusterName);
    String jobId = clusterName + "-1";
    JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn1, jobId);
    String jobId2 = clusterName + "-2";
    JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn1, jobId2);
    jobClusterActor.tell(new ListJobIdsRequest(), probe.getRef());
    ListJobIdsResponse listResp = probe.expectMsgClass(ListJobIdsResponse.class);
    assertEquals(SUCCESS, listResp.responseCode);
    assertEquals(2, listResp.getJobIds().size());
    boolean foundJob1 = false;
    boolean foundJob2 = false;
    for (JobClusterProtoAdapter.JobIdInfo jobIdInfo : listResp.getJobIds()) {
        if (jobIdInfo.getJobId().equals(jobId)) {
            foundJob1 = true;
        } else if (jobIdInfo.getJobId().equals(jobId2)) {
            foundJob2 = true;
        }
    }
    assertTrue(foundJob1);
    assertTrue(foundJob2);
    JobTestHelper.killJobAndVerify(probe, clusterName, new JobId(clusterName, 1), jobClusterActor);
    jobClusterActor.tell(new ListJobIdsRequest(empty(), empty(), of(true), empty(), empty(), empty()), probe.getRef());
    ListJobIdsResponse listResp2 = probe.expectMsgClass(ListJobIdsResponse.class);
    assertEquals(SUCCESS, listResp2.responseCode);
    assertEquals(1, listResp2.getJobIds().size());
    // assertFalse(listResp2.getJobIds().contains(JobId.fromId(jobId).get()));
    // assertTrue(listResp2.getJobIds().contains(JobId.fromId(jobId2).get()));
    foundJob1 = false;
    foundJob2 = false;
    for (JobClusterProtoAdapter.JobIdInfo jobIdInfo : listResp2.getJobIds()) {
        if (jobIdInfo.getJobId().equals(jobId)) {
            foundJob1 = true;
        } else if (jobIdInfo.getJobId().equals(jobId2)) {
            foundJob2 = true;
        }
    }
    assertFalse(foundJob1);
    assertTrue(foundJob2);
    JobTestHelper.killJobAndVerify(probe, clusterName, new JobId(clusterName, 2), jobClusterActor);
    jobClusterActor.tell(new ListJobIdsRequest(), probe.getRef());
    ListJobIdsResponse listResp3 = probe.expectMsgClass(ListJobIdsResponse.class);
    assertEquals(SUCCESS, listResp3.responseCode);
    assertEquals(0, listResp3.getJobIds().size());
    // assertFalse(listResp3.getJobIds().contains(JobId.fromId(jobId).get()));
    // assertFalse(listResp3.getJobIds().contains(JobId.fromId(jobId2).get()));
    foundJob1 = false;
    foundJob2 = false;
    for (JobClusterProtoAdapter.JobIdInfo jobIdInfo : listResp3.getJobIds()) {
        if (jobIdInfo.getJobId().equals(jobId)) {
            foundJob1 = true;
        } else if (jobIdInfo.getJobId().equals(jobId2)) {
            foundJob2 = true;
        }
    }
    assertFalse(foundJob1);
    assertFalse(foundJob2);
}
Also used : JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) ActorRef(akka.actor.ActorRef) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) TestKit(akka.testkit.javadsl.TestKit) Matchers.anyString(org.mockito.Matchers.anyString) ListJobIdsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobIdsResponse) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) ListJobIdsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobIdsRequest) JobClusterProtoAdapter(io.mantisrx.master.api.akka.route.proto.JobClusterProtoAdapter) Test(org.junit.Test)

Example 2 with ListJobIdsRequest

use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobIdsRequest in project mantis by Netflix.

the class JobClusterTest method testJobSubmitTriggersSLAToKillOldHandlesErrors.

// TODO   @Test
public void testJobSubmitTriggersSLAToKillOldHandlesErrors() {
    TestKit probe = new TestKit(system);
    String clusterName = "testJobSubmitTriggersSLAToKillOldHandlesErrors";
    MantisScheduler schedulerMock = mock(MantisScheduler.class);
    MantisJobStore jobStoreMock = mock(MantisJobStore.class);
    SLA sla = new SLA(1, 1, null, null);
    final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName, Lists.newArrayList(), sla);
    ActorRef jobClusterActor = system.actorOf(props(clusterName, jobStoreMock, schedulerMock, eventPublisher));
    jobClusterActor.tell(new JobClusterProto.InitializeJobClusterRequest(fakeJobCluster, user, probe.getRef()), probe.getRef());
    JobClusterProto.InitializeJobClusterResponse createResp = probe.expectMsgClass(JobClusterProto.InitializeJobClusterResponse.class);
    assertEquals(SUCCESS, createResp.responseCode);
    try {
        doThrow(new NullPointerException("NPE archiving worker")).when(jobStoreMock).archiveWorker(any());
        final JobDefinition jobDefn = createJob(clusterName, 1, MantisJobDurationType.Transient);
        String jobId = clusterName + "-1";
        JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn, jobId);
        JobTestHelper.getJobDetailsAndVerify(probe, jobClusterActor, jobId, SUCCESS, JobState.Accepted);
        JobTestHelper.sendLaunchedInitiatedStartedEventsToWorker(probe, jobClusterActor, jobId, 1, new WorkerId(clusterName, jobId, 0, 1));
        JobTestHelper.getJobDetailsAndVerify(probe, jobClusterActor, jobId, SUCCESS, JobState.Launched);
        // submit 2nd job
        String jobId2 = clusterName + "-2";
        JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn, jobId2);
        JobTestHelper.getJobDetailsAndVerify(probe, jobClusterActor, jobId2, SUCCESS, JobState.Accepted);
        JobTestHelper.sendLaunchedInitiatedStartedEventsToWorker(probe, jobClusterActor, jobId2, 1, new WorkerId(clusterName, jobId2, 0, 1));
        JobTestHelper.getJobDetailsAndVerify(probe, jobClusterActor, jobId2, SUCCESS, JobState.Launched);
        boolean completed = false;
        assertTrue(JobTestHelper.verifyJobStatusWithPolling(probe, jobClusterActor, jobId, JobState.Completed));
        // try a few times for timing issue
        // for(int i=0; i<10; i++) {
        // jobClusterActor.tell(new GetJobDetailsRequest("nj", JobId.fromId(jobId).get()), probe.getRef());
        // GetJobDetailsResponse detailsResp = probe.expectMsgClass(GetJobDetailsResponse.class);
        // if(JobState.Completed.equals(detailsResp.getJobMetadata().get().getState())) {
        // completed = true;
        // break;
        // }
        // }
        // assertTrue(completed);
        jobClusterActor.tell(new ListJobIdsRequest(), probe.getRef());
        ListJobIdsResponse listResp = probe.expectMsgClass(ListJobIdsResponse.class);
        assertEquals(1, listResp.getJobIds().size());
        assertEquals(jobId2, listResp.getJobIds().get(0).getJobId());
    // JobTestHelper.getJobDetailsAndVerify(probe, jobClusterActor, jobId, SUCCESS, JobState.Completed);
    // JobTestHelper.killJobAndVerify(probe, clusterName, new JobId(clusterName, 2), jobClusterActor);
    // verify(jobStoreMock, times(1)).createJobCluster(any());
    // verify(jobStoreMock, times(1)).updateJobCluster(any());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        fail();
    }
// Mockito.doThrow(IOException.class).when(jobStoreMock).storeNewJob(any());
}
Also used : JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) ActorRef(akka.actor.ActorRef) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) TestKit(akka.testkit.javadsl.TestKit) Matchers.anyString(org.mockito.Matchers.anyString) ListJobIdsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobIdsResponse) WorkerId(io.mantisrx.server.core.domain.WorkerId) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) ListJobIdsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobIdsRequest)

Aggregations

ActorRef (akka.actor.ActorRef)2 TestKit (akka.testkit.javadsl.TestKit)2 ListJobIdsRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobIdsRequest)2 ListJobIdsResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobIdsResponse)2 JobClusterProto (io.mantisrx.master.jobcluster.proto.JobClusterProto)2 MantisJobStore (io.mantisrx.server.master.persistence.MantisJobStore)2 MantisScheduler (io.mantisrx.server.master.scheduler.MantisScheduler)2 Matchers.anyString (org.mockito.Matchers.anyString)2 JobClusterProtoAdapter (io.mantisrx.master.api.akka.route.proto.JobClusterProtoAdapter)1 InvalidJobException (io.mantisrx.runtime.command.InvalidJobException)1 WorkerId (io.mantisrx.server.core.domain.WorkerId)1 Test (org.junit.Test)1