Skip to content

Commit

Permalink
Merge pull request #1492 from dilanSachi/multi-config-master
Browse files Browse the repository at this point in the history
Fix client configuration getting overwritten when mutliple clients are available
  • Loading branch information
dilanSachi committed Dec 19, 2023
2 parents cabe701 + da1e2c7 commit 5884f20
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 9 deletions.
27 changes: 27 additions & 0 deletions ballerina-tests/tests/79_multiple_client_configurations.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

syntax = "proto3";

import "google/protobuf/empty.proto";

service MultipleClientConfigsService1 {
rpc call1(google.protobuf.Empty) returns (google.protobuf.Empty);
}

service MultipleClientConfigsService2 {
rpc call1(google.protobuf.Empty) returns (google.protobuf.Empty);
}
38 changes: 38 additions & 0 deletions ballerina-tests/tests/79_multiple_client_configurations_client.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
//
// WSO2 Inc. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/grpc;
import ballerina/test;

grpc:ClientConfiguration config1 = {
secureSocket: {
cert: "tests/resources/public.crt"
}
};

grpc:ClientConfiguration config2 = {
secureSocket: {
cert: "tests/resources/public2.crt"
}
};

@test:Config {enable: true}
function testMultipleConfigurationsInMultiClientScenario() returns error? {
MultipleClientConfigsService1Client ep1 = check new ("https://localhost:9179", config1);
MultipleClientConfigsService2Client ep2 = check new ("https://localhost:9279", config2);
check ep1->call1();
check ep2->call1();
}
71 changes: 71 additions & 0 deletions ballerina-tests/tests/79_multiple_client_configurations_pb.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/grpc;
import ballerina/protobuf.types.empty;

public const string MULTIPLE_CLIENT_CONFIGURATIONS_DESC = "0A2737395F6D756C7469706C655F636C69656E745F636F6E66696775726174696F6E732E70726F746F1A1B676F6F676C652F70726F746F6275662F656D7074792E70726F746F32580A1D4D756C7469706C65436C69656E74436F6E66696773536572766963653112370A0563616C6C3112162E676F6F676C652E70726F746F6275662E456D7074791A162E676F6F676C652E70726F746F6275662E456D70747932580A1D4D756C7469706C65436C69656E74436F6E66696773536572766963653212370A0563616C6C3112162E676F6F676C652E70726F746F6275662E456D7074791A162E676F6F676C652E70726F746F6275662E456D707479620670726F746F33";

public isolated client class MultipleClientConfigsService1Client {
*grpc:AbstractClientEndpoint;

private final grpc:Client grpcClient;

public isolated function init(string url, *grpc:ClientConfiguration config) returns grpc:Error? {
self.grpcClient = check new (url, config);
check self.grpcClient.initStub(self, MULTIPLE_CLIENT_CONFIGURATIONS_DESC);
}

isolated remote function call1() returns grpc:Error? {
empty:Empty message = {};
map<string|string[]> headers = {};
_ = check self.grpcClient->executeSimpleRPC("MultipleClientConfigsService1/call1", message, headers);
}

isolated remote function call1Context() returns empty:ContextNil|grpc:Error {
empty:Empty message = {};
map<string|string[]> headers = {};
var payload = check self.grpcClient->executeSimpleRPC("MultipleClientConfigsService1/call1", message, headers);
[anydata, map<string|string[]>] [_, respHeaders] = payload;
return {headers: respHeaders};
}
}

