Skip to content

Commit

Permalink
ConnectionIsClosedException --> ConnectionClosedException.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmehta19 committed Apr 29, 2024
1 parent 2dd1c7e commit d1f413b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion s2a/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ java_library(
java_library(
name = "s2a_handshaker",
srcs = [
"src/main/java/io/grpc/s2a/handshaker/ConnectionIsClosedException.java",
"src/main/java/io/grpc/s2a/handshaker/ConnectionClosedException.java",
"src/main/java/io/grpc/s2a/handshaker/GetAuthenticationMechanisms.java",
"src/main/java/io/grpc/s2a/handshaker/ProtoUtil.java",
"src/main/java/io/grpc/s2a/handshaker/S2AConnectionException.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

/** Indicates that a connection has been closed. */
@SuppressWarnings("serial") // This class is never serialized.
final class ConnectionIsClosedException extends IOException {
public ConnectionIsClosedException(String errorMessage) {
final class ConnectionClosedException extends IOException {
public ConnectionClosedException(String errorMessage) {
super(errorMessage);
}
}
20 changes: 10 additions & 10 deletions s2a/src/main/java/io/grpc/s2a/handshaker/S2AStub.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,20 @@ BlockingQueue<Result> getResponses() {

/**
* Sends a request and returns the response. Caller must wait until this method executes prior to
* calling it again. If this method throws {@code ConnectionIsClosedException}, then it should not
* calling it again. If this method throws {@code ConnectionClosedException}, then it should not
* be called again, and both {@code reader} and {@code writer} are closed.
*
* @param req the {@code SessionReq} message to be sent to the S2A server.
* @return the {@code SessionResp} message received from the S2A server.
* @throws ConnectionIsClosedException if {@code reader} or {@code writer} calls their {@code
* @throws ConnectionClosedException if {@code reader} or {@code writer} calls their {@code
* onCompleted} method.
* @throws IOException if an unexpected response is received, or if the {@code reader} or {@code
* writer} calls their {@code onError} method.
*/
public SessionResp send(SessionReq req) throws IOException, InterruptedException {
if (doneWriting && doneReading) {
logger.log(Level.INFO, "Stream to the S2A is closed.");
throw new ConnectionIsClosedException("Stream to the S2A is closed.");
throw new ConnectionClosedException("Stream to the S2A is closed.");
}
createWriterIfNull();
if (!responses.isEmpty()) {
Expand Down Expand Up @@ -121,10 +121,10 @@ public SessionResp send(SessionReq req) throws IOException, InterruptedException
}
try {
return responses.take().getResultOrThrow();
} catch (ConnectionIsClosedException e) {
// A ConnectionIsClosedException is thrown by getResultOrThrow when reader calls its
} catch (ConnectionClosedException e) {
// A ConnectionClosedException is thrown by getResultOrThrow when reader calls its
// onCompleted method. The close method is called to also close the writer, and then the
// ConnectionIsClosedException is re-thrown in order to indicate to the caller that send
// ConnectionClosedException is re-thrown in order to indicate to the caller that send
// should not be called again.
close();
throw e;
Expand Down Expand Up @@ -177,7 +177,7 @@ public void onError(Throwable t) {
}

/**
* Sets {@code doneReading} to true, and places a {@code ConnectionIsClosedException} in the
* Sets {@code doneReading} to true, and places a {@code ConnectionClosedException} in the
* {@code responses} queue.
*/
@Override
Expand All @@ -186,7 +186,7 @@ public void onCompleted() {
doneReading = true;
responses.offer(
Result.createWithThrowable(
new ConnectionIsClosedException("Reading from the S2A is complete.")));
new ConnectionClosedException("Reading from the S2A is complete.")));
}
}

Expand All @@ -211,8 +211,8 @@ private Result(Optional<SessionResp> response, Optional<Throwable> throwable) {
/** Throws {@code throwable} if present, and returns {@code response} otherwise. */
SessionResp getResultOrThrow() throws IOException {
if (throwable.isPresent()) {
if (throwable.get() instanceof ConnectionIsClosedException) {
ConnectionIsClosedException exception = (ConnectionIsClosedException) throwable.get();
if (throwable.get() instanceof ConnectionClosedException) {
ConnectionClosedException exception = (ConnectionClosedException) throwable.get();
throw exception;
} else {
throw new IOException(throwable.get());
Expand Down
8 changes: 4 additions & 4 deletions s2a/src/test/java/io/grpc/s2a/handshaker/S2AStubTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ public void send_receiveErrorResponse() throws InterruptedException {
public void send_receiveCompleteStatus() throws Exception {
writer.setBehavior(FakeWriter.Behavior.COMPLETE_STATUS);

ConnectionIsClosedException expected =
ConnectionClosedException expected =
assertThrows(
ConnectionIsClosedException.class, () -> stub.send(SessionReq.getDefaultInstance()));
ConnectionClosedException.class, () -> stub.send(SessionReq.getDefaultInstance()));

assertThat(expected).hasMessageThat().contains("Reading from the S2A is complete.");
}
Expand Down Expand Up @@ -216,9 +216,9 @@ public void send_afterEarlyClose_receivesClosedException() throws InterruptedExc
stub.close();
expect.that(writer.isFakeWriterClosed()).isTrue();

ConnectionIsClosedException expected =
ConnectionClosedException expected =
assertThrows(
ConnectionIsClosedException.class, () -> stub.send(SessionReq.getDefaultInstance()));
ConnectionClosedException.class, () -> stub.send(SessionReq.getDefaultInstance()));

assertThat(expected).hasMessageThat().contains("Stream to the S2A is closed.");
}
Expand Down

0 comments on commit d1f413b

Please sign in to comment.