OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // 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 » » » » keys, err := ds.AllocateIDs(keys...) |
166 So(err, ShouldBeNil) | 167 So(err, ShouldBeNil) |
167 » » » » So(start, ShouldEqual, 2) | 168 » » » » So(len(keys), ShouldEqual, 100) |
168 | 169 |
| 170 // Assert that none of our keys share the same I
D. |
| 171 ids := make(map[int64]struct{}) |
| 172 for _, k := range keys { |
| 173 ids[k.IntID()] = struct{}{} |
| 174 } |
| 175 So(len(ids), ShouldEqual, len(keys)) |
| 176 |
| 177 // Put a new object and ensure that it is alloca
ted an unused ID. |
169 f := &Foo{Val: 10} | 178 f := &Foo{Val: 10} |
170 So(ds.Put(f), ShouldBeNil) | 179 So(ds.Put(f), ShouldBeNil) |
171 k := ds.KeyForObj(f) | 180 k := ds.KeyForObj(f) |
172 So(k.String(), ShouldEqual, "dev~app::/Foo,102") | 181 So(k.String(), ShouldEqual, "dev~app::/Foo,102") |
| 182 |
| 183 _, ok := ids[k.IntID()] |
| 184 So(ok, ShouldBeFalse) |
173 }) | 185 }) |
174 }) | 186 }) |
175 | 187 |
176 Convey("implements DSTransactioner", func() { | 188 Convey("implements DSTransactioner", func() { |
177 Convey("Put", func() { | 189 Convey("Put", func() { |
178 f := &Foo{Val: 10} | 190 f := &Foo{Val: 10} |
179 So(ds.Put(f), ShouldBeNil) | 191 So(ds.Put(f), ShouldBeNil) |
180 k := ds.KeyForObj(f) | 192 k := ds.KeyForObj(f) |
181 So(k.String(), ShouldEqual, "dev~app::/Foo,1") | 193 So(k.String(), ShouldEqual, "dev~app::/Foo,1") |
182 | 194 |
(...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. | 768 // 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) | 769 So(dsS.Get(infoS.Get(ctx).MustNamespace("qux")).PutMulti
(foos), ShouldBeNil) |
758 dsS.Get(ctx).Testable().CatchupIndexes() | 770 dsS.Get(ctx).Testable().CatchupIndexes() |
759 | 771 |
760 results = nil | 772 results = nil |
761 So(dsS.Get(infoS.Get(ctx).MustNamespace("qux")).GetAll(q
, &results), ShouldBeNil) | 773 So(dsS.Get(infoS.Get(ctx).MustNamespace("qux")).GetAll(q
, &results), ShouldBeNil) |
762 So(len(results), ShouldEqual, 2) | 774 So(len(results), ShouldEqual, 2) |
763 }) | 775 }) |
764 }) | 776 }) |
765 } | 777 } |
OLD | NEW |