~ubuntu-branches/ubuntu/trusty/swift/trusty-updates

« back to all changes in this revision

Viewing changes to test/unit/obj/test_replicator.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Soren Hansen, Chuck Short
  • Date: 2012-09-07 19:02:36 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20120907190236-fqrmbzm7v6zivs8d
Tags: 1.7.0-0ubuntu1
[ Soren Hansen ]
* Update debian/watch to account for symbolically named tarballs and
  use newer URL.
* Run unit tests at build time.
* Fix Launchpad URLs in debian/watch.

[ Chuck Short ]
* New upstream release
* debian/control: Add pubthon-moc as a build dep
* debian/rules: Dont fail if testsuite fails.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from contextlib import contextmanager
28
28
from eventlet.green import subprocess
29
29
from eventlet import Timeout, tpool
30
 
from test.unit import FakeLogger
 
30
from test.unit import FakeLogger, mock
31
31
from swift.common import utils
32
32
from swift.common.utils import hash_path, mkdirs, normalize_timestamp
33
33
from swift.common import ring
209
209
        self.assertEquals(hashed, 1)
210
210
        self.assert_('a83' in hashes)
211
211
 
 
212
    def test_get_hashes_unmodified(self):
 
213
        df = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o', FakeLogger())
 
214
        mkdirs(df.datadir)
 
215
        with open(os.path.join(df.datadir, normalize_timestamp(
 
216
                    time.time()) + '.ts'), 'wb') as f:
 
217
            f.write('1234567890')
 
218
        part = os.path.join(self.objects, '0')
 
219
        hashed, hashes = object_replicator.get_hashes(part)
 
220
        i = [0]
 
221
        def getmtime(filename):
 
222
            i[0] += 1
 
223
            return 1
 
224
        with mock({'os.path.getmtime': getmtime}):
 
225
            hashed, hashes = object_replicator.get_hashes(
 
226
                part, recalculate=['a83'])
 
227
        self.assertEquals(i[0], 2)
 
228
 
 
229
    def test_get_hashes_modified(self):
 
230
        df = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o', FakeLogger())
 
231
        mkdirs(df.datadir)
 
232
        with open(os.path.join(df.datadir, normalize_timestamp(
 
233
                    time.time()) + '.ts'), 'wb') as f:
 
234
            f.write('1234567890')
 
235
        part = os.path.join(self.objects, '0')
 
236
        hashed, hashes = object_replicator.get_hashes(part)
 
237
        i = [0]
 
238
        def getmtime(filename):
 
239
            if i[0] < 3:
 
240
                i[0] += 1
 
241
            return i[0]
 
242
        with mock({'os.path.getmtime': getmtime}):
 
243
            hashed, hashes = object_replicator.get_hashes(
 
244
                part, recalculate=['a83'])
 
245
        self.assertEquals(i[0], 3)
 
246
 
212
247
    def test_hash_suffix_hash_dir_is_file_quarantine(self):
213
248
        df = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o', FakeLogger())
214
249
        mkdirs(os.path.dirname(df.datadir))