Skip to content

Commit

Permalink
use internal client instead of go-pilosa, use ADD instead of wget
Browse files Browse the repository at this point in the history
  • Loading branch information
jaffee committed Nov 13, 2018
1 parent 37ac8b7 commit 0d4a46a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 92 deletions.
2 changes: 1 addition & 1 deletion Dockerfile-withgo
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN cd /go/src/github.com/pilosa/pilosa \
&& CGO_ENABLED=0 make install-dep install FLAGS="-a"

# download pumba for fault injection
RUN wget https://github.com/alexei-led/pumba/releases/download/0.6.0/pumba_linux_amd64 -O /pumba
ADD https://github.com/alexei-led/pumba/releases/download/0.6.0/pumba_linux_amd64 /pumba
RUN chmod +x /pumba

RUN cp /go/bin/pilosa /pilosa
Expand Down
120 changes: 29 additions & 91 deletions internal/clustertests/cluster_test.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,54 @@
package clustertest

import (
"io"
"context"
"os"
"os/exec"
"testing"
"time"

"github.com/pilosa/go-pilosa"
pi "github.com/pilosa/pilosa"
"github.com/pilosa/pilosa"
picli "github.com/pilosa/pilosa/http"
)

func TestClusterStuff(t *testing.T) {
if os.Getenv("ENABLE_PILOSA_CLUSTER_TESTS") != "1" {
t.Skip()
}
cli := getPilosaClient(t)
cli, err := picli.NewInternalClient("pilosa1:10101", picli.GetHTTPClient(nil))
if err != nil {
t.Fatalf("getting client: %v", err)
}

t.Run("long pause", func(t *testing.T) {
idx := pilosa.NewIndex("testidx")
err := cli.CreateIndex(idx)
err := cli.CreateIndex(context.Background(), "testidx", pilosa.IndexOptions{})
if err != nil {
t.Fatalf("creating index: %v", err)
}
f := idx.Field("testf", pilosa.OptFieldTypeSet(pilosa.CacheTypeRanked, 10))
err = cli.CreateField(f)
err = cli.CreateFieldWithOptions(context.Background(), "testidx", "testf", pilosa.FieldOptions{CacheType: pilosa.CacheTypeRanked, CacheSize: 100})
if err != nil {
t.Fatalf("creating field: %v", err)
}

data := make([]pilosa.Column, 1000)
for i := range data {
data[i].RowID = 0
data[i].ColumnID = uint64((i/10)*pi.ShardWidth + i%10)
data := make([]pilosa.Bit, 10)
for i := 0; i < 1000; i++ {
data[i%10].RowID = 0
data[i%10].ColumnID = uint64((i/10)*pilosa.ShardWidth + i%10)
shard := uint64(i / 10)
if i%10 == 9 {
err = cli.Import(context.Background(), "testidx", "testf", shard, data)
if err != nil {
t.Fatalf("importing: %v", err)
}
}
}

err = cli.ImportField(f, &colIterator{cols: data}, pilosa.OptImportBatchSize(1000))
if err != nil {
t.Fatalf("importing: %v", err)
}

r, err := cli.Query(idx.Count(f.Row(0)))
r, err := cli.Query(context.Background(), "testidx", &pilosa.QueryRequest{Index: "testidx", Query: "Count(Row(testf=0))"})
if err != nil {
t.Fatalf("count querying: %v", err)
}
if r.Result().Count() != 1000 {
t.Fatalf("count after import is %d", r.Result().Count())
if r.Results[0].(uint64) != 1000 {
t.Fatalf("count after import is %d", r.Results[0].(uint64))
}

pcmd := exec.Command("/pumba", "pause", "clustertests_pilosa3_1", "--duration", "10s")
Expand All @@ -60,84 +63,19 @@ func TestClusterStuff(t *testing.T) {
if err != nil {
t.Fatalf("waiting on pumba pause cmd: %v", err)
}
// TODO change the sleep to wait for status to return to NORMAL or timeout once we have Status.State support in go-pilosa

// TODO change the sleep to wait for status to return to NORMAL - need support in internal client for getting status
t.Log("done with pause, waiting for stability")
time.Sleep(time.Second * 3)
t.Log("done waiting for stability")

r, err = cli.Query(idx.Count(f.Row(0)))
r, err = cli.Query(context.Background(), "testidx", &pilosa.QueryRequest{Index: "testidx", Query: "Count(Row(testf=0))"})
if err != nil {
t.Fatalf("count querying: %v", err)
} else if r.Result().Count() != 1000 {
t.Fatalf("count after import is %d", r.Result().Count())
}
if r.Results[0].(uint64) != 1000 {
t.Fatalf("count after import is %d", r.Results[0].(uint64))
}
})

}

// Utils

func getPilosaClient(t *testing.T) *pilosa.Client {
cli, err := pilosa.NewClient("pilosa1:10101")
if err != nil {
time.Sleep(time.Millisecond * 40)
}
time.Sleep(time.Second * 2)
// TODO uncomment the following once we get the version of go-pilosa that has the State field on Status.
// start := time.Now()
// for i := 0; true; i++ {
// s, err := cli.Status()
// if i > 800 {
// t.Fatalf("couldn't connect to cluster after %d attempts and %v: state: %s, err: %v", i, time.Since(start), s.State, err)
// }
// if err != nil {
// time.Sleep(time.Millisecond * 40)
// continue
// }
// if s.State == "NORMAL" {
// break
// } else {
// time.Sleep(time.Millisecond * 40)
// }
// }

return cli
}

type colIterator struct {
cols []pilosa.Column
i uint
}

func (c *colIterator) NextRecord() (pilosa.Record, error) {
if int(c.i) >= len(c.cols) {
return nil, io.EOF
}
c.i++
return c.cols[c.i-1], nil
}

func TestColIterator(t *testing.T) {
data := make([]pilosa.Column, 3)
for i := range data {
data[i].RowID = 0
data[i].ColumnID = uint64((i/10)*pi.ShardWidth + i%10)
}

ci := colIterator{cols: data}
col := pilosa.Column{}
if rec, err := ci.NextRecord(); rec != col {
t.Fatalf("first record wrong: %v, err: %v", rec, err)
}
col.ColumnID = 1
if rec, err := ci.NextRecord(); rec != col || err != nil {
t.Fatalf("second record wrong: %v, err: %v", rec, err)
}
col.ColumnID = 2
if rec, err := ci.NextRecord(); rec != col || err != nil {
t.Fatalf("third record wrong: %v, err: %v", rec, err)
}
if rec, err := ci.NextRecord(); err != io.EOF {
t.Fatalf("should be EOF, but got %v, err: %v", rec, err)
}
}

0 comments on commit 0d4a46a

Please sign in to comment.