Exemple #1
0
func TestStorage_Datasets(t *testing.T) {
	bucket, _ := redis.NewBucket(config)

	dataset1 := storage.NewDataset("posts", bucket)
	dataset2 := storage.NewDataset("users", bucket)

	storage := storage.New(bucket)
	storage.Clean()

	storage.Insert(dataset1)
	storage.Insert(dataset2)

	datasets := storage.Datasets()

	if len(datasets) != 2 {
		t.Errorf("Want 2 got %d\n", len(datasets))
	}
}
Exemple #2
0
func (handler *DatasetHandler) Create(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	puaro.HTTPLogger(r)

	storage := handler.Storage
	dataset := storage.NewDataset("")

	unmarshaller.IoReader(r.Body, dataset)

	err := storage.Insert(dataset)
	if err != nil {
		w.WriteHeader(400)
		fmt.Fprint(w, err)
		return
	}

	w.WriteHeader(200)
}
Exemple #3
0
func TestDataset_Insert(t *testing.T) {
	bucket, _ := redis.NewBucket(config)

	dataset := storage.NewDataset("iris", bucket)
	dataset.Clean()

	col1 := collections.NewList("setosa", bucket)
	col2 := collections.NewHash("virginica", bucket)

	dataset.Insert(col1.Name, col1)
	dataset.Insert(col1.Name, col2)

	// TODO(datagentleman): will be fixed after Hash.All() will be implemented
	// collections := dataset.All()

	// if len(collections) != 2 {
	// 	t.Errorf("Want 2 got %d\n", len(collections))
	// }
}
Exemple #4
0
func (handler *InstanceHandler) Create(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	storage := handler.Storage
	dataset := storage.NewDataset(params.ByName("dataset"))

	instance := &instance.Attributes{}
	if err := unmarshaller.IoReader(r.Body, instance); err != nil {
		w.WriteHeader(400)
		fmt.Fprint(w, err)
		return
	}

	collection := dataset.NewListCollection(params.ByName("collection"))
	if err := collection.Insert(instance); err != nil {
		w.WriteHeader(400)
		fmt.Fprint(w, err)
		return
	}

	w.WriteHeader(200)
}
Exemple #5
0
//
// /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
}
Exemple #6
0
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
}