|
51 | 51 | # Default user password |
52 | 52 | FBTEST_PASSWORD = 'masterkey' |
53 | 53 |
|
| 54 | +cfg = driver_config.register_server('FBTEST_HOST') |
| 55 | +cfg.host.value = FBTEST_HOST |
| 56 | +cfg.user.value = FBTEST_USER |
| 57 | +cfg.password.value = FBTEST_PASSWORD |
| 58 | + |
54 | 59 | trace = False |
55 | 60 |
|
56 | 61 | if not sys.warnoptions: |
@@ -653,29 +658,46 @@ def setUp(self): |
653 | 658 | super().setUp() |
654 | 659 | self.dbfile = os.path.join(self.dbpath, self.FBTEST_DB) |
655 | 660 | self.db1 = os.path.join(self.dbpath, 'fbtest-1.fdb') |
656 | | - self.db2 = os.path.join(self.dbpath, 'fbtest-2.fdb') |
657 | | - self.con1 = create_database(self.db1, user=FBTEST_USER, password=FBTEST_PASSWORD, overwrite=True) |
| 661 | + cfg = driver_config.register_database('dts-1') |
| 662 | + cfg.server.value = 'FBTEST_HOST' |
| 663 | + cfg.database.value = self.db1 |
| 664 | + cfg.no_linger.value = True |
| 665 | + self.con1 = create_database('dts-1', user=FBTEST_USER, password=FBTEST_PASSWORD, overwrite=True) |
658 | 666 | self.con1._logging_id_ = self.__class__.__name__ |
659 | 667 | self.con1.execute_immediate("recreate table T (PK integer, C1 integer)") |
660 | 668 | self.con1.commit() |
661 | | - self.con2 = create_database(self.db2, user=FBTEST_USER, password=FBTEST_PASSWORD, overwrite=True) |
| 669 | + |
| 670 | + self.db2 = os.path.join(self.dbpath, 'fbtest-2.fdb') |
| 671 | + cfg = driver_config.register_database('dts-2') |
| 672 | + cfg.server.value = 'FBTEST_HOST' |
| 673 | + cfg.database.value = self.db2 |
| 674 | + cfg.no_linger.value = True |
| 675 | + self.con2 = create_database('dts-2', user=FBTEST_USER, password=FBTEST_PASSWORD, overwrite=True) |
662 | 676 | self.con2._logging_id_ = self.__class__.__name__ |
663 | 677 | self.con2.execute_immediate("recreate table T (PK integer, C1 integer)") |
664 | 678 | self.con2.commit() |
665 | 679 | def tearDown(self): |
666 | 680 | #if self.con1 and self.con1.group: |
667 | 681 | ## We can't drop database via connection in group |
668 | 682 | #self.con1.group.disband() |
669 | | - if not self.con1: |
670 | | - self.con1 = connect(host=FBTEST_HOST, database=self.db1, |
671 | | - user=FBTEST_USER, password=FBTEST_PASSWORD, no_linger=True) |
672 | | - self.con1.drop_database() |
673 | | - self.con1.close() |
674 | | - if not self.con2: |
675 | | - self.con2 = connect(host=FBTEST_HOST, database=self.db2, |
676 | | - user=FBTEST_USER, password=FBTEST_PASSWORD, no_linger=True) |
677 | | - self.con2.drop_database() |
678 | | - self.con2.close() |
| 683 | + if self.con1 is not None: |
| 684 | + self.con1.close() |
| 685 | + if self.con2 is not None: |
| 686 | + self.con2.close() |
| 687 | + # |
| 688 | + with connect_server('FBTEST_HOST') as srv: |
| 689 | + srv.database.shutdown(database=self.db1, mode=ShutdownMode.FULL, |
| 690 | + method=ShutdownMethod.FORCED, timeout=0) |
| 691 | + srv.database.bring_online(database=self.db1) |
| 692 | + with connect('dts-1') as con: |
| 693 | + con.drop_database() |
| 694 | + # |
| 695 | + with connect_server('FBTEST_HOST') as srv: |
| 696 | + srv.database.shutdown(database=self.db2, mode=ShutdownMode.FULL, |
| 697 | + method=ShutdownMethod.FORCED, timeout=0) |
| 698 | + srv.database.bring_online(database=self.db2) |
| 699 | + with connect('dts-2') as con: |
| 700 | + con.drop_database() |
679 | 701 | def test_context_manager(self): |
680 | 702 | with DistributedTransactionManager((self.con1, self.con2)) as dt: |
681 | 703 | q = 'select * from T order by pk' |
@@ -785,62 +807,54 @@ def test_simple_dt(self): |
785 | 807 | def test_limbo_transactions(self): |
786 | 808 | self.skipTest('Not implemented yet') |
787 | 809 | #return |
788 | | - with connect_server(host=FBTEST_HOST, user=FBTEST_USER, password=FBTEST_PASSWORD) as svc: |
789 | | - dt = DistributedTransactionManager((self.con1, self.con2)) |
790 | | - ids1 = svc.get_limbo_transaction_ids(database=self.db1) |
791 | | - self.assertEqual(ids1, []) |
792 | | - ids2 = svc.get_limbo_transaction_ids(database=self.db2) |
793 | | - self.assertEqual(ids2, []) |
794 | | - dt.execute_immediate('insert into t (pk) values (3)') |
795 | | - dt.prepare() |
796 | | - # Force out both connections |
797 | | - dt._tra.release() |
798 | | - dt._tra = None |
799 | | - dt.close() |
800 | | - self.con1.close() |
801 | | - self.con1 = None |
802 | | - self.con2.close() |
803 | | - self.con2 = None |
804 | | - # |
805 | | - ids1 = svc.get_limbo_transaction_ids(database=self.db1) |
806 | | - id1 = ids1[0] |
807 | | - ids2 = svc.get_limbo_transaction_ids(database=self.db2) |
808 | | - id2 = ids2[0] |
809 | | - # Data chould be blocked by limbo transaction |
810 | | - if not self.con1: |
811 | | - self.con1 = connect(host=FBTEST_HOST, database=self.db1, user=FBTEST_USER, |
812 | | - password=FBTEST_PASSWORD, no_linger=True) |
813 | | - self.con1._logging_id_ = self.__class__.__name__ |
814 | | - if not self.con2: |
815 | | - self.con2 = connect(host=FBTEST_HOST, database=self.db2, user=FBTEST_USER, |
816 | | - password=FBTEST_PASSWORD, no_linger=True) |
817 | | - self.con2._logging_id_ = self.__class__.__name__ |
818 | | - c1 = self.con1.cursor() |
819 | | - c1.execute('select * from t') |
820 | | - with self.assertRaises(DatabaseError) as cm: |
821 | | - row = c1.fetchall() |
822 | | - self.assertTupleEqual(cm.exception.args, |
823 | | - ('Cursor.fetchone:\n- SQLCODE: -911\n- record from transaction %i is stuck in limbo' % id1, -911, 335544459)) |
824 | | - c2 = self.con2.cursor() |
825 | | - c2.execute('select * from t') |
826 | | - with self.assertRaises(DatabaseError) as cm: |
827 | | - row = c2.fetchall() |
828 | | - self.assertTupleEqual(cm.exception.args, |
829 | | - ('Cursor.fetchone:\n- SQLCODE: -911\n- record from transaction %i is stuck in limbo' % id2, -911, 335544459)) |
830 | | - # resolve via service |
831 | | - svc = connect_server(host=FBTEST_HOST, password=FBTEST_PASSWORD) |
832 | | - svc.commit_limbo_transaction(database=self.db1, transaction_id=id1) |
833 | | - svc.rollback_limbo_transaction(database=self.db2, transaction_id=id2) |
834 | | - |
835 | | - # check the resolution |
836 | | - c1 = self.con1.cursor() |
837 | | - c1.execute('select * from t') |
838 | | - row = c1.fetchall() |
839 | | - self.assertListEqual(row, [(3, None)]) |
840 | | - c2 = self.con2.cursor() |
841 | | - c2.execute('select * from t') |
842 | | - row = c2.fetchall() |
843 | | - self.assertListEqual(row, []) |
| 810 | + #with connect_server('FBTEST_HOST') as svc: |
| 811 | + #dt = DistributedTransactionManager([self.con1, self.con2]) |
| 812 | + #ids1 = svc.database.get_limbo_transaction_ids(database=self.db1) |
| 813 | + #self.assertEqual(ids1, []) |
| 814 | + #ids2 = svc.database.get_limbo_transaction_ids(database=self.db2) |
| 815 | + #self.assertEqual(ids2, []) |
| 816 | + #dt.execute_immediate('insert into t (pk) values (3)') |
| 817 | + #dt.prepare() |
| 818 | + ## Force out both connections |
| 819 | + #dt._tra.release() |
| 820 | + #dt._tra = None |
| 821 | + #dt.close() |
| 822 | + #self.con1.close() |
| 823 | + #self.con2.close() |
| 824 | + ## |
| 825 | + #self.con1 = connect('dts-1') |
| 826 | + #self.con2 = connect('dts-2') |
| 827 | + #ids1 = svc.database.get_limbo_transaction_ids(database=self.db1) |
| 828 | + #id1 = ids1[0] |
| 829 | + #ids2 = svc.database.get_limbo_transaction_ids(database=self.db2) |
| 830 | + #id2 = ids2[0] |
| 831 | + ## Data should be blocked by limbo transaction |
| 832 | + #c1 = self.con1.cursor() |
| 833 | + #c1.execute('select * from t') |
| 834 | + #with self.assertRaises(DatabaseError) as cm: |
| 835 | + #row = c1.fetchall() |
| 836 | + #self.assertTupleEqual(cm.exception.args, |
| 837 | + #('Cursor.fetchone:\n- SQLCODE: -911\n- record from transaction %i is stuck in limbo' % id1, -911, 335544459)) |
| 838 | + #c2 = self.con2.cursor() |
| 839 | + #c2.execute('select * from t') |
| 840 | + #with self.assertRaises(DatabaseError) as cm: |
| 841 | + #row = c2.fetchall() |
| 842 | + #self.assertTupleEqual(cm.exception.args, |
| 843 | + #('Cursor.fetchone:\n- SQLCODE: -911\n- record from transaction %i is stuck in limbo' % id2, -911, 335544459)) |
| 844 | + ## resolve via service |
| 845 | + #svc = connect_server(host=FBTEST_HOST, password=FBTEST_PASSWORD) |
| 846 | + #svc.database.commit_limbo_transaction(database=self.db1, transaction_id=id1) |
| 847 | + #svc.database.rollback_limbo_transaction(database=self.db2, transaction_id=id2) |
| 848 | + |
| 849 | + ## check the resolution |
| 850 | + #c1 = self.con1.cursor() |
| 851 | + #c1.execute('select * from t') |
| 852 | + #row = c1.fetchall() |
| 853 | + #self.assertListEqual(row, [(3, None)]) |
| 854 | + #c2 = self.con2.cursor() |
| 855 | + #c2.execute('select * from t') |
| 856 | + #row = c2.fetchall() |
| 857 | + #self.assertListEqual(row, []) |
844 | 858 |
|
845 | 859 | class TestCursor(DriverTestBase): |
846 | 860 | def setUp(self): |
@@ -1614,8 +1628,8 @@ def fetchline(line): |
1614 | 1628 | self.assertGreater(len(output), 0) |
1615 | 1629 | self.assertEqual(output, log) |
1616 | 1630 | def test_04_get_limbo_transaction_ids(self): |
1617 | | - self.skipTest('Not implemented yet') |
1618 | | - ids = self.svc.get_limbo_transaction_ids(database='employee') |
| 1631 | + #self.skipTest('Not implemented yet') |
| 1632 | + ids = self.svc.database.get_limbo_transaction_ids(database='employee') |
1619 | 1633 | self.assertIsInstance(ids, type(list())) |
1620 | 1634 | def test_05_trace(self): |
1621 | 1635 | #self.skipTest('Not implemented yet') |
|
0 commit comments