Java Code Examples for scala.concurrent.Future#successful()

The following examples show how to use scala.concurrent.Future#successful() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockJournalPlugin.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Future<Void> doAsyncDeleteMessagesTo(final String persistenceId, final long toSequenceNr) {
    LOGGER.debug("[doAsyncDeleteMessagesTo]: persistenceId {}, toSequenceNr {}", persistenceId, toSequenceNr);
    journalMock.doAsyncDeleteMessagesTo(persistenceId, toSequenceNr);
    if (FAIL_DELETE_MESSAGE.equals(persistenceId)) {
        final CompletableFuture<Void> failDeleteMessage = new CompletableFuture<>();
        failDeleteMessage.completeExceptionally(new IllegalStateException(FAIL_DELETE_MESSAGE));
        return FutureConverters.toScala(failDeleteMessage);
    } else if (SLOW_DELETE.equals(persistenceId)) {
        final CompletableFuture<Void> completableFuture = new CompletableFuture<>();
        // do not complete future to simulate long running delete
        return FutureConverters.toScala(completableFuture);
    }else {
        return Future.successful(null);
    }
}
 
Example 2
Source File: MockSnapshotStorePlugin.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Future<Optional<SelectedSnapshot>> doLoadAsync(final String persistenceId,
        final SnapshotSelectionCriteria criteria) {
    // return something - not relevant for current tests
    final SnapshotMetadata metadata = new SnapshotMetadata(persistenceId, 0, 0);
    final SelectedSnapshot selectedSnapshot = SelectedSnapshot.apply(metadata, 1L);
    return Future.successful(Optional.of(selectedSnapshot));
}
 
Example 3
Source File: MockSnapshotStorePlugin.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Future<Void> doDeleteAsync(final SnapshotMetadata metadata) {
    LOGGER.debug("[doDeleteAsync]: {}", metadata);
    snapshotStore.doDeleteAsync(metadata);
    if (FAIL_DELETE_SNAPSHOT.equals(metadata.persistenceId())) {
        final CompletableFuture<Void> failDeleteSnapshot = new CompletableFuture<>();
        failDeleteSnapshot.completeExceptionally(new IllegalStateException(FAIL_DELETE_SNAPSHOT));
        return FutureConverters.toScala(failDeleteSnapshot);
    } else {
        return Future.successful(null);
    }
}
 
Example 4
Source File: MockSnapshotStorePlugin.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Future<Void> doDeleteAsync(final String persistenceId, final SnapshotSelectionCriteria criteria) {
    LOGGER.debug("[doDeleteAsync]: {} -> {}", persistenceId, criteria);
    snapshotStore.doDeleteAsync(persistenceId, criteria);
    if (FAIL_DELETE_SNAPSHOT.equals(persistenceId)) {
        final CompletableFuture<Void> failDeleteSnapshot = new CompletableFuture<>();
        failDeleteSnapshot.completeExceptionally(new IllegalStateException(FAIL_DELETE_SNAPSHOT));
        return FutureConverters.toScala(failDeleteSnapshot);
    } else {
        return Future.successful(null);
    }
}
 
Example 5
Source File: MockJournalPlugin.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Future<Void> doAsyncReplayMessages(final String persistenceId, final long fromSequenceNr,
        final long toSequenceNr,
        final long max, final Consumer<PersistentRepr> replayCallback) {
    LOGGER.debug("[doAsyncReplayMessages]: persistenceId {}, fromSequenceNr {}, toSequenceNr {}, max {}",
            persistenceId,
            fromSequenceNr, toSequenceNr, max);
    return Future.successful(null);
}
 
Example 6
Source File: MockJournalPlugin.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Future<Iterable<Optional<Exception>>> doAsyncWriteMessages(final Iterable<AtomicWrite> messages) {
    LOGGER.debug("[doAsyncWriteMessages]: messages {}", messages);
    final Iterable<Optional<Exception>> collect =
            Stream.of(messages).map(m -> Optional.<Exception>empty()).collect(Collectors.toList());
    return Future.successful(collect);
}
 
Example 7
Source File: ScalaFutureBenchmark.java    From future with Apache License 2.0 4 votes vote down vote up
@Benchmark
public Future<String> value() {
  return Future.successful(string);
}
 
Example 8
Source File: ScalaFutureBenchmark.java    From future with Apache License 2.0 4 votes vote down vote up
private Future<Integer> loop(int i) {
  if (i > 0)
    return Future.successful(i - 1).flatMap(this::loop, ec);
  else
    return Future.successful(0);
}
 
Example 9
Source File: MockSnapshotStorePlugin.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Future<Void> doSaveAsync(final SnapshotMetadata metadata, final Object snapshot) {
    LOGGER.debug("[doSaveAsync]: {} -> {}", metadata, snapshot);
    return Future.successful(null);
}
 
Example 10
Source File: MockJournalPlugin.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Future<Long> doAsyncReadHighestSequenceNr(final String persistenceId, final long fromSequenceNr) {
    LOGGER.debug("[doAsyncReadHighestSequenceNr]: persistenceId {}, fromSequenceNr {}", persistenceId,
            fromSequenceNr);
    return Future.successful(0L);
}
 
Example 11
Source File: ScalaFutureBenchmark.java    From future with Apache License 2.0 4 votes vote down vote up
@Benchmark
public Future<String> value() {
  return Future.successful(string);
}
 
Example 12
Source File: ScalaFutureBenchmark.java    From future with Apache License 2.0 4 votes vote down vote up
private Future<Integer> loop(int i) {
  if (i > 0)
    return Future.successful(i - 1).flatMap(this::loop, ec);
  else
    return Future.successful(0);
}