Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions TestEnvironment.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestEnvironment.Docker.Cont
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestEnvironment.Docker.Containers.Postgres", "src\TestEnvironment.Docker.Containers.Postgres\TestEnvironment.Docker.Containers.Postgres.csproj", "{8542AE96-7EC5-4965-98B1-95B63F7DFE6E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestEnvironment.Docker.Containers.Oracle", "src\TestEnvironment.Docker.Containers.Oracle\TestEnvironment.Docker.Containers.Oracle.csproj", "{22205A7A-5669-44F5-AF9C-D48E325BDF74}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestEnvironment.Docker.Containers.Firebird", "src\TestEnvironment.Docker.Containers.Firebird\TestEnvironment.Docker.Containers.Firebird.csproj", "{FAD25D60-C50D-4559-B4B2-D0E09A14471C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -67,6 +71,14 @@ Global
{8542AE96-7EC5-4965-98B1-95B63F7DFE6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8542AE96-7EC5-4965-98B1-95B63F7DFE6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8542AE96-7EC5-4965-98B1-95B63F7DFE6E}.Release|Any CPU.Build.0 = Release|Any CPU
{22205A7A-5669-44F5-AF9C-D48E325BDF74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{22205A7A-5669-44F5-AF9C-D48E325BDF74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{22205A7A-5669-44F5-AF9C-D48E325BDF74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{22205A7A-5669-44F5-AF9C-D48E325BDF74}.Release|Any CPU.Build.0 = Release|Any CPU
{FAD25D60-C50D-4559-B4B2-D0E09A14471C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FAD25D60-C50D-4559-B4B2-D0E09A14471C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FAD25D60-C50D-4559-B4B2-D0E09A14471C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FAD25D60-C50D-4559-B4B2-D0E09A14471C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -81,6 +93,8 @@ Global
{CAB21076-1316-44EE-9718-8F487E1E7B73} = {9E3390D1-D6AB-48E9-8FBA-C622BCF2C54D}
{5F1E7192-A8D9-49B9-8F24-A29CB06B43DC} = {9E3390D1-D6AB-48E9-8FBA-C622BCF2C54D}
{8542AE96-7EC5-4965-98B1-95B63F7DFE6E} = {9E3390D1-D6AB-48E9-8FBA-C622BCF2C54D}
{22205A7A-5669-44F5-AF9C-D48E325BDF74} = {9E3390D1-D6AB-48E9-8FBA-C622BCF2C54D}
{FAD25D60-C50D-4559-B4B2-D0E09A14471C} = {9E3390D1-D6AB-48E9-8FBA-C622BCF2C54D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5DB4A55C-3900-4F7F-89FF-81D2698214C0}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Collections.Generic;

namespace TestEnvironment.Docker.Containers.Firebird
{
public static class DockerEnvironmentBuilderExtensions
{
public static IDockerEnvironmentBuilder AddFirebirdContainer(
this IDockerEnvironmentBuilder builder,
string name,
string userName = "user1",
string password = "p4ssw0rd",
string imageName = "jacobalberty/firebird",
string tag = "latest",
IDictionary<string, string> environmentVariables = null,
IDictionary<ushort, ushort> ports = null,
bool reuseContainer = false)
{
return builder.AddDependency(
new FirebirdContainer(
builder.DockerClient,
name.GetContainerName(builder.EnvironmentName),
userName,
password,
imageName,
tag,
new Dictionary<string, string>
{
["FIREBIRD_USER"] = userName,
["FIREBIRD_PASSWORD"] = password,
["FIREBIRD_DATABASE"] = "SampleDatabase",
["EnableWireCrypt"] = "true",
["ISC_PASSWORD"] = password,
}.MergeDictionaries(environmentVariables),
ports,
builder.IsDockerInDocker,
reuseContainer,
new FirebirdContainerWaiter(builder.Logger),
new FirebirdContainerCleaner(builder.Logger, userName),
builder.Logger));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Collections.Generic;
using Docker.DotNet;
using Microsoft.Extensions.Logging;
using IP = System.Net.IPAddress;

namespace TestEnvironment.Docker.Containers.Firebird
{
public class FirebirdContainer : Container
{
private readonly string _userName;
private readonly string _password;

public FirebirdContainer(
DockerClient dockerClient,
string name,
string userName,
string password,
string imageName = "jacobalberty/firebird",
string tag = "latest",
IDictionary<string, string> environmentVariables = null,
IDictionary<ushort, ushort> ports = null,
bool isDockerInDocker = false,
bool reuseContainer = false,
IContainerWaiter containerWaiter = null,
IContainerCleaner containerCleaner = null,
ILogger logger = null)
: base(
dockerClient,
name,
imageName,
tag,
environmentVariables,
ports,
isDockerInDocker,
reuseContainer,
containerWaiter,
containerCleaner,
logger)
{
_userName = userName;
_password = password;
}

public string GetConnectionString()
{
var host = IsDockerInDocker ? IPAddress : IP.Loopback.ToString();
var port = IsDockerInDocker ? 3050 : Ports[3050];
return $"DataSource={host};Port={port};User={_userName};Password={_password};Pooling=false;Database=SampleDatabase";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using FirebirdSql.Data.FirebirdClient;
using Microsoft.Extensions.Logging;

namespace TestEnvironment.Docker.Containers.Firebird
{
public class FirebirdContainerCleaner : IContainerCleaner<FirebirdContainer>
{
private readonly ILogger _logger;
private readonly string _userName;

public FirebirdContainerCleaner(ILogger logger, string userName)
{
_logger = logger;
_userName = userName;
}

public async Task Cleanup(FirebirdContainer container, CancellationToken token = default)
{
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}

var cleanUpQuery = $"DROP OWNED BY {_userName}";

using (var connection = new FbConnection(container.GetConnectionString()))
using (var cleanUpCommand = new FbCommand(cleanUpQuery, connection))
{
try
{
await connection.OpenAsync(token);
await cleanUpCommand.ExecuteNonQueryAsync(token);
}
catch (Exception ex)
{
_logger?.LogError($"Firebird cleanup issue: {ex.Message}");
}
}
}

public Task Cleanup(Container container, CancellationToken token = default) => Cleanup((FirebirdContainer)container, token);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Threading;
using System.Threading.Tasks;
using FirebirdSql.Data.FirebirdClient;
using Microsoft.Extensions.Logging;

namespace TestEnvironment.Docker.Containers.Firebird
{
public class FirebirdContainerWaiter : BaseContainerWaiter<FirebirdContainer>
{
public FirebirdContainerWaiter(ILogger logger)
: base(logger)
{
}

protected override async Task<bool> PerformCheck(FirebirdContainer container, CancellationToken cancellationToken)
{
using var connection = new FbConnection(container.GetConnectionString());
using var command = new FbCommand("SELECT rdb$get_context('SYSTEM', 'ENGINE_VERSION') from rdb$database;", connection);

await connection.OpenAsync(cancellationToken);
await command.ExecuteNonQueryAsync(cancellationToken);

return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>TestEnvironment.Docker.Containers.Firebird</AssemblyName>
<RootNamespace>TestEnvironment.Docker.Containers.Firebird</RootNamespace>
<Version>1.0.7</Version>
<PackageId>TestEnvironment.Docker.Containers.Firebird</PackageId>
<Authors>Fabien Ménager</Authors>
<Description>Add Firebird container specific functionality.</Description>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageTags>docker tests firebird container</PackageTags>
<PackageReleaseNotes>Update to the latest nugets.</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\TestEnvironment.Docker\TestEnvironment.Docker.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="7.5.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Collections.Generic;

namespace TestEnvironment.Docker.Containers.Oracle
{
public static class DockerEnvironmentBuilderExtensions
{
public static IDockerEnvironmentBuilder AddOracleContainer(
this IDockerEnvironmentBuilder builder,
string name,
string userName = "system",
string password = "oracle",
string imageName = "wnameless/oracle-xe-11g-r2",
string tag = "latest",
IDictionary<string, string> environmentVariables = null,
IDictionary<ushort, ushort> ports = null,
bool reuseContainer = false)
{
return builder.AddDependency(
new OracleContainer(
builder.DockerClient,
name.GetContainerName(builder.EnvironmentName),
userName,
password,
imageName,
tag,
new Dictionary<string, string>
{
}.MergeDictionaries(environmentVariables),
ports,
builder.IsDockerInDocker,
reuseContainer,
new OracleContainerWaiter(builder.Logger),
new OracleContainerCleaner(builder.Logger, userName),
builder.Logger));
}
}
}
51 changes: 51 additions & 0 deletions src/TestEnvironment.Docker.Containers.Oracle/OracleContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Collections.Generic;
using Docker.DotNet;
using Microsoft.Extensions.Logging;
using IP = System.Net.IPAddress;

namespace TestEnvironment.Docker.Containers.Oracle
{
public class OracleContainer : Container
{
private readonly string _userName;
private readonly string _password;

public OracleContainer(
DockerClient dockerClient,
string name,
string userName,
string password,
string imageName = "wnameless/oracle-xe-11g-r2",
string tag = "latest",
IDictionary<string, string> environmentVariables = null,
IDictionary<ushort, ushort> ports = null,
bool isDockerInDocker = false,
bool reuseContainer = false,
IContainerWaiter containerWaiter = null,
IContainerCleaner containerCleaner = null,
ILogger logger = null)
: base(
dockerClient,
name,
imageName,
tag,
environmentVariables,
ports,
isDockerInDocker,
reuseContainer,
containerWaiter,
containerCleaner,
logger)
{
_userName = userName;
_password = password;
}

public string GetConnectionString()
{
var host = IsDockerInDocker ? IPAddress : IP.Loopback.ToString();
var port = IsDockerInDocker ? 1521 : Ports[1521];
return $"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={host})(PORT={port})))(CONNECT_DATA=(SERVICE_NAME=XE)));User ID={_userName};Password={_password}";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Oracle.ManagedDataAccess.Client;

namespace TestEnvironment.Docker.Containers.Oracle
{
public class OracleContainerCleaner : IContainerCleaner<OracleContainer>
{
private readonly ILogger _logger;
private readonly string _userName;

public OracleContainerCleaner(ILogger logger, string userName)
{
_logger = logger;
_userName = userName;
}

public async Task Cleanup(OracleContainer container, CancellationToken token = default)
{
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}

var cleanUpQuery = $"DROP OWNED BY {_userName}";

using (var connection = new OracleConnection(container.GetConnectionString()))
using (var cleanUpCommand = new OracleCommand(cleanUpQuery, connection))
{
try
{
await connection.OpenAsync(token);
await cleanUpCommand.ExecuteNonQueryAsync(token);
}
catch (Exception ex)
{
_logger?.LogError($"Oracle cleanup issue: {ex.Message}");
}
}
}

public Task Cleanup(Container container, CancellationToken token = default) => Cleanup((OracleContainer)container, token);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Oracle.ManagedDataAccess.Client;

namespace TestEnvironment.Docker.Containers.Oracle
{
public class OracleContainerWaiter : BaseContainerWaiter<OracleContainer>
{
public OracleContainerWaiter(ILogger logger)
: base(logger)
{
}

protected override async Task<bool> PerformCheck(OracleContainer container, CancellationToken cancellationToken)
{
using var connection = new OracleConnection(container.GetConnectionString());
using var command = new OracleCommand("SELECT * FROM V$VERSION", connection);

await connection.OpenAsync(cancellationToken);

var info = connection.GetSessionInfo();
info.TimeZone = "UTC";
connection.SetSessionInfo(info);

await command.ExecuteNonQueryAsync(cancellationToken);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are failing with error:

test-env-my-oracle check failed with exception ORA-00604: error occurred at recursive SQL level 1
      ORA-01882: timezone region not found
Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-00604: error occurred at recursive SQL level 1
ORA-01882: timezone region not found

Probably you need to specify additional parameters to default connection string or configure IsRetryable property in the similar way as in https://github.com/Deffiss/testenvironment-docker/blob/master/src/TestEnvironment.Docker.Containers.MariaDB/MariaDBContainerWaiter.cs#L29

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I tried to add the timezone in the env vars, let's see if that's enough

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the AppVeyoir build timed out :(

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still ORA-01882: timezone region not found errors in appveyor, I suspect there is no UTC timezone inside Docker image. I'll try to troubleshoot locally.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still no luck ... Maybe with a more "common" timezone like "Europe/Paris" ? I checked, UTC exists in the Oracle timezone table though.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, very strange. Locally it works just fine.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some research and found that in HealthCheck project Oracle tests are skipped for some reasons on AppVeyor:
https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/blob/master/test/FunctionalTests/HealthChecks.Oracle/OracleHealthCheckTests.cs

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My current feeling that in AppVeyor there is a discrepancy between timezones inside container and on builder machine, we need to find a way to identify timezone that exists in two places.


return true;
}
}
}
Loading