package benchcontroller
import (
- //"./dbconnector";
+ "./dbconnector";
"fmt";
- "time";
"strings";
"strconv";
"os";
func MainLoop(conf *BenchControllerConfig, commInChan chan string, commOutChan chan string)
{
for {
- time.Sleep(1000000000);
i := <-commInChan;
fmt.Printf("coms: %s\n", i);
conf.dbpass = calls[4];
conf.dbname = calls[5];
- case "asdf":
+ case "begin":
// get ready to bench - start the clients
os.Stdout.WriteString("ready clients\n");
+
+ comchan := make(chan int);
+ var cont bool;
+
+
+ go dbconnector.DBSetup("mysql", conf.dbhost, conf.dbuser, conf.dbpass, conf.dbname, conf.datamult, comchan);
+ cont=true;
+
+ for cont{
+ val := <- comchan;
+ fmt.Printf("val: %d\n", val);
+ if val == 100 {
+ cont = false;
+ }
+ }
+
+ os.Stdout.WriteString("ok, im done\n");
case "qwer":
// start the clients
os.Stdout.WriteString("start clients\n");
// um yes... its a db connector
package dbconnector
+import (
+ "./dbibridge";
+ "time";
+ "rand";
+)
+
type DBConnector struct {
// err, yes
}
+
+func CreateRandomText(len int) (str string)
+{
+ buf := make([]byte, len+2);
+
+ rand.Seed(time.Nanoseconds());
+
+ for i:=0; i<len; i++ {
+ switch(rand.Int()%3) {
+ case 0:
+ buf[i] = uint8(rand.Int()%26+65);
+ case 1:
+ buf[i] = uint8(rand.Int()%26+97);
+ case 2:
+ buf[i] = uint8(rand.Int()%10+48);
+ }
+ buf[i+1] = 0;
+
+ }
+
+ return string(buf);
+}
+
func DBSetup(dbtype string, host string, username string, password string, database string, datamult int, comout chan int)
{
dbibridge.DBIConnect(Dbconn, "mysql", host, username, password, database);
if dbtype == "mysql" {
- dbibridge.ExecSQL("create table WAREHOUSE (
- W_ID integer NOT NULL,
- W_NAME CHARACTER(10),
- W_STREET_1 CHARACTER(20),
- W_STREET_2 CHARACTER(20),
- W_CITY CHARACTER(20),
- W_STATE CHARACTER(2),
- W_ZIP CHARACTER(9),
- W_TAX integer,
- W_YTD integer,
+ dbibridge.ExecSQL(Dbconn,"create table WAREHOUSE ( \
+ W_ID integer NOT NULL, \
+ W_NAME CHARACTER(10), \
+ W_STREET_1 CHARACTER(20), \
+ W_STREET_2 CHARACTER(20), \
+ W_CITY CHARACTER(20), \
+ W_STATE CHARACTER(2), \
+ W_ZIP CHARACTER(9), \
+ W_TAX integer, \
+ W_YTD integer, \
PRIMARY KEY(W_ID))");
- dbibridge.ExecSQL("create table DISTRICT (
- D_ID integer NOT NULL,
- D_W_ID integer NOT NULL,
- D_NAME CHARACTER(10),
- D_STREET_1 CHARACTER(20),
- D_STREET_2 CHARACTER(20),
- D_CITY CHARACTER(20),
- D_STATE CHARACTER(2),
- D_ZIP CHARACTER(9),
- D_TAX integer,
- D_YTD integer,
- D_NEXT_O_ID integer,
+ dbibridge.ExecSQL(Dbconn,"create table DISTRICT ( \
+ D_ID integer NOT NULL, \
+ D_W_ID integer NOT NULL, \
+ D_NAME CHARACTER(10), \
+ D_STREET_1 CHARACTER(20), \
+ D_STREET_2 CHARACTER(20), \
+ D_CITY CHARACTER(20), \
+ D_STATE CHARACTER(2), \
+ D_ZIP CHARACTER(9), \
+ D_TAX integer, \
+ D_YTD integer, \
+ D_NEXT_O_ID integer, \
PRIMARY KEY(D_W_ID, D_ID))");
- dbibridge.ExecSQL("create table ITEM (
- I_ID integer NOT NULL,
- I_IM_ID integer,
- I_NAME CHARACTER(24),
- I_PRICE integer,
- I_DATA CHARACTER(50),
+ dbibridge.ExecSQL(Dbconn,"create table ITEM ( \
+ I_ID integer NOT NULL, \
+ I_IM_ID integer, \
+ I_NAME CHARACTER(24), \
+ I_PRICE integer, \
+ I_DATA CHARACTER(50), \
PRIMARY KEY(I_ID))");
}
+
+ for i := 1; i < 100; i += 10 {
+ time.Sleep(1000000000);
+ comout <- i;
+ }
+ comout <- 100;
+
+ // now we need to actually create data in the tables...
+
dbibridge.DBIDisconnect(Dbconn);
}