当前位置: 首页>>代码示例>>Java>>正文


Java Job.setCurrentState方法代码示例

本文整理汇总了Java中com.google.api.services.dataflow.model.Job.setCurrentState方法的典型用法代码示例。如果您正苦于以下问题:Java Job.setCurrentState方法的具体用法?Java Job.setCurrentState怎么用?Java Job.setCurrentState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.api.services.dataflow.model.Job的用法示例。


在下文中一共展示了Job.setCurrentState方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testEmptyMetricUpdates

import com.google.api.services.dataflow.model.Job; //导入方法依赖的package包/类
@Test
public void testEmptyMetricUpdates() throws IOException {
  Job modelJob = new Job();
  modelJob.setCurrentState(State.RUNNING.toString());

  DataflowPipelineJob job = mock(DataflowPipelineJob.class);
  DataflowPipelineOptions options = mock(DataflowPipelineOptions.class);
  when(options.isStreaming()).thenReturn(false);
  when(job.getDataflowOptions()).thenReturn(options);
  when(job.getState()).thenReturn(State.RUNNING);
  job.jobId = JOB_ID;

  JobMetrics jobMetrics = new JobMetrics();
  jobMetrics.setMetrics(null /* this is how the APIs represent empty metrics */);
  DataflowClient dataflowClient = mock(DataflowClient.class);
  when(dataflowClient.getJobMetrics(JOB_ID)).thenReturn(jobMetrics);

  DataflowMetrics dataflowMetrics = new DataflowMetrics(job, dataflowClient);
  MetricQueryResults result = dataflowMetrics.queryMetrics();
  assertThat(ImmutableList.copyOf(result.counters()), is(empty()));
  assertThat(ImmutableList.copyOf(result.distributions()), is(empty()));
}
 
开发者ID:apache,项目名称:beam,代码行数:23,代码来源:DataflowMetricsTest.java

示例2: testCachingMetricUpdates

import com.google.api.services.dataflow.model.Job; //导入方法依赖的package包/类
@Test
public void testCachingMetricUpdates() throws IOException {
  Job modelJob = new Job();
  modelJob.setCurrentState(State.RUNNING.toString());

  DataflowPipelineJob job = mock(DataflowPipelineJob.class);
  DataflowPipelineOptions options = mock(DataflowPipelineOptions.class);
  when(options.isStreaming()).thenReturn(false);
  when(job.getDataflowOptions()).thenReturn(options);
  when(job.getState()).thenReturn(State.DONE);
  job.jobId = JOB_ID;

  JobMetrics jobMetrics = new JobMetrics();
  jobMetrics.setMetrics(ImmutableList.<MetricUpdate>of());
  DataflowClient dataflowClient = mock(DataflowClient.class);
  when(dataflowClient.getJobMetrics(JOB_ID)).thenReturn(jobMetrics);

  DataflowMetrics dataflowMetrics = new DataflowMetrics(job, dataflowClient);
  verify(dataflowClient, times(0)).getJobMetrics(JOB_ID);
  dataflowMetrics.queryMetrics(null);
  verify(dataflowClient, times(1)).getJobMetrics(JOB_ID);
  dataflowMetrics.queryMetrics(null);
  verify(dataflowClient, times(1)).getJobMetrics(JOB_ID);
}
 
开发者ID:apache,项目名称:beam,代码行数:25,代码来源:DataflowMetricsTest.java

示例3: mockWaitToFinishInState

import com.google.api.services.dataflow.model.Job; //导入方法依赖的package包/类
public State mockWaitToFinishInState(State state) throws Exception {
  Dataflow.Projects.Locations.Jobs.Get statusRequest =
      mock(Dataflow.Projects.Locations.Jobs.Get.class);

  Job statusResponse = new Job();
  statusResponse.setCurrentState("JOB_STATE_" + state.name());
  if (state == State.UPDATED) {
    statusResponse.setReplacedByJobId(REPLACEMENT_JOB_ID);
  }

  when(mockJobs.get(eq(PROJECT_ID), eq(REGION_ID), eq(JOB_ID))).thenReturn(statusRequest);
  when(statusRequest.execute()).thenReturn(statusResponse);

  DataflowPipelineJob job =
      new DataflowPipelineJob(
          DataflowClient.create(options),
          JOB_ID,
          options,
          ImmutableMap.<AppliedPTransform<?, ?, ?>, String>of());

  return job.waitUntilFinish(Duration.standardMinutes(1), null, fastClock, fastClock);
}
 
