2121import copy
2222import glob
2323import itertools
24- import json
2524import logging
2625import os
2726import random
3938
4039import mock
4140import requests
42- from testcontainers .core .container import DockerContainer
4341
4442from apache_beam .coders import Coder
4543from apache_beam .coders .coder_impl import CoderImpl
46- from apache_beam .yaml .test_utils .datadog_test_utils import temp_fake_datadog_server
4744
4845
4946class BigEndianIntegerCoderImpl (CoderImpl ):
@@ -399,11 +396,10 @@ def temp_debezium_postgres_database():
399396 """Provides a temporary PostgreSQL database configured for Debezium CDC."""
400397
401398 container = (
402- DockerContainer ('quay.io/debezium/example-postgres:latest' )
403- .with_env ('POSTGRES_USER' , 'debezium' )
404- .with_env ('POSTGRES_PASSWORD' , 'dbz' )
405- .with_env ('POSTGRES_DB' , 'inventory' )
406- .with_exposed_ports (5432 ))
399+ DockerContainer ('quay.io/debezium/example-postgres:latest' ).with_env (
400+ 'POSTGRES_USER' ,
401+ 'debezium' ).with_env ('POSTGRES_PASSWORD' , 'dbz' ).with_env (
402+ 'POSTGRES_DB' , 'inventory' ).with_exposed_ports (5432 ))
407403
408404 try :
409405 container .start ()
@@ -416,29 +412,30 @@ def temp_debezium_postgres_database():
416412 for _ in range (30 ):
417413 try :
418414 connection = psycopg2 .connect (
419- host = host ,
420- port = port ,
421- user = 'debezium' ,
422- password = 'dbz' ,
423- dbname = 'inventory' )
415+ host = host ,
416+ port = port ,
417+ user = 'debezium' ,
418+ password = 'dbz' ,
419+ dbname = 'inventory' )
424420 break
425421 except psycopg2 .OperationalError :
426422 time .sleep (1 )
427423
428424 if connection is None :
429- raise RuntimeError ('Debezium PostgreSQL container failed to become ready.' )
425+ raise RuntimeError (
426+ 'Debezium PostgreSQL container failed to become ready.' )
430427
431428 try :
432429 with connection .cursor () as cursor :
433430 cursor .execute (
434- """
431+ """
435432 CREATE TABLE IF NOT EXISTS customers (
436433 id INTEGER PRIMARY KEY,
437434 name VARCHAR(255)
438435 )
439436 """ )
440437 cursor .execute (
441- """
438+ """
442439 INSERT INTO customers (id, name)
443440 VALUES
444441 (1, 'Alice'),
@@ -450,12 +447,12 @@ def temp_debezium_postgres_database():
450447 connection .close ()
451448
452449 yield {
453- 'HOST' : host ,
454- 'PORT' : port ,
455- 'USERNAME' : 'debezium' ,
456- 'PASSWORD' : 'dbz' ,
457- 'DATABASE' : 'inventory' ,
458- 'TABLE' : 'public.customers' ,
450+ 'HOST' : host ,
451+ 'PORT' : port ,
452+ 'USERNAME' : 'debezium' ,
453+ 'PASSWORD' : 'dbz' ,
454+ 'DATABASE' : 'inventory' ,
455+ 'TABLE' : 'public.customers' ,
459456 }
460457
461458 finally :
0 commit comments