func ExampleRegister_Cluster() { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { response := Response{Message: "Factory was succesfully registered"} params, _ := json.Marshal(response) fmt.Fprintln(w, string(params)) })) defer ts.Close() conf["Clsuter"] = ts.URL address := map[string]string{"Host": ts.URL} params, _ := marshaller.IoReader(address) req, err := http.NewRequest("POST", "http://www.datagentleman.io/cluster/", params) if err != nil { log.Fatal(err) } w := httptest.NewRecorder() cluster := &api.ClusterHandler{"", ""} cluster.Register(w, req, nil) fmt.Printf("%d", w.Code) // Output: // 200 }
func ExampleAccept_Job() { stream, err := stream.New("jobs", conf) if err != nil { fmt.Printf("ERROR: %s\n", err) return } stream.Clean() job := &Job{Id: "1"} params, _ := marshaller.IoReader(job) req, _ := http.NewRequest("POST", "/job/1", params) newJob := &api.JobHandler{stream} resp := httptest.NewRecorder() ps := httprouter.Params{ httprouter.Param{"id", "1"}, } newJob.Create(resp, req, ps) qsize := stream.Size() fmt.Printf("Resonse code: %d\n", resp.Code) fmt.Printf("Jobs in queue: %d\n", qsize) // Output: // Resonse code: 200 // Jobs in queue: 1 }
func ExampleJob_Create() { job := &models.Job{} body, _ := marshaller.IoReader(job) req, err := http.NewRequest("POST", "http://example.com/factories", body) if err != nil { log.Fatal(err) } w := httptest.NewRecorder() db, err := redis.NewDB(config) if err != nil { fmt.Printf("ERROR: %s\n", err) return } newCluster := cluster.NewCluster("test", db) newCluster.Jobs.Clean() newJob := api.JobHandler{newCluster} newJob.Create(w, req, nil) fmt.Printf("%d\n", newCluster.Jobs.Size()) // Output: // 1 }
func joinCluster(name, addr string) error { factory := &models.Factory{Name: name} params, err := marshaller.IoReader(factory) if err != nil { return err } if _, err := http.Post(addr, "text/html", params); err != nil { return err } return nil }
func (w *Warehouse) CreateCollection(col *collections.Collection) error { addr := w.address + DATASETS + w.Dataset + COLLECTIONS params, err := marshaller.IoReader(col) if err != nil { return err } _, err = http.Post(addr, "text/html", params) if err != nil { return err } return nil }
func (w *Warehouse) CreateDataset(ds *storage.Dataset) error { addr := w.address + DATASETS params, err := marshaller.IoReader(ds) if err != nil { return err } _, err = http.Post(addr, "text/html", params) if err != nil { return err } return nil }
// Insert(instance) // func (w *Warehouse) Insert(item *instance.Attributes) error { path := DATASETS + w.Dataset + COLLECTIONS + w.Collection + ITEMS addr := w.address + path params, err := marshaller.IoReader(item) if err != nil { return err } _, err = http.Post(addr, "text/html", params) if err != nil { return err } return nil }
func ExampleDataset_Create() { ds := &storage.Dataset{Name: "Iris"} params, _ := marshaller.IoReader(ds) req, _ := http.NewRequest("POST", "/datasets/", params) db, _ := redis.NewDB(config) storage := storage.New(db) dataset := &api.DatasetHandler{storage} resp := httptest.NewRecorder() dataset.Create(resp, req, nil) fmt.Printf("%d", resp.Code) // Output: // 200 }
// // /nodes/ => POST => register new node // func ExampleFactories_Register() { fa := models.Factory{ Name: "factory_1", Host: "localhost:9001", } body, _ := marshaller.IoReader(fa) req, err := http.NewRequest("POST", "http://example.com/nodes", body) if err != nil { log.Fatal(err) } w := httptest.NewRecorder() db, _ := redis.NewDB(config) storage := storage.New(db) if err != nil { fmt.Printf("%s\n", err) return } dataset := storage.NewDataset("puaro") storage.Insert(dataset) newCluster := cluster.NewCluster("test", db) factory := api.FactoryHandler{newCluster} factory.Register(w, req, nil) fmt.Printf("%d", w.Code) newCluster.Factories.Clean() // Output: // 200 }
func ExampleFactories_Index() { factory1 := &models.Factory{Name: "factory_1"} factory2 := &models.Factory{Name: "factory_2"} factory3 := &models.Factory{Name: "factory_3"} body, _ := marshaller.IoReader(factory1) req, err := http.NewRequest("POST", "http://example.com/factories", body) if err != nil { log.Fatal(err) } w := httptest.NewRecorder() db, _ := redis.NewDB(config) storage := storage.New(db) dataset := storage.NewDataset("puaro") storage.Insert(dataset) newCluster := cluster.NewCluster("test", db) newCluster.Register(factory1) newCluster.Register(factory2) newCluster.Register(factory3) factory := api.FactoryHandler{newCluster} factory.Index(w, req, nil) factoriesResponse := []string{} json.Unmarshal([]byte(w.Body.String()), &factoriesResponse) fmt.Printf("%d - %d", w.Code, len(factoriesResponse)) // Output: // 200 - 3 }
func ExampleInstance_Create() { config, _ := puaro.ConfigFromFile("../../configs/test.json") ds := &storage.Dataset{Name: "Iris"} attrs := &instance.Attributes{ "attr1": "value1", "attr2": "value2", "attr3": "value3", } ps := httprouter.Params{ httprouter.Param{"dataset", "iris"}, httprouter.Param{"collection", "satosa"}, } params, _ := marshaller.IoReader(attrs) req, _ := http.NewRequest("POST", "/", params) db, _ := redis.NewDB(config) storage := storage.New(db) storage.Clean() if err := storage.Insert(ds); err != nil { fmt.Printf("%s\n", err) return } instance := api.InstanceHandler{storage} resp := httptest.NewRecorder() instance.Create(resp, req, ps) fmt.Printf("RESPONSE CODE: %d\n", resp.Code) // Output: // RESPONSE CODE: 200 }