Skip to content

Commit

Permalink
Merge pull request #1493 from dilanSachi/multiconfig-u1
Browse files Browse the repository at this point in the history
[2201.0.0] Fix client configuration getting overwritten when mutliple clients are available
  • Loading branch information
dilanSachi authored Dec 18, 2023
2 parents 7ab040b + 2baf5fa commit 098f4cb
Show file tree
Hide file tree
Showing 13 changed files with 313 additions and 12 deletions.
9 changes: 6 additions & 3 deletions ballerina-tests/tests/03_bidirectional_streaming_client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,13 @@ isolated function testBidiStreamingWithPublicCertPrivateKey() returns grpc:Error
ChatClient chatEp = check new ("https://localhost:9093", {
secureSocket: {
key: {
certFile: PUBLIC_CRT_PATH,
keyFile: PRIVATE_KEY_PATH
path: KEYSTORE_PATH,
password: "ballerina"
},
cert: {
path: TRUSTSTORE_PATH,
password: "ballerina"
},
cert: PUBLIC_CRT_PATH,
protocol:{
name: grpc:TLS,
versions: ["TLSv1.2", "TLSv1.1"]
Expand Down
27 changes: 27 additions & 0 deletions ballerina-tests/tests/65_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/65_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.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.

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:9165", config1);
MultipleClientConfigsService2Client ep2 = check new ("https://localhost:9265", config2);
check ep1->call1();
check ep2->call1();
}
123 changes: 123 additions & 0 deletions ballerina-tests/tests/65_multiple_client_configurations_pb.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// 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.

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

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, ROOT_DESCRIPTOR_65_MULTIPLE_CLIENT_CONFIGURATIONS, getDescriptorMap65MultipleClientConfigurations());
}

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, ROOT_DESCRIPTOR_65_MULTIPLE_CLIENT_CONFIGURATIONS, getDescriptorMap65MultipleClientConfigurations());
}

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};
}
}

public client class MultipleClientConfigsService1NilCaller {
private grpc:Caller caller;

public isolated function init(grpc:Caller caller) {
self.caller = caller;
}

public isolated function getId() returns int {
return self.caller.getId();
}

isolated remote function sendError(grpc:Error response) returns grpc:Error? {
return self.caller->sendError(response);
}

isolated remote function complete() returns grpc:Error? {
return self.caller->complete();
}

public isolated function isCancelled() returns boolean {
return self.caller.isCancelled();
}
}

public client class MultipleClientConfigsService2NilCaller {
private grpc:Caller caller;

public isolated function init(grpc:Caller caller) {
self.caller = caller;
}

public isolated function getId() returns int {
return self.caller.getId();
}

isolated remote function sendError(grpc:Error response) returns grpc:Error? {
return self.caller->sendError(response);
}

isolated remote function complete() returns grpc:Error? {
return self.caller->complete();
}

public isolated function isCancelled() returns boolean {
return self.caller.isCancelled();
}
}

const string ROOT_DESCRIPTOR_65_MULTIPLE_CLIENT_CONFIGURATIONS = "0A2736355F6D756C7469706C655F636C69656E745F636F6E66696775726174696F6E732E70726F746F1A1B676F6F676C652F70726F746F6275662F656D7074792E70726F746F32580A1D4D756C7469706C65436C69656E74436F6E66696773536572766963653112370A0563616C6C3112162E676F6F676C652E70726F746F6275662E456D7074791A162E676F6F676C652E70726F746F6275662E456D70747932580A1D4D756C7469706C65436C69656E74436F6E66696773536572766963653212370A0563616C6C3112162E676F6F676C652E70726F746F6275662E456D7074791A162E676F6F676C652E70726F746F6275662E456D707479620670726F746F33";

