Ejemplo n.º 1
0
    def test_touch_expulsion(self):
        sz1 = os.path.getsize(self._work_file)
        work_sums = ["1", "XX", "III", "four"]
        max = sz1 * (len(work_sums) - 1)

        cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
        for i in range(0, len(work_sums) - 1):
            sum = work_sums[i]
            rc = cache.add(self._work_file, sum)
            time.sleep(1.1)
            self.assertEqual(rc, True)
        (osf, newfile) = tempfile.mkstemp()
        os.close(osf)
        print cache.list_cache()
        rc = cache.lookup(work_sums[0], newfile)
        self.assertEqual(rc, True)
        print cache.list_cache()
        sum = work_sums[i]
        rc = cache.add(self._work_file, work_sums[len(work_sums) - 1])
        self.assertEqual(rc, True)

        list = cache.list_cache()
        self.assertEqual(len(list), 3)
        print list
        print work_sums
        self.assertTrue(work_sums[0] in list)
        self.assertTrue(work_sums[1] not in list)
Ejemplo n.º 2
0
    def test_touch_expulsion(self):
        sz1 = os.path.getsize(self._work_file)
        work_sums = ["1", "XX", "III", "four"]
        max = sz1 * (len(work_sums) - 1)

        cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
        for i in range(0, len(work_sums) - 1):
            sum = work_sums[i]
            rc = cache.add(self._work_file, sum)
            time.sleep(1.1)
            self.assertEqual(rc, True)
        (osf, newfile) = tempfile.mkstemp()
        os.close(osf)
        print cache.list_cache()
        rc = cache.lookup(work_sums[0], newfile)
        self.assertEqual(rc, True)
        print cache.list_cache()
        sum = work_sums[i]
        rc = cache.add(self._work_file, work_sums[len(work_sums) - 1])
        self.assertEqual(rc, True)

        list = cache.list_cache()
        self.assertEqual(len(list), 3)
        print list
        print work_sums
        self.assertTrue(work_sums[0] in list)
        self.assertTrue(work_sums[1] not in list)
Ejemplo n.º 3
0
 def test_noroom(self):
     sz1 = os.path.getsize(self._work_file)
     max = sz1 - 1
     cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
     try:
         cache.add(self._work_file, self._work_sum)
         passes = False
     except:
         passes = True
     self.assertTrue(passes)
Ejemplo n.º 4
0
 def test_noroom(self):
     sz1 = os.path.getsize(self._work_file)
     max = sz1 - 1
     cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
     try:
         cache.add(self._work_file, self._work_sum)
         passes = False
     except:
         passes = True
     self.assertTrue(passes)
Ejemplo n.º 5
0
    def test_exceedsize(self):
        sz1 = os.path.getsize(self._work_file)
        work_sums = ["1", "XX", "III", "four"]
        max = sz1 * (len(work_sums) - 1)

        cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
        for i in range(0, len(work_sums)):
            sum = work_sums[i]
            rc = cache.add(self._work_file, sum)
            self.assertEqual(rc, True)
Ejemplo n.º 6
0
    def test_exceedsize(self):
        sz1 = os.path.getsize(self._work_file)
        work_sums = ["1", "XX", "III", "four"]
        max = sz1 * (len(work_sums) - 1)

        cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
        for i in range(0, len(work_sums)):
            sum = work_sums[i]
            rc = cache.add(self._work_file, sum)
            self.assertEqual(rc, True)
Ejemplo n.º 7
0
    def test_flush_cache(self):
        work_sums = ["1", "XX", "III", "four"]

        cache = WSCCacheObj(self._dir, self.lockfilepath)
        for sum in work_sums:
            rc = cache.add(self._work_file, sum)
            self.assertEqual(rc, True)
        cache.flush_cache()

        list = cache.list_cache()
        self.assertEqual(len(list), 0)
Ejemplo n.º 8
0
    def test_flush_cache(self):
        work_sums = ["1", "XX", "III", "four"]

        cache = WSCCacheObj(self._dir, self.lockfilepath)
        for sum in work_sums:
            rc = cache.add(self._work_file, sum)
            self.assertEqual(rc, True)
        cache.flush_cache()

        list = cache.list_cache()
        self.assertEqual(len(list), 0)
Ejemplo n.º 9
0
    def test_basic_sequence(self):
        cache = WSCCacheObj(self._dir, self.lockfilepath)
        rc = cache.add(self._work_file, self._work_sum)
        self.assertEqual(rc, True)

        (osf, newfile) = tempfile.mkstemp()
        os.close(osf)
        rc = cache.lookup(self._work_sum, newfile)
        self.assertEqual(rc, True)

        rc = filecmp.cmp(newfile, self._work_file)
        self.assertEqual(rc, 1)

        rc = cache.remove(self._work_sum)
        self.assertEqual(rc, True)
Ejemplo n.º 10
0
    def test_lookupmiss(self):
        sz1 = os.path.getsize(self._work_file)
        work_sums = ["1", "XX", "III", "four"]
        max = sz1 * (len(work_sums) - 1)

        cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
        for i in range(0, len(work_sums)):
            sum = work_sums[i]
            time.sleep(1.1)
            rc = cache.add(self._work_file, sum)
            self.assertEqual(rc, True)
        (osf, newfile) = tempfile.mkstemp()
        os.close(osf)
        rc = cache.lookup(work_sums[0], newfile)
        self.assertEqual(rc, False)
Ejemplo n.º 11
0
    def test_lookupmiss(self):
        sz1 = os.path.getsize(self._work_file)
        work_sums = ["1", "XX", "III", "four"]
        max = sz1 * (len(work_sums) - 1)

        cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
        for i in range(0, len(work_sums)):
            sum = work_sums[i]
            time.sleep(1.1)
            rc = cache.add(self._work_file, sum)
            self.assertEqual(rc, True)
        (osf, newfile) = tempfile.mkstemp()
        os.close(osf)
        rc = cache.lookup(work_sums[0], newfile)
        self.assertEqual(rc, False)
