OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package memory | 5 package memory |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 "testing" | 9 "testing" |
10 "time" | 10 "time" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 "Val": {dsS.MkProperty(
10)}, | 155 "Val": {dsS.MkProperty(
10)}, |
156 "Name": {dsS.MkProperty(
"")}, | 156 "Name": {dsS.MkProperty(
"")}, |
157 "$key": {dsS.MkPropertyN
I(keys[i])}, | 157 "$key": {dsS.MkPropertyN
I(keys[i])}, |
158 }) | 158 }) |
159 } | 159 } |
160 }) | 160 }) |
161 | 161 |
162 }) | 162 }) |
163 | 163 |
164 Convey("allocating ids prevents their use", func() { | 164 Convey("allocating ids prevents their use", func() { |
165 » » » » start, err := ds.AllocateIDs(ds.MakeKey("Foo", 0
), 100) | 165 » » » » keys := ds.NewIncompleteKeys(100, "Foo", nil) |
166 » » » » So(err, ShouldBeNil) | 166 » » » » So(ds.AllocateIDs(keys), ShouldBeNil) |
167 » » » » So(start, ShouldEqual, 2) | 167 » » » » So(len(keys), ShouldEqual, 100) |
168 | 168 |
| 169 // Assert that none of our keys share the same I
D. |
| 170 ids := make(map[int64]struct{}) |
| 171 for _, k := range keys { |
| 172 ids[k.IntID()] = struct{}{} |
| 173 } |
| 174 So(len(ids), ShouldEqual, len(keys)) |
| 175 |
| 176 // Put a new object and ensure that it is alloca
ted an unused ID. |
169 f := &Foo{Val: 10} | 177 f := &Foo{Val: 10} |
170 So(ds.Put(f), ShouldBeNil) | 178 So(ds.Put(f), ShouldBeNil) |
171 k := ds.KeyForObj(f) | 179 k := ds.KeyForObj(f) |
172 So(k.String(), ShouldEqual, "dev~app::/Foo,102") | 180 So(k.String(), ShouldEqual, "dev~app::/Foo,102") |
| 181 |
| 182 _, ok := ids[k.IntID()] |
| 183 So(ok, ShouldBeFalse) |
173 }) | 184 }) |
174 }) | 185 }) |
175 | 186 |
176 Convey("implements DSTransactioner", func() { | 187 Convey("implements DSTransactioner", func() { |
177 Convey("Put", func() { | 188 Convey("Put", func() { |
178 f := &Foo{Val: 10} | 189 f := &Foo{Val: 10} |
179 So(ds.Put(f), ShouldBeNil) | 190 So(ds.Put(f), ShouldBeNil) |
180 k := ds.KeyForObj(f) | 191 k := ds.KeyForObj(f) |
181 So(k.String(), ShouldEqual, "dev~app::/Foo,1") | 192 So(k.String(), ShouldEqual, "dev~app::/Foo,1") |
182 | 193 |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 // Add "foos" to a new namespace, then confirm that it g
ets indexed. | 767 // Add "foos" to a new namespace, then confirm that it g
ets indexed. |
757 So(dsS.Get(infoS.Get(ctx).MustNamespace("qux")).PutMulti
(foos), ShouldBeNil) | 768 So(dsS.Get(infoS.Get(ctx).MustNamespace("qux")).PutMulti
(foos), ShouldBeNil) |
758 dsS.Get(ctx).Testable().CatchupIndexes() | 769 dsS.Get(ctx).Testable().CatchupIndexes() |
759 | 770 |
760 results = nil | 771 results = nil |
761 So(dsS.Get(infoS.Get(ctx).MustNamespace("qux")).GetAll(q
, &results), ShouldBeNil) | 772 So(dsS.Get(infoS.Get(ctx).MustNamespace("qux")).GetAll(q
, &results), ShouldBeNil) |
762 So(len(results), ShouldEqual, 2) | 773 So(len(results), ShouldEqual, 2) |
763 }) | 774 }) |
764 }) | 775 }) |
765 } | 776 } |
OLD | NEW |