开发者ID:apache,项目名称:beam,代码行数:23,代码来源:DataflowPipelineJobTest.java

示例4: testCumulativeTimeOverflow

import com.google.api.services.dataflow.model.Job; //导入方法依赖的package包/类
@Test
public void testCumulativeTimeOverflow() throws Exception {
  Dataflow.Projects.Locations.Jobs.Get statusRequest =
      mock(Dataflow.Projects.Locations.Jobs.Get.class);

  Job statusResponse = new Job();
  statusResponse.setCurrentState("JOB_STATE_RUNNING");
  when(mockJobs.get(eq(PROJECT_ID), eq(REGION_ID), eq(JOB_ID))).thenReturn(statusRequest);
  when(statusRequest.execute()).thenReturn(statusResponse);

  FastNanoClockAndFuzzySleeper clock = new FastNanoClockAndFuzzySleeper();

  DataflowPipelineJob job =
      new DataflowPipelineJob(
          DataflowClient.create(options),
          JOB_ID,
          options,
          ImmutableMap.<AppliedPTransform<?, ?, ?>, String>of());
  long startTime = clock.nanoTime();
  State state = job.waitUntilFinish(Duration.millis(4), null, clock, clock);
  assertEquals(null, state);
  long timeDiff = TimeUnit.NANOSECONDS.toMillis(clock.nanoTime() - startTime);
  // Should only have slept for the 4 ms allowed.
  assertThat(timeDiff, lessThanOrEqualTo(4L));
}
 
开发者ID:apache,项目名称:beam,代码行数:26,代码来源:DataflowPipelineJobTest.java

示例5: testGetStateReturnsServiceState

import com.google.api.services.dataflow.model.Job; //导入方法依赖的package包/类
@Test
public void testGetStateReturnsServiceState() throws Exception {
  Dataflow.Projects.Locations.Jobs.Get statusRequest =
      mock(Dataflow.Projects.Locations.Jobs.Get.class);

  Job statusResponse = new Job();
  statusResponse.setCurrentState("JOB_STATE_" + State.RUNNING.name());

  when(mockJobs.get(eq(PROJECT_ID), eq(REGION_ID), eq(JOB_ID))).thenReturn(statusRequest);
  when(statusRequest.execute()).thenReturn(statusResponse);

  DataflowPipelineJob job =
      new DataflowPipelineJob(
          DataflowClient.create(options),
          JOB_ID,
          options,
          ImmutableMap.<AppliedPTransform<?, ?, ?>, String>of());

  assertEquals(
      State.RUNNING,
      job.getStateWithRetries(
          BackOffAdapter.toGcpBackOff(
              DataflowPipelineJob.STATUS_BACKOFF_FACTORY.backoff()),
          fastClock));
}
 
开发者ID:apache,项目名称:beam,代码行数:26,代码来源:DataflowPipelineJobTest.java

示例6: testCancelUnterminatedJobThatFails

import com.google.api.services.dataflow.model.Job; //导入方法依赖的package包/类
@Test
public void testCancelUnterminatedJobThatFails() throws IOException {
  Dataflow.Projects.Locations.Jobs.Get statusRequest =
      mock(Dataflow.Projects.Locations.Jobs.Get.class);

  Job statusResponse = new Job();
  statusResponse.setCurrentState("JOB_STATE_RUNNING");
  when(mockJobs.get(PROJECT_ID, REGION_ID, JOB_ID)).thenReturn(statusRequest);
  when(statusRequest.execute()).thenReturn(statusResponse);

  Dataflow.Projects.Locations.Jobs.Update update = mock(
      Dataflow.Projects.Locations.Jobs.Update.class);
  when(mockJobs.update(eq(PROJECT_ID), eq(REGION_ID), eq(JOB_ID), any(Job.class)))
      .thenReturn(update);
  when(update.execute()).thenThrow(new IOException("Some random IOException"));

  DataflowPipelineJob job =
      new DataflowPipelineJob(DataflowClient.create(options), JOB_ID, options, null);

  thrown.expect(IOException.class);
  thrown.expectMessage("Failed to cancel job in state RUNNING, "
      + "please go to the Developers Console to cancel it manually:");
  job.cancel();
}
 
