+// Test keep-rsync initialization, with src and dst keep servers with blobSigningKey.
+// Do a Put and Get in src, both of which should succeed.
+// 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) TestRsyncWithBlobSigning_PutInOne_GetFromOtherShouldFail(c *C) {
+ setupRsync(c, true, true)
+
+ // Put a block in src using kcSrc and Get it
+ srcData := []byte("test-data1")
+ locatorInSrc := fmt.Sprintf("%x", md5.Sum(srcData))
+
+ 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)
+
+ tomorrow := time.Now().AddDate(0, 0, 1)
+ signedLocator := keepclient.SignLocator(locatorInSrc, arvSrc.ApiToken, tomorrow, []byte(blobSigningKey))
+
+ reader, blocklen, _, err := kcSrc.Get(signedLocator)
+ c.Check(err, IsNil)
+ c.Check(blocklen, Equals, int64(10))
+ all, err := ioutil.ReadAll(reader)
+ c.Check(all, DeepEquals, srcData)
+
+ // 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)
+
+ signedLocator = keepclient.SignLocator(locatorInDst, arvDst.ApiToken, tomorrow, []byte(blobSigningKey))
+
+ reader, blocklen, _, err = kcDst.Get(signedLocator)
+ c.Check(err, IsNil)
+ c.Check(blocklen, Equals, int64(10))
+ all, err = ioutil.ReadAll(reader)
+ c.Check(all, DeepEquals, dstData)
+
+ // Get srcLocator using kcDst should fail with Not Found error
+ signedLocator = keepclient.SignLocator(locatorInSrc, arvDst.ApiToken, tomorrow, []byte(blobSigningKey))
+ _, _, _, err = kcDst.Get(locatorInSrc)
+ c.Assert(err.Error(), Equals, "Block not found")
+
+ // Get dstLocator using kcSrc should fail with Not Found error
+ signedLocator = keepclient.SignLocator(locatorInDst, arvSrc.ApiToken, tomorrow, []byte(blobSigningKey))
+ _, _, _, err = kcSrc.Get(locatorInDst)
+ 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, 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) {
+ // First set replications to 3 to mimic passing input argument
+ replications = 3
+
+ setupRsync(c, false, 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 some blocks in Src and some more in Dst
+// Use prefix while doing rsync
+// And copy missing blocks from Src to Dst
+func (s *ServerRequiredSuite) TestKeepRsync_WithPrefix(c *C) {
+ data := []byte("test-data-4")
+ hash := fmt.Sprintf("%x", md5.Sum(data))
+
+ testKeepRsync(c, false, hash[0:3])
+}
+
+// Put some blocks in Src and some more in Dst
+// Use prefix not in src while doing rsync
+// And copy missing blocks from Src to Dst
+func (s *ServerRequiredSuite) TestKeepRsync_WithNoSuchPrefixInSrc(c *C) {
+ testKeepRsync(c, false, "999")
+}
+