7167: Update test to also put a block in dst and attempt get from src.
authorradhika <radhika@curoverse.com>
Mon, 5 Oct 2015 21:22:37 +0000 (17:22 -0400)
committerradhika <radhika@curoverse.com>
Mon, 5 Oct 2015 21:22:37 +0000 (17:22 -0400)
sdk/python/tests/run_test_server.py
tools/keep-rsync/keep-rsync_test.go

index 62a2a82349b5a5cd2149d2d266f5834804489e88..fba9bb69295a9cdf4dec4999aa2c8d4ee40b56bb 100644 (file)
@@ -353,9 +353,11 @@ def run_keep(blob_signing_key=None, enforce_permissions=False):
         api.keep_disks().delete(uuid=d['uuid']).execute()
 
     start_index = 0
+    end_index = 2
     if keep_existing is not None:
         start_index = 2
-    for d in range(start_index, start_index+2):
+        end_index = 3
+    for d in range(start_index, end_index):
         port = _start_keep(d, keep_args)
         svc = api.keep_services().create(body={'keep_service': {
             'uuid': 'zzzzz-bi6l4-keepdisk{:07d}'.format(d),
@@ -380,9 +382,8 @@ def _stop_keep(n):
 def stop_keep():
     _stop_keep(0)
     _stop_keep(1)
-    # We may have created 2 additional keep servers when keep_existing is used
+    # We may have created an additional keep servers when keep_existing is used
     _stop_keep(2)
-    _stop_keep(3)
 
 def run_keep_proxy():
     if 'ARVADOS_TEST_PROXY_SERVICES' in os.environ:
index 7636c2e564aed4cab4b3c66b768d9c20da2cc504..97db5717d0dbb6d7f0cff8369a3cb8d22a45d669 100644 (file)
@@ -68,6 +68,7 @@ func setupRsync(c *C) {
        // load kcDst
        kcDst, err = keepclient.MakeKeepClient(&arvDst)
        c.Assert(err, Equals, nil)
+       kcDst.Want_replicas = 1
 }
 
 // Test readConfigFromFile method
@@ -94,27 +95,48 @@ func (s *ServerRequiredSuite) TestReadConfigFromFile(c *C) {
 
 // Test keep-rsync initialization, with src and dst keep servers.
 // Do a Put and Get in src, both of which should succeed.
-// Do a Get in dst for the same hash, which should raise block not found error.
-func (s *ServerRequiredSuite) TestRsyncPutInSrc_GetFromDstShouldFail(c *C) {
+// Do a Put and Get in dst, both of which should succeed.
+// Do a Get in dst for the src hash, which should raise block not found error.
+// Do a Get in src for the dst hash, which should raise block not found error.
+func (s *ServerRequiredSuite) TestRsyncPutInOne_GetFromOtherShouldFail(c *C) {
        setupRsync(c)
 
        // Put a block in src using kcSrc and Get it
-       data := []byte("test-data")
-       hash := fmt.Sprintf("%x", md5.Sum(data))
+       srcData := []byte("test-data1")
+       locatorInSrc := fmt.Sprintf("%x", md5.Sum(srcData))
 
-       hash2, rep, err := kcSrc.PutB(data)
-       c.Check(hash2, Matches, fmt.Sprintf(`^%s\+9(\+.+)?$`, hash))
+       hash, rep, err := kcSrc.PutB(srcData)
+       c.Check(hash, Matches, fmt.Sprintf(`^%s\+10(\+.+)?$`, locatorInSrc))
        c.Check(rep, Equals, 2)
        c.Check(err, Equals, nil)
 
-       reader, blocklen, _, err := kcSrc.Get(hash)
+       reader, blocklen, _, err := kcSrc.Get(locatorInSrc)
        c.Assert(err, Equals, nil)
-       c.Check(blocklen, Equals, int64(9))
+       c.Check(blocklen, Equals, int64(10))
        all, err := ioutil.ReadAll(reader)
-       c.Check(all, DeepEquals, data)
+       c.Check(all, DeepEquals, srcData)
 
-       // Get using kcDst should fail with NotFound error
-       _, _, _, err = kcDst.Get(hash)
+       // Put a different block in src using kcSrc and Get it
+       dstData := []byte("test-data2")
+       locatorInDst := fmt.Sprintf("%x", md5.Sum(dstData))
+
+       hash, rep, err = kcDst.PutB(dstData)
+       c.Check(hash, Matches, fmt.Sprintf(`^%s\+10(\+.+)?$`, locatorInDst))
+       c.Check(rep, Equals, 1)
+       c.Check(err, Equals, nil)
+
+       reader, blocklen, _, err = kcDst.Get(locatorInDst)
+       c.Assert(err, Equals, nil)
+       c.Check(blocklen, Equals, int64(10))
+       all, err = ioutil.ReadAll(reader)
+       c.Check(all, DeepEquals, dstData)
+
+       // Get srcLocator using kcDst should fail with NotFound error
+       _, _, _, err = kcDst.Get(locatorInSrc)
+       c.Assert(err.Error(), Equals, "Block not found")
+
+       // Get dstLocator using kcSrc should fail with NotFound error
+       _, _, _, err = kcSrc.Get(locatorInDst)
        c.Assert(err.Error(), Equals, "Block not found")
 }