开发者ID:apache,项目名称:beam,代码行数:25,代码来源:DataflowPipelineJobTest.java

示例7: testCancelTerminatedJobWithStaleState

import com.google.api.services.dataflow.model.Job; //导入方法依赖的package包/类
/**
 * Test that {@link DataflowPipelineJob#cancel} doesn't throw if the Dataflow service returns
 * non-terminal state even though the cancel API call failed, which can happen in practice.
 *
 * <p>TODO: delete this code if the API calls become consistent.
 */
@Test
public void testCancelTerminatedJobWithStaleState() throws IOException {
  Dataflow.Projects.Locations.Jobs.Get statusRequest =
      mock(Dataflow.Projects.Locations.Jobs.Get.class);

  Job statusResponse = new Job();
  statusResponse.setCurrentState("JOB_STATE_RUNNING");
  when(mockJobs.get(PROJECT_ID, REGION_ID, JOB_ID)).thenReturn(statusRequest);
  when(statusRequest.execute()).thenReturn(statusResponse);

  Dataflow.Projects.Locations.Jobs.Update update = mock(
      Dataflow.Projects.Locations.Jobs.Update.class);
  when(mockJobs.update(eq(PROJECT_ID), eq(REGION_ID), eq(JOB_ID), any(Job.class)))
      .thenReturn(update);
  when(update.execute()).thenThrow(new IOException("Job has terminated in state SUCCESS"));

  DataflowPipelineJob job =
      new DataflowPipelineJob(DataflowClient.create(options), JOB_ID, options, null);
  State returned = job.cancel();
  assertThat(returned, equalTo(State.RUNNING));
  expectedLogs.verifyWarn("Cancel failed because job is already terminated.");
}
 
开发者ID:apache,项目名称:beam,代码行数:29,代码来源:DataflowPipelineJobTest.java

示例8: testWaitToFinishMessagesFail

import com.google.api.services.dataflow.model.Job; //导入方法依赖的package包/类
@Test
public void testWaitToFinishMessagesFail() throws Exception {
  Dataflow.Projects.Locations.Jobs.Get statusRequest =
      mock(Dataflow.Projects.Locations.Jobs.Get.class);

  Job statusResponse = new Job();
  statusResponse.setCurrentState("JOB_STATE_" + State.DONE.name());
  when(mockJobs.get(eq(PROJECT_ID), eq(REGION_ID), eq(JOB_ID))).thenReturn(statusRequest);
  when(statusRequest.execute()).thenReturn(statusResponse);

  MonitoringUtil.JobMessagesHandler jobHandler = mock(MonitoringUtil.JobMessagesHandler.class);
  Dataflow.Projects.Locations.Jobs.Messages mockMessages =
      mock(Dataflow.Projects.Locations.Jobs.Messages.class);
  Messages.List listRequest = mock(Dataflow.Projects.Locations.Jobs.Messages.List.class);
  when(mockJobs.messages()).thenReturn(mockMessages);
  when(mockMessages.list(eq(PROJECT_ID), eq(REGION_ID), eq(JOB_ID))).thenReturn(listRequest);
  when(listRequest.setPageToken(eq((String) null))).thenReturn(listRequest);
  when(listRequest.execute()).thenThrow(SocketTimeoutException.class);

  DataflowPipelineJob job =
      new DataflowPipelineJob(
          DataflowClient.create(options),
          JOB_ID,
          options,
          ImmutableMap.<AppliedPTransform<?, ?, ?>, String>of());

  State state = job.waitUntilFinish(
      Duration.standardMinutes(5), jobHandler, fastClock, fastClock);
  assertEquals(null, state);
}
 
