func tearDownTests() { storage.CloseInfoDB() os.RemoveAll(config.GetConfig().GetDataDir()) os.RemoveAll(config.GetConfig().GetInfoDir()) os.Mkdir(config.GetConfig().GetDataDir(), 0777) os.Mkdir(config.GetConfig().GetInfoDir(), 0777) }
func tearDownTests() { os.RemoveAll(config.GetConfig().GetDataDir()) os.RemoveAll(config.GetConfig().GetInfoDir()) os.Mkdir(config.GetConfig().GetDataDir(), 0777) os.Mkdir(config.GetConfig().GetInfoDir(), 0777) storage.CloseInfoDB() sketchesManager.Destroy() }
func tearDownTests() { utils.PanicOnError(os.RemoveAll(config.GetConfig().DataDir)) utils.PanicOnError(os.RemoveAll(config.GetConfig().InfoDir)) utils.PanicOnError(os.Mkdir(config.GetConfig().DataDir, 0777)) utils.PanicOnError(os.Mkdir(config.GetConfig().InfoDir, 0777)) utils.PanicOnError(storage.CloseInfoDB()) sketchesManager.Destroy() }
/* Run ... */ func (srv *Server) Run() { conf := config.GetConfig() port := int(conf.Port) logger.Info.Println("Server up and running on port: " + strconv.Itoa(port)) err := gracehttp.Serve(&http.Server{Addr: ":" + strconv.Itoa(port), Handler: srv}) utils.PanicOnError(err) }
/* save ... */ func (sp *SketchProxy) save(force bool) { if !sp.dirty { return } id := fmt.Sprintf("%s.%s", sp.ID, sp.Type) if sp.ops%config.GetConfig().SaveThresholdOps == 0 || force { sp.ops++ sp.dirty = false manager := storage.Manager() serialized, err := sp.sketch.Marshal() if err != nil { logger.Error.Println(err) } err = manager.SaveData(id, serialized, 0) if err != nil { logger.Error.Println(err) } info, _ := json.Marshal(sp.Info) err = manager.SaveInfo(sp.Info.ID, info) if err != nil { logger.Error.Println(err) } } }
func (sp *SketchProxy) autosave() { for { time.Sleep(time.Duration(config.GetConfig().SaveThresholdSeconds) * time.Second) if sp.dirty { sp.save(true) sp.dirty = false } } }
func main() { var port uint flag.UintVar(&port, "p", 3596, "specifies the port for Counts to run on") flag.Parse() //TODO: Add arguments for dataDir and infoDir err := os.Setenv("COUNTS_PORT", strconv.Itoa(int(port))) utils.PanicOnError(err) logger.Info.Println("Starting counts...") conf := config.GetConfig() logger.Info.Println("Using data dir: ", conf.DataDir) server, err := server.New() utils.PanicOnError(err) server.Run() }
func TestSaveAndDeleteData(t *testing.T) { setupTests() defer tearDownTests() m := newManager() m.Create("phoenix") m.SaveData("phoenix", []byte("phoenix"), 0) path := filepath.Join(config.GetConfig().GetDataDir(), "phoenix") if _, err := os.Stat(path); err != nil { t.Error("Expected data in,", path, "got", err) } err := m.DeleteData("phoenix") if err != nil { t.Error("Expected no error deleting data, got", err) } if _, err := os.Stat(path); err == nil { t.Error("Expected no data in,", path, "got", err) } }
func newManager() *ManagerStruct { conf = config.GetConfig() dataPath = conf.DataDir cacheSize := int(conf.CacheSize) if cacheSize == 0 { cacheSize = 250 // default cache size } cache, err := lru.NewWithEvict(cacheSize, func(k interface{}, v interface{}) { f := v.(*os.File) err := f.Close() if err != nil { logger.Error.Println(err) } }) utils.PanicOnError(err) err = os.MkdirAll(dataPath, 0777) utils.PanicOnError(err) return &ManagerStruct{cache} }
func tearDownTests() { if err := storage.CloseInfoDB(); err != nil { panic("Could not close info db") } if err := os.RemoveAll(config.GetConfig().DataDir); err != nil { panic(fmt.Sprintf("Could not remove data dir %s", config.GetConfig().DataDir)) } if err := os.RemoveAll(config.GetConfig().InfoDir); err != nil { panic(fmt.Sprintf("Could not remove info dir %s", config.GetConfig().InfoDir)) } if err := os.Mkdir(config.GetConfig().DataDir, 0777); err != nil { //panic(fmt.Sprintf("Could not remove info dir %s", config.GetConfig().InfoDir)) } if err := os.Mkdir(config.GetConfig().InfoDir, 0777); err != nil { //panic(fmt.Sprintf("Could not remove info dir %s", config.GetConfig().InfoDir)) } manager.Destroy() }
func tearDownTests() { os.RemoveAll(config.GetConfig().GetDataDir()) os.RemoveAll(config.GetConfig().GetInfoDir()) os.Mkdir(config.GetConfig().GetDataDir(), 0777) os.Mkdir(config.GetConfig().GetInfoDir(), 0777) }
/* Run ... */ func (srv *Server) Run() { conf := config.GetConfig() port := int(conf.GetPort()) logger.Info.Println("Server up and running on port: " + strconv.Itoa(port)) http.ListenAndServe(":"+strconv.Itoa(port), srv) }
func tearDownTests() { os.RemoveAll(config.GetConfig().DataDir) os.RemoveAll(config.GetConfig().InfoDir) os.Mkdir(config.GetConfig().DataDir, 0777) os.Mkdir(config.GetConfig().InfoDir, 0777) }