|
| 1 | +# OpenLogReplicator Test Framework |
| 2 | + |
| 3 | +Automated regression testing for OpenLogReplicator. Each test runs OLR in batch |
| 4 | +mode against captured Oracle redo logs and compares JSON output against golden |
| 5 | +files validated by Oracle LogMiner. |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +- Docker with Compose v2 |
| 10 | +- Python 3.6+ (stdlib only, no pip dependencies) |
| 11 | +- Bash |
| 12 | + |
| 13 | +No C++ toolchain needed on the host — OLR is built inside Docker. |
| 14 | + |
| 15 | +## Quick Start |
| 16 | + |
| 17 | +```bash |
| 18 | +# Build OLR Docker image (includes binary + gtest) |
| 19 | +make build |
| 20 | + |
| 21 | +# Start OLR dev container + Oracle (~30s with slim-faststart image) |
| 22 | +make up |
| 23 | + |
| 24 | +# Generate all fixtures (validates each against LogMiner) |
| 25 | +make testdata |
| 26 | + |
| 27 | +# Run regression tests |
| 28 | +make test |
| 29 | + |
| 30 | +# Generate just one fixture |
| 31 | +make testdata SCENARIO=basic-crud |
| 32 | + |
| 33 | +# Cleanup |
| 34 | +make down |
| 35 | +``` |
| 36 | + |
| 37 | +## How It Works |
| 38 | + |
| 39 | +### Build (`make build`) |
| 40 | + |
| 41 | +Builds OLR inside a Docker image (`olr-dev`) using `Dockerfile.dev` at the |
| 42 | +project root via `docker compose build olr`. The image includes all optional |
| 43 | +dependencies (Oracle client, Kafka, Protobuf, Prometheus) with ccache for |
| 44 | +fast incremental rebuilds. Google Test is auto-fetched via CMake FetchContent. |
| 45 | + |
| 46 | +### Fixture Generation (`make testdata`) |
| 47 | + |
| 48 | +The `scripts/generate.sh` script runs 7 stages per scenario: |
| 49 | + |
| 50 | +| Stage | Action | |
| 51 | +|-------|--------| |
| 52 | +| 0 | (DDL only) Build LogMiner dictionary into redo logs | |
| 53 | +| 1 | Run SQL scenario against Oracle, capture start/end SCN | |
| 54 | +| 2 | Force log switches, copy archived redo logs out of container | |
| 55 | +| 3 | Generate schema checkpoint via `gencfg.sql` | |
| 56 | +| 4 | Run LogMiner, convert output to JSON | |
| 57 | +| 5 | Run OLR in batch mode via `docker run` against captured redo logs | |
| 58 | +| 6 | Compare OLR output vs LogMiner — **fail if mismatch** | |
| 59 | +| 7 | Save OLR output as golden file | |
| 60 | + |
| 61 | +### Regression Tests (`make test`) |
| 62 | + |
| 63 | +Runs `ctest` inside the `olr-dev` Docker image with fixture directories mounted. |
| 64 | +The C++ test runner (`test_pipeline.cpp`) auto-discovers fixtures from |
| 65 | +`3-expected/*/output.json`, builds a batch-mode config for each, runs OLR, |
| 66 | +and compares output line-by-line against the golden file. |
| 67 | + |
| 68 | +No Oracle instance is needed to run tests — only the pre-generated fixtures. |
| 69 | + |
| 70 | +## Directory Structure |
| 71 | + |
| 72 | +``` |
| 73 | +Makefile # Build, run, test targets |
| 74 | +Dockerfile.dev # Builds OLR + gtest (full dev image) |
| 75 | +docker-compose.yaml # olr (dev container) + oracle (test DB) |
| 76 | +scripts/run.sh # Docker entrypoint script |
| 77 | +tests/ |
| 78 | + CMakeLists.txt # gtest build config |
| 79 | + test_pipeline.cpp # Parameterized gtest runner |
| 80 | + scripts/ |
| 81 | + generate.sh # Generate + validate one fixture |
| 82 | + compare.py # OLR vs LogMiner comparison |
| 83 | + logminer2json.py # LogMiner spool → JSON converter |
| 84 | + oracle-init/ |
| 85 | + 01-setup.sh # Enables archivelog + supplemental logging |
| 86 | + 0-inputs/ # SQL scenarios (committed) |
| 87 | + basic-crud.sql |
| 88 | + data-types.sql |
| 89 | + ... |
| 90 | + 1-schema/ # Schema checkpoints (gitignored) |
| 91 | + 2-redo/ # Redo log files (gitignored) |
| 92 | + 3-expected/ # Golden files (gitignored) |
| 93 | +``` |
| 94 | + |
| 95 | +Only `0-inputs/`, `scripts/`, and build files are committed to git. The `1-schema/`, `2-redo/`, and `3-expected/` directories are generated |
| 96 | +and distributed as CI artifacts. |
| 97 | + |
| 98 | +## Writing New Scenarios |
| 99 | + |
| 100 | +Create a SQL file in `0-inputs/` that: |
| 101 | + |
| 102 | +1. Creates test table(s) with supplemental logging |
| 103 | +2. Records start SCN via `DBMS_OUTPUT.PUT_LINE('FIXTURE_SCN_START: ' || scn)` |
| 104 | +3. Performs DML operations with explicit COMMITs |
| 105 | +4. Records end SCN via `DBMS_OUTPUT.PUT_LINE('FIXTURE_SCN_END: ' || scn)` |
| 106 | +5. Ends with `EXIT` |
| 107 | + |
| 108 | +See `0-inputs/basic-crud.sql` for the template. |
| 109 | + |
| 110 | +**Note:** Log switches are handled by `generate.sh` — don't run |
| 111 | +`ALTER SYSTEM SWITCH LOGFILE` from the scenario SQL. |
| 112 | + |
| 113 | +### DDL Scenarios |
| 114 | + |
| 115 | +For scenarios with DDL (ALTER TABLE, etc.), add `-- @DDL` at the top. |
| 116 | +This switches LogMiner to `DICT_FROM_REDO_LOGS` + `DDL_DICT_TRACKING` |
| 117 | +so it can track schema changes inline. |
| 118 | + |
| 119 | +See `0-inputs/ddl-add-column.sql` for an example. |
| 120 | + |
| 121 | +### Long-Spanning Transactions |
| 122 | + |
| 123 | +For transactions that should span multiple archive logs, add `-- @MID_SWITCH` |
| 124 | +markers in the SQL where log switches should occur. The SQL should use |
| 125 | +`DBMS_SESSION.SLEEP()` at those points to allow time for the switch. |
| 126 | + |
| 127 | +See `0-inputs/long-spanning-txn.sql` for an example. |
| 128 | + |
| 129 | +## Comparison Details |
| 130 | + |
| 131 | +The comparison tool (`scripts/compare.py`) handles: |
| 132 | + |
| 133 | +- **Content-based matching**: pairs records by operation type, table, and column |
| 134 | + values rather than strict ordering (LogMiner orders by redo SCN, OLR by |
| 135 | + commit SCN) |
| 136 | +- **Type tolerance**: `"100"` matches `100`, float precision differences allowed |
| 137 | +- **Date/timestamp conversion**: Oracle format strings vs epoch seconds |
| 138 | +- **LOB merging**: Oracle splits LOB writes into INSERT(EMPTY_CLOB) + UPDATE; |
| 139 | + these are merged to match OLR's coalesced output |
| 140 | +- **Supplemental log columns**: OLR includes all columns via supplemental |
| 141 | + logging; extra columns beyond what LogMiner shows are allowed |
| 142 | + |
| 143 | +## CI Workflows |
| 144 | + |
| 145 | +### `generate-fixtures.yaml` |
| 146 | + |
| 147 | +Runs weekly (or manually via `workflow_dispatch`). Starts Oracle, generates all |
| 148 | +fixtures with LogMiner validation, uploads as artifact (90-day retention). |
| 149 | + |
| 150 | +### `run-tests.yaml` |
| 151 | + |
| 152 | +Runs on push/PR to master. Downloads the latest fixture artifact and runs |
| 153 | +`ctest` inside the `olr-dev` Docker image. **Fails hard** if no artifact exists — |
| 154 | +run `generate-fixtures` first. |
| 155 | + |
| 156 | +## Makefile Targets |
| 157 | + |
| 158 | +| Target | Description | |
| 159 | +|--------|-------------| |
| 160 | +| `build` | Build OLR Docker image with tests | |
| 161 | +| `up` | Start OLR dev container + Oracle container | |
| 162 | +| `down` | Stop all containers | |
| 163 | +| `test` | Run regression tests via `ctest` (inside Docker) | |
| 164 | +| `testdata` | Generate all fixtures (or one with `SCENARIO=name`) | |
| 165 | +| `clean` | Remove generated fixture data | |
| 166 | + |
| 167 | +## Environment Variables |
| 168 | + |
| 169 | +| Variable | Default | Description | |
| 170 | +|----------|---------|-------------| |
| 171 | +| `ORACLE_CONTAINER` | `oracle` | Docker container name for Oracle | |
| 172 | +| `ORACLE_PASSWORD` | `oracle` | SYS/SYSTEM password | |
| 173 | +| `DB_CONN` | `olr_test/olr_test@//localhost:1521/FREEPDB1` | Test user connect string | |
| 174 | +| `SCHEMA_OWNER` | `OLR_TEST` | Schema owner for LogMiner filter | |
| 175 | +| `PDB_NAME` | `FREEPDB1` | PDB name for schema generation | |
| 176 | + |
| 177 | +## Troubleshooting |
| 178 | + |
| 179 | +If fixture generation fails at comparison, the working directory is preserved: |
| 180 | + |
| 181 | +```bash |
| 182 | +# LogMiner parsed output |
| 183 | +cat tests/.work/basic-crud_XXXXXX/logminer.json |
| 184 | + |
| 185 | +# OLR raw output |
| 186 | +cat tests/.work/basic-crud_XXXXXX/olr_output.json |
| 187 | + |
| 188 | +# OLR log (includes redo parsing details) |
| 189 | +cat tests/.work/basic-crud_XXXXXX/olr_stdout.log |
| 190 | + |
| 191 | +# Generated OLR config |
| 192 | +cat tests/.work/basic-crud_XXXXXX/olr_config.json |
| 193 | +``` |
0 commit comments