Esempio n. 1
0
func GenerateJsons(count, seed int, prodfile, bagdir string) tc.KeyValues {
	runtime.GOMAXPROCS(45)
	keyValues := make(tc.KeyValues)
	options.outfile = "./out.txt"
	options.bagdir = bagdir
	options.count = count

	var err error

	// read production-file
	text, err := ioutil.ReadFile(prodfile)
	if err != nil {
		log.Fatal(err)
	}
	scope := compile(parsec.NewScanner(text)).(common.Scope)
	scope = monster.BuildContext(scope, uint64(seed), bagdir, prodfile)
	nterms := scope["_nonterminals"].(common.NTForms)
	// evaluate
	for i := 0; i < options.count; i++ {
		scope = scope.RebuildContext()
		val := evaluate("root", scope, nterms["s"])
		jsonString := val.(string)
		byt := []byte(jsonString)
		var dat map[string]interface{}
		if err := json.Unmarshal(byt, &dat); err != nil {
			panic(err)
		}
		dockey := dat["docid"].(string)
		keyValues[dockey] = dat
	}

	return keyValues
}
Esempio n. 2
0
func generate(text []byte, count int, prodfile string, outch chan<- []byte) {
	// compile
	root := compile(parsec.NewScanner(text)).(common.Scope)
	seed, bagdir, prodfile := uint64(options.seed), options.bagdir, prodfile
	scope := monster.BuildContext(root, seed, bagdir, prodfile)
	nterms := scope["_nonterminals"].(common.NTForms)

	// verify the sanity of json generated from production file
	var value map[string]interface{}
	if options.json {
		scope = scope.RebuildContext()
		val := evaluate("root", scope, nterms[options.nonterm])
		if err := json.Unmarshal([]byte(val.(string)), &value); err != nil {
			log.Fatalf("Invalid JSON %v\n", err)
		} else {
			outch <- []byte(val.(string))
		}
	}

	for i := 0; i < count; i++ {
		scope = scope.RebuildContext()
		val := evaluate("root", scope, nterms[options.nonterm])
		outch <- []byte(val.(string))
	}
}
Esempio n. 3
0
func generate(repeat int, prodfile string, outch chan<- [][]interface{}) {
	text, err := ioutil.ReadFile(prodfile)
	if err != nil {
		log.Fatal(err)
	}
	root := compile(parsec.NewScanner(text)).(mcommon.Scope)
	seed, bagdir, prodfile := uint64(options.seed), options.bagdir, prodfile
	scope := monster.BuildContext(root, seed, bagdir, prodfile)
	nterms := scope["_nonterminals"].(mcommon.NTForms)
	for i := 0; i < repeat; i++ {
		scope = scope.RebuildContext()
		val := evaluate("root", scope, nterms["s"])
		var arr [][]interface{}
		if err := json.Unmarshal([]byte(val.(string)), &arr); err != nil {
			log.Fatal(err)
		}
		outch <- arr
	}
}
Esempio n. 4
0
func generate(text []byte, count int, prodfile string, outch chan<- []byte) {
	// compile
	root := compile(parsec.NewScanner(text)).(common.Scope)
	seed, bagdir, prodfile := uint64(options.seed), options.bagdir, prodfile
	scope := monster.BuildContext(root, seed, bagdir, prodfile)
	nterms := scope["_nonterminals"].(common.NTForms)

	// verify the sanity of json generated from production file
	var value map[string]interface{}
	rnd := rand.New(rand.NewSource(int64(seed)))
	for i := 0; i < count; i++ {
		nonterm := options.nonterms[rnd.Intn(len(options.nonterms))]
		scope = scope.RebuildContext()
		val := []byte(evaluate("root", scope, nterms[nonterm]).(string))
		if !options.json {
			outch <- val
		} else if err := json.Unmarshal(val, &value); err == nil {
			outch <- val
		} else {
			log.Fatalf("Invalid JSON %v\n", err)
		}
	}
}
Esempio n. 5
0
func genDocuments(b *couchbase.Bucket, prodfile string, idx, n int) {
	// compile
	text, err := ioutil.ReadFile(prodfile)
	if err != nil {
		log.Fatal(err)
	}
	scope := compile(parsec.NewScanner(text)).(mcommon.Scope)
	seed, bagdir := uint64(options.seed), options.bagdir
	scope = monster.BuildContext(scope, seed, bagdir, prodfile)
	nterms := scope["_nonterminals"].(mcommon.NTForms)
	// evaluate
	for i := 0; i < options.count; i++ {
		scope = scope.RebuildContext()
		doc := evaluate("root", scope, nterms["s"]).(string)
		key := makeKey(prodfile, idx, i+1)
		err = b.SetRaw(key, options.expiry, []byte(doc))
		if err != nil {
			fmt.Printf("%T %v\n", err, err)
		}
		mf(err, "error setting document")
	}
	fmt.Printf("routine %v generated %v documents for %q\n", idx, n, b.Name)
	done <- true
}