Skip to content

Commit

Permalink
added testdata generator
Browse files Browse the repository at this point in the history
  • Loading branch information
alash3al committed Dec 29, 2018
1 parent b763a02 commit f1dc7ec
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 35 deletions.
44 changes: 44 additions & 0 deletions init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"flag"
"log"
"math/rand"
"runtime"

"github.com/alash3al/libsrchx"
"github.com/icrowley/fake"
)

func init() {
var err error
flag.Parse()

runtime.GOMAXPROCS(*flagWorkers)

store, err = srchx.NewStore(*flagEngine, *flagStoragePath)
if err != nil {
log.Fatal(err)
}

if *flagGenFakeData > 0 {
go func() {
ndx, _ := store.GetIndex("test/fake")
fake.SetLang("en")
for i := 0; i < *flagGenFakeData; i++ {
ndx.Put(map[string]interface{}{
"full_name": fake.FullName(),
"country": fake.Country(),
"brand": fake.Brand(),
"email": fake.EmailAddress(),
"ip": fake.IPv4(),
"industry": fake.Industry(),
"age": rand.Intn(100),
"salary": rand.Intn(20) * 1000,
"power": rand.Intn(10),
"family": rand.Intn(10),
})
}
}()
}
}
36 changes: 1 addition & 35 deletions vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ package main

import (
"flag"
"log"
"math/rand"
"os"
"path"
"runtime"

"github.com/icrowley/fake"

"github.com/alash3al/libsrchx"
)

Expand All @@ -18,39 +14,9 @@ var (
flagEngine = flag.String("engine", "boltdb", "the engine to be used as a backend")
flagStoragePath = flag.String("storage", path.Join(path.Dir(os.Args[0]), "data"), "the storage path")
flagWorkers = flag.Int("workers", runtime.NumCPU(), "number of workers to be used")
flagGenFakeData = flag.Int("testdata", 0, "this will generate a `test/fake` collection with fake data just for testing")
)

var (
store *srchx.Store
)

func init() {
var err error
flag.Parse()

runtime.GOMAXPROCS(*flagWorkers)

store, err = srchx.NewStore(*flagEngine, *flagStoragePath)
if err != nil {
log.Fatal(err)
}

go func() {
ndx, _ := store.GetIndex("test/fake")
fake.SetLang("en")
for i := 0; i < 100000; i++ {
ndx.Put(map[string]interface{}{
"full_name": fake.FullName(),
"country": fake.Country(),
"brand": fake.Brand(),
"email": fake.EmailAddress(),
"ip": fake.IPv4(),
"industry": fake.Industry(),
"age": rand.Intn(100),
"salary": rand.Intn(20) * 1000,
"power": rand.Intn(10),
"family": rand.Intn(10),
})
}
}()
}

0 comments on commit f1dc7ec

Please sign in to comment.