MCPcopy Create free account
hub / github.com/grpc/grpc-java / sendMessage

Method sendMessage

alts/src/test/java/io/grpc/alts/internal/TsiTest.java:119–157  ·  view source on GitHub ↗

Sends a message between the sender and receiver.

(
      TsiFrameProtector sender,
      TsiFrameProtector receiver,
      int recvFragmentSize,
      String message,
      RegisterRef ref)

Source from the content-addressed store, hash-verified

117
118 /** Sends a message between the sender and receiver. */
119 private static void sendMessage(
120 TsiFrameProtector sender,
121 TsiFrameProtector receiver,
122 int recvFragmentSize,
123 String message,
124 RegisterRef ref)
125 throws GeneralSecurityException {
126
127 ByteBuf plaintextBuffer = Unpooled.wrappedBuffer(message.getBytes(UTF_8));
128 final List<ByteBuf> protectOut = new ArrayList<>();
129 List<Object> unprotectOut = new ArrayList<>();
130
131 sender.protectFlush(
132 Collections.singletonList(plaintextBuffer),
133 new Consumer<ByteBuf>() {
134 @Override
135 public void accept(ByteBuf buf) {
136 protectOut.add(buf);
137 }
138 },
139 alloc);
140 assertThat(protectOut.size()).isEqualTo(1);
141
142 ByteBuf protect = ref.register(protectOut.get(0));
143 while (protect.isReadable()) {
144 ByteBuf buf = protect;
145 if (recvFragmentSize > 0) {
146 int size = Math.min(protect.readableBytes(), recvFragmentSize);
147 buf = protect.readSlice(size);
148 }
149 receiver.unprotect(buf, unprotectOut, alloc);
150 }
151 ByteBuf plaintextRecvd = getDirectBuffer(message.getBytes(UTF_8).length, ref);
152 for (Object unprotect : unprotectOut) {
153 ByteBuf unprotectBuf = ref.register((ByteBuf) unprotect);
154 plaintextRecvd.writeBytes(unprotectBuf);
155 }
156 assertThat(plaintextRecvd).isEqualTo(Unpooled.wrappedBuffer(message.getBytes(UTF_8)));
157 }
158
159 /** Ping pong test. */
160 public static void pingPongTest(Handshakers handshakers, RegisterRef ref)

Callers 5

pingPongTestMethod · 0.95

Calls 10

getBytesMethod · 0.80
getDirectBufferMethod · 0.80
protectFlushMethod · 0.65
sizeMethod · 0.65
registerMethod · 0.65
getMethod · 0.65
readableBytesMethod · 0.65
unprotectMethod · 0.65
minMethod · 0.45
writeBytesMethod · 0.45

Tested by

no test coverage detected