mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-07 11:27:50 +00:00
refactor executor_test.go
This commit is contained in:
parent
ea77db895a
commit
29ad1287d4
4 changed files with 360 additions and 552 deletions
880
executor_test.go
880
executor_test.go
File diff suppressed because it is too large
Load diff
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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{})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue