2752: arv-put saves and restores write progress information.
authorBrett Smith <brett@curoverse.com>
Tue, 27 May 2014 14:04:19 +0000 (10:04 -0400)
committerBrett Smith <brett@curoverse.com>
Fri, 30 May 2014 14:40:10 +0000 (10:40 -0400)
This will make output less confusing to the user, and help them
understand that an upload is resuming.

sdk/python/arvados/commands/put.py
sdk/python/tests/test_arv-put.py

index 4568565d11acd1f09abc427cc7ed26ff996d0b73..4398c5bca60851c874dc8fefb9762baf839d0f82 100644 (file)
@@ -224,14 +224,17 @@ class ResumeCache(object):
 
 
 class ArvPutCollectionWriter(arvados.ResumableCollectionWriter):
+    STATE_PROPS = (arvados.ResumableCollectionWriter.STATE_PROPS +
+                   ['bytes_written'])
+
     def __init__(self, cache=None, reporter=None, bytes_expected=None):
+        self.bytes_written = 0
         self.__init_locals__(cache, reporter, bytes_expected)
         super(ArvPutCollectionWriter, self).__init__()
 
     def __init_locals__(self, cache, reporter, bytes_expected):
         self.cache = cache
         self.report_func = reporter
-        self.bytes_written = 0
         self.bytes_expected = bytes_expected
 
     @classmethod
index a98eaa6a5eca83ee5b7eb7f5a173df53119ff93e..cd0e9658eb4030b592899dd49cd6702a32251191 100644 (file)
@@ -236,17 +236,36 @@ class ArvadosPutCollectionWriterTest(ArvadosKeepLocalStoreTestCase):
                 self.cache)
         self.assertEquals(cwriter.manifest_text(), new_writer.manifest_text())
 
+    def make_progress_tester(self):
+        progression = []
+        def record_func(written, expected):
+            progression.append((written, expected))
+        return progression, record_func
+
     def test_progress_reporting(self):
         for expect_count in (None, 8):
-            progression = []
+            progression, reporter = self.make_progress_tester()
             cwriter = arv_put.ArvPutCollectionWriter(
-                reporter=lambda *args: progression.append(args),
-                bytes_expected=expect_count)
+                reporter=reporter, bytes_expected=expect_count)
             with self.make_test_file() as testfile:
                 cwriter.write_file(testfile.name, 'test')
             cwriter.finish_current_stream()
             self.assertIn((4, expect_count), progression)
 
+    def test_resume_progress(self):
+        cwriter = arv_put.ArvPutCollectionWriter(self.cache, bytes_expected=4)
+        with self.make_test_file() as testfile:
+            # Set up a writer with some flushed bytes.
+            cwriter.write_file(testfile.name, 'test')
+            cwriter.finish_current_stream()
+            cwriter.checkpoint_state()
+            # Restore a writer from that state and check its progress report.
+            progression, reporter = self.make_progress_tester()
+            new_writer = arv_put.ArvPutCollectionWriter.from_cache(
+                self.cache, reporter, bytes_expected=4)
+            new_writer.flush_data()
+            self.assertIn((4, 4), progression)
+
 
 class ArvadosExpectedBytesTest(ArvadosBaseTestCase):
     TEST_SIZE = os.path.getsize(__file__)