Fix #208: Set replication factor from loaded json

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
This commit is contained in:
Hector Sanjuan 2017-10-26 16:14:19 +02:00
parent 3c48c35920
commit 64dfaa2efd
2 changed files with 17 additions and 2 deletions

View File

@ -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

View File

@ -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) {