コード例 #1
0
  @Override
  public F.Promise<Void> store(Path path, String key) {
    Promise<Void> promise = Futures.promise();

    TransferManager transferManager = new TransferManager(credentials);
    Upload upload = transferManager.upload(bucketName, key, path.toFile());

    upload.addProgressListener(
        (ProgressListener)
            progressEvent -> {
              if (progressEvent.getEventType().isTransferEvent()) {
                if (progressEvent
                    .getEventType()
                    .equals(ProgressEventType.TRANSFER_COMPLETED_EVENT)) {
                  transferManager.shutdownNow();
                  promise.success(null);
                } else if (progressEvent
                    .getEventType()
                    .equals(ProgressEventType.TRANSFER_FAILED_EVENT)) {
                  transferManager.shutdownNow();
                  promise.failure(new Exception("Upload failed"));
                }
              }
            });

    return F.Promise.wrap(promise.future());
  }
コード例 #2
0
  @Override
  public void start(String jobManagerAkkaUrl) throws Exception {
    LOG.info("Starting with JobManager {} on port {}", jobManagerAkkaUrl, getServerPort());

    synchronized (startupShutdownLock) {
      jobManagerAddressPromise.success(jobManagerAkkaUrl);
      leaderRetrievalService.start(retriever);

      long delay = backPressureStatsTracker.getCleanUpInterval();

      // Scheduled back pressure stats tracker cache cleanup. We schedule
      // this here repeatedly, because cache clean up only happens on
      // interactions with the cache. We need it to make sure that we
      // don't leak memory after completed jobs or long ago accessed stats.
      bootstrap
          .childGroup()
          .scheduleWithFixedDelay(
              new Runnable() {
                @Override
                public void run() {
                  try {
                    backPressureStatsTracker.cleanUpOperatorStatsCache();
                  } catch (Throwable t) {
                    LOG.error("Error during back pressure stats cache cleanup.", t);
                  }
                }
              },
              delay,
              delay,
              TimeUnit.MILLISECONDS);
    }
  }
コード例 #3
0
  @Test
  public void testTriggerSavepointFailure() throws Exception {
    replaceStdOutAndStdErr();

    try {
      JobID jobId = new JobID();
      ActorGateway jobManager = mock(ActorGateway.class);

      Promise<Object> triggerResponse = new scala.concurrent.impl.Promise.DefaultPromise<>();

      when(jobManager.ask(
              Mockito.eq(new JobManagerMessages.TriggerSavepoint(jobId)),
              Mockito.any(FiniteDuration.class)))
          .thenReturn(triggerResponse.future());

      Exception testException = new Exception("expectedTestException");

      triggerResponse.success(new JobManagerMessages.TriggerSavepointFailure(jobId, testException));

      CliFrontend frontend = new MockCliFrontend(CliFrontendTestUtils.getConfigDir(), jobManager);

      String[] parameters = {jobId.toString()};
      int returnCode = frontend.savepoint(parameters);

      assertTrue(returnCode != 0);
      verify(jobManager, times(1))
          .ask(
              Mockito.eq(new JobManagerMessages.TriggerSavepoint(jobId)),
              Mockito.any(FiniteDuration.class));

      assertTrue(buffer.toString().contains("expectedTestException"));
    } finally {
      restoreStdOutAndStdErr();
    }
  }
コード例 #4
0
  @Test
  public void testDisposeSavepointSuccess() throws Exception {
    replaceStdOutAndStdErr();

    try {
      String savepointPath = "expectedSavepointPath";
      ActorGateway jobManager = mock(ActorGateway.class);

      Promise<Object> triggerResponse = new scala.concurrent.impl.Promise.DefaultPromise<>();

      when(jobManager.ask(
              Mockito.eq(new JobManagerMessages.DisposeSavepoint(savepointPath)),
              Mockito.any(FiniteDuration.class)))
          .thenReturn(triggerResponse.future());

      triggerResponse.success(JobManagerMessages.getDisposeSavepointSuccess());

      CliFrontend frontend = new MockCliFrontend(CliFrontendTestUtils.getConfigDir(), jobManager);

      String[] parameters = {"-d", savepointPath};
      int returnCode = frontend.savepoint(parameters);

      assertEquals(0, returnCode);
      verify(jobManager, times(1))
          .ask(
              Mockito.eq(new JobManagerMessages.DisposeSavepoint(savepointPath)),
              Mockito.any(FiniteDuration.class));

      String outMsg = buffer.toString();
      assertTrue(outMsg.contains(savepointPath));
      assertTrue(outMsg.contains("disposed"));
    } finally {
      restoreStdOutAndStdErr();
    }
  }
