Skip to content

Commit

Permalink
Addressed Code review suggestion for muti-db test cases
Browse files Browse the repository at this point in the history
Ignored file containing multi-db test from jdbc schedule.
Removed set config change for multi-db
Added basic test cases seperately to verify IO Triggers.

Task:BABEL-2170

Signed-off-by: Deepakshi Mittal <[email protected]>
  • Loading branch information
deepakshi-mittal committed Jan 2, 2024
1 parent 4d891ab commit f105495
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 70 deletions.
4 changes: 2 additions & 2 deletions test/JDBC/expected/BABEL-2170-vu-cleanup.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- clean all objects in first database
USE db1_BABEL2170;
USE babel_2170_db1;
GO

DROP TRIGGER IF EXISTS babel_2170_vu_employees_view_iot_insert;
Expand Down Expand Up @@ -35,5 +35,5 @@ GO
USE MASTER;
GO

DROP DATABASE IF EXISTS db1_BABEL2170;
DROP DATABASE IF EXISTS babel_2170_db1;
GO
5 changes: 2 additions & 3 deletions test/JDBC/expected/BABEL-2170-vu-prepare.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
-- We will create two databases db1_BABEL2170, db2_BABEL2170
CREATE DATABASE db1_BABEL2170;
CREATE DATABASE babel_2170_db1;
GO

USE db1_BABEL2170;
USE babel_2170_db1;
GO

CREATE TABLE babel_2170_vu_employees
Expand Down
61 changes: 22 additions & 39 deletions test/JDBC/expected/BABEL-2170-vu-verify.out
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
USE db1_BABEL2170;
USE babel_2170_db1;
GO

-- Instead of Insert Trigger on View
CREATE TRIGGER babel_2170_vu_employees_view_iot_insert ON babel_2170_vu_employees_view
INSTEAD OF INSERT
AS
BEGIN
SELECT 'Trigger db1_BABEL2170.dbo.babel_2170_vu_employees_view_iot_insert Invoked'
SELECT 'Trigger babel_2170_db1.dbo.babel_2170_vu_employees_view_iot_insert Invoked'
END
GO

INSERT INTO babel_2170_vu_employees_view VALUES(3, 'adam', '1st Street', '3000');
GO
~~START~~
varchar
Trigger db1_BABEL2170.dbo.babel_2170_vu_employees_view_iot_insert Invoked
Trigger babel_2170_db1.dbo.babel_2170_vu_employees_view_iot_insert Invoked
~~END~~

~~ROW COUNT: 1~~
Expand All @@ -41,15 +41,15 @@ CREATE TRIGGER babel_2170_vu_employees_view_iot_update ON babel_2170_vu_employee
INSTEAD OF UPDATE
AS
BEGIN
SELECT 'Trigger db1_BABEL2170.dbo.babel_2170_vu_employees_view_iot_update Invoked'
SELECT 'Trigger babel_2170_db1.dbo.babel_2170_vu_employees_view_iot_update Invoked'
END
GO

UPDATE babel_2170_vu_employees_view SET MonthSalary = MonthSalary +1 WHERE EmployeeID = 2;
GO
~~START~~
varchar
Trigger db1_BABEL2170.dbo.babel_2170_vu_employees_view_iot_update Invoked
Trigger babel_2170_db1.dbo.babel_2170_vu_employees_view_iot_update Invoked
~~END~~

~~ROW COUNT: 1~~
Expand All @@ -70,7 +70,7 @@ COMMIT TRANSACTION;
GO
~~START~~
varchar
Trigger db1_BABEL2170.dbo.babel_2170_vu_employees_view_iot_update Invoked
Trigger babel_2170_db1.dbo.babel_2170_vu_employees_view_iot_update Invoked
~~END~~

~~ROW COUNT: 2~~
Expand All @@ -90,7 +90,7 @@ CREATE TRIGGER babel_2170_vu_employees_view_iot_delete ON babel_2170_vu_employee
INSTEAD OF DELETE
AS
BEGIN
SELECT 'Trigger db1_BABEL2170.dbo.babel_2170_vu_employees_view_iot_delete Invoked'
SELECT 'Trigger babel_2170_db1.dbo.babel_2170_vu_employees_view_iot_delete Invoked'
END
GO

Expand All @@ -100,7 +100,7 @@ COMMIT TRANSACTION;
GO
~~START~~
varchar
Trigger db1_BABEL2170.dbo.babel_2170_vu_employees_view_iot_delete Invoked
Trigger babel_2170_db1.dbo.babel_2170_vu_employees_view_iot_delete Invoked
~~END~~

