• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #19615

03 Jan 2025 06:42PM UTC coverage: 88.553% (+0.009%) from 88.544%
#19615

push

github

web-flow
Fix equality and hashcode of CancelServerStreamCommand. (#11785)

In e036b1b19, CancelServerStreamCommand got another field. But, its hashCode and equals methods were not updated.

33619 of 37965 relevant lines covered (88.55%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.37
/../netty/src/main/java/io/grpc/netty/CancelServerStreamCommand.java
1
/*
2
 * Copyright 2015 The gRPC Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package io.grpc.netty;
18

19
import com.google.common.base.MoreObjects;
20
import com.google.common.base.Objects;
21
import com.google.common.base.Preconditions;
22
import io.grpc.Status;
23

24
/**
25
 * Command sent from a Netty server stream to the handler to cancel the stream.
26
 */
27
final class CancelServerStreamCommand extends WriteQueue.AbstractQueuedCommand {
28
  private final NettyServerStream.TransportState stream;
29
  private final Status reason;
30
  private final PeerNotify peerNotify;
31

32
  private CancelServerStreamCommand(
33
          NettyServerStream.TransportState stream, Status reason, PeerNotify peerNotify) {
1✔
34
    this.stream = Preconditions.checkNotNull(stream, "stream");
1✔
35
    this.reason = Preconditions.checkNotNull(reason, "reason");
1✔
36
    this.peerNotify = Preconditions.checkNotNull(peerNotify, "peerNotify");
1✔
37
  }
1✔
38

39
  static CancelServerStreamCommand withReset(
40
          NettyServerStream.TransportState stream, Status reason) {
41
    return new CancelServerStreamCommand(stream, reason, PeerNotify.RESET);
1✔
42
  }
43

44
  static CancelServerStreamCommand withReason(
45
          NettyServerStream.TransportState stream, Status reason) {
46
    return new CancelServerStreamCommand(stream, reason, PeerNotify.BEST_EFFORT_STATUS);
1✔
47
  }
48

49
  NettyServerStream.TransportState stream() {
50
    return stream;
1✔
51
  }
52

53
  Status reason() {
54
    return reason;
1✔
55
  }
56

57
  boolean wantsHeaders() {
58
    return peerNotify == PeerNotify.BEST_EFFORT_STATUS;
1✔
59
  }
60

61
  @Override
62
  public boolean equals(Object o) {
63
    if (this == o) {
1✔
64
      return true;
×
65
    }
66
    if (o == null || getClass() != o.getClass()) {
1✔
67
      return false;
×
68
    }
69

70
    CancelServerStreamCommand that = (CancelServerStreamCommand) o;
1✔
71

72
    return this.stream.equals(that.stream)
1✔
73
        && this.reason.equals(that.reason)
1✔
74
        && this.peerNotify.equals(that.peerNotify);
1✔
75
  }
76

77
  @Override
78
  public int hashCode() {
79
    return Objects.hashCode(stream, reason, peerNotify);
×
80
  }
81

82
  @Override
83
  public String toString() {
84
    return MoreObjects.toStringHelper(this)
×
85
        .add("stream", stream)
×
86
        .add("reason", reason)
×
87
        .add("peerNotify", peerNotify)
×
88
        .toString();
×
89
  }
90

91
  private enum PeerNotify {
1✔
92
    /** Notify the peer by sending a RST_STREAM with no other information. */
93
    RESET,
1✔
94
    /** Notify the peer about the {@link #reason} by sending structured headers, if possible. */
95
    BEST_EFFORT_STATUS,
1✔
96
  }
97
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc