Skip to content

Commit fd13a23

Browse files
kenrickyapyanw-bq14yapkc1
authored
feat: Add NHibernate support (#85)
* ef integration test * add pull request to register the workflow and then run manually * install dotnet-ef tool * install dotnet ef in docker * fix PATH * fix migration name * log ef tests * failover for ef * fix wrapper connection string * fix logging * pass connection string to UseMySql * remove efm from tests * MakeSureFirstInstanceWriter * dispose transaction on catch * use cluster endpoint * more logging * fix connection type * fix stale dns using old writer host spec * fix stale dns using old writer ip * enable connect failover * check for instance id * more logging * more logging * check for connection state * test * try to fix logs * log connection role * use proxy cluster endpoint * use non proxy cluster endpoint and fix dns patterns * force refresh anyway * more tests * more tests * use proxy cluster for simulation tests * fix wrong ClusterInstanceHostPattern * fix simulation to use proxy cluster endpoint * disable both cluster and writer * refresh host list after failover on connect * add is initial connection in connection * not throw exception when there are dialect candidates and update fails * not use plugins when adding ef migrations * remove is initial connection var * truncate tables inside each test after cluster status ok * fix tests * fix test * fix test * change timeout settings * increase temp failure time to trigger failover on BeginDbTransaction * typo * increase temp failure time * make sure readers are up after failover * remove cluster status check * fix logger format * dispose transaction after commit rollback and dispose * remove null check for target transaction * check for null before disposing * fix test * truncate tables * fix test * more tests * revert to use cluster endpoint for IAM and EFM tests * revert some test cases to use cluster endpoint * move dispose to finally for transaction * ignore exception thrown by rollback * fix github action matrix * debug: check for all roles * fix host creation * added implementation of nhibernate * pipeline run * fix docker build issues * CreateConnection alterations * added delayed intialzation of AwsWrapperConnection * wrong constructor called * fixed missing table issue * i'm a potato * fixed test errors * check generic ado exception for failover * missing type * added pg failover tests * linting * timeout param error * revert connection string changes * test without timeout * test edits * fixed to use helper function for config * linting * linting * added initial connection strat * removed initial connection * add back efm to reproduce error * add DbTransaction to command if there is an active transaction * add network failure efm test * increase min thread pool size * run async * fix test case * fix test * more logging * fix build * dispose monitoring connection once invalid * change to use reader * disable connection pooling for mysql * use close rather than dispose for aborting * more logging * more logging * more logging * remove mysql efm tests since mysql does not support abort connection in a separate thread * remove efm from ef mysql tests as efm does not support mysql * fixing pipeline tests * fix temp test * updated to use proxy endpoint * removed pg proxy test * fixed before open test * remove result logging to fix rows not updated in efm * add logging * added logging * refreshing after inital connection set * refreshing after inital hostlist set * rethrow exception in EFM execute pipeline * rename * bump mysql ef version to 9.0.0 * added logging messages * try to reopen connection after close * fixed unit tests * passed connection by reference * dispose old connection * set isInitialconnection to false * fixed unit tests * removed unused imports * use force open instead of open * linting * check for both transaction and ado ex * fixed typo * force open * changed to open * removed ref * fix unit test * linting * update workflow * reverting unnessary changes * temp run changes * revert unit test changes * changed tests * simplifiying test * catch transaction error instead * updated multiaz pg is dialect * updated multiaz pg is dialect * fixed execution * test query * updated dialect candidates * retry logic * force refresh * address comments * address comments * added CreateCriteria test * test re-order * added session query test * lossen dbexception catch * lossen dbexception catch * set isClosed to false after failover success * add addtional log messages * linting * reverting some changes * changed test cases * changed test cases * clear sessions after failover * linting * added additional logging * added additional logging * RCA loggging * fixed sql * addtional logging * disabled pooling * pooling test * failover pooling tests * added retry for when connection pool is out of date * linting * integ test changes * linting errors * enabled multi-az tests * added test tag * test fix * addressing pipeline build errors * test changes * updated sleep query * added timeout and no pooling when force open * linting * fix build error * fixed build error * test adjustments * toxy proxy changes * changed instance endpoint * removed inital connections strategy * test edits * ping returns inner exception * retry logic * Update AwsWrapperDataProvider/Driver/Dialects/RdsMultiAzDbClusterPgDialect.cs Co-authored-by: Yan Wang <68562925+yanw-bq@users.noreply.github.com> * addressed pr comments * removed initialconenction plugin for non aurora tests * reverted exception check for cluster monitor topology query * added try catch for open in cluster topology monitor * added intialconnection plugin * fixed linting issues * removed initial connection strategy from failover test * deafult connection plugin changes * linting * addressed PR comments * fixed unit test * integration test fix * reverted default open changes * reverted resource string change * added example project * fixed build error * fixed build error * add readme * added new test tasks to the integration test section * restored dispose override * delayed init for connection * fixed constructor * remove pipeline call from CreateDbParameter --------- Co-authored-by: Yan Wang <yan.wang@improving.com> Co-authored-by: Yan Wang <68562925+yanw-bq@users.noreply.github.com> Co-authored-by: kenrick.yap@improving.com <14yapkc1@gmail.com>
1 parent 67591d3 commit fd13a23

49 files changed

Lines changed: 1863 additions & 149 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: NHibernate Integration Tests
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
id-token: write # This is required for requesting the JWT
8+
contents: read # This is required for actions/checkout
9+
10+
jobs:
11+
run-integration-tests:
12+
name: Run NHibernate Integration Tests
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
dbEngine: ["mysql", "pg"]
18+
deployment: ["aurora", "multi-az-cluster", "multi-az-instance"]
19+
# deployment: ["aurora"]
20+
steps:
21+
- name: 'Clone repository'
22+
uses: actions/checkout@v4
23+
- name: "Set up JDK 8"
24+
uses: actions/setup-java@v4
25+
with:
26+
distribution: "corretto"
27+
java-version: 8
28+
- name: Setup .NET 8.0
29+
uses: actions/setup-dotnet@v4
30+
with:
31+
dotnet-version: '8.0.407'
32+
- name: Configure AWS Credentials
33+
id: creds
34+
uses: aws-actions/configure-aws-credentials@v4
35+
with:
36+
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_DEPLOY_ROLE }}
37+
role-session-name: dotnet_nhibernate_integration_test
38+
role-duration-seconds: 21600
39+
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
40+
output-credentials: true
41+
- name: Run NHibernate Integration Tests
42+
run: |
43+
cd test/integration/host && ./gradlew --no-parallel --no-daemon test-all-${{ matrix.dbEngine }}-${{ matrix.deployment }}-nh --info
44+
env:
45+
RDS_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
46+
AWS_ACCESS_KEY_ID: ${{ steps.creds.outputs.aws-access-key-id }}
47+
AWS_SECRET_ACCESS_KEY: ${{ steps.creds.outputs.aws-secret-access-key }}
48+
AWS_SESSION_TOKEN: ${{ steps.creds.outputs.aws-session-token }}
49+
MYSQL_VERSION: "default"
50+
PG_VERSION: "default"
51+
- name: Archive results
52+
if: always()
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: nhibernate-integration-report-${{ matrix.dbEngine }}-${{ matrix.deployment }}
56+
path: ./test/integration/container/reports
57+
retention-days: 5

