Giter Club home page Giter Club logo

ingesting-sqlserver-to-s3's Introduction

Airflow integration testing

Background

This code is for tutorial purposes of the Agile Actors Data Chapter. It continues in a more advanced manner from Basic integration Testing in the spirirt of Testing in Airflow Part 2 โ€” Integration Tests and End-To-End Pipeline Tests

In summary the project sets up an SQL Server with "transactions". Airflow scans the table and when it finds new transactions, it ingests the transactions in S3Ninja emulating S3 store. Then it marks in another table that the task has been accomplished.

Integration testing

Tested with python 3.11.3.

First install dependencies

pip install -r requirements-dev.txt

and then build "good" image.

docker compose build

Now testing is as easy as executing

 rm -rf logs s3data s3logs
 pytest -vvv -s --log-cli-level=DEBUG tests/integration/test_automatically_sample_dag.py

The integration tests (not complete) create the bucket in docker-compose.yaml, the test database, user, schema and table also in docker-compose.yaml. Then it runs tha dag.

Manual testing

Here we run manually the steps leading to the integration tests. For maintaining state uncomment the sections in docker compose for volumes, not recommended. Please comment them again before running the integration tests.

Start the deployment by running

rm -rf logs s3data s3logs
docker compose up

Now you need to what is in docker-compose.yaml.

Create bucket

Connect to S3Ninja and create a bucket named mybucket. This is the name that appears in airflow variable.

Create users and tables.

Connect with DBeaver to the SQL Server with credentials

user = 'sa'
password = 'newcross_123'
host = '127.0.0.1'
port = 1433
database = 'master'

Now for cleaning everything up (if you need it), just run teardown_database.sql

To create the database used in the deployment execute

IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = N'ncintegration')
    BEGIN
        CREATE DATABASE ncintegration;
    END

and to create the rest, just run setup_database.sql

You can optionally for your tests add

delete from ncproject.fintransacts;
insert into  ncproject.fintransacts values (1, convert(DATETIME, '1968-10-23 12:45:37', 20), 'buy 1');
insert into  ncproject.fintransacts values (2, convert(DATETIME, '1968-10-24 12:45:37', 20), 'buy 2');
insert into  ncproject.fintransacts values (3, convert(DATETIME, '1968-10-25 12:45:37', 20), 'buy 3');
insert into  ncproject.fintransacts values (4, convert(DATETIME, '1968-10-26 12:45:37', 20), 'buy 4');
insert into  ncproject.fintransacts values (5, convert(DATETIME, '1968-10-27 12:45:37', 20), 'buy 5');

Run the dag

Visit the airflow server and activate your dag. Extra info in official Airflow Documentation. Airflow Apache Project.

Have fun!

ingesting-sqlserver-to-s3's People

Contributors

fithisux avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.