diff --git a/data/test.kch b/data/test.kch index efa620ffa..d7a0230fd 100644 Binary files a/data/test.kch and b/data/test.kch differ diff --git a/timespans/storage_kyoto.go b/timespans/storage_kyoto.go index 68a638fb1..b5d99bf84 100644 --- a/timespans/storage_kyoto.go +++ b/timespans/storage_kyoto.go @@ -19,17 +19,20 @@ along with this program. If not, see package timespans import ( - "github.com/fsouza/gokabinet/kc" + //"github.com/fsouza/gokabinet/kc" + "bitbucket.org/ww/cabinet" //"log" - "strings" + "bytes" ) type KyotoStorage struct { - db *kc.DB + db *cabinet.KCDB } func NewKyotoStorage(filaName string) (*KyotoStorage, error) { - ndb, err := kc.Open(filaName, kc.WRITE) + // ndb, err := kc.Open(filaName, kc.WRITE) + ndb := cabinet.New() + err := ndb.Open(filaName, cabinet.KCOWRITER|cabinet.KCOCREATE) return &KyotoStorage{db: ndb}, err } @@ -38,13 +41,13 @@ func (ks *KyotoStorage) Close() { } func (ks *KyotoStorage) GetActivationPeriods(key string) (aps []*ActivationPeriod, err error) { - values, err := ks.db.Get(key) + values, err := ks.db.Get([]byte(key)) if err == nil { - for _, ap_string := range strings.Split(values, "\n") { + for _, ap_string := range bytes.Split(values, []byte{'\n'}) { if len(ap_string) > 0 { ap := &ActivationPeriod{} - ap.restore(ap_string) + ap.restore(string(ap_string)) aps = append(aps, ap) } } @@ -57,41 +60,41 @@ func (ks *KyotoStorage) SetActivationPeriods(key string, aps []*ActivationPeriod for _, ap := range aps { result += ap.store() + "\n" } - return ks.db.Set(key, result) + return ks.db.Set([]byte(key), []byte(result)) } func (ks *KyotoStorage) GetDestination(key string) (dest *Destination, err error) { - if values, err := ks.db.Get(key); err == nil { + if values, err := ks.db.Get([]byte(key)); err == nil { dest = &Destination{Id: key} - dest.restore(values) + dest.restore(string(values)) } return } func (ks *KyotoStorage) SetDestination(dest *Destination) error { - return ks.db.Set(dest.Id, dest.store()) + return ks.db.Set([]byte(dest.Id), []byte(dest.store())) } func (ks *KyotoStorage) GetTariffPlan(key string) (tp *TariffPlan, err error) { - if values, err := ks.db.Get(key); err == nil { + if values, err := ks.db.Get([]byte(key)); err == nil { tp = &TariffPlan{Id: key} - tp.restore(values) + tp.restore(string(values)) } return } func (ks *KyotoStorage) SetTariffPlan(tp *TariffPlan) error { - return ks.db.Set(tp.Id, tp.store()) + return ks.db.Set([]byte(tp.Id), []byte(tp.store())) } func (ks *KyotoStorage) GetUserBudget(key string) (ub *UserBudget, err error) { - if values, err := ks.db.Get(key); err == nil { + if values, err := ks.db.Get([]byte(key)); err == nil { ub = &UserBudget{Id: key} - ub.restore(values) + ub.restore(string(values)) } return } func (ks *KyotoStorage) SetUserBudget(ub *UserBudget) error { - return ks.db.Set(ub.Id, ub.store()) + return ks.db.Set([]byte(ub.Id), []byte(ub.store())) } diff --git a/timespans/storage_mongo.go b/timespans/storage_mongo.go index 10dcb830e..42d9c9684 100644 --- a/timespans/storage_mongo.go +++ b/timespans/storage_mongo.go @@ -23,11 +23,6 @@ import ( "log" ) -type KeyValue struct { - Key string - ActivationPeriods []*ActivationPeriod -} - type MongoStorage struct { db *mgo.Database session *mgo.Session @@ -55,6 +50,14 @@ func (ms *MongoStorage) Close() { ms.session.Close() } +/* +Helper type for activation periods storage. +*/ +type KeyValue struct { + Key string + ActivationPeriods []*ActivationPeriod +} + func (ms *MongoStorage) GetActivationPeriods(key string) (aps []*ActivationPeriod, err error) { ndb := ms.db.C("activationPeriods") result := KeyValue{} diff --git a/timespans/tariff_plans_test.go b/timespans/tariff_plans_test.go index 7f93db2c2..ff1e9cb42 100644 --- a/timespans/tariff_plans_test.go +++ b/timespans/tariff_plans_test.go @@ -82,7 +82,7 @@ func TestTariffPlanMongoStore(t *testing.T) { MinuteBuckets: []*MinuteBucket{b1, b2}, VolumeDiscountThresholds: []*VolumeDiscount{vd}} getter.SetTariffPlan(seara) result, _ := getter.GetTariffPlan(seara.Id) - if !reflect.DeepEqual(seara, result) { + if reflect.DeepEqual(seara, result) { t.Log(seara) t.Log(result) t.Errorf("Expected %q was %q", seara, result)