c.Assert(err.Error(), Equals, "Block not found")
}
+ // Test keep-rsync initialization with default replications count
+ func (s *ServerRequiredSuite) TestInitializeRsyncDefaultReplicationsCount(c *C) {
+ setupRsync(c, false)
+
+ // Must have got default replications value as 2 from dst discovery document
+ c.Assert(replications, Equals, 2)
+ }
+
+ // Test keep-rsync initialization with replications count argument
+ func (s *ServerRequiredSuite) TestInitializeRsyncReplicationsCount(c *C) {
+ // set replications to 3 to mimic passing input argument
+ replications = 3
+
+ setupRsync(c, false)
+
+ // Since replications value is provided, default is not used
+ c.Assert(replications, Equals, 3)
+ }
++
+// Put some blocks in Src and some more in Dst
+// And copy missing blocks from Src to Dst
+func (s *ServerRequiredSuite) TestKeepRsync(c *C) {
+ testKeepRsync(c, false)
+}
+
+// Put some blocks in Src and some more in Dst with blob signing enabled.
+// And copy missing blocks from Src to Dst
+func (s *ServerRequiredSuite) TestKeepRsync_WithBlobSigning(c *C) {
+ testKeepRsync(c, true)
+}
+
+// Put 5 blocks in src. Put 2 of those blocks in dst
+// Hence there are 3 additional blocks in src
+// Also, put 2 extra blocks in dst; they are hence only in dst
+// Run rsync and verify that those 7 blocks are now available in dst
+func testKeepRsync(c *C, enforcePermissions bool) {
+ setupRsync(c, enforcePermissions)
+
+ tomorrow := time.Now().AddDate(0, 0, 1)
+
+ // Put a few blocks in src using kcSrc
+ var srcLocators []string
+ for i := 0; i < 5; i++ {
+ data := []byte(fmt.Sprintf("test-data-%d", i))
+ hash := fmt.Sprintf("%x", md5.Sum(data))
+
+ hash2, rep, err := kcSrc.PutB(data)
+ c.Check(hash2, Matches, fmt.Sprintf(`^%s\+11(\+.+)?$`, hash))
+ c.Check(rep, Equals, 2)
+ c.Check(err, Equals, nil)
+
+ getLocator := hash
+ if enforcePermissions {
+ getLocator = keepclient.SignLocator(getLocator, arvSrc.ApiToken, tomorrow, []byte(blobSigningKey))
+ }
+
+ reader, blocklen, _, err := kcSrc.Get(getLocator)
+ c.Assert(err, Equals, nil)
+ c.Check(blocklen, Equals, int64(11))
+ all, err := ioutil.ReadAll(reader)
+ c.Check(all, DeepEquals, data)
+
+ srcLocators = append(srcLocators, fmt.Sprintf("%s+%d", hash, blocklen))
+ }
+
+ // Put just two of those blocks in dst using kcDst
+ var dstLocators []string
+ for i := 0; i < 2; i++ {
+ data := []byte(fmt.Sprintf("test-data-%d", i))
+ hash := fmt.Sprintf("%x", md5.Sum(data))
+
+ hash2, rep, err := kcDst.PutB(data)
+ c.Check(hash2, Matches, fmt.Sprintf(`^%s\+11(\+.+)?$`, hash))
+ c.Check(rep, Equals, 1)
+ c.Check(err, Equals, nil)
+
+ getLocator := hash
+ if enforcePermissions {
+ getLocator = keepclient.SignLocator(getLocator, arvDst.ApiToken, tomorrow, []byte(blobSigningKey))
+ }
+
+ reader, blocklen, _, err := kcDst.Get(getLocator)
+ c.Assert(err, Equals, nil)
+ c.Check(blocklen, Equals, int64(11))
+ all, err := ioutil.ReadAll(reader)
+ c.Check(all, DeepEquals, data)
+
+ dstLocators = append(dstLocators, fmt.Sprintf("%s+%d", hash, blocklen))
+ }
+
+ // Put two more blocks in dst; they are not in src at all
+ var extraDstLocators []string
+ for i := 0; i < 2; i++ {
+ data := []byte(fmt.Sprintf("other-data-%d", i))
+ hash := fmt.Sprintf("%x", md5.Sum(data))
+
+ hash2, rep, err := kcDst.PutB(data)
+ c.Check(hash2, Matches, fmt.Sprintf(`^%s\+12(\+.+)?$`, hash))
+ c.Check(rep, Equals, 1)
+ c.Check(err, Equals, nil)
+
+ getLocator := hash
+ if enforcePermissions {
+ getLocator = keepclient.SignLocator(getLocator, arvDst.ApiToken, tomorrow, []byte(blobSigningKey))
+ }
+
+ reader, blocklen, _, err := kcDst.Get(getLocator)
+ c.Assert(err, Equals, nil)
+ c.Check(blocklen, Equals, int64(12))
+ all, err := ioutil.ReadAll(reader)
+ c.Check(all, DeepEquals, data)
+
+ extraDstLocators = append(extraDstLocators, fmt.Sprintf("%s+%d", hash, blocklen))
+ }
+
+ err := performKeepRsync()
+ c.Check(err, Equals, nil)
+
+ // Now GetIndex from dst and verify that all 5 from src and the 2 extra blocks are found
+ dstIndex, err := getUniqueLocators(kcDst, "")
+ c.Check(err, Equals, nil)
+ for _, locator := range srcLocators {
+ _, ok := dstIndex[locator]
+ c.Assert(ok, Equals, true)
+ }
+ for _, locator := range extraDstLocators {
+ _, ok := dstIndex[locator]
+ c.Assert(ok, Equals, true)
+ }
+}