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.
This commit is contained in:
Chris Vest 2021-08-11 21:41:16 +02:00 committed by GitHub
parent 99bd5895dc
commit 11fcfe1f73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 287 deletions

View File

@ -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 <V> the type of value returned by the {@link Future}
* @param <F> the type of {@link Future}
*/
@Deprecated
public class PromiseAggregator<V, F extends Future<V>> implements GenericFutureListener<F> {
private final Promise<?> aggregatePromise;
private final boolean failPending;
private Set<Promise<V>> 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<Void> 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<Void> aggregatePromise) {
this(aggregatePromise, true);
}
/**
* Add the given {@link Promise}s to the aggregator.
*/
@SafeVarargs
public final PromiseAggregator<V, F> add(Promise<V>... 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<V> 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<V> pendingFuture : pendingPromises) {
pendingFuture.setFailure(cause);
}
}
} else {
if (pendingPromises.isEmpty()) {
aggregatePromise.setSuccess(null);
}
}
}
}
}

View File

@ -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<Void, Future<Void>>(null));
}
@Test
public void testAddNullFuture() {
@SuppressWarnings("unchecked")
Promise<Void> p = mock(Promise.class);
PromiseAggregator<Void, Future<Void>> a =
new PromiseAggregator<>(p);
assertThrows(NullPointerException.class, () -> a.add((Promise<Void>[]) null));
}
@SuppressWarnings("unchecked")
@Test
public void testSuccessfulNoPending() throws Exception {
Promise<Void> p = mock(Promise.class);
PromiseAggregator<Void, Future<Void>> a =
new PromiseAggregator<>(p);
Future<Void> 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<Void> p = mock(Promise.class);
PromiseAggregator<Void, Future<Void>> a =
new PromiseAggregator<>(p);
Promise<Void> p1 = mock(Promise.class);
Promise<Void> 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<Void> p = mock(Promise.class);
PromiseAggregator<Void, Future<Void>> a =
new PromiseAggregator<>(p);
Promise<Void> p1 = mock(Promise.class);
Promise<Void> 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<Void> p = mock(Promise.class);
PromiseAggregator<Void, Future<Void>> a =
new PromiseAggregator<>(p, false);
Promise<Void> p1 = mock(Promise.class);
Promise<Void> 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);
}
}

View File

@ -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<Void, ChannelFuture>
implements ChannelFutureListener {
public ChannelPromiseAggregator(ChannelPromise aggregatePromise) {
super(aggregatePromise);
}
}