Skip to content

Commit

Permalink
Merge pull request #948 from kalaiyarasiganeshalingam/master
Browse files Browse the repository at this point in the history
Fix spread-field error in connection pool config
  • Loading branch information
kalaiyarasiganeshalingam authored Jun 16, 2023
2 parents e7f5d51 + 0eb5442 commit fe4dea6
Show file tree
Hide file tree
Showing 8 changed files with 419 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,34 @@ public void testOptionsWithVariables() {

Assert.assertEquals(availableErrors, 0);
}

@Test
public void testConnectionPoolWithSpreadField() {
Package currentPackage = loadPackage("sample5");
PackageCompilation compilation = currentPackage.getCompilation();
DiagnosticResult diagnosticResult = compilation.diagnosticResult();
List<Diagnostic> diagnosticErrorStream = diagnosticResult.diagnostics().stream()
.filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR))
.collect(Collectors.toList());
long availableErrors = diagnosticErrorStream.size();
Assert.assertEquals(availableErrors, 0);
}

@Test
public void negativeTestConnectionPoolWithSpreadField() {
Package currentPackage = loadPackage("sample6");
PackageCompilation compilation = currentPackage.getCompilation();
DiagnosticResult diagnosticResult = compilation.diagnosticResult();
List<Diagnostic> diagnosticErrorStream = diagnosticResult.diagnostics().stream()
.filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR))
.collect(Collectors.toList());
long availableErrors = diagnosticErrorStream.size();
Assert.assertEquals(availableErrors, 3);
Assert.assertEquals(diagnosticErrorStream.get(0).diagnosticInfo().messageFormat(),
"invalid value: expected value is greater than one");
Assert.assertEquals(diagnosticErrorStream.get(1).diagnosticInfo().messageFormat(),
"invalid value: expected value is greater than or equal to 30");
Assert.assertEquals(diagnosticErrorStream.get(2).diagnosticInfo().messageFormat(),
"invalid value: expected value is greater than zero");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
org = "mysql_test"
name = "sample5"
version = "0.1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). All Rights Reserved.
//
// This software is the property of WSO2 LLC. and its suppliers, if any.
// Dissemination of any information or reproduction of any material contained
// herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
// You may not alter or remove any copyright or other notice from copies of this content.

import ballerinax/mysql;
import ballerinax/mysql.driver as _;

# sql:ConnectionPool parameter record with default optimized values
#
# + maxOpenConnections - The maximum open connections
# + maxConnectionLifeTime - The maximum lifetime of a connection
# + minIdleConnections - The minimum idle time of a connection
type SqlConnectionPoolConfig record {|
int maxOpenConnections = 10;
decimal maxConnectionLifeTime = 180;
int minIdleConnections = 5;
|};

# mysql:Options parameter record with default optimized values
#
# + connectTimeout - Timeout to be used when establishing a connection
type MysqlOptionsConfig record {|
decimal connectTimeout = 10;
|};

# [Configurable] Allocation MySQL Database
#
# + hostname - database hostname
# + username - database username
# + password - database password
# + database - database name
# + port - database port
# + connectionPool - sql:ConnectionPool configurations, type: SqlConnectionPoolConfig
# + mysqlOptions - mysql:Options configurations, type: MysqlOptionsConfig
type AllocationDatabase record {|
string hostname;
string username;
string password;
string database;
int port = 3306;
SqlConnectionPoolConfig connectionPool;
MysqlOptionsConfig mysqlOptions;
|};

configurable AllocationDatabase allocationDatabase = ?;

final mysql:Client allocationDbClient = check new (
host = allocationDatabase.hostname,
user = allocationDatabase.username,
password = allocationDatabase.password,
port = allocationDatabase.port,
database = allocationDatabase.database,
connectionPool = {
...allocationDatabase.connectionPool
},
options = {
ssl: {
mode: mysql:SSL_PREFERRED
},
connectTimeout: allocationDatabase.mysqlOptions.connectTimeout
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
org = "mysql_test"
name = "sample6"
version = "0.1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). All Rights Reserved.
//
// This software is the property of WSO2 LLC. and its suppliers, if any.
// Dissemination of any information or reproduction of any material contained
// herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
// You may not alter or remove any copyright or other notice from copies of this content.

import ballerinax/mysql;
import ballerinax/mysql.driver as _;

# sql:ConnectionPool parameter record with default optimized values
#
# + maxOpenConnections - The maximum open connections
# + maxConnectionLifeTime - The maximum lifetime of a connection
# + minIdleConnections - The minimum idle time of a connection
type SqlConnectionPoolConfig record {|
int maxOpenConnections = -10;
decimal maxConnectionLifeTime = -180;
int minIdleConnections = -5;
|};

# mysql:Options parameter record with default optimized values
#
# + connectTimeout - Timeout to be used when establishing a connection
type MysqlOptionsConfig record {|
decimal connectTimeout = 10;
|};

# [Configurable] Allocation MySQL Database
#
# + hostname - database hostname
# + username - database username
# + password - database password
# + database - database name
# + port - database port
# + connectionPool - sql:ConnectionPool configurations, type: SqlConnectionPoolConfig
# + mysqlOptions - mysql:Options configurations, type: MysqlOptionsConfig
type AllocationDatabase record {|
string hostname;
string username;
string password;
string database;
int port = 3306;
SqlConnectionPoolConfig connectionPool;
MysqlOptionsConfig mysqlOptions;
|};

configurable AllocationDatabase allocationDatabase = ?;

final mysql:Client allocationDbClient = check new (
host = allocationDatabase.hostname,
user = allocationDatabase.username,
password = allocationDatabase.password,
port = allocationDatabase.port,
database = allocationDatabase.database,
connectionPool = {
...allocationDatabase.connectionPool
},
options = {
ssl: {
mode: mysql:SSL_PREFERRED
},
connectTimeout: allocationDatabase.mysqlOptions.connectTimeout
}
);
Loading

0 comments on commit fe4dea6

Please sign in to comment.