mirror of https://github.com/grpc/grpc-java.git
style: fix styles and error-prones (#2560)
"Because of spurious wakeups, wait() must always be called in a loop". Got rid of wait(). "If you return or throw from a finally, then values returned or thrown from the try-catch block will be ignored. Consider using try-with-resources instead." Ignored the exception thrown from finally.
This commit is contained in:
parent
1aaf1a989c
commit
4693492fda
|
|
@ -72,7 +72,7 @@ public class PickFirstLoadBalancer2Test {
|
|||
private List<ResolvedServerInfoGroup> servers = Lists.newArrayList();
|
||||
private List<SocketAddress> socketAddresses = Lists.newArrayList();
|
||||
|
||||
private static Attributes.Key<String> FOO = Attributes.Key.of("foo");
|
||||
private static final Attributes.Key<String> FOO = Attributes.Key.of("foo");
|
||||
private Attributes affinity = Attributes.newBuilder().set(FOO, "bar").build();
|
||||
|
||||
@Captor
|
||||
|
|
|
|||
|
|
@ -88,15 +88,13 @@ public class RoundRobinLoadBalancer2Test {
|
|||
private RoundRobinLoadBalancer loadBalancer;
|
||||
private Map<ResolvedServerInfoGroup, EquivalentAddressGroup> servers = Maps.newHashMap();
|
||||
private Map<EquivalentAddressGroup, Subchannel> subchannels = Maps.newLinkedHashMap();
|
||||
private static Attributes.Key<String> MAJOR_KEY = Attributes.Key.of("major-key");
|
||||
private static final Attributes.Key<String> MAJOR_KEY = Attributes.Key.of("major-key");
|
||||
private Attributes affinity = Attributes.newBuilder().set(MAJOR_KEY, "I got the keys").build();
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<Picker> pickerCaptor;
|
||||
@Captor
|
||||
private ArgumentCaptor<EquivalentAddressGroup> eagCaptor;
|
||||
@Captor
|
||||
private ArgumentCaptor<Attributes> attrsCaptor;
|
||||
@Mock
|
||||
private Helper mockHelper;
|
||||
@Mock
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ import java.util.List;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
|
@ -1450,10 +1451,15 @@ public class OkHttpClientTransportTest {
|
|||
}
|
||||
|
||||
private static class MockFrameReader implements FrameReader {
|
||||
CountDownLatch closed = new CountDownLatch(1);
|
||||
boolean throwExceptionForNextFrame;
|
||||
boolean returnFalseInNextFrame;
|
||||
boolean throwErrorForNextFrame;
|
||||
final CountDownLatch closed = new CountDownLatch(1);
|
||||
|
||||
enum Result {
|
||||
THROW_EXCEPTION,
|
||||
RETURN_FALSE,
|
||||
THROW_ERROR
|
||||
}
|
||||
|
||||
final LinkedBlockingQueue<Result> nextResults = new LinkedBlockingQueue<Result>();
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
|
|
@ -1472,41 +1478,36 @@ public class OkHttpClientTransportTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean nextFrame(Handler handler) throws IOException {
|
||||
if (throwErrorForNextFrame) {
|
||||
throw new Error(ERROR_MESSAGE);
|
||||
}
|
||||
if (throwExceptionForNextFrame) {
|
||||
throw new IOException(NETWORK_ISSUE_MESSAGE);
|
||||
}
|
||||
if (returnFalseInNextFrame) {
|
||||
return false;
|
||||
}
|
||||
public boolean nextFrame(Handler handler) throws IOException {
|
||||
Result result;
|
||||
try {
|
||||
wait();
|
||||
result = nextResults.take();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IOException(e);
|
||||
}
|
||||
if (throwExceptionForNextFrame) {
|
||||
switch (result) {
|
||||
case THROW_EXCEPTION:
|
||||
throw new IOException(NETWORK_ISSUE_MESSAGE);
|
||||
case RETURN_FALSE:
|
||||
return false;
|
||||
case THROW_ERROR:
|
||||
throw new Error(ERROR_MESSAGE);
|
||||
default:
|
||||
throw new UnsupportedOperationException("unimplemented: " + result);
|
||||
}
|
||||
return !returnFalseInNextFrame;
|
||||
}
|
||||
|
||||
synchronized void throwIoExceptionForNextFrame() {
|
||||
throwExceptionForNextFrame = true;
|
||||
notifyAll();
|
||||
void throwIoExceptionForNextFrame() {
|
||||
nextResults.add(Result.THROW_EXCEPTION);
|
||||
}
|
||||
|
||||
synchronized void throwErrorForNextFrame() {
|
||||
throwErrorForNextFrame = true;
|
||||
notifyAll();
|
||||
void throwErrorForNextFrame() {
|
||||
nextResults.add(Result.THROW_ERROR);
|
||||
}
|
||||
|
||||
synchronized void nextFrameAtEndOfStream() {
|
||||
returnFalseInNextFrame = true;
|
||||
notifyAll();
|
||||
void nextFrameAtEndOfStream() {
|
||||
nextResults.add(Result.RETURN_FALSE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -1574,7 +1575,7 @@ public class OkHttpClientTransportTest {
|
|||
try {
|
||||
message.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue