~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Martin
  • Date: 2010-05-03 20:57:39 UTC
  • mto: This revision was merged to the branch mainline in revision 5204.
  • Revision ID: gzlist@googlemail.com-20100503205739-n326zdvevv0rmruh
Retain original stack and error message when translating to ValueError in bencode

Show diffs side-by-side

added added

removed removed

Lines of Context:
767
767
class TestLockedBranch(tests.TestCaseWithMemoryTransport):
768
768
 
769
769
    def get_lock_tokens(self, branch):
770
 
        branch_token = branch.lock_write().branch_token
771
 
        repo_token = branch.repository.lock_write().repository_token
 
770
        branch_token = branch.lock_write()
 
771
        repo_token = branch.repository.lock_write()
772
772
        branch.repository.unlock()
773
773
        return branch_token, repo_token
774
774
 
1073
1073
            response)
1074
1074
 
1075
1075
 
1076
 
class TestSmartServerBranchRequestSetParent(TestLockedBranch):
 
1076
class TestSmartServerBranchRequestSetParent(tests.TestCaseWithMemoryTransport):
1077
1077
 
1078
1078
    def test_set_parent_none(self):
1079
1079
        branch = self.make_branch('base', format="1.9")
1082
1082
        branch.unlock()
1083
1083
        request = smart_branch.SmartServerBranchRequestSetParentLocation(
1084
1084
            self.get_transport())
1085
 
        branch_token, repo_token = self.get_lock_tokens(branch)
 
1085
        branch_token = branch.lock_write()
 
1086
        repo_token = branch.repository.lock_write()
1086
1087
        try:
1087
1088
            response = request.execute('base', branch_token, repo_token, '')
1088
1089
        finally:
 
1090
            branch.repository.unlock()
1089
1091
            branch.unlock()
1090
1092
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
1091
1093
        self.assertEqual(None, branch.get_parent())
1094
1096
        branch = self.make_branch('base', format="1.9")
1095
1097
        request = smart_branch.SmartServerBranchRequestSetParentLocation(
1096
1098
            self.get_transport())
1097
 
        branch_token, repo_token = self.get_lock_tokens(branch)
 
1099
        branch_token = branch.lock_write()
 
1100
        repo_token = branch.repository.lock_write()
1098
1101
        try:
1099
1102
            response = request.execute('base', branch_token, repo_token,
1100
1103
            'http://bar/')
1101
1104
        finally:
 
1105
            branch.repository.unlock()
1102
1106
            branch.unlock()
1103
1107
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
1104
1108
        self.assertEqual('http://bar/', branch.get_parent())
1133
1137
            response)
1134
1138
 
1135
1139
 
1136
 
class TestSmartServerBranchRequestLockWrite(TestLockedBranch):
 
1140
class TestSmartServerBranchRequestLockWrite(tests.TestCaseWithMemoryTransport):
1137
1141
 
1138
1142
    def setUp(self):
1139
1143
        tests.TestCaseWithMemoryTransport.setUp(self)
1161
1165
        backing = self.get_transport()
1162
1166
        request = smart_branch.SmartServerBranchRequestLockWrite(backing)
1163
1167
        branch = self.make_branch('.')
1164
 
        branch_token = branch.lock_write().branch_token
 
1168
        branch_token = branch.lock_write()
1165
1169
        branch.leave_lock_in_place()
1166
1170
        branch.unlock()
1167
1171
        response = request.execute('')
1176
1180
        backing = self.get_transport()
1177
1181
        request = smart_branch.SmartServerBranchRequestLockWrite(backing)
1178
1182
        branch = self.make_branch('.', format='knit')
1179
 
        branch_token, repo_token = self.get_lock_tokens(branch)
 
1183
        branch_token = branch.lock_write()
 
1184
        repo_token = branch.repository.lock_write()
 
1185
        branch.repository.unlock()
1180
1186
        branch.leave_lock_in_place()
1181
1187
        branch.repository.leave_lock_in_place()
1182
1188
        branch.unlock()
1197
1203
        backing = self.get_transport()
1198
1204
        request = smart_branch.SmartServerBranchRequestLockWrite(backing)
1199
1205
        branch = self.make_branch('.', format='knit')
1200
 
        branch_token, repo_token = self.get_lock_tokens(branch)
 
1206
        branch_token = branch.lock_write()
 
1207
        repo_token = branch.repository.lock_write()
 
1208
        branch.repository.unlock()
1201
1209
        branch.leave_lock_in_place()
1202
1210
        branch.repository.leave_lock_in_place()
1203
1211
        branch.unlock()
1218
1226
        request = smart_branch.SmartServerBranchRequestLockWrite(backing)
1219
1227
        branch = self.make_branch('.', format='knit')
1220
1228
        repo = branch.repository
1221
 
        repo_token = repo.lock_write().repository_token
 
1229
        repo_token = repo.lock_write()
1222
1230
        repo.leave_lock_in_place()
1223
1231
        repo.unlock()
1224
1232
        response = request.execute('')
1241
1249
        self.assertEqual('LockFailed', error_name)
1242
1250
 
1243
1251
 
1244
 
class TestSmartServerBranchRequestUnlock(TestLockedBranch):
 
1252
class TestSmartServerBranchRequestUnlock(tests.TestCaseWithMemoryTransport):
1245
1253
 
1246
1254
    def setUp(self):
1247
1255
        tests.TestCaseWithMemoryTransport.setUp(self)
1251
1259
        request = smart_branch.SmartServerBranchRequestUnlock(backing)
1252
1260
        branch = self.make_branch('.', format='knit')
1253
1261
        # Lock the branch
1254
 
        branch_token, repo_token = self.get_lock_tokens(branch)
 
1262
        branch_token = branch.lock_write()
 
1263
        repo_token = branch.repository.lock_write()
 
1264
        branch.repository.unlock()
1255
1265
        # Unlock the branch (and repo) object, leaving the physical locks
1256
1266
        # in place.
1257
1267
        branch.leave_lock_in_place()
1281
1291
        request = smart_branch.SmartServerBranchRequestUnlock(backing)
1282
1292
        branch = self.make_branch('.', format='knit')
1283
1293
        # Lock the repository.
1284
 
        repo_token = branch.repository.lock_write().repository_token
 
1294
        repo_token = branch.repository.lock_write()
1285
1295
        branch.repository.leave_lock_in_place()
1286
1296
        branch.repository.unlock()
1287
1297
        # Issue branch lock_write request on the unlocked branch (with locked
1288
1298
        # repo).
1289
 
        response = request.execute('', 'branch token', repo_token)
 
1299
        response = request.execute(
 
1300
            '', 'branch token', repo_token)
1290
1301
        self.assertEqual(
1291
1302
            smart_req.SmartServerResponse(('TokenMismatch',)), response)
1292
1303
        # Cleanup
1599
1610
        backing = self.get_transport()
1600
1611
        request = smart_repo.SmartServerRepositoryLockWrite(backing)
1601
1612
        repository = self.make_repository('.', format='knit')
1602
 
        repo_token = repository.lock_write().repository_token
 
1613
        repo_token = repository.lock_write()
1603
1614
        repository.leave_lock_in_place()
1604
1615
        repository.unlock()
1605
1616
        response = request.execute('')
1647
1658
        request = smart_repo.SmartServerRepositoryInsertStreamLocked(
1648
1659
            backing)
1649
1660
        repository = self.make_repository('.', format='knit')
1650
 
        lock_token = repository.lock_write().repository_token
 
1661
        lock_token = repository.lock_write()
1651
1662
        response = request.execute('', '', lock_token)
1652
1663
        self.assertEqual(None, response)
1653
1664
        response = request.do_chunk(self.make_empty_byte_stream(repository))
1661
1672
        request = smart_repo.SmartServerRepositoryInsertStreamLocked(
1662
1673
            backing)
1663
1674
        repository = self.make_repository('.', format='knit')
1664
 
        lock_token = repository.lock_write().repository_token
 
1675
        lock_token = repository.lock_write()
1665
1676
        self.assertRaises(
1666
1677
            errors.TokenMismatch, request.execute, '', '', 'wrong-token')
1667
1678
        repository.unlock()
1676
1687
        backing = self.get_transport()
1677
1688
        request = smart_repo.SmartServerRepositoryUnlock(backing)
1678
1689
        repository = self.make_repository('.', format='knit')
1679
 
        token = repository.lock_write().repository_token
 
1690
        token = repository.lock_write()
1680
1691
        repository.leave_lock_in_place()
1681
1692
        repository.unlock()
1682
1693
        response = request.execute('', token)