From 64dfaa2efdb6ddc8653333b884508670e2da2422 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 26 Oct 2017 16:14:19 +0200 Subject: [PATCH] Fix #208: Set replication factor from loaded json License: MIT Signed-off-by: Hector Sanjuan --- cluster_config.go | 4 +++- cluster_config_test.go | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cluster_config.go b/cluster_config.go index 3ad63bf0..0348c5f8 100644 --- a/cluster_config.go +++ b/cluster_config.go @@ -274,9 +274,11 @@ func (cfg *Config) LoadJSON(raw []byte) error { } cfg.ListenAddr = clusterAddr - if jcfg.ReplicationFactor == 0 { + if rf := jcfg.ReplicationFactor; rf == 0 { logger.Warning("Replication factor set to -1 (pin everywhere)") cfg.ReplicationFactor = -1 + } else { + cfg.ReplicationFactor = rf } // Validation will detect problems here diff --git a/cluster_config_test.go b/cluster_config_test.go index 03a68bc2..2d48b874 100644 --- a/cluster_config_test.go +++ b/cluster_config_test.go @@ -20,7 +20,7 @@ var ccfgTestJSON = []byte(` "listen_multiaddress": "/ip4/127.0.0.1/tcp/10000", "state_sync_interval": "1m0s", "ipfs_sync_interval": "2m10s", - "replication_factor": -1, + "replication_factor": 5, "monitor_ping_interval": "2s" } `) @@ -36,6 +36,10 @@ func TestLoadJSON(t *testing.T) { t.Error("expected 1 peer and 1 bootstrap") } + if cfg.ReplicationFactor != 5 { + t.Error("expected replication factor 5") + } + j := &configJSON{} json.Unmarshal(ccfgTestJSON, j) @@ -99,6 +103,15 @@ func TestLoadJSON(t *testing.T) { if err == nil { t.Error("expected error state_sync_interval") } + + j = &configJSON{} + json.Unmarshal(ccfgTestJSON, j) + j.ReplicationFactor = 0 + tst, _ = json.Marshal(j) + err = cfg.LoadJSON(tst) + if cfg.ReplicationFactor != -1 { + t.Error("expected default replication factor") + } } func TestToJSON(t *testing.T) {