add SetFieldValue() method to TestCluster and use in tests

This commit is contained in:
Travis Turner 2017-11-06 10:43:55 -06:00
parent 7116232625
commit 0d5a2e7bfd
No known key found for this signature in database
GPG key ID: 7F08008DFD9314C9
2 changed files with 62 additions and 2 deletions

View file

@ -499,11 +499,30 @@ func TestCluster_ResizeStates(t *testing.T) {
t.Fatal(err)
}
// Add Data to node0.
// Add Bit Data to node0.
tc.CreateFrame("i", "f", pilosa.FrameOptions{})
tc.SetBit("i", "f", "standard", 1, 101, nil)
tc.SetBit("i", "f", "standard", 1, 1300000, nil)
// Add Field Data to node0.
tc.CreateFrame("i", "fields", pilosa.FrameOptions{
InverseEnabled: false,
RangeEnabled: true,
CacheType: pilosa.CacheTypeNone,
Fields: []*pilosa.Field{
{
Name: "fld0",
Type: pilosa.FieldTypeInt,
Min: -100,
Max: 100,
},
},
})
tc.SetFieldValue("i", "fields", 1, "fld0", -10)
tc.SetFieldValue("i", "fields", 1, "fld0", 10)
tc.SetFieldValue("i", "fields", 1300000, "fld0", -99)
tc.SetFieldValue("i", "fields", 1300000, "fld0", 99)
// AddNode needs to block until the resize process has completed.
tc.AddNode(false)
@ -528,6 +547,7 @@ func TestCluster_ResizeStates(t *testing.T) {
t.Errorf("expected node1 topology: %v, but got: %v", expectedTop, node1.Topology)
}
// Bits
// Verify that node-1 contains the fragment (i/f/standard/1) transferred from node-0.
node0Frame := node0.Holder.Frame("i", "f")
node0View := node0Frame.View("standard")
@ -540,7 +560,23 @@ func TestCluster_ResizeStates(t *testing.T) {
// Ensure checksums are the same.
orig := node0Fragment.Checksum()
if chksum := node1Fragment.Checksum(); !bytes.Equal(chksum, orig) {
t.Fatalf("expected checksum to match: %x - %x", chksum, orig)
t.Fatalf("expected standard view checksum to match: %x - %x", chksum, orig)
}
// Values
// Verify that node-1 contains the fragment (i/fields/field_fld0/1) transferred from node-0.
node0Frame = node0.Holder.Frame("i", "fields")
node0View = node0Frame.View("field_fld0")
node0Fragment = node0View.Fragment(1)
node1Frame = node1.Holder.Frame("i", "fields")
node1View = node1Frame.View("field_fld0")
node1Fragment = node1View.Fragment(1)
// Ensure checksums are the same.
orig = node0Fragment.Checksum()
if chksum := node1Fragment.Checksum(); !bytes.Equal(chksum, orig) {
t.Fatalf("expected field view checksum to match: %x - %x", chksum, orig)
}
// Close TestCluster.

View file

@ -129,6 +129,30 @@ func (t *TestCluster) SetBit(index, frame, view string, rowID, colID uint64, x *
return nil
}
func (t *TestCluster) SetFieldValue(index, frame string, columnID uint64, name string, value int64) error {
// Determine which node should receive the SetFieldValue.
c0 := t.Clusters[0] // use the first node's cluster to determine slice location.
slice := columnID / pilosa.SliceWidth
nodes := c0.FragmentNodes(index, slice)
for _, node := range nodes {
c := t.clusterByURI(node.URI)
if c == nil {
continue
}
f := c.Holder.Frame(index, frame)
if f == nil {
return fmt.Errorf("index/frame does not exist: %s/%s", index, frame)
}
_, err := f.SetFieldValue(columnID, name, value)
if err != nil {
return err
}
}
return nil
}
func (t *TestCluster) clusterByURI(uri pilosa.URI) *pilosa.Cluster {
for _, c := range t.Clusters {
if c.URI == uri {