Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #74 from pengweiqhca/decode
Browse files Browse the repository at this point in the history
metadata value should decode.
  • Loading branch information
huynhminhtan authored Oct 29, 2021
2 parents 06b1b94 + 7130f18 commit 5ddc22b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Run test:
| 4 | Proto Root Directory | Root directory contains proto files |
| 5 | Library Directory (Optional) | Using a different underlying library (googleapis) |
| 6 | Full Method | Full Method to test |
| 7 | Metadata | Store token, authentication method, format: key1:value1,key2:value2 |
| 7 | Metadata | Store token, authentication method, format: key1:value1,key2:value2, value should url encode with utf-8 |
| 8 | Deadline | How long gRPC clients are willing to wait for an RPC to complete |
| 9 | Send JSON Format With the Request | Data request with JSON format |

Expand Down
11 changes: 10 additions & 1 deletion src/main/java/vn/zalopay/benchmark/core/ClientCaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import vn.zalopay.benchmark.core.protobuf.ServiceResolver;
import vn.zalopay.benchmark.core.specification.GrpcResponse;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -90,7 +93,13 @@ private Map<String, String> buildHashMetadata(String metadata) {
Preconditions.checkArgument(keyValue.length == 2,
"Metadata entry must be defined in key1:value1,key2:value2 format: " + metadata);

metadataHash.put(keyValue[0], keyValue[1]);
String value = keyValue[1];
try {
value = URLDecoder.decode(keyValue[1], StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException ignored) {
}

metadataHash.put(keyValue[0], value);
}

return metadataHash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

import javax.net.ssl.SSLException;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

import static org.mockito.Mockito.any;

public class ClientCallerTest extends BaseTest {
Expand Down Expand Up @@ -108,6 +112,16 @@ public void testCanSendGrpcUnaryRequestWithMetaData() {
Assert.assertTrue(resp.getGrpcMessageString().contains("\"theme\": \"Hello server"));
}

@Test
public void testCanSendGrpcUnaryRequestWithEncodedMetaData() throws UnsupportedEncodingException {
clientCaller = new ClientCaller(HOST_PORT, PROTO_WITH_EXTERNAL_IMPORT_FOLDER.toString(), LIB_FOLDER.toString(), FULL_METHOD, false, false, "tracestate:" + URLEncoder.encode("a=3,b:4", StandardCharsets.UTF_8.name()));
clientCaller.buildRequest(REQUEST_JSON);
GrpcResponse resp = clientCaller.call("2000");
clientCaller.shutdownNettyChannel();
Assert.assertNotNull(resp);
Assert.assertTrue(resp.getGrpcMessageString().contains("\"theme\": \"Hello server"));
}

@Test
public void testCanSendGrpcUnaryRequestWithSSLAndDisableSSLVerification() {
clientCaller = new ClientCaller(HOST_PORT_TLS, PROTO_WITH_EXTERNAL_IMPORT_FOLDER.toString(), LIB_FOLDER.toString(), FULL_METHOD, true, true, METADATA);
Expand Down

0 comments on commit 5ddc22b

Please sign in to comment.