@@ -0,0 +1,3113 @@
+/*%0A * Copyright 2014, gRPC Authors All rights reserved.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage io.grpc.testing;%0A%0Aimport com.google.common.util.concurrent.ListenableFuture;%0Aimport com.google.common.util.concurrent.SettableFuture;%0Aimport io.grpc.ExperimentalApi;%0Aimport io.grpc.stub.StreamObserver;%0Aimport java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.List;%0Aimport java.util.concurrent.CountDownLatch;%0Aimport java.util.concurrent.TimeUnit;%0Aimport javax.annotation.Nullable;%0A%0A/**%0A * Utility implementation of %7B@link StreamObserver%7D used in testing. Records all the observed%0A * values produced by the stream as well as any errors.%0A *%0A * @deprecated Not for public use%0A */%0A@Deprecated%0A@ExperimentalApi(%22https://github.com/grpc/grpc-java/issues/1791%22)%0Apublic class StreamRecorder%3CT%3E implements StreamObserver%3CT%3E %7B%0A%0A  /**%0A   * Creates a new recorder.%0A   */%0A  public static %3CT%3E StreamRecorder%3CT%3E create() %7B%0A    return new StreamRecorder%3CT%3E();%0A  %7D%0A%0A  private final CountDownLatch latch;%0A  private final List%3CT%3E results;%0A  private Throwable error;%0A  private final SettableFuture%3CT%3E firstValue;%0A%0A  private StreamRecorder() %7B%0A    firstValue = SettableFuture.create();%0A    latch = new CountDownLatch(1);%0A    results = Collections.synchronizedList(new ArrayList%3CT%3E());%0A  %7D%0A%0A  @Override%0A  public void onNext(T value) %7B%0A    if (!firstValue.isDone()) %7B%0A      firstValue.set(value);%0A    %7D%0A    results.add(value);%0A  %7D%0A%0A  @Override%0A  public void onError(Throwable t) %7B%0A    if (!firstValue.isDone()) %7B%0A      firstValue.setException(t);%0A    %7D%0A    error = t;%0A    latch.countDown();%0A  %7D%0A%0A  @Override%0A  public void onCompleted() %7B%0A    if (!firstValue.isDone()) %7B%0A      firstValue.setException(new IllegalStateException(%22No first value provided%22));%0A    %7D%0A    latch.countDown();%0A  %7D%0A%0A  /**%0A   * Waits for the stream to terminate.%0A   */%0A  public void awaitCompletion() throws Exception %7B%0A    latch.await();%0A  %7D%0A%0A  /**%0A   * Waits a fixed timeout for the stream to terminate.%0A   */%0A  public boolean awaitCompletion(int timeout, TimeUnit unit) throws Exception %7B%0A    return latch.await(timeout, unit);%0A  %7D%0A%0A  /**%0A   * Returns the current set of received values.%0A   */%0A  public List%3CT%3E getValues() %7B%0A    return Collections.unmodifiableList(results);%0A  %7D%0A%0A  /**%0A   * Returns the stream terminating error.%0A   */%0A  @Nullable public Throwable getError() %7B%0A    return error;%0A  %7D%0A%0A  /**%0A   * Returns a %7B@link ListenableFuture%7D for the first value received from the stream. Useful%0A   * for testing unary call patterns.%0A   */%0A  public ListenableFuture%3CT%3E firstValue() %7B%0A    return firstValue;%0A  %7D%0A%7D%0A

Revert "testing: delete deprecated StreamRecorder" (#3801)