Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Unified Diff: server/logdog/storage/bigtable/rowKey_test.go

Issue 1872903002: LogDog: Enable keys-only BigTable queries. (Closed) Base URL: https://github.com/luci/luci-go@logdog-archive-v2
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: server/logdog/storage/bigtable/rowKey_test.go
diff --git a/server/logdog/storage/bigtable/rowKey_test.go b/server/logdog/storage/bigtable/rowKey_test.go
index e5651f0a18d2c3c405557e301ba529d0aad4a172..2ba96413f0311cc87d9e45ad5e12fd01687b0308 100644
--- a/server/logdog/storage/bigtable/rowKey_test.go
+++ b/server/logdog/storage/bigtable/rowKey_test.go
@@ -6,6 +6,7 @@ package bigtable
import (
"fmt"
+ "strings"
"testing"
. "github.com/smartystreets/goconvey/convey"
@@ -16,10 +17,10 @@ func TestRowKey(t *testing.T) {
Convey(`A row key, constructed from "a/b/+/c/d"`, t, func() {
path := "a/b/+/c/d"
- rk := newRowKey(path, 1337)
+ rk := newRowKey(path, 1337, 42)
Convey(`Shares a path with a row key from the same Path.`, func() {
- So(rk.sharesPathWith(newRowKey(path, 2468)), ShouldBeTrue)
+ So(rk.sharesPathWith(newRowKey(path, 2468, 0)), ShouldBeTrue)
})
for _, v := range []string{
@@ -28,11 +29,11 @@ func TestRowKey(t *testing.T) {
"",
} {
Convey(fmt.Sprintf(`Does not share a path with: %q`, v), func() {
- So(rk.sharesPathWith(newRowKey(v, 0)), ShouldBeFalse)
+ So(rk.sharesPathWith(newRowKey(v, 0, 0)), ShouldBeFalse)
})
}
- Convey(`Can be encoded, then decoded into its hash and index.`, func() {
+ Convey(`Can be encoded, then decoded into its fields.`, func() {
enc := rk.encode()
So(len(enc), ShouldBeLessThanOrEqualTo, maxEncodedKeySize)
@@ -41,10 +42,11 @@ func TestRowKey(t *testing.T) {
So(drk.pathHash, ShouldResemble, rk.pathHash)
So(drk.index, ShouldEqual, rk.index)
+ So(drk.count, ShouldEqual, rk.count)
})
})
- Convey(`A series of row keys should be ascendingly sorted and parsable.`, t, func() {
+ Convey(`A series of ordered row keys`, t, func() {
prev := ""
for _, i := range []int64{
-1, /* Why not? */
@@ -55,23 +57,47 @@ func TestRowKey(t *testing.T) {
1029,
1337,
} {
- rk := newRowKey("test", i)
+ Convey(fmt.Sprintf(`Row key %d should be ascendingly sorted and parsable.`, i), func() {
+ rk := newRowKey("test", i, i)
- // Test that it encodes/decodes back to identity.
- enc := rk.encode()
- drk, err := decodeRowKey(enc)
- So(err, ShouldBeNil)
- So(drk.index, ShouldEqual, i)
+ // Test that it encodes/decodes back to identity.
+ enc := rk.encode()
+ drk, err := decodeRowKey(enc)
+ So(err, ShouldBeNil)
+ So(drk.index, ShouldEqual, i)
- // Assert that it is ordered.
- if prev != "" {
- So(prev, ShouldBeLessThan, enc)
+ // Assert that it is ordered.
+ if prev != "" {
+ So(prev, ShouldBeLessThan, enc)
- prevp, err := decodeRowKey(prev)
- So(err, ShouldBeNil)
- So(prevp.sharesPathWith(rk), ShouldBeTrue)
- So(prevp.index, ShouldBeLessThan, drk.index)
- }
+ prevp, err := decodeRowKey(prev)
+ So(err, ShouldBeNil)
+ So(prevp.sharesPathWith(rk), ShouldBeTrue)
+ So(prevp.index, ShouldBeLessThan, drk.index)
+ So(prevp.count, ShouldBeLessThan, drk.count)
+ }
+
+ Convey(`Legacy row key value will parse with count 0.`, func() {
+ if rk.count > 0 {
+ enc = enc[:strings.LastIndex(enc, "~")]
+ }
+
+ drk, err = decodeRowKey(enc)
+ So(err, ShouldBeNil)
+ So(drk.index, ShouldEqual, i)
+ So(drk.count, ShouldEqual, 0)
+
+ // Assert that it is ordered.
+ if prev != "" {
+ So(prev, ShouldBeLessThan, enc)
+
+ prevp, err := decodeRowKey(prev)
+ So(err, ShouldBeNil)
+ So(prevp.sharesPathWith(rk), ShouldBeTrue)
+ So(prevp.index, ShouldBeLessThan, drk.index)
+ }
+ })
+ })
}
})

Powered by Google App Engine
This is Rietveld 408576698