开发者ID:apache,项目名称:beam,代码行数:31,代码来源:DataflowPipelineJobTest.java

示例9: testCancelTerminatedJob

import com.google.api.services.dataflow.model.Job; //导入方法依赖的package包/类
@Test
public void testCancelTerminatedJob() throws IOException {
  Dataflow.Projects.Locations.Jobs.Get statusRequest = mock(
      Dataflow.Projects.Locations.Jobs.Get.class);

  Job statusResponse = new Job();
  statusResponse.setCurrentState("JOB_STATE_FAILED");
  when(mockJobs.get(PROJECT_ID, REGION_ID, JOB_ID)).thenReturn(statusRequest);
  when(statusRequest.execute()).thenReturn(statusResponse);

  Dataflow.Projects.Locations.Jobs.Update update = mock(
      Dataflow.Projects.Locations.Jobs.Update.class);
  when(mockJobs.update(eq(PROJECT_ID), eq(REGION_ID), eq(JOB_ID), any(Job.class)))
      .thenReturn(update);
  when(update.execute()).thenThrow(new IOException());

  DataflowPipelineJob job =
      new DataflowPipelineJob(DataflowClient.create(options), JOB_ID, options, null);

  assertEquals(State.FAILED, job.cancel());
  Job content = new Job();
  content.setProjectId(PROJECT_ID);
  content.setId(JOB_ID);
  content.setRequestedState("JOB_STATE_CANCELLED");
  verify(mockJobs).update(eq(PROJECT_ID), eq(REGION_ID), eq(JOB_ID), eq(content));
  verify(mockJobs).get(PROJECT_ID, REGION_ID, JOB_ID);
  verifyNoMoreInteractions(mockJobs);
}
 
开发者ID:apache,项目名称:beam,代码行数:29,代码来源:DataflowPipelineJobTest.java

示例10: testWaitUntilFinishNoRepeatedLogs

import com.google.api.services.dataflow.model.Job; //导入方法依赖的package包/类
/**
 * Tests that a {@link DataflowPipelineJob} does not duplicate messages.
 */
@Test
public void testWaitUntilFinishNoRepeatedLogs() throws Exception {
  DataflowPipelineJob job = new DataflowPipelineJob(mockDataflowClient, JOB_ID, options, null);
  Sleeper sleeper = new ZeroSleeper();
  NanoClock nanoClock = mock(NanoClock.class);

  Instant separatingTimestamp = new Instant(42L);
  JobMessage theMessage = infoMessage(separatingTimestamp, "nothing");

  MonitoringUtil mockMonitor = mock(MonitoringUtil.class);
  when(mockMonitor.getJobMessages(anyString(), anyLong()))
      .thenReturn(ImmutableList.of(theMessage));

  // The Job just always reports "running" across all calls
  Job fakeJob = new Job();
  fakeJob.setCurrentState("JOB_STATE_RUNNING");
  when(mockDataflowClient.getJob(anyString())).thenReturn(fakeJob);

  // After waitUntilFinish the DataflowPipelineJob should record the latest message timestamp
  when(nanoClock.nanoTime()).thenReturn(0L).thenReturn(2000000000L);
  job.waitUntilFinish(Duration.standardSeconds(1), mockHandler, sleeper, nanoClock, mockMonitor);
  verify(mockHandler).process(ImmutableList.of(theMessage));

  // Second waitUntilFinish should request jobs with `separatingTimestamp` so the monitor
  // will only return new messages
  when(nanoClock.nanoTime()).thenReturn(3000000000L).thenReturn(6000000000L);
  job.waitUntilFinish(Duration.standardSeconds(1), mockHandler, sleeper, nanoClock, mockMonitor);
  verify(mockMonitor).getJobMessages(anyString(), eq(separatingTimestamp.getMillis()));
}
 
开发者ID:apache,项目名称:beam,代码行数:33,代码来源:DataflowPipelineJobTest.java


注:本文中的com.google.api.services.dataflow.model.Job.setCurrentState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。