Changes between Initial Version and Version 1 of DockerRdbmsTestEnvironment


Ignore:
Timestamp:
Feb 1, 2018, 7:45:48 AM (6 years ago)
Author:
jng
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DockerRdbmsTestEnvironment

    v1 v1  
     1= A simple RDBMS test environment with Docker =
     2
     3== Introduction ==
     4
     5When developing or maintaining the FDO code base, its unit test suite should be run and updated constantly to ensure any changes do not break existing behavior.
     6
     7While the test suites are easy to run for the FDO core and for file-based FDO providers like SDF, SHP, SQLite, etc. It is a bit more difficult when testing the GenericRdbms-based providers as this requires an actual installation of the RDBMS in question to be able to run the specific provider unit tests against.
     8
     9With the advent of [https://www.docker.com/ Docker] and containerization, it is very simple to set up an RDBMS test environment for one or more GenericRdbms FDO providers without the overhead of having to physically install the required RDBMSes "bare metal" on the host development machine or needing to stand up an actual server with the RDBMSes installed.
     10
     11A docker-based environment is easy to setup and easy to tear down, which makes it ideal for spinning up a RDBMS test environment.
     12
     13== Requirements ==
     14
     15To setup such an environment, you need an operating system that supports Docker. This can be:
     16
     17 * Windows 10 (with container support enabled)
     18 * Any Linux distribution running kernel 3.10 or later
     19
     20For a full list of platforms supported by docker, [https://docs.docker.com/install/#supported-platforms click here]
     21
     22It is recommended that you have 6GB or RAM available to be able to spin up all the RDBMSes together at once.
     23
     24If you are on Windows 10, you must make sure the Docker daemon is on Linux containers mode.
     25
     26If your host OS is none of the above (eg. You are on Windows 7/8/8.1), you can use a virtual machine that is running one of the above OSes.
     27
     28= An example docker compose file =
     29
     30With the `docker-compose` tool that comes with a docker installation, you can spin up all the required databases to hit your RDBMS provider test suites against.
     31
     32Here's an example `docker-compose.yml` file that defines an environment with:
     33
     34 * MySQL 5.5
     35 * PostgreSQL 9.6 with PostGIS 2.4
     36 * SQL Server 2017
     37
     38{{{
     39version: "3"
     40services:
     41  postgis:
     42    image: "mdillon/postgis:9.6"
     43    ports:
     44      - "5432:5432"
     45    environment:
     46      POSTGRES_PASSWORD: "changeme"
     47  mysql_55:
     48    image: "mysql:5.5"
     49    ports:
     50      - "3306:3306"
     51    environment:
     52      MYSQL_ROOT_PASSWORD: "fdotest"
     53  mssql:
     54    image: "microsoft/mssql-server-linux"
     55    ports:
     56      - "1433:1433"
     57    environment:
     58      SA_PASSWORD: "Sql2016!"
     59      ACCEPT_EULA: "Y"
     60}}}
     61
     62In the directory where you have this file, you can then run the following command to spin up all 3 RDBMSes at once:
     63
     64{{{
     65docker-compose up
     66}}}
     67
     68On the first run, this will download the required docker images for all 3 RDBMSes and then spin them up as running containers.
     69
     70Stopping the command (eg. By `CTRL-C`) will stop all the running containers.
     71
     72On subsequent runs, the images are not downloaded (as they have been downloaded locally)
     73
     74== Running the GenericRdbms test suites against it ==
     75
     76Firstly, build FDO, its providers and its unit tests as usual.
     77
     78Then make a copy of the following files under `<FDO_DIR>/Providers/GenericRdbms/Src/UnitTest`:
     79
     80 * `SqlServerSpatialInit.txt`
     81 * `MySqlInit.txt`
     82 * `PostGisInit.txt`
     83 * `OdbcInit.txt`
     84
     85**Windows only:** Where required, make sure `libmysql.dll` and `libpq.dll` are present in the directories where `UnitTestMySQL.exe` and `UnitTestPostGIS.exe` are present.
     86
     87Edit these copies so that the service points to the hostname or IP address of the docker host (if the docker host sits inside the virtual machine, then you want to point your configs to the hostname/IP of the virtual machine). Change any credentials if required to match what is defined in your `docker-compose.yml` file.
     88
     89Then it's a case of leveraging the `initfiletest` parameter that all GenericRdbms-based unit test executables support to run the test suite against this modified configuration
     90
     91Here is a simple window batch script that can run the battery of applicable GenericRdbms test suites against this spun up docker environment, assuming:
     92 * You built FDO for `Debug|x64`
     93 * Your FDO source tree is in `D:\fdo-trunk`
     94 * Your modified init text files reside in `D:\fdo_test`
     95 * You want to capture test output for all tests to files in `D:\fdo_results`
     96{{{
     97cd /D D:\fdo-trunk\Providers\GenericRdbms\Src\UnitTest
     98Dbg64\UnitTestSQLServerSpatial.exe -NoWAIT initfiletest=D:\fdo_test\SqlServerSpatialInit.txt 2>&1 | tee D:\fdo_results\Dbg64_UnitTestSQLServerSpatial.txt
     99cd /D D:\fdo-trunk\Providers\GenericRdbms\Src\UnitTest
     100Dbg64\UnitTestMySQL.exe -NoWAIT initfiletest=D:\fdo_test\SqlServerSpatialInit.txt 2>&1 | tee D:\fdo_results\Dbg64_UnitTestSQLServerSpatial.txt
     101cd /D D:\fdo-trunk\Providers\GenericRdbms\Src\UnitTest
     102Dbg64\UnitTestPostGIS.exe -NoWAIT initfiletest=D:\fdo_test\SqlServerSpatialInit.txt 2>&1 | tee D:\fdo_results\Dbg64_UnitTestSQLServerSpatial.txt
     103cd /D D:\fdo-trunk\Providers\GenericRdbms\Src\UnitTest
     104Dbg64\UnitTestODBC.exe OdbcSqlServerTests -NoWAIT initfiletest=D:\fdo_test\OdbcInit.txt 2>&1 | tee D:\fdo_results\Dbg64_UnitTestODBC_SqlServer.txt
     105cd /D D:\fdo-trunk\Providers\GenericRdbms\Src\UnitTest
     106Dbg64\UnitTestODBC.exe OdbcMySqlTests -NoWAIT initfiletest=D:\fdo_test\OdbcInit.txt 2>&1 | tee D:\fdo_results\Dbg64_UnitTestODBC_MySQL.txt
     107}}}
     108
     109If you want to test against different versions of one or more RDBMSes, assuming a [https://hub.docker.com/ docker image] is available for your version of interest, you can edit your `docker-compose.yml` to replace or add on the extra docker image (NOTE: Adding extra docker images will impose an additional burden on your system resources).