Server IP : 127.0.0.2 / Your IP : 18.116.14.133 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/lib/python2.7/dist-packages/psycopg2/tests/ |
Upload File : |
""" Python DB API 2.0 driver Two Phase Commit compliance test suite. """ import unittest class TwoPhaseCommitTests(unittest.TestCase): driver = None def connect(self): """Make a database connection.""" raise NotImplementedError _last_id = 0 _global_id_prefix = "dbapi20_tpc:" def make_xid(self, con): id = TwoPhaseCommitTests._last_id TwoPhaseCommitTests._last_id += 1 return con.xid(42, "%s%d" % (self._global_id_prefix, id), "qualifier") def test_xid(self): con = self.connect() try: xid = con.xid(42, "global", "bqual") except self.driver.NotSupportedError: self.fail("Driver does not support transaction IDs.") self.assertEquals(xid[0], 42) self.assertEquals(xid[1], "global") self.assertEquals(xid[2], "bqual") # Try some extremes for the transaction ID: xid = con.xid(0, "", "") self.assertEquals(tuple(xid), (0, "", "")) xid = con.xid(0x7fffffff, "a" * 64, "b" * 64) self.assertEquals(tuple(xid), (0x7fffffff, "a" * 64, "b" * 64)) def test_tpc_begin(self): con = self.connect() try: xid = self.make_xid(con) try: con.tpc_begin(xid) except self.driver.NotSupportedError: self.fail("Driver does not support tpc_begin()") finally: con.close() def test_tpc_commit_without_prepare(self): con = self.connect() try: xid = self.make_xid(con) con.tpc_begin(xid) cursor = con.cursor() cursor.execute("SELECT 1") con.tpc_commit() finally: con.close() def test_tpc_rollback_without_prepare(self): con = self.connect() try: xid = self.make_xid(con) con.tpc_begin(xid) cursor = con.cursor() cursor.execute("SELECT 1") con.tpc_rollback() finally: con.close() def test_tpc_commit_with_prepare(self): con = self.connect() try: xid = self.make_xid(con) con.tpc_begin(xid) cursor = con.cursor() cursor.execute("SELECT 1") con.tpc_prepare() con.tpc_commit() finally: con.close() def test_tpc_rollback_with_prepare(self): con = self.connect() try: xid = self.make_xid(con) con.tpc_begin(xid) cursor = con.cursor() cursor.execute("SELECT 1") con.tpc_prepare() con.tpc_rollback() finally: con.close() def test_tpc_begin_in_transaction_fails(self): con = self.connect() try: xid = self.make_xid(con) cursor = con.cursor() cursor.execute("SELECT 1") self.assertRaises(self.driver.ProgrammingError, con.tpc_begin, xid) finally: con.close() def test_tpc_begin_in_tpc_transaction_fails(self): con = self.connect() try: xid = self.make_xid(con) cursor = con.cursor() cursor.execute("SELECT 1") self.assertRaises(self.driver.ProgrammingError, con.tpc_begin, xid) finally: con.close() def test_commit_in_tpc_fails(self): # calling commit() within a TPC transaction fails with # ProgrammingError. con = self.connect() try: xid = self.make_xid(con) con.tpc_begin(xid) self.assertRaises(self.driver.ProgrammingError, con.commit) finally: con.close() def test_rollback_in_tpc_fails(self): # calling rollback() within a TPC transaction fails with # ProgrammingError. con = self.connect() try: xid = self.make_xid(con) con.tpc_begin(xid) self.assertRaises(self.driver.ProgrammingError, con.rollback) finally: con.close()