AwsWrapperDataProvider.Dialect.MySqlClient/MySqlClientDialect.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
using System.Data;
1516
using AwsWrapperDataProvider.Driver.Dialects;
1617
using AwsWrapperDataProvider.Driver.HostInfo;
1718
using AwsWrapperDataProvider.Driver.Plugins;
@@ -27,9 +28,26 @@ public class MySqlClientDialect : AbstractTargetConnectionDialect
2728

2829
public override Type DriverConnectionType { get; } = typeof(MySqlConnection);
2930

30-
public override string PrepareConnectionString(IDialect dialect, HostSpec? hostSpec, Dictionary<string, string> props)
31+
public override string PrepareConnectionString(IDialect dialect, HostSpec? hostSpec, Dictionary<string, string> props, bool isForceOpen = false)
3132
{
32-
return this.PrepareConnectionString(dialect, hostSpec, props, PropertyDefinition.Server);
33+
Dictionary<string, string> copyOfProps = new(props);
34+
35+
if (isForceOpen)
36+
{
37+
copyOfProps[DefaultPoolingParameterName] = "false";
38+
}
39+
40+
return this.PrepareConnectionString(dialect, hostSpec, copyOfProps, PropertyDefinition.Server);
41+
}
42+
43+
public override (bool ConnectionAlive, Exception? ConnectionException) Ping(IDbConnection connection)
44+
{
45+
if (connection is MySqlConnection mySqlConnection)
46+
{
47+
return (mySqlConnection.Ping(), null);
48+
}
49+
50+
return (false, null);
3351
}
3452

3553
public override string GetPluginCodesOrDefault(Dictionary<string, string> props)

