7167: add tests to replications count
authorradhika <radhika@curoverse.com>
Thu, 8 Oct 2015 20:19:37 +0000 (16:19 -0400)
committerradhika <radhika@curoverse.com>
Thu, 8 Oct 2015 20:19:37 +0000 (16:19 -0400)
tools/keep-rsync/keep-rsync.go
tools/keep-rsync/keep-rsync_test.go

index 3c1a402dfeba524fc0e3eda0d8f6a5e760c82a82..d569421430de6e0872fdea6c380de9575c449e37 100644 (file)
@@ -58,7 +58,7 @@ func main() {
        flag.IntVar(
                &replications,
                "replications",
-               3,
+               0,
                "Number of replications to write to the destination.")
 
        flag.StringVar(
@@ -151,10 +151,14 @@ func initializeKeepRsync() (err error) {
                return
        }
 
-       // Get default replication value from destination
-       value, err := arvDst.Discovery("defaultCollectionReplication")
-       if err == nil {
-               replications = int(value.(float64))
+       // Get default replications value from destination, if it is not already provided
+       if replications == 0 {
+               value, err := arvDst.Discovery("defaultCollectionReplication")
+               if err == nil {
+                       replications = int(value.(float64))
+               } else {
+                       replications = 2
+               }
        }
 
        // if srcKeepServicesJSON is provided, use it to load services; else, use DiscoverKeepServers
index 52a4eba9cb8e187f2d6960f94b0ffdec0f87b162..6bc0cb7f359e86554dddfdfe8717d426c5eb367a 100644 (file)
@@ -66,9 +66,6 @@ func setupRsync(c *C, enforcePermissions bool) {
        err := initializeKeepRsync()
        c.Assert(err, Equals, nil)
 
-       // Must have got replication value as 2 from dst discovery document
-       c.Assert(replications, Equals, 2)
-
        // Create two more keep servers to be used as destination
        arvadostest.StartKeepWithParams(true, enforcePermissions)
 
@@ -228,3 +225,22 @@ func (s *ServerRequiredSuite) TestRsyncWithBlobSigning_PutInOne_GetFromOtherShou
        _, _, _, 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)
+
+       // 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)
+}