Ejemplo n.º 12
0
    def test_correct_expulsion(self):
        sz1 = os.path.getsize(self._work_file)
        work_sums = ["1", "XX", "III", "four"]
        max = sz1 * (len(work_sums) - 1)

        cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
        for i in range(0, len(work_sums)):
            sum = work_sums[i]
            rc = cache.add(self._work_file, sum)
            time.sleep(1.1)
            self.assertEqual(rc, True)

        list = cache.list_cache()
        self.assertEqual(len(list), 3)
        self.assertTrue(work_sums[0] not in list)
Ejemplo n.º 13
0
    def test_correct_expulsion(self):
        sz1 = os.path.getsize(self._work_file)
        work_sums = ["1", "XX", "III", "four"]
        max = sz1 * (len(work_sums) - 1)

        cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
        for i in range(0, len(work_sums)):
            sum = work_sums[i]
            rc = cache.add(self._work_file, sum)
            time.sleep(1.1)
            self.assertEqual(rc, True)

        list = cache.list_cache()
        self.assertEqual(len(list), 3)
        self.assertTrue(work_sums[0] not in list)
Ejemplo n.º 14
0
    def test_basic_sequence(self):
        cache = WSCCacheObj(self._dir, self.lockfilepath)
        rc = cache.add(self._work_file, self._work_sum)
        self.assertEqual(rc, True)

        (osf, newfile) = tempfile.mkstemp()
        os.close(osf)
        rc = cache.lookup(self._work_sum, newfile)
        self.assertEqual(rc, True)

        rc = filecmp.cmp(newfile, self._work_file)
        self.assertEqual(rc, 1)

        rc = cache.remove(self._work_sum)
        self.assertEqual(rc, True)
Ejemplo n.º 15
0
    def test_list_cache(self):
        work_sums = ["1", "XX", "III", "four"]

        cache = WSCCacheObj(self._dir, self.lockfilepath)
        for sum in work_sums:
            rc = cache.add(self._work_file, sum)
            self.assertEqual(rc, True)

        count = 0
        first_len = len(work_sums)
        list = cache.list_cache()
        for l in list:
            work_sums.remove(l)
            count = count + 1

        self.assertEqual(len(work_sums), 0)
        self.assertEqual(count, first_len)
Ejemplo n.º 16
0
    def test_list_cache(self):
        work_sums = ["1", "XX", "III", "four"]

        cache = WSCCacheObj(self._dir, self.lockfilepath)
        for sum in work_sums:
            rc = cache.add(self._work_file, sum)
            self.assertEqual(rc, True)

        count = 0
        first_len = len(work_sums)
        list = cache.list_cache()
        for l in list:
            work_sums.remove(l)
            count = count + 1

        self.assertEqual(len(work_sums), 0)
        self.assertEqual(count, first_len)
Ejemplo n.º 17
0
 def test_add_twice(self):
     cache = WSCCacheObj(self._dir, self.lockfilepath)
     rc = cache.add(self._work_file, self._work_sum)
     self.assertEqual(rc, True)
     rc = cache.add(self._work_file, self._work_sum)
     self.assertEqual(rc, False)
Ejemplo n.º 18
0
 def test_add_twice(self):
     cache = WSCCacheObj(self._dir, self.lockfilepath)
     rc = cache.add(self._work_file, self._work_sum)
     self.assertEqual(rc, True)
     rc = cache.add(self._work_file, self._work_sum)
     self.assertEqual(rc, False)
Ejemplo n.º 19
0
                    if self.c.dryrun:
                        self.c.log.debug("dryrun, not propagating")
                        return

                    adapter.propagate(l_file._propagation_source, l_file.path)

                    if not os.path.exists(l_file.path):
                        raise UnexpectedError(
                            "propagated from '%s' to '%s' but the file does not exist"
                            % (l_file._propagation_source, l_file.path))

                    if cache:
                        try:
                            self.c.log.debug("adding %s" % (cache_key))
                            cache.add(l_file.path, cache_key)
                        except Exception, ex:
                            self.c.log.warn(
                                "an exception occured while adding a file to the cache %s %s | %s"
                                % (cache_key, l_file.path, str(ex)))

                    return

    def _unpropagate(self, l_files):
        for l_file in l_files:

            if not l_file._unpropagate_needed:
                continue
            for keyword in self.adapters.keys():
                schemestring = keyword + "://"
                scheme_len = len(schemestring)
Ejemplo n.º 20
0
                    
                    self.c.log.debug("propagating from '%s' to '%s'" % (l_file._propagation_source, l_file.path))
                    
                    if self.c.dryrun:
                        self.c.log.debug("dryrun, not propagating")
                        return
                    
                    adapter.propagate(l_file._propagation_source, l_file.path)
                    
                    if not os.path.exists(l_file.path):
                        raise UnexpectedError("propagated from '%s' to '%s' but the file does not exist" % (l_file._propagation_source, l_file.path))
                    
                    if cache:
                        try:
                            self.c.log.debug("adding %s" % (cache_key))
                            cache.add(l_file.path, cache_key)
                        except Exception, ex:
                            self.c.log.warn("an exception occured while adding a file to the cache %s %s | %s" % (cache_key, l_file.path, str(ex)))

                    return
        
    def _unpropagate(self, l_files):
        for l_file in l_files:
            
            if not l_file._unpropagate_needed:
                continue
            for keyword in self.adapters.keys():
                schemestring = keyword + "://"
                scheme_len = len(schemestring)
                target_scheme = l_file._unpropagation_target[:scheme_len]