AwsWrapperDataProvider.Dialect.MySqlConnector/MySqlConnectorDialect.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
using System.Data;
1516
using AwsWrapperDataProvider.Driver.Dialects;
1617
using AwsWrapperDataProvider.Driver.HostInfo;
1718
using AwsWrapperDataProvider.Driver.Plugins;
@@ -30,10 +31,28 @@ public class MySqlConnectorDialect : AbstractTargetConnectionDialect
3031
public override string PrepareConnectionString(
3132
IDialect dialect,
3233
HostSpec? hostSpec,
33-
Dictionary<string, string> props)
34+
Dictionary<string, string> props,
35+
bool isForceOpen = false)
3436
{
3537
PropertyDefinition.Port.GetInt(props);
36-
return this.PrepareConnectionString(dialect, hostSpec, props, PropertyDefinition.Server);
38+
Dictionary<string, string> copyOfProps = new(props);
39+
40+
if (isForceOpen)
41+
{
42+
copyOfProps[DefaultPoolingParameterName] = "false";
43+
}
44+
45+
return this.PrepareConnectionString(dialect, hostSpec, copyOfProps, PropertyDefinition.Server);
46+
}
47+
48+
public override (bool ConnectionAlive, Exception? ConnectionException) Ping(IDbConnection connection)
49+
{
50+
if (connection is MySqlConnection mySqlConnection)
51+
{
52+
return (mySqlConnection.Ping(), null);
53+
}
54+
55+
return (false, null);
3756
}
3857

3958
public override string GetPluginCodesOrDefault(Dictionary<string, string> props)

AwsWrapperDataProvider.Dialect.Npgsql/NpgsqlDialect.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
using System.Data;
1516
using AwsWrapperDataProvider.Driver.Dialects;
1617
using AwsWrapperDataProvider.Driver.HostInfo;
1718
using AwsWrapperDataProvider.Driver.TargetConnectionDialects;
@@ -27,8 +28,35 @@ public class NpgsqlDialect : AbstractTargetConnectionDialect
2728
public override string PrepareConnectionString(
2829
IDialect dialect,
2930
HostSpec? hostSpec,
30-
Dictionary<string, string> props)
31+
Dictionary<string, string> props,
32+
bool isForceOpen = false)
3133
{
32-
return this.PrepareConnectionString(dialect, hostSpec, props, PropertyDefinition.Host);
34+
Dictionary<string, string> copyOfProps = new(props);
35+
36+
if (isForceOpen)
37+
{
38+
copyOfProps[DefaultPoolingParameterName] = "false";
39+
}
40+
41+
return this.PrepareConnectionString(dialect, hostSpec, copyOfProps, PropertyDefinition.Host);
42+
}
43+
44+
public override (bool ConnectionAlive, Exception? ConnectionException) Ping(IDbConnection connection)
45+
{
46+
try
47+
{
48+
if (connection is NpgsqlConnection npgsqlConnection)
49+
{
50+
using var cmd = new NpgsqlCommand("SELECT 1", npgsqlConnection);
51+
cmd.ExecuteScalar();
52+
return (true, null);
53+
}
54+
}
55+
catch (Exception ex)
56+
{
57+
return (false, ex);
58+
}
59+
60+
return (false, null);
3361
}
3462
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>false</IsPackable>
8+
<IsTestProject>true</IsTestProject>
9+
<OutputType>Exe</OutputType>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="AWSSDK.EC2" Version="4.0.44.1" />
14+
<PackageReference Include="AWSSDK.RDS" Version="4.0.10.7" />
15+
<PackageReference Include="coverlet.collector" Version="6.0.4">
16+
<PrivateAssets>all</PrivateAssets>
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
</PackageReference>
19+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
20+
<PackageReference Include="Moq" Version="4.20.72" />
21+
<PackageReference Include="MySqlConnector" Version="2.4.0" />
22+
<PackageReference Include="NHibernate.Driver.MySqlConnector" Version="2.0.5" />
23+
<PackageReference Include="Npgsql" Version="9.0.3" />
24+
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
25+
<PackageReference Include="ToxiproxyNetCore" Version="1.0.40" />
26+
<PackageReference Include="xunit.v3" Version="3.0.1" />
27+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4">
28+
<PrivateAssets>all</PrivateAssets>
29+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
30+
</PackageReference>
31+
</ItemGroup>
32+
33+
<ItemGroup>
34+
<ProjectReference Include="..\AwsWrapperDataProvider.NHibernate\AwsWrapperDataProvider.NHibernate.csproj" />
35+
<ProjectReference Include="..\AwsWrapperDataProvider.Tests\AwsWrapperDataProvider.Tests.csproj" />
36+
</ItemGroup>
37+
38+
<ItemGroup>
39+
<Using Include="Xunit" />
40+
</ItemGroup>
41+
42+
<ItemGroup>
43+
<EmbeddedResource Include="Person.hbm.xml" />
44+
</ItemGroup>
45+
46+
</Project>

0 commit comments

Comments
 (0)