Skip to content

Commit

Permalink
adding faker generator
Browse files Browse the repository at this point in the history
  • Loading branch information
aviaIguazio committed Jul 3, 2019
1 parent 689ada1 commit 9105c1d
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 1 deletion.
4 changes: 3 additions & 1 deletion httpblaster/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func (self *Executor) load_request_generator() (chan *request_generators.Request
}
break


case request_generators.LINE2STREAM:
req_gen = &request_generators.Line2StreamGenerator{}
break
Expand Down Expand Up @@ -123,6 +122,9 @@ func (self *Executor) load_request_generator() (chan *request_generators.Request
case request_generators.STATS2TSDB:
req_gen = &request_generators.Stats2TSDB{}
break
case request_generators.FAKER2KV:
req_gen = &request_generators.Faker2kv{}
break

default:
panic(fmt.Sprintf("unknown request generator %s", self.Workload.Generator))
Expand Down
5 changes: 5 additions & 0 deletions httpblaster/igz_data/igz_emd_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func NewEmdItem() *IgzEmdItem {
return i
}

func (self *IgzEmdItem) InitItem() {
self.Key = make(map[string]map[string]interface{})
self.Item = make(map[string]map[string]interface{})
}

type IgzEmdItemUpdate struct {
//TableName string
UpdateMode string
Expand Down
1 change: 1 addition & 0 deletions httpblaster/request_generators/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
REPLAY = "replay"
CSV2TSDB = "csv2tsdb"
STATS2TSDB = "stats2tsdb"
FAKER2KV = "faker2kv"
)

type RequestCommon struct {
Expand Down
64 changes: 64 additions & 0 deletions httpblaster/request_generators/faker2kv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package request_generators

import (
"github.com/v3io/http_blaster/httpblaster/config"
"github.com/v3io/http_blaster/httpblaster/data_generator"
"runtime"
"sync"
)

type Faker2KV struct {
workload config.Workload
RequestCommon
}

func (self *Faker2KV) UseCommon(c RequestCommon) {

}

func (self *Faker2KV) generate_request(ch_records chan []string, ch_req chan *Request, host string,
wg *sync.WaitGroup, cpuNumber int, wl config.Workload) {
defer wg.Done()
var faker = data_generator.Fake{}
for i := 0; i < wl.Count; i++ {

var contentType string = "text/html"
faker.GenerateRandomData()
json_payload := faker.ConvertToIgzEmdItemJson()
req := AcquireRequest()
self.PrepareRequest(contentType, self.workload.Header, "PUT",
self.base_uri, json_payload, host, req.Request)
ch_req <- req
}
}

func (self *Faker2KV) generate(ch_req chan *Request, payload string, host string, wl config.Workload) {
defer close(ch_req)
var ch_records chan []string = make(chan []string, 1000)
wg := sync.WaitGroup{}
wg.Add(runtime.NumCPU())
for c := 0; c < runtime.NumCPU(); c++ {
go self.generate_request(ch_records, ch_req, host, &wg, c, wl)
}

close(ch_records)
wg.Wait()
}

func (self *Faker2KV) GenerateRequests(global config.Global, wl config.Workload, tls_mode bool, host string, ret_ch chan *Response, worker_qd int) chan *Request {

self.workload = wl

if self.workload.Header == nil {
self.workload.Header = make(map[string]string)
}
self.workload.Header["X-v3io-function"] = "PutItem"

self.SetBaseUri(tls_mode, host, self.workload.Container, self.workload.Target)

ch_req := make(chan *Request, worker_qd)

go self.generate(ch_req, self.workload.Payload, host, wl)

return ch_req
}
19 changes: 19 additions & 0 deletions tests/fakerGenerator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package tests

import (
"fmt"
"github.com/v3io/http_blaster/httpblaster/data_generator"
"testing"
)

func Test_facker_generator(t *testing.T) {
gen := data_generator.Faker{}
gen.GenerateRandomData()
}

func Test_facker_generator_to_igzemditem(t *testing.T) {
gen := data_generator.Faker{}
gen.GenerateRandomData()
str := gen.ConvertToIgzEmdItemJson()
fmt.Println(str)
}

0 comments on commit 9105c1d

Please sign in to comment.