Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Some stupid tests #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func mapDiff(a, b destination.Map, aName, bName string) (diff []string) {
}

func TestSimpleConfig(t *testing.T) {
m, err := parseConfig(bytes.NewBufferString(`* 127.0.0.1`))
m, _, err := parseConfig(bytes.NewBufferString(`* 127.0.0.1`))
if err != nil {
t.Fatalf("Could not parse config: %s", err.Error())
}
Expand All @@ -73,7 +73,7 @@ func TestSimpleConfig(t *testing.T) {
}

func TestParseConfig(t *testing.T) {
m, err := parseConfig(bytes.NewBufferString(`
m, _, err := parseConfig(bytes.NewBufferString(`
@target_port 3304;
# Forward all unknown ;tables to default host
* default;
Expand Down Expand Up @@ -112,7 +112,7 @@ table3 =db3*100

func TestBadParseConfig(t *testing.T) {
needError := func(conf, substr string) {
_, err := parseConfig(bytes.NewBufferString(conf))
_, _, err := parseConfig(bytes.NewBufferString(conf))
if err == nil {
t.Errorf("Expected error for config %s", conf)
} else if !strings.Contains(err.Error(), substr) {
Expand Down
30 changes: 30 additions & 0 deletions core/inmem/buffer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package inmem

import (
"fmt"
"strconv"
"sync"
"testing"
)

func TestBuffer(t *testing.T) {
var wg sync.WaitGroup
file := "table1"
const len = 4

append := func(i int) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest to use another name for func. It is not recommended to use go reserved names

defer wg.Done()
k := ("Key:" + strconv.Itoa(i))
err := Write(fmt.Sprintf("%s.%d", file, i%2), []byte(k), true)
if err != nil {
t.Error(err)
}
}
for i := 1; i <= len; i++ {
wg.Add(1)
go append(i)

}
wg.Wait()
//fmt.Println(string(tableBufMap.v["table1.0"].values.b.Bytes()))
}
29 changes: 27 additions & 2 deletions core/persist/log_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package persist

import (
"fmt"
"strconv"
"sync"
"testing"
)

Expand All @@ -15,15 +18,37 @@ func TestAppendCrcHex(t *testing.T) {
}

func TestParseFileName(t *testing.T) {
if res := getTableFromFileName(getTableFileName("video_log_buffer (...)")); res != "video_log_buffer" {
if res := getTableFromFileName(getTableFileName("video_log_buffer (...)", false)); res != "video_log_buffer" {
t.Errorf("Could not parse filename: got '%s' instead of 'video_log_buffer'", res)
}

if res := getTableFromFileName(getTableFileName("video_log(...)")); res != "video_log" {
if res := getTableFromFileName(getTableFileName("video_log(...)", false)); res != "video_log" {
t.Errorf("Could not parse filename: got '%s' instead of 'video_log'", res)
}

if res := getTableFromFileName("random_stuff"); res != "" {
t.Errorf("Could not parse filename: got '%s' instead of ''", res)
}
}

func TestBuffer(t *testing.T) {
var wg sync.WaitGroup
file := "table1"
const len = 4

append := func(i int) {
defer wg.Done()
k := ("Key:" + strconv.Itoa(i))
err := Write(fmt.Sprintf("%s.%d", file, i%2), []byte(k), true)
if err != nil {
t.Error(err)
}
}
for i := 1; i <= len; i++ {
wg.Add(1)
go append(i)

}
wg.Wait()
//fmt.Println(string(tableBufMap.v["table1.0"].values.b.Bytes()))
}
57 changes: 57 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

//go test -timeout 50s github.com/recoilme/proxyhouse -run Test_Base
/*
func TestBase(t *testing.T) {
//log.SetOutput(ioutil.Discard) //disable log message on test
go main()

time.Sleep(1 * time.Second)

addr := ":8124"
//pipeline

c, err := net.Dial("tcp", addr)
if err != nil {
panic(err)
}
defer c.Close()
fmt.Println("Hello, test")

lotsa.Output = os.Stdout
lotsa.MemUsage = true

println("-- bulk --")
N := 10000
fmt.Printf("\n")
fmt.Printf("go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)
fmt.Printf("\n")
fmt.Printf(" number of cpus: %d\n", runtime.NumCPU())
fmt.Printf(" number of inserts: %d\n", N)
lotsa.Ops(N, runtime.NumCPU(), func(i, _ int) {
post(fmt.Sprintf("(%d)", i))
})
println("done")

time.Sleep(time.Duration(2) * time.Second)

}

func post(b string) {
bod := strings.NewReader(b)
req, err := http.NewRequest("POST", "http://127.0.0.1:8124/?query=INSERT%20INTO%20t%20VALUES", bod)
if err != nil {
panic(err)
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
_, err = ioutil.ReadAll(resp.Body)

if err != nil {
panic(err)
}
}
*/