コード例 #5
0
ファイル: JavaFutureTests.java プロジェクト: robinmasque/akka
 @Test
 public void blockMustBeCallable() throws Exception {
   Promise<String> p = Futures.promise();
   Duration d = Duration.create(1, TimeUnit.SECONDS);
   p.success("foo");
   Await.ready(p.future(), d);
   assertEquals(Await.result(p.future(), d), "foo");
 }
コード例 #6
0
 @Override
 public void start(String jobManagerAkkaUrl) throws Exception {
   LOG.info("Starting with JobManager {} on port {}", jobManagerAkkaUrl, getServerPort());
   synchronized (startupShutdownLock) {
     jobManagerAddressPromise.success(jobManagerAkkaUrl);
     leaderRetrievalService.start(retriever);
   }
 }
コード例 #7
0
ファイル: JavaFutureTests.java プロジェクト: robinmasque/akka
 @Test
 public void mapToMustBeCallable() throws Exception {
   Promise<Object> p = Futures.promise();
   Future<String> f = p.future().mapTo(classTag(String.class));
   Duration d = Duration.create(1, TimeUnit.SECONDS);
   p.success("foo");
   Await.ready(p.future(), d);
   assertEquals(Await.result(p.future(), d), "foo");
 }
コード例 #8
0
ファイル: JavaFutureTests.java プロジェクト: robinmasque/akka
  @Test
  public void mustBeAbleToExecuteAnOnResultCallback() throws Throwable {
    final CountDownLatch latch = new CountDownLatch(1);
    Promise<String> cf = Futures.promise();
    Future<String> f = cf.future();
    f.onSuccess(
        new OnSuccess<String>() {
          public void onSuccess(String result) {
            if (result.equals("foo")) latch.countDown();
          }
        },
        system.dispatcher());

    cf.success("foo");
    assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
    assertEquals(Await.result(f, timeout), "foo");
  }
コード例 #9
0
ファイル: JavaFutureTests.java プロジェクト: robinmasque/akka
  @Test
  public void mustBeAbleToForeachAFuture() throws Throwable {
    final CountDownLatch latch = new CountDownLatch(1);
    Promise<String> cf = Futures.promise();
    Future<String> f = cf.future();
    f.foreach(
        new Foreach<String>() {
          public void each(String future) {
            latch.countDown();
          }
        },
        system.dispatcher());

    cf.success("foo");
    assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
    assertEquals(Await.result(f, timeout), "foo");
  }
コード例 #10
0
ファイル: JavaFutureTests.java プロジェクト: robinmasque/akka
  @Test
  public void mustBeAbleToFilterAFuture() throws Throwable {
    final CountDownLatch latch = new CountDownLatch(1);
    Promise<String> cf = Futures.promise();
    Future<String> f = cf.future();
    Future<String> r =
        f.filter(
            Filter.filterOf(
                new Function<String, Boolean>() {
                  public Boolean apply(String r) {
                    latch.countDown();
                    return r.equals("foo");
                  }
                }),
            system.dispatcher());

    cf.success("foo");
    assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
    assertEquals(Await.result(f, timeout), "foo");
    assertEquals(Await.result(r, timeout), "foo");
  }
コード例 #11
0
  @Override
  public F.Promise<Void> delete(String key) {
    Promise<Void> promise = Futures.promise();

    AmazonS3 amazonS3 = new AmazonS3Client(credentials);
    DeleteObjectRequest request = new DeleteObjectRequest(bucketName, key);
    request.withGeneralProgressListener(
        progressEvent -> {
          if (progressEvent.getEventType().isTransferEvent()) {
            if (progressEvent.getEventType().equals(ProgressEventType.TRANSFER_COMPLETED_EVENT)) {
              promise.success(null);
            } else if (progressEvent
                .getEventType()
                .equals(ProgressEventType.TRANSFER_FAILED_EVENT)) {
              promise.failure(new Exception("Delete failed"));
            }
          }
        });
    amazonS3.deleteObject(request);

    return F.Promise.wrap(promise.future());
  }
コード例 #12
0
ファイル: JavaFutureTests.java プロジェクト: robinmasque/akka
  @Test
  public void mustBeAbleToFlatMapAFuture() throws Throwable {
    final CountDownLatch latch = new CountDownLatch(1);
    Promise<String> cf = Futures.promise();
    cf.success("1000");
    Future<String> f = cf.future();
    Future<Integer> r =
        f.flatMap(
            new Mapper<String, Future<Integer>>() {
              public Future<Integer> checkedApply(String r) throws Throwable {
                if (false) throw new IOException("Just here to make sure this compiles.");
                latch.countDown();
                Promise<Integer> cf = Futures.promise();
                cf.success(Integer.parseInt(r));
                return cf.future();
              }
            },
            system.dispatcher());

    assertEquals(Await.result(f, timeout), "1000");
    assertEquals(Await.result(r, timeout).intValue(), 1000);
    assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
  }