~~ROW COUNT: 2~~
Expand Down Expand Up @@ -174,7 +174,7 @@ CREATE TRIGGER babel_2170_vu_employees_view_iot_update ON babel_2170_vu_employee
INSTEAD OF INSERT
AS
BEGIN
SELECT 'Trigger db1_BABEL2170.dbo.babel_2170_vu_employees_view2_iot_update Invoked'
SELECT 'Trigger babel_2170_db1.dbo.babel_2170_vu_employees_view_iot_update Invoked'
END
GO
~~ERROR (Code: 33557097)~~
Expand All @@ -187,7 +187,7 @@ CREATE TRIGGER babel_2170_vu_employees_view_iot_update ON babel_2170_vu_employee
INSTEAD OF INSERT
AS
BEGIN
SELECT 'Trigger db1_BABEL2170.dbo.babel_2170_vu_employees__table_iot_update Invoked'
SELECT 'Trigger babel_2170_db1.dbo.babel_2170_vu_employees_view_iot_update Invoked'
END
GO
~~ERROR (Code: 33557097)~~
Expand All @@ -204,20 +204,20 @@ GO
CREATE TRIGGER [schema_2170].[babel_2170_vu_employees_view_iot_update] ON [schema_2170].[babel_2170_vu_employees_view]
INSTEAD OF UPDATE
AS
SELECT 'Trigger db1_BABEL2170.schema_2170.babel_2170_vu_employees_view_iot_update Invoked'
SELECT 'Trigger babel_2170_db1.schema_2170.babel_2170_vu_employees_view_iot_update Invoked'
GO

CREATE TRIGGER [babel_2170_vu_employees_view_iot_update] ON [babel_2170_vu_employees_view]
INSTEAD OF UPDATE
AS
SELECT 'Trigger db1_BABEL2170.dbo.babel_2170_vu_employees_view_iot_update Invoked'
SELECT 'Trigger babel_2170_db1.dbo.babel_2170_vu_employees_view_iot_update Invoked'
GO

UPDATE [schema_2170].[babel_2170_vu_employees_view] SET MonthSalary = MonthSalary +1 WHERE EmployeeID = 2;
GO
~~START~~
varchar
Trigger db1_BABEL2170.schema_2170.babel_2170_vu_employees_view_iot_update Invoked
Trigger babel_2170_db1.schema_2170.babel_2170_vu_employees_view_iot_update Invoked
~~END~~

~~ROW COUNT: 1~~
Expand All @@ -236,7 +236,7 @@ UPDATE [dbo].[babel_2170_vu_employees_view] SET MonthSalary = MonthSalary +1 WHE
GO
~~START~~
varchar
Trigger db1_BABEL2170.dbo.babel_2170_vu_employees_view_iot_update Invoked
Trigger babel_2170_db1.dbo.babel_2170_vu_employees_view_iot_update Invoked
~~END~~

~~ROW COUNT: 1~~
Expand All @@ -259,7 +259,7 @@ UPDATE [schema_2170].[babel_2170_vu_employees_view] SET MonthSalary = MonthSalar
GO
~~START~~
varchar
Trigger db1_BABEL2170.schema_2170.babel_2170_vu_employees_view_iot_update Invoked
Trigger babel_2170_db1.schema_2170.babel_2170_vu_employees_view_iot_update Invoked
~~END~~

~~ROW COUNT: 1~~
Expand Down Expand Up @@ -664,27 +664,10 @@ GO
DROP TABLE IF EXISTS babel_2170_vu_employees_t2;
GO

-- test multi-db mode
SELECT set_config('role', 'jdbc_user', false);
CREATE DATABASE babel_2170_db2;
GO
~~START~~
text
jdbc_user
~~END~~


SELECT set_config('babelfishpg_tsql.migration_mode', 'multi-db', false);
GO
~~START~~
text
multi-db
~~END~~


CREATE DATABASE db2_BABEL2170;
GO

USE db2_BABEL2170;
USE babel_2170_db2;
GO

CREATE TABLE babel_2170_vu_employees
Expand Down Expand Up @@ -718,22 +701,22 @@ CREATE TRIGGER babel_2170_vu_employees_view_iot_insert ON babel_2170_vu_employee
INSTEAD OF INSERT
AS
BEGIN
SELECT 'Trigger db2_BABEL2170.dbo.babel_2170_vu_employees_view_iot_insert Invoked'
SELECT 'Trigger babel_2170_db2.dbo.babel_2170_vu_employees_view_iot_insert Invoked'
END
GO

-- should fire IOT trigger of second db
INSERT INTO babel_2170_vu_employees_view VALUES(3, 'adam', '1st Street db2_BABEL2170', '3000');
INSERT INTO babel_2170_vu_employees_view VALUES(3, 'adam', '1st Street babel_2170_db2', '3000');
GO
~~START~~
varchar
Trigger db2_BABEL2170.dbo.babel_2170_vu_employees_view_iot_insert Invoked
Trigger babel_2170_db2.dbo.babel_2170_vu_employees_view_iot_insert Invoked
~~END~~

~~ROW COUNT: 1~~


SELECT EmployeeID, EmployeeName, EmployeeAddress, MonthSalary FROM babel_2170_vu_employees_view ORDER BY EmployeeID;
SELECT EmployeeID, EmployeeName, EmployeeAddress, MonthSalary FROM babel_2170_vu_employees_view ORDER BY EmployeeID;
GO
~~START~~
int#!#varchar#!#varchar#!#numeric
Expand All @@ -755,5 +738,5 @@ GO
USE MASTER;
GO

