From 11fcfe1f7390cef5bf3cbb618650f0ffb64f9585 Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Wed, 11 Aug 2021 21:41:16 +0200 Subject: [PATCH] Remove PromiseAggregator (#11571) Motivation: This class was deprecated, since a better alternative exists in `PromiseCombiner`. Modification: Remove `PromiseAggregator`, its Channel companion, and its test. Result: Less deprecated code. --- .../util/concurrent/PromiseAggregator.java | 113 --------------- .../concurrent/PromiseAggregatorTest.java | 136 ------------------ .../channel/ChannelPromiseAggregator.java | 38 ----- 3 files changed, 287 deletions(-) delete mode 100644 common/src/main/java/io/netty/util/concurrent/PromiseAggregator.java delete mode 100644 common/src/test/java/io/netty/util/concurrent/PromiseAggregatorTest.java delete mode 100644 transport/src/main/java/io/netty/channel/ChannelPromiseAggregator.java diff --git a/common/src/main/java/io/netty/util/concurrent/PromiseAggregator.java b/common/src/main/java/io/netty/util/concurrent/PromiseAggregator.java deleted file mode 100644 index 9910c92d48..0000000000 --- a/common/src/main/java/io/netty/util/concurrent/PromiseAggregator.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2014 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.util.concurrent; - -import static java.util.Objects.requireNonNull; - -import java.util.LinkedHashSet; -import java.util.Set; - -/** - * @deprecated Use {@link PromiseCombiner#PromiseCombiner(EventExecutor)}. - * - * {@link GenericFutureListener} implementation which consolidates multiple {@link Future}s - * into one, by listening to individual {@link Future}s and producing an aggregated result - * (success/failure) when all {@link Future}s have completed. - * - * @param the type of value returned by the {@link Future} - * @param the type of {@link Future} - */ -@Deprecated -public class PromiseAggregator> implements GenericFutureListener { - - private final Promise aggregatePromise; - private final boolean failPending; - private Set> pendingPromises; - - /** - * Creates a new instance. - * - * @param aggregatePromise the {@link Promise} to notify - * @param failPending {@code true} to fail pending promises, false to leave them unaffected - */ - public PromiseAggregator(Promise aggregatePromise, boolean failPending) { - requireNonNull(aggregatePromise, "aggregatePromise"); - this.aggregatePromise = aggregatePromise; - this.failPending = failPending; - } - - /** - * See {@link PromiseAggregator#PromiseAggregator(Promise, boolean)}. - * Defaults {@code failPending} to true. - */ - public PromiseAggregator(Promise aggregatePromise) { - this(aggregatePromise, true); - } - - /** - * Add the given {@link Promise}s to the aggregator. - */ - @SafeVarargs - public final PromiseAggregator add(Promise... promises) { - requireNonNull(promises, "promises"); - if (promises.length == 0) { - return this; - } - synchronized (this) { - if (pendingPromises == null) { - int size; - if (promises.length > 1) { - size = promises.length; - } else { - size = 2; - } - pendingPromises = new LinkedHashSet<>(size); - } - for (Promise p : promises) { - if (p == null) { - continue; - } - pendingPromises.add(p); - p.addListener(this); - } - } - return this; - } - - @Override - public synchronized void operationComplete(F future) throws Exception { - if (pendingPromises == null) { - aggregatePromise.setSuccess(null); - } else { - pendingPromises.remove(future); - if (!future.isSuccess()) { - Throwable cause = future.cause(); - aggregatePromise.setFailure(cause); - if (failPending) { - for (Promise pendingFuture : pendingPromises) { - pendingFuture.setFailure(cause); - } - } - } else { - if (pendingPromises.isEmpty()) { - aggregatePromise.setSuccess(null); - } - } - } - } - -} diff --git a/common/src/test/java/io/netty/util/concurrent/PromiseAggregatorTest.java b/common/src/test/java/io/netty/util/concurrent/PromiseAggregatorTest.java deleted file mode 100644 index f0f4790d1b..0000000000 --- a/common/src/test/java/io/netty/util/concurrent/PromiseAggregatorTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright 2014 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.util.concurrent; - -import org.junit.jupiter.api.Test; - -import static org.hamcrest.CoreMatchers.*; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.*; - -public class PromiseAggregatorTest { - - @Test - public void testNullAggregatePromise() { - assertThrows(NullPointerException.class, () -> new PromiseAggregator>(null)); - } - - @Test - public void testAddNullFuture() { - @SuppressWarnings("unchecked") - Promise p = mock(Promise.class); - PromiseAggregator> a = - new PromiseAggregator<>(p); - assertThrows(NullPointerException.class, () -> a.add((Promise[]) null)); - } - - @SuppressWarnings("unchecked") - @Test - public void testSuccessfulNoPending() throws Exception { - Promise p = mock(Promise.class); - PromiseAggregator> a = - new PromiseAggregator<>(p); - - Future future = mock(Future.class); - when(p.setSuccess(null)).thenReturn(p); - - a.add(); - a.operationComplete(future); - verifyNoMoreInteractions(future); - verify(p).setSuccess(null); - } - - @SuppressWarnings("unchecked") - @Test - public void testSuccessfulPending() throws Exception { - Promise p = mock(Promise.class); - PromiseAggregator> a = - new PromiseAggregator<>(p); - Promise p1 = mock(Promise.class); - Promise p2 = mock(Promise.class); - - when(p1.addListener(a)).thenReturn(p1); - when(p2.addListener(a)).thenReturn(p2); - when(p1.isSuccess()).thenReturn(true); - when(p2.isSuccess()).thenReturn(true); - when(p.setSuccess(null)).thenReturn(p); - - assertThat(a.add(p1, null, p2), is(a)); - a.operationComplete(p1); - a.operationComplete(p2); - - verify(p1).addListener(a); - verify(p2).addListener(a); - verify(p1).isSuccess(); - verify(p2).isSuccess(); - verify(p).setSuccess(null); - } - - @SuppressWarnings("unchecked") - @Test - public void testFailedFutureFailPending() throws Exception { - Promise p = mock(Promise.class); - PromiseAggregator> a = - new PromiseAggregator<>(p); - Promise p1 = mock(Promise.class); - Promise p2 = mock(Promise.class); - Throwable t = mock(Throwable.class); - - when(p1.addListener(a)).thenReturn(p1); - when(p2.addListener(a)).thenReturn(p2); - when(p1.isSuccess()).thenReturn(false); - when(p1.cause()).thenReturn(t); - when(p.setFailure(t)).thenReturn(p); - when(p2.setFailure(t)).thenReturn(p2); - - a.add(p1, p2); - a.operationComplete(p1); - - verify(p1).addListener(a); - verify(p2).addListener(a); - verify(p1).cause(); - verify(p).setFailure(t); - verify(p2).setFailure(t); - } - - @SuppressWarnings("unchecked") - @Test - public void testFailedFutureNoFailPending() throws Exception { - Promise p = mock(Promise.class); - PromiseAggregator> a = - new PromiseAggregator<>(p, false); - Promise p1 = mock(Promise.class); - Promise p2 = mock(Promise.class); - Throwable t = mock(Throwable.class); - - when(p1.addListener(a)).thenReturn(p1); - when(p2.addListener(a)).thenReturn(p2); - when(p1.isSuccess()).thenReturn(false); - when(p1.cause()).thenReturn(t); - when(p.setFailure(t)).thenReturn(p); - - a.add(p1, p2); - a.operationComplete(p1); - - verify(p1).addListener(a); - verify(p2).addListener(a); - verify(p1).isSuccess(); - verify(p1).cause(); - verify(p).setFailure(t); - } -} diff --git a/transport/src/main/java/io/netty/channel/ChannelPromiseAggregator.java b/transport/src/main/java/io/netty/channel/ChannelPromiseAggregator.java deleted file mode 100644 index be56fbbe8c..0000000000 --- a/transport/src/main/java/io/netty/channel/ChannelPromiseAggregator.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2012 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel; - -import io.netty.util.concurrent.PromiseAggregator; -import io.netty.util.concurrent.PromiseCombiner; - -/** - * @deprecated Use {@link PromiseCombiner} - * - * Class which is used to consolidate multiple channel futures into one, by - * listening to the individual futures and producing an aggregated result - * (success/failure) when all futures have completed. - */ -@Deprecated -public final class ChannelPromiseAggregator - extends PromiseAggregator - implements ChannelFutureListener { - - public ChannelPromiseAggregator(ChannelPromise aggregatePromise) { - super(aggregatePromise); - } - -}