mirror of https://github.com/grpc/grpc-java.git
cronet: Update to StandardCharsets and assertNotNull API's
This commit is contained in:
parent
163efa3716
commit
77e59b29dd
|
@ -42,7 +42,7 @@ import io.grpc.internal.TransportTracer;
|
|||
import io.grpc.internal.WritableBuffer;
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -372,10 +372,10 @@ class CronetClientStream extends AbstractClientStream {
|
|||
// String and byte array.
|
||||
byte[][] serializedHeaders = TransportFrameUtil.toHttp2Headers(headers);
|
||||
for (int i = 0; i < serializedHeaders.length; i += 2) {
|
||||
String key = new String(serializedHeaders[i], Charset.forName("UTF-8"));
|
||||
String key = new String(serializedHeaders[i], StandardCharsets.UTF_8);
|
||||
// TODO(ericgribkoff): log an error or throw an exception
|
||||
if (isApplicationHeader(key)) {
|
||||
String value = new String(serializedHeaders[i + 1], Charset.forName("UTF-8"));
|
||||
String value = new String(serializedHeaders[i + 1], StandardCharsets.UTF_8);
|
||||
builder.addHeader(key, value);
|
||||
}
|
||||
}
|
||||
|
@ -552,8 +552,8 @@ class CronetClientStream extends AbstractClientStream {
|
|||
|
||||
byte[][] headerValues = new byte[headerList.size()][];
|
||||
for (int i = 0; i < headerList.size(); i += 2) {
|
||||
headerValues[i] = headerList.get(i).getBytes(Charset.forName("UTF-8"));
|
||||
headerValues[i + 1] = headerList.get(i + 1).getBytes(Charset.forName("UTF-8"));
|
||||
headerValues[i] = headerList.get(i).getBytes(StandardCharsets.UTF_8);
|
||||
headerValues[i + 1] = headerList.get(i + 1).getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
Metadata metadata =
|
||||
InternalMetadata.newMetadata(TransportFrameUtil.toRawSerializedHeaders(headerValues));
|
||||
|
|
|
@ -18,6 +18,7 @@ package io.grpc.cronet;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
|
@ -46,7 +47,7 @@ import io.grpc.testing.TestMethodDescriptors;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -102,7 +103,7 @@ public final class CronetClientStreamTest {
|
|||
@Override
|
||||
@SuppressWarnings("GuardedBy")
|
||||
public void run() {
|
||||
assertTrue(stream != null);
|
||||
assertNotNull(stream);
|
||||
stream.transportState().start(factory);
|
||||
}
|
||||
}
|
||||
|
@ -168,7 +169,7 @@ public final class CronetClientStreamTest {
|
|||
for (int i = 0; i < 5; ++i) {
|
||||
requests[i] = "request" + i;
|
||||
buffers[i] = allocator.allocate(requests[i].length());
|
||||
buffers[i].write(requests[i].getBytes(Charset.forName("UTF-8")), 0, requests[i].length());
|
||||
buffers[i].write(requests[i].getBytes(StandardCharsets.UTF_8), 0, requests[i].length());
|
||||
// The 3rd and 5th writeFrame calls have flush=true.
|
||||
clientStream.abstractClientStreamSink().writeFrame(buffers[i], false, i == 2 || i == 4, 1);
|
||||
}
|
||||
|
@ -253,7 +254,7 @@ public final class CronetClientStreamTest {
|
|||
callback.onReadCompleted(
|
||||
cronetStream,
|
||||
info,
|
||||
createMessageFrame(new String("response1").getBytes(Charset.forName("UTF-8"))),
|
||||
createMessageFrame("response1".getBytes(StandardCharsets.UTF_8)),
|
||||
false);
|
||||
// Haven't request any message, so no callback is called here.
|
||||
verify(clientListener, times(0)).messagesAvailable(isA(MessageProducer.class));
|
||||
|
@ -283,9 +284,9 @@ public final class CronetClientStreamTest {
|
|||
verify(cronetStream, times(0)).write(isA(ByteBuffer.class), isA(Boolean.class));
|
||||
// Send the first data frame.
|
||||
CronetWritableBufferAllocator allocator = new CronetWritableBufferAllocator();
|
||||
String request = new String("request");
|
||||
String request = "request";
|
||||
WritableBuffer writableBuffer = allocator.allocate(request.length());
|
||||
writableBuffer.write(request.getBytes(Charset.forName("UTF-8")), 0, request.length());
|
||||
writableBuffer.write(request.getBytes(StandardCharsets.UTF_8), 0, request.length());
|
||||
clientStream.abstractClientStreamSink().writeFrame(writableBuffer, false, true, 1);
|
||||
ArgumentCaptor<ByteBuffer> bufferCaptor = ArgumentCaptor.forClass(ByteBuffer.class);
|
||||
verify(cronetStream, times(1)).write(bufferCaptor.capture(), isA(Boolean.class));
|
||||
|
@ -304,7 +305,7 @@ public final class CronetClientStreamTest {
|
|||
callback.onReadCompleted(
|
||||
cronetStream,
|
||||
info,
|
||||
createMessageFrame(new String("response").getBytes(Charset.forName("UTF-8"))),
|
||||
createMessageFrame("response".getBytes(StandardCharsets.UTF_8)),
|
||||
false);
|
||||
verify(clientListener, times(1)).messagesAvailable(isA(MessageProducer.class));
|
||||
verify(cronetStream, times(2)).read(isA(ByteBuffer.class));
|
||||
|
@ -680,7 +681,7 @@ public final class CronetClientStreamTest {
|
|||
.newBidirectionalStreamBuilder(
|
||||
isA(String.class), isA(BidirectionalStream.Callback.class), isA(Executor.class));
|
||||
|
||||
byte[] msg = "request".getBytes(Charset.forName("UTF-8"));
|
||||
byte[] msg = "request".getBytes(StandardCharsets.UTF_8);
|
||||
stream.writeMessage(new ByteArrayInputStream(msg));
|
||||
// We still haven't built the stream or sent anything.
|
||||
verify(cronetStream, times(0)).write(isA(ByteBuffer.class), isA(Boolean.class));
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package io.grpc.cronet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
@ -91,7 +91,7 @@ public final class CronetClientTransportTest {
|
|||
false,
|
||||
false);
|
||||
Runnable callback = transport.start(clientTransportListener);
|
||||
assertTrue(callback != null);
|
||||
assertNotNull(callback);
|
||||
callback.run();
|
||||
verify(clientTransportListener).transportReady();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue