// Ensure a cursor iterator does not go past the end time. func TestFloatCursorIterator_EndTime(t *testing.T) { cur := NewCursor([]CursorItem{ {Key: 0, Value: float64(100)}, {Key: 3, Value: float64(200)}, {Key: 4, Value: float64(300)}, }, true) itr := tsdb.NewFloatCursorIterator("x", nil, cur, influxql.IteratorOptions{ Expr: &influxql.VarRef{Val: "value"}, Ascending: true, EndTime: 3, }) defer itr.Close() // Verify that only two points are emitted. if p := itr.Next(); p == nil || p.Time != 0 { t.Fatalf("unexpected point(0): %s", spew.Sdump(p)) } if p := itr.Next(); p == nil || p.Time != 3 { t.Fatalf("unexpected point(1): %s", spew.Sdump(p)) } if p := itr.Next(); p != nil { t.Fatalf("expected eof, got: %s", spew.Sdump(p)) } }
// Ensure a cursor with a single ref value can be converted into an iterator. func TestFloatCursorIterator_SingleValue(t *testing.T) { cur := NewCursor([]CursorItem{ {Key: 0, Value: float64(100)}, {Key: 3, Value: float64(200)}, }, true) opt := influxql.IteratorOptions{ Expr: &influxql.VarRef{Val: "value"}, Ascending: true, StartTime: influxql.MinTime, EndTime: influxql.MaxTime, } itr := tsdb.NewFloatCursorIterator("series0", map[string]string{"host": "serverA"}, cur, opt) defer itr.Close() if p := itr.Next(); !deep.Equal(p, &influxql.FloatPoint{ Name: "series0", Time: 0, Value: float64(100), }) { t.Fatalf("unexpected point(0): %s", spew.Sdump(p)) } if p := itr.Next(); !deep.Equal(p, &influxql.FloatPoint{ Name: "series0", Time: 3, Value: float64(200), }) { t.Fatalf("unexpected point(1): %s", spew.Sdump(p)) } if p := itr.Next(); p != nil { t.Fatalf("expected eof, got: %s", spew.Sdump(p)) } }
// Ensure a cursor with multiple values can be converted into an iterator. func TestFloatCursorIterator_Aux_MultipleValues(t *testing.T) { cur := NewCursor([]CursorItem{ {Key: 0, Value: map[string]interface{}{"val1": float64(100), "val2": "foo"}}, {Key: 3, Value: map[string]interface{}{"val1": float64(200), "val2": "bar"}}, }, true) opt := influxql.IteratorOptions{ Aux: []string{"val1", "val2"}, Ascending: true, StartTime: influxql.MinTime, EndTime: influxql.MaxTime, } itr := tsdb.NewFloatCursorIterator("series0", map[string]string{"host": "serverA"}, cur, opt) defer itr.Close() if p := itr.Next(); !deep.Equal(p, &influxql.FloatPoint{ Name: "series0", Time: 0, Value: math.NaN(), Aux: []interface{}{float64(100), "foo"}, }) { t.Fatalf("unexpected point(0): %s", spew.Sdump(p)) } if p := itr.Next(); !deep.Equal(p, &influxql.FloatPoint{ Name: "series0", Time: 3, Value: math.NaN(), Aux: []interface{}{float64(200), "bar"}, }) { t.Fatalf("unexpected point(1): %s", spew.Sdump(p)) } if p := itr.Next(); p != nil { t.Fatalf("expected eof, got: %s", spew.Sdump(p)) } }