DROP DATABASE IF EXISTS db2_BABEL2170;
DROP DATABASE IF EXISTS babel_2170_db2;
GO
126 changes: 126 additions & 0 deletions test/JDBC/expected/BABEL-2170.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
CREATE TABLE babel_2170_employees
(
EmployeeID int NOT NULL,
EmployeeName VARCHAR(50),
EmployeeAddress VARCHAR(50),
MonthSalary NUMERIC(10, 2)
)
GO

INSERT INTO babel_2170_employees VALUES(1, 'ash', '1st Street', '1000');
INSERT INTO babel_2170_employees VALUES(2, 'bob', '1st Street', '2000');
GO
~~ROW COUNT: 1~~

~~ROW COUNT: 1~~


CREATE VIEW babel_2170_employees_view AS
SELECT EmployeeID,
EmployeeName,
EmployeeAddress,
MonthSalary
FROM babel_2170_employees;
GO

-- Instead of Insert Trigger on View
CREATE TRIGGER babel_2170_employees_view_iot_insert ON babel_2170_employees_view
INSTEAD OF INSERT
AS
BEGIN
SELECT 'Trigger babel_2170_employees_view_iot_insert Invoked'
END
GO

INSERT INTO babel_2170_employees_view VALUES(3, 'john', '1st Street', '3000');
GO
~~START~~
varchar
Trigger babel_2170_employees_view_iot_insert Invoked
~~END~~

~~ROW COUNT: 1~~


SELECT EmployeeID, EmployeeName, EmployeeAddress, MonthSalary FROM babel_2170_employees_view ORDER BY EmployeeID;
GO
~~START~~
int#!#varchar#!#varchar#!#numeric
1#!#ash#!#1st Street#!#1000.00
2#!#bob#!#1st Street#!#2000.00
~~END~~


-- Instead of Update Trigger on View
CREATE TRIGGER babel_2170_employees_view_iot_update ON babel_2170_employees_view
INSTEAD OF UPDATE
AS
BEGIN
SELECT 'Trigger babel_2170_employees_view_iot_update Invoked'
END
GO

UPDATE babel_2170_employees_view SET MonthSalary = MonthSalary +1 WHERE EmployeeID = 2;
GO
~~START~~
varchar
Trigger babel_2170_employees_view_iot_update Invoked
~~END~~

~~ROW COUNT: 1~~


SELECT EmployeeID, EmployeeName, EmployeeAddress, MonthSalary FROM babel_2170_employees_view ORDER BY EmployeeID;
GO
~~START~~
int#!#varchar#!#varchar#!#numeric
1#!#ash#!#1st Street#!#1000.00
2#!#bob#!#1st Street#!#2000.00
~~END~~



-- Instead of Delete Trigger on View
CREATE TRIGGER babel_2170_employees_view_iot_delete ON babel_2170_employees_view
INSTEAD OF DELETE
AS
BEGIN
SELECT 'Trigger babel_2170_employees_view_iot_delete Invoked'
END
GO

BEGIN TRANSACTION
DELETE FROM babel_2170_employees_view WHERE EmployeeID IN (1, 2);
COMMIT TRANSACTION;
GO
~~START~~
varchar
Trigger babel_2170_employees_view_iot_delete Invoked
~~END~~

~~ROW COUNT: 2~~


SELECT EmployeeID, EmployeeName, EmployeeAddress, MonthSalary FROM babel_2170_employees_view ORDER BY EmployeeID;
GO
~~START~~
int#!#varchar#!#varchar#!#numeric
1#!#ash#!#1st Street#!#1000.00
2#!#bob#!#1st Street#!#2000.00
~~END~~


DROP TRIGGER IF EXISTS babel_2170_employees_view_iot_insert;
GO

DROP TRIGGER IF EXISTS babel_2170_employees_view_iot_update;
GO

DROP TRIGGER IF EXISTS babel_2170_employees_view_iot_delete;
GO

DROP VIEW IF EXISTS babel_2170_employees_view;
GO

DROP TABLE IF EXISTS babel_2170_employees;
GO
4 changes: 2 additions & 2 deletions test/JDBC/input/triggers/BABEL-2170-vu-cleanup.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- clean all objects in first database
USE db1_BABEL2170;
USE babel_2170_db1;
GO

DROP TRIGGER IF EXISTS babel_2170_vu_employees_view_iot_insert;
Expand Down Expand Up @@ -35,5 +35,5 @@ GO
USE MASTER;
GO

DROP DATABASE IF EXISTS db1_BABEL2170;
DROP DATABASE IF EXISTS babel_2170_db1;
GO
5 changes: 2 additions & 3 deletions test/JDBC/input/triggers/BABEL-2170-vu-prepare.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
-- We will create two databases db1_BABEL2170, db2_BABEL2170
CREATE DATABASE db1_BABEL2170;
CREATE DATABASE babel_2170_db1;
GO

USE db1_BABEL2170;
USE babel_2170_db1;
GO

CREATE TABLE babel_2170_vu_employees
Expand Down
Loading

0 comments on commit f105495

Please sign in to comment.