public isolated function getDescriptorMap65MultipleClientConfigurations() returns map<string> {
return {"65_multiple_client_configurations.proto": "0A2736355F6D756C7469706C655F636C69656E745F636F6E66696775726174696F6E732E70726F746F1A1B676F6F676C652F70726F746F6275662F656D7074792E70726F746F32580A1D4D756C7469706C65436C69656E74436F6E66696773536572766963653112370A0563616C6C3112162E676F6F676C652E70726F746F6275662E456D7074791A162E676F6F676C652E70726F746F6275662E456D70747932580A1D4D756C7469706C65436C69656E74436F6E66696773536572766963653212370A0563616C6C3112162E676F6F676C652E70726F746F6275662E456D7074791A162E676F6F676C652E70726F746F6275662E456D707479620670726F746F33", "google/protobuf/empty.proto": "0A1B676F6F676C652F70726F746F6275662F656D7074792E70726F746F120F676F6F676C652E70726F746F62756622070A05456D70747942540A13636F6D2E676F6F676C652E70726F746F627566420A456D70747950726F746F50015A057479706573F80101A20203475042AA021E476F6F676C652E50726F746F6275662E57656C6C4B6E6F776E5479706573620670726F746F33"};
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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.

import ballerina/grpc;

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

@grpc:ServiceDescriptor {descriptor: ROOT_DESCRIPTOR_65_MULTIPLE_CLIENT_CONFIGURATIONS, descMap: getDescriptorMap65MultipleClientConfigurations()}
service "MultipleClientConfigsService1" on multiConfigListener1 {

remote function call1() returns error? {
}
}

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

@grpc:ServiceDescriptor {descriptor: ROOT_DESCRIPTOR_65_MULTIPLE_CLIENT_CONFIGURATIONS, descMap: getDescriptorMap65MultipleClientConfigurations()}
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
co7XNFJnAgMBAAECggEABT1L7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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
BQAwaDELMAkGA1UEBhMCTEsxEDAOBgNVBAgMB1dlc3Rlcm4xEDAOBgNVBAcMB0Nv
bG9tYm8xDTALBgNVBAoMBFdTTzIxEjAQBgNVBAsMCUJhbGxlcmluYTESMBAGA1UE
AwwJbG9jYWxob3N0MB4XDTIzMTIxODEwMDc0MloXDTI0MTIxNzEwMDc0MlowaDEL
MAkGA1UEBhMCTEsxEDAOBgNVBAgMB1dlc3Rlcm4xEDAOBgNVBAcMB0NvbG9tYm8x
DTALBgNVBAoMBFdTTzIxEjAQBgNVBAsMCUJhbGxlcmluYTESMBAGA1UEAwwJbG9j
YWxob3N0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAknXyDnKPx+hB
VcB9iQNFzcOufCt3W1BzaYhvbWscYflmcqhsEycqW8M7EsLZhyZJi0k58MFyqQCr
83FdJdT5tU5It/EPa3LsENQyjoejr43+1IxdyWK6pIKZ9l4BsZZbFT0LIIyXdhkN
nNFim6v2rvlgZnuhivoM1AQ2SuYcol3G2rmJ4wPav6+qRszveRYSB28HbQg/Dp7X
zLJbWllf42HFIzG//o+Jo9/Im+zIa85v3zU9rJ2pczKp0p03tYBK5bb969Gw10BV
PsDstMZG/tGgLf0UW6lqKlTPoTsn8rjg1yYgqA525qd8zzpMPbrcpJIbjswQC6qp
AHKO1zRSZwIDAQABo1MwUTAdBgNVHQ4EFgQUI1DNyHFRIMZuPPhfZrK+O+F//xUw
HwYDVR0jBBgwFoAUI1DNyHFRIMZuPPhfZrK+O+F//xUwDwYDVR0TAQH/BAUwAwEB
/zANBgkqhkiG9w0BAQsFAAOCAQEAbqFWpIPHV32QtomaKZaF5PGfFEGS6+sgtiz3
fbli6R0floI7kfEHwinCyfv/u4qI2i8unXP2kBUXrsGeoDrMsoJUc94LX5L1pdpo
c+qaCpP8CyTktiSlPmqfklGJzTh8h7+OJVPcWunnNwL6op2ZyyqMEgsRrzB0iCSA
5URZRtTwLq/JJnnUE1YQFrndmOs4Go4+Xdx5Q/rquYBSGt8fpceTDxzrIdR2QS5a
1FriP1l2k/Yi+st9XtYx6SiN5jcIpPWgQco8kxYtAtCER0dqJM3/UyuaAzYSJAnI
cxANjATsH+ALr5F7bDCOqvMiSndJYh1V4d0ufC2YqbvIq/9XOg==
-----END CERTIFICATE-----
6 changes: 3 additions & 3 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.2.3"
version = "1.2.4"
distribution = "2201.0.4"
authors = ["Ballerina"]
keywords = ["network", "grpc", "protobuf", "server-streaming", "client-streaming", "bidirectional-streaming"]
Expand All @@ -11,10 +11,10 @@ license = ["Apache-2.0"]
export = ["grpc", "grpc.types.duration", "grpc.types.struct", "grpc.types.timestamp", "grpc.types.wrappers", "grpc.types.any"]

[[platform.java11.dependency]]
path = "../native/build/libs/grpc-native-1.2.3.jar"
path = "../native/build/libs/grpc-native-1.2.4-SNAPSHOT.jar"

[[platform.java11.dependency]]
path = "../test-utils/build/libs/grpc-test-utils-1.2.3.jar"
path = "../test-utils/build/libs/grpc-test-utils-1.2.4-SNAPSHOT.jar"
scope = "testOnly"

[[platform.java11.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.2.3.jar"
path = "../compiler-plugin/build/libs/grpc-compiler-plugin-1.2.4-SNAPSHOT.jar"
4 changes: 2 additions & 2 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ modules = [
[[package]]
org = "ballerina"
name = "grpc"
version = "1.2.3"
version = "1.2.4"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "crypto"},
Expand Down Expand Up @@ -195,7 +195,7 @@ modules = [
[[package]]
org = "ballerina"
name = "observe"
version = "1.0.4"
version = "1.0.6"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand Down
15 changes: 15 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

## [1.2.3] - 2022-05-30
### Fixed
- [Incorrect stub generated for message with Any type field in gRPC tool](https://github.com/ballerina-platform/ballerina-standard-library/issues/2750)
- [Incorrect stub generation for repeated values of any, struct, timestamp, and duration messages](https://github.com/ballerina-platform/ballerina-standard-library/issues/2732)
- [Unable to pass protobuf predefined types as repeated values and values in messages](https://github.com/ballerina-platform/ballerina-standard-library/issues/2740)
- [Fixes incorrect caller type name validation in gRPC compiler plugin](https://github.com/ballerina-platform/ballerina-standard-library/issues/2867)

### Added
- [Improve imports generation logic in gRPC tool](https://github.com/ballerina-platform/ballerina-standard-library/issues/2762)

## [1.2.1] - 2022-02-18
### Fixed
- [Fix issue in ordering of services with duplicate output types](https://github.com/ballerina-platform/ballerina-standard-library/issues/2637)
- [Improve the enum creation logic to escape case sensitivity](https://github.com/ballerina-platform/ballerina-standard-library/issues/2678)
- [Constraint the compiler plugin validations only for remote functions](https://github.com/ballerina-platform/ballerina-standard-library/issues/2695)
- [Fix name conflict - similar user defined messages as predefined Google types](https://github.com/ballerina-platform/ballerina-standard-library/issues/2692)

## [1.2.0] - 2022-01-29
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
org.gradle.caching=true
group=io.ballerina.stdlib
version=1.2.4
version=1.2.4-SNAPSHOT
#dependency versions
ballerinaLangVersion=2201.0.4
ballerinaTomlParserVersion=1.2.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,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 098f4cb

Please sign in to comment.