public isolated client class MultipleClientConfigsService2Client {
*grpc:AbstractClientEndpoint;

private final grpc:Client grpcClient;

public isolated function init(string url, *grpc:ClientConfiguration config) returns grpc:Error? {
self.grpcClient = check new (url, config);
check self.grpcClient.initStub(self, MULTIPLE_CLIENT_CONFIGURATIONS_DESC);
}

isolated remote function call1() returns grpc:Error? {
empty:Empty message = {};
map<string|string[]> headers = {};
_ = check self.grpcClient->executeSimpleRPC("MultipleClientConfigsService2/call1", message, headers);
}

isolated remote function call1Context() returns empty:ContextNil|grpc:Error {
empty:Empty message = {};
map<string|string[]> headers = {};
var payload = check self.grpcClient->executeSimpleRPC("MultipleClientConfigsService2/call1", message, headers);
[anydata, map<string|string[]>] [_, respHeaders] = payload;
return {headers: respHeaders};
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/grpc;

listener grpc:Listener multiConfigListener1 = new (9179, secureSocket = {
key: {
certFile: "tests/resources/public.crt",
keyFile: "tests/resources/private.key"
}
});

@grpc:Descriptor {value: MULTIPLE_CLIENT_CONFIGURATIONS_DESC}
service "MultipleClientConfigsService1" on multiConfigListener1 {

remote function call1() returns error? {
}
}

listener grpc:Listener multiConfigListener2 = new (9279, secureSocket = {
key: {
certFile: "tests/resources/public2.crt",
keyFile: "tests/resources/private2.key"
}
});

@grpc:Descriptor {value: MULTIPLE_CLIENT_CONFIGURATIONS_DESC}
service "MultipleClientConfigsService2" on multiConfigListener2 {

remote function call1() returns error? {
}
}
28 changes: 28 additions & 0 deletions ballerina-tests/tests/resources/private2.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCSdfIOco/H6EFV
wH2JA0XNw658K3dbUHNpiG9taxxh+WZyqGwTJypbwzsSwtmHJkmLSTnwwXKpAKvz
cV0l1Pm1Tki38Q9rcuwQ1DKOh6Ovjf7UjF3JYrqkgpn2XgGxllsVPQsgjJd2GQ2c
0WKbq/au+WBme6GK+gzUBDZK5hyiXcbauYnjA9q/r6pGzO95FhIHbwdtCD8OntfM
sltaWV/jYcUjMb/+j4mj38ib7Mhrzm/fNT2snalzMqnSnTe1gErltv3r0bDXQFU+
wOy0xkb+0aAt/RRbqWoqVM+hOyfyuODXJiCoDnbmp3zPOkw9utykkhuOzBALqqkA
co7XNFJnAgMBAAECggEABT1L7gFiLGQeJjuvIf4oep5z+QQzDmS35EAZwF/TEZwy
8ooc56iAhuzaiabH0mJnwiBZ/sdk2y/ndtuI2gge8MH+rvnkM9NWJ5n3vwqSK/8X
7TGiT0iFZco4SMx/IgO/eWiII99zsalex8vjy67gsczBCpmEo2yjldgaux41Swei
8DuUZSg8f9BqzEHEVrhhRdFBfxbHbh/b/M8/vwwI2jD4SYWkKCfz9LpWHEwsPsCT
Nwv+t3hXZaUxPygvWh7uI7XYbbHfvIB03xDiYh5Hn4W4palnJbTgc5SUrfunaQai
IwrhYipdUmp1Ie32iQ9ccYzqcvTL+uKQuZp9C2tACQKBgQDGiYwsN6VvVLwCRpgQ
2yqd7ypaoNMm4QCHXdfyD7MwsXfiyjKC4MdKjxmbYPTe0ipy+skIYKsSByrgDmrW
X+ZXb7djuerE5GY947x8m1qXTIaH0pmZ7GgM839qiiT+OQQeaUqG5wg/9c3OH47+
MnBV4M+JXYzjHg8NKXQkLlhGXwKBgQC82dQkbVVk6lVC7MNosPMm++ATPIkdigSB
YxbXwuSnLAljacQJi536G1kqmFnaUk2s5WHqVyIos/pejntft7vhl72GsybqYQFc
COCS7mGdQ8Dy+Lp4ZxA16Ov4HCCoNFLZ8NTWu4mg04B3qnjcs1k2WsmdLhuj+1xt
6AEhWPQg+QKBgDudi9CvOObwO7A3QGw3U1mvOjmSdzUCdSUwoapW2oixkX0xF+/C
zTTvOVI1z/GkjAiQk5MHa/by3gX/bkdG7qSssBWq+vr6VlUZMDz+bTpnSTI5o9Pb
b/cLmuQD7U3FEx6KoU1WzFxgU9ckFMzxmle/NLJbu/Vqzjw2iWBf5jPjAoGAai5P
iOuwR705kxdsB0D2dcTIiAhRT7p6LgV4oneB+DxaSvr8riFCAY2+5KQkYQxFgCC4
nPnAywHmk6Oo2niDuqOGfGXeS4mfKhATtIkzeSjPI82VinzoMGd1xVqLQgepTcCK
6vEmwLYqVR4UNoLgdh81nJqAEAMURPddK1LIcIECgYEAso51I7hipW/Bu+x9m+Oy
dCpM/S0i9sVdvTQoy3mkiCGii1YRySVeHl2d4gnrT+872FBOI0PnhO8Cen5KVq4F
HlHOpenNz9CPfjoyKO1ZzWDEf1dpxdJh8TbHnMi46DaG6xlxt46Raqbqmrp/aQkt
IkDD4NBPFxZ0q4QsTi6vFhQ=
-----END PRIVATE KEY-----
22 changes: 22 additions & 0 deletions ballerina-tests/tests/resources/public2.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-----BEGIN CERTIFICATE-----
MIIDsTCCApmgAwIBAgIUQNhCNPDDTuFXfM6peyjmUXFU1vkwDQYJKoZIhvcNAQEL
BQAwaDELMAkGA1UEBhMCTEsxEDAOBgNVBAgMB1dlc3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yi+st9XtYx6SiN5jcIpPWgQco8kxYtAtCER0dqJM3/UyuaAzYSJAnI
cxANjATsH+ALr5F7bDCOqvMiSndJYh1V4d0ufC2YqbvIq/9XOg==
-----END CERTIFICATE-----
8 changes: 4 additions & 4 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerina"
name = "grpc"
version = "1.10.3"
version = "1.10.4"
distribution = "2201.8.0"
authors = ["Ballerina"]
keywords = ["network", "grpc", "protobuf", "server-streaming", "client-streaming", "bidirectional-streaming"]
Expand All @@ -16,11 +16,11 @@ graalvmCompatible = true
[[platform.java17.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "grpc-native"
version = "1.10.3"
path = "../native/build/libs/grpc-native-1.10.3.jar"
version = "1.10.4"
path = "../native/build/libs/grpc-native-1.10.4-SNAPSHOT.jar"

[[platform.java17.dependency]]
path = "../test-utils/build/libs/grpc-test-utils-1.10.3.jar"
path = "../test-utils/build/libs/grpc-test-utils-1.10.4-SNAPSHOT.jar"
scope = "testOnly"

[[platform.java17.dependency]]
Expand Down
2 changes: 1 addition & 1 deletion ballerina/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id = "grpc-compiler-plugin"
class = "io.ballerina.stdlib.grpc.plugin.GrpcCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/grpc-compiler-plugin-1.10.3.jar"
path = "../compiler-plugin/build/libs/grpc-compiler-plugin-1.10.4-SNAPSHOT.jar"
4 changes: 2 additions & 2 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "grpc"
version = "1.10.3"
version = "1.10.4"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "crypto"},
Expand All @@ -94,7 +94,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.10.3"
version = "2.10.5"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This file contains all the notable changes done to the Ballerina gRPC package th
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Fixed
- [Fixed `grpc:ClientConfiguration` getting overwritten when mutliple clients are present](https://github.com/ballerina-platform/ballerina-library/issues/5892)

## [1.10.3] - 2023-11-21
### Fixed
- [Fixed serializing issue in repeated packed fields](https://github.com/ballerina-platform/ballerina-library/issues/5080)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public static Object externInit(BObject clientEndpoint, BString urlString,
Map<String, Object> properties =
HttpConnectorUtil.getTransportProperties(connectionManager.getTransportConfig());
properties.put(HttpConstants.CLIENT_CONFIG_HASH_CODE, optionsString.hashCode());
SenderConfiguration senderConfiguration =
HttpConnectorUtil.getSenderConfiguration(connectionManager.getTransportConfig(), scheme);
SenderConfiguration senderConfiguration = new SenderConfiguration();
senderConfiguration.setScheme(scheme);

if (connectionManager.isHTTPTraceLoggerEnabled()) {
senderConfiguration.setHttpTraceLogEnabled(true);
Expand Down

0 comments on commit 5884f20

Please sign in to comment.