Fix deprecations around ListenableFuture (#3865)

* Fix deprecations around ListenableFuture

SF has deprecated a `ListenableFuture` and API around it

* Migrate to `CompletableFuture` everywhere a `ListenableFuture` has been used
* Suppress a deprecation for `ListenableFuture` keeping the functionality until the next version
* Resolve deprecations nad removals from the latest Spring for Apache Kafka
* Fix documentation for the `ListenableFuture` in favor of `CompletableFuture`

NOTE: the AMQP module is left as is until `ListenableFuture` deprecation is resolved in Spring AMQP

* * Restore some `ListenableFuture` test for messaging gateway
This commit is contained in:
Artem Bilan
2022-07-28 09:32:01 -04:00
committed by GitHub
parent 2e9beada0b
commit 5572c2161d
23 changed files with 196 additions and 259 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 the original author or authors.
* Copyright 2016-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ package org.springframework.integration.stomp;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -30,8 +31,6 @@ import org.springframework.messaging.simp.stomp.StompSession;
import org.springframework.messaging.simp.stomp.StompSessionHandler;
import org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter;
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.SettableListenableFuture;
/**
* @author Artem Bilan
@@ -49,14 +48,14 @@ public class StompSessionManagerTests {
private final AtomicBoolean thrown = new AtomicBoolean();
@Override
protected ListenableFuture<StompSession> doConnect(StompSessionHandler handler) {
protected CompletableFuture<StompSession> doConnect(StompSessionHandler handler) {
if (!this.thrown.getAndSet(true)) {
throw new RuntimeException("intentional");
}
else {
SettableListenableFuture<StompSession> future = new SettableListenableFuture<>();
CompletableFuture<StompSession> future = new CompletableFuture<>();
StompSession stompSession = mock(StompSession.class);
future.set(stompSession);
future.complete(stompSession);
handler.afterConnected(stompSession, getConnectHeaders());
return future;
}
@@ -66,12 +65,12 @@ public class StompSessionManagerTests {
sessionManager.start();
final SettableListenableFuture<StompSession> stompSessionFuture = new SettableListenableFuture<>();
final CompletableFuture<StompSession> stompSessionFuture = new CompletableFuture<>();
sessionManager.connect(new StompSessionHandlerAdapter() {
@Override
public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
stompSessionFuture.set(session);
stompSessionFuture.complete(session);
}
});