refactor executor_test.go

This commit is contained in:
Matt Jaffee 2018-06-30 08:41:19 -05:00
parent ea77db895a
commit 29ad1287d4
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
4 changed files with 360 additions and 552 deletions

File diff suppressed because it is too large Load diff

View file

@ -37,20 +37,15 @@ func init() {
}
// modHasher represents a simple, mod-based hashing.
type modHasher struct{}
func (*modHasher) Hash(key uint64, n int) int { return int(key) % n }
// Test distributed TopN Row count across 3 nodes.
func TestClient_MultiNode(t *testing.T) {
c := test.MustRunCluster(t, 3,
[]server.CommandOption{
server.OptCommandServerOptions(pilosa.OptServerNodeID("node0"), pilosa.OptServerClusterHasher(&modHasher{}))},
server.OptCommandServerOptions(pilosa.OptServerNodeID("node0"), pilosa.OptServerClusterHasher(&test.ModHasher{}))},
[]server.CommandOption{
server.OptCommandServerOptions(pilosa.OptServerNodeID("node1"), pilosa.OptServerClusterHasher(&modHasher{}))},
server.OptCommandServerOptions(pilosa.OptServerNodeID("node1"), pilosa.OptServerClusterHasher(&test.ModHasher{}))},
[]server.CommandOption{
server.OptCommandServerOptions(pilosa.OptServerNodeID("node2"), pilosa.OptServerClusterHasher(&modHasher{}))},
server.OptCommandServerOptions(pilosa.OptServerNodeID("node2"), pilosa.OptServerClusterHasher(&test.ModHasher{}))},
)
defer c.Close()

View file

@ -21,6 +21,11 @@ import (
"github.com/pilosa/pilosa"
)
// modHasher represents a simple, mod-based hashing.
type ModHasher struct{}
func (*ModHasher) Hash(key uint64, n int) int { return int(key) % n }
// NewCluster returns a cluster with n nodes and uses a mod-based hasher.
func NewCluster(n int) *pilosa.Cluster {
path, err := ioutil.TempDir("", "pilosa-cluster-")
@ -30,7 +35,7 @@ func NewCluster(n int) *pilosa.Cluster {
c := pilosa.NewCluster()
c.ReplicaN = 1
c.Hasher = &modHasher{}
c.Hasher = &ModHasher{}
c.Path = path
c.Topology = pilosa.NewTopology()
@ -56,8 +61,3 @@ func newURI(scheme, host string, port uint16) pilosa.URI {
uri.SetPort(port)
return *uri
}
// modHasher represents a simple, mod-based hashing.
type modHasher struct{}
func (*modHasher) Hash(key uint64, n int) int { return int(key) % n }

View file

@ -121,6 +121,15 @@ func (h *Holder) Row(index, field string, rowID uint64) *pilosa.Row {
return row
}
func (h *Holder) RowAttrStore(index, field string) pilosa.AttrStore {
idx := h.MustCreateIndexIfNotExists(index, pilosa.IndexOptions{})
f, err := idx.CreateFieldIfNotExists(field, pilosa.FieldOptions{})
if err != nil {
panic(err)
}
return f.RowAttrStore()
}
// ViewRow returns a Row for a given field and view.
func (h *Holder) ViewRow(index, field, view string, rowID uint64) *pilosa.Row {
idx := h.MustCreateIndexIfNotExists(index, pilosa.IndexOptions{})