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 storetest is imported exclusively by tests for Store implementations. | 5 // Package storetest is imported exclusively by tests for Store implementations. |
6 package storetest | 6 package storetest |
7 | 7 |
8 import ( | 8 import ( |
9 "bytes" | 9 "bytes" |
10 "fmt" | 10 "fmt" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 wantIncrSuccess: false, | 160 wantIncrSuccess: false, |
161 }, | 161 }, |
162 } | 162 } |
163 | 163 |
164 Convey("Set and get", t, func() { | 164 Convey("Set and get", t, func() { |
165 Convey("With no fields", func() { | 165 Convey("With no fields", func() { |
166 for i, test := range tests { | 166 for i, test := range tests { |
167 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { | 167 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { |
168 var m types.Metric | 168 var m types.Metric |
169 if test.bucketer != nil { | 169 if test.bucketer != nil { |
170 » » » » » » m = &fakeDistributionMetric{Fake
Metric{"m", "", []field.Field{}, test.typ}, test.bucketer} | 170 » » » » » » m = &fakeDistributionMetric{Fake
Metric{ |
| 171 » » » » » » » types.MetricInfo{"m", ""
, []field.Field{}, test.typ}, |
| 172 » » » » » » » types.MetricMetadata{}},
test.bucketer} |
171 } else { | 173 } else { |
172 » » » » » » m = &FakeMetric{"m", "", []field
.Field{}, test.typ} | 174 » » » » » » m = &FakeMetric{ |
| 175 » » » » » » » types.MetricInfo{"m", ""
, []field.Field{}, test.typ}, |
| 176 » » » » » » » types.MetricMetadata{}, |
| 177 » » » » » » } |
173 } | 178 } |
174 | 179 |
175 s := opts.Factory() | 180 s := opts.Factory() |
176 s.Register(m) | 181 s.Register(m) |
177 | 182 |
178 // Value should be nil initially. | 183 // Value should be nil initially. |
179 v, err := s.Get(ctx, m, time.Time{}, []i
nterface{}{}) | 184 v, err := s.Get(ctx, m, time.Time{}, []i
nterface{}{}) |
180 So(err, ShouldBeNil) | 185 So(err, ShouldBeNil) |
181 So(v, ShouldBeNil) | 186 So(v, ShouldBeNil) |
182 | 187 |
(...skipping 13 matching lines...) Expand all Loading... |
196 } | 201 } |
197 }) | 202 }) |
198 } | 203 } |
199 }) | 204 }) |
200 | 205 |
201 Convey("With fields", func() { | 206 Convey("With fields", func() { |
202 for i, test := range tests { | 207 for i, test := range tests { |
203 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { | 208 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { |
204 var m types.Metric | 209 var m types.Metric |
205 if test.bucketer != nil { | 210 if test.bucketer != nil { |
206 » » » » » » m = &fakeDistributionMetric{Fake
Metric{"m", "", []field.Field{field.String("f")}, test.typ}, test.bucketer} | 211 » » » » » » m = &fakeDistributionMetric{Fake
Metric{ |
| 212 » » » » » » » types.MetricInfo{"m", ""
, []field.Field{field.String("f")}, test.typ}, |
| 213 » » » » » » » types.MetricMetadata{}},
test.bucketer} |
207 } else { | 214 } else { |
208 » » » » » » m = &FakeMetric{"m", "", []field
.Field{field.String("f")}, test.typ} | 215 » » » » » » m = &FakeMetric{ |
| 216 » » » » » » » types.MetricInfo{"m", ""
, []field.Field{field.String("f")}, test.typ}, |
| 217 » » » » » » » types.MetricMetadata{}} |
209 } | 218 } |
210 | 219 |
211 s := opts.Factory() | 220 s := opts.Factory() |
212 s.Register(m) | 221 s.Register(m) |
213 | 222 |
214 // Values should be nil initially. | 223 // Values should be nil initially. |
215 v, err := s.Get(ctx, m, time.Time{}, mak
eInterfaceSlice("one")) | 224 v, err := s.Get(ctx, m, time.Time{}, mak
eInterfaceSlice("one")) |
216 So(err, ShouldBeNil) | 225 So(err, ShouldBeNil) |
217 So(v, ShouldBeNil) | 226 So(v, ShouldBeNil) |
218 v, err = s.Get(ctx, m, time.Time{}, make
InterfaceSlice("two")) | 227 v, err = s.Get(ctx, m, time.Time{}, make
InterfaceSlice("two")) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 263 |
255 Convey("With a fixed reset time", func() { | 264 Convey("With a fixed reset time", func() { |
256 for i, test := range tests { | 265 for i, test := range tests { |
257 if !test.wantSetSuccess { | 266 if !test.wantSetSuccess { |
258 continue | 267 continue |
259 } | 268 } |
260 | 269 |
261 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { | 270 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { |
262 var m types.Metric | 271 var m types.Metric |
263 if test.bucketer != nil { | 272 if test.bucketer != nil { |
264 » » » » » » m = &fakeDistributionMetric{Fake
Metric{"m", "", []field.Field{}, test.typ}, test.bucketer} | 273 » » » » » » m = &fakeDistributionMetric{Fake
Metric{ |
| 274 » » » » » » » types.MetricInfo{"m", ""
, []field.Field{}, test.typ}, |
| 275 » » » » » » » types.MetricMetadata{}},
test.bucketer} |
265 } else { | 276 } else { |
266 » » » » » » m = &FakeMetric{"m", "", []field
.Field{}, test.typ} | 277 » » » » » » m = &FakeMetric{ |
| 278 » » » » » » » types.MetricInfo{"m", ""
, []field.Field{}, test.typ}, |
| 279 » » » » » » » types.MetricMetadata{}} |
267 } | 280 } |
268 | 281 |
269 s := opts.Factory() | 282 s := opts.Factory() |
270 s.Register(m) | 283 s.Register(m) |
271 opts.RegistrationFinished(s) | 284 opts.RegistrationFinished(s) |
272 | 285 |
273 // Do the set with a fixed time. | 286 // Do the set with a fixed time. |
274 t := time.Date(1972, 5, 6, 7, 8, 9, 0, t
ime.UTC) | 287 t := time.Date(1972, 5, 6, 7, 8, 9, 0, t
ime.UTC) |
275 So(s.Set(ctx, m, t, []interface{}{}, tes
t.values[0]), ShouldBeNil) | 288 So(s.Set(ctx, m, t, []interface{}{}, tes
t.values[0]), ShouldBeNil) |
276 | 289 |
(...skipping 22 matching lines...) Expand all Loading... |
299 | 312 |
300 Convey("With a target set in the context", func() { | 313 Convey("With a target set in the context", func() { |
301 for i, test := range tests { | 314 for i, test := range tests { |
302 if !test.wantSetSuccess { | 315 if !test.wantSetSuccess { |
303 continue | 316 continue |
304 } | 317 } |
305 | 318 |
306 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { | 319 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { |
307 var m types.Metric | 320 var m types.Metric |
308 if test.bucketer != nil { | 321 if test.bucketer != nil { |
309 » » » » » » m = &fakeDistributionMetric{Fake
Metric{"m", "", []field.Field{}, test.typ}, test.bucketer} | 322 » » » » » » m = &fakeDistributionMetric{Fake
Metric{ |
| 323 » » » » » » » types.MetricInfo{"m", ""
, []field.Field{}, test.typ}, |
| 324 » » » » » » » types.MetricMetadata{}},
test.bucketer} |
310 } else { | 325 } else { |
311 » » » » » » m = &FakeMetric{"m", "", []field
.Field{}, test.typ} | 326 » » » » » » m = &FakeMetric{ |
| 327 » » » » » » » types.MetricInfo{"m", ""
, []field.Field{}, test.typ}, |
| 328 » » » » » » » types.MetricMetadata{}} |
312 } | 329 } |
313 | 330 |
314 s := opts.Factory() | 331 s := opts.Factory() |
315 s.Register(m) | 332 s.Register(m) |
316 opts.RegistrationFinished(s) | 333 opts.RegistrationFinished(s) |
317 | 334 |
318 // Create a context with a different tar
get. | 335 // Create a context with a different tar
get. |
319 t := target.Task{} | 336 t := target.Task{} |
320 t.AsProto().ServiceName = proto.String("
foo") | 337 t.AsProto().ServiceName = proto.String("
foo") |
321 ctxWithTarget := target.Set(ctx, &t) | 338 ctxWithTarget := target.Set(ctx, &t) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 }) | 371 }) |
355 } | 372 } |
356 }) | 373 }) |
357 | 374 |
358 Convey("With a decreasing value", func() { | 375 Convey("With a decreasing value", func() { |
359 for i, test := range tests { | 376 for i, test := range tests { |
360 if !test.typ.IsCumulative() || test.bucketer !=
nil { | 377 if !test.typ.IsCumulative() || test.bucketer !=
nil { |
361 continue | 378 continue |
362 } | 379 } |
363 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { | 380 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { |
364 » » » » » m := &FakeMetric{"m", "", []field.Field{
}, test.typ} | 381 » » » » » m := &FakeMetric{ |
| 382 » » » » » » types.MetricInfo{"m", "", []fiel
d.Field{}, test.typ}, |
| 383 » » » » » » types.MetricMetadata{}} |
365 s := opts.Factory() | 384 s := opts.Factory() |
366 s.Register(m) | 385 s.Register(m) |
367 | 386 |
368 // Set the bigger value. | 387 // Set the bigger value. |
369 So(s.Set(ctx, m, time.Time{}, []interfac
e{}{}, test.values[1]), ShouldBeNil) | 388 So(s.Set(ctx, m, time.Time{}, []interfac
e{}{}, test.values[1]), ShouldBeNil) |
370 | 389 |
371 // Setting the smaller value should fail
. | 390 // Setting the smaller value should fail
. |
372 So(s.Set(ctx, m, time.Time{}, []interfac
e{}{}, test.values[0]), ShouldNotBeNil) | 391 So(s.Set(ctx, m, time.Time{}, []interfac
e{}{}, test.values[0]), ShouldNotBeNil) |
373 }) | 392 }) |
374 } | 393 } |
375 }) | 394 }) |
376 }) | 395 }) |
377 | 396 |
378 Convey("Increment and get", t, func() { | 397 Convey("Increment and get", t, func() { |
379 Convey("With no fields", func() { | 398 Convey("With no fields", func() { |
380 for i, test := range tests { | 399 for i, test := range tests { |
381 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { | 400 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { |
382 var m types.Metric | 401 var m types.Metric |
383 if test.bucketer != nil { | 402 if test.bucketer != nil { |
384 » » » » » » m = &fakeDistributionMetric{Fake
Metric{"m", "", []field.Field{}, test.typ}, test.bucketer} | 403 » » » » » » m = &fakeDistributionMetric{Fake
Metric{ |
| 404 » » » » » » » types.MetricInfo{"m", ""
, []field.Field{}, test.typ}, |
| 405 » » » » » » » types.MetricMetadata{}},
test.bucketer} |
| 406 |
385 } else { | 407 } else { |
386 » » » » » » m = &FakeMetric{"m", "", []field
.Field{}, test.typ} | 408 » » » » » » m = &FakeMetric{ |
| 409 » » » » » » » types.MetricInfo{"m", ""
, []field.Field{}, test.typ}, |
| 410 » » » » » » » types.MetricMetadata{}} |
387 } | 411 } |
388 | 412 |
389 s := opts.Factory() | 413 s := opts.Factory() |
390 s.Register(m) | 414 s.Register(m) |
391 | 415 |
392 // Value should be nil initially. | 416 // Value should be nil initially. |
393 v, err := s.Get(ctx, m, time.Time{}, []i
nterface{}{}) | 417 v, err := s.Get(ctx, m, time.Time{}, []i
nterface{}{}) |
394 So(err, ShouldBeNil) | 418 So(err, ShouldBeNil) |
395 So(v, ShouldBeNil) | 419 So(v, ShouldBeNil) |
396 | 420 |
(...skipping 19 matching lines...) Expand all Loading... |
416 } | 440 } |
417 }) | 441 }) |
418 } | 442 } |
419 }) | 443 }) |
420 | 444 |
421 Convey("With fields", func() { | 445 Convey("With fields", func() { |
422 for i, test := range tests { | 446 for i, test := range tests { |
423 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { | 447 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { |
424 var m types.Metric | 448 var m types.Metric |
425 if test.bucketer != nil { | 449 if test.bucketer != nil { |
426 » » » » » » m = &fakeDistributionMetric{Fake
Metric{"m", "", []field.Field{field.String("f")}, test.typ}, test.bucketer} | 450 » » » » » » m = &fakeDistributionMetric{Fake
Metric{ |
| 451 » » » » » » » types.MetricInfo{"m", ""
, []field.Field{field.String("f")}, test.typ}, |
| 452 » » » » » » » types.MetricMetadata{}},
test.bucketer} |
427 } else { | 453 } else { |
428 » » » » » » m = &FakeMetric{"m", "", []field
.Field{field.String("f")}, test.typ} | 454 » » » » » » m = &FakeMetric{ |
| 455 » » » » » » » types.MetricInfo{"m", ""
, []field.Field{field.String("f")}, test.typ}, |
| 456 » » » » » » » types.MetricMetadata{}} |
429 } | 457 } |
430 | 458 |
431 s := opts.Factory() | 459 s := opts.Factory() |
432 s.Register(m) | 460 s.Register(m) |
433 | 461 |
434 // Values should be nil initially. | 462 // Values should be nil initially. |
435 v, err := s.Get(ctx, m, time.Time{}, mak
eInterfaceSlice("one")) | 463 v, err := s.Get(ctx, m, time.Time{}, mak
eInterfaceSlice("one")) |
436 So(err, ShouldBeNil) | 464 So(err, ShouldBeNil) |
437 So(v, ShouldBeNil) | 465 So(v, ShouldBeNil) |
438 v, err = s.Get(ctx, m, time.Time{}, make
InterfaceSlice("two")) | 466 v, err = s.Get(ctx, m, time.Time{}, make
InterfaceSlice("two")) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 | 498 |
471 Convey("With a fixed reset time", func() { | 499 Convey("With a fixed reset time", func() { |
472 for i, test := range tests { | 500 for i, test := range tests { |
473 if !test.wantIncrSuccess { | 501 if !test.wantIncrSuccess { |
474 continue | 502 continue |
475 } | 503 } |
476 | 504 |
477 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { | 505 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { |
478 var m types.Metric | 506 var m types.Metric |
479 if test.bucketer != nil { | 507 if test.bucketer != nil { |
480 » » » » » » m = &fakeDistributionMetric{Fake
Metric{"m", "", []field.Field{}, test.typ}, test.bucketer} | 508 » » » » » » m = &fakeDistributionMetric{Fake
Metric{ |
| 509 » » » » » » » types.MetricInfo{"m", ""
, []field.Field{}, test.typ}, |
| 510 » » » » » » » types.MetricMetadata{}},
test.bucketer} |
481 } else { | 511 } else { |
482 » » » » » » m = &FakeMetric{"m", "", []field
.Field{}, test.typ} | 512 » » » » » » m = &FakeMetric{ |
| 513 » » » » » » » types.MetricInfo{"m", ""
, []field.Field{}, test.typ}, |
| 514 » » » » » » » types.MetricMetadata{}} |
483 } | 515 } |
484 | 516 |
485 s := opts.Factory() | 517 s := opts.Factory() |
486 s.Register(m) | 518 s.Register(m) |
487 opts.RegistrationFinished(s) | 519 opts.RegistrationFinished(s) |
488 | 520 |
489 // Do the incr with a fixed time. | 521 // Do the incr with a fixed time. |
490 t := time.Date(1972, 5, 6, 7, 8, 9, 0, t
ime.UTC) | 522 t := time.Date(1972, 5, 6, 7, 8, 9, 0, t
ime.UTC) |
491 So(s.Incr(ctx, m, t, []interface{}{}, te
st.deltas[0]), ShouldBeNil) | 523 So(s.Incr(ctx, m, t, []interface{}{}, te
st.deltas[0]), ShouldBeNil) |
492 | 524 |
(...skipping 14 matching lines...) Expand all Loading... |
507 | 539 |
508 Convey("With a target set in the context", func() { | 540 Convey("With a target set in the context", func() { |
509 for i, test := range tests { | 541 for i, test := range tests { |
510 if !test.wantIncrSuccess { | 542 if !test.wantIncrSuccess { |
511 continue | 543 continue |
512 } | 544 } |
513 | 545 |
514 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { | 546 Convey(fmt.Sprintf("%d. %s", i, test.typ), func(
) { |
515 var m types.Metric | 547 var m types.Metric |
516 if test.bucketer != nil { | 548 if test.bucketer != nil { |
517 » » » » » » m = &fakeDistributionMetric{Fake
Metric{"m", "", []field.Field{}, test.typ}, test.bucketer} | 549 » » » » » » m = &fakeDistributionMetric{ |
| 550 » » » » » » » FakeMetric{types.MetricI
nfo{"m", "", []field.Field{}, test.typ}, |
| 551 » » » » » » » » types.MetricMeta
data{}}, |
| 552 » » » » » » » test.bucketer} |
518 } else { | 553 } else { |
519 » » » » » » m = &FakeMetric{"m", "", []field
.Field{}, test.typ} | 554 » » » » » » m = &FakeMetric{ |
| 555 » » » » » » » types.MetricInfo{"m", ""
, []field.Field{}, test.typ}, |
| 556 » » » » » » » types.MetricMetadata{}} |
520 } | 557 } |
521 | 558 |
522 s := opts.Factory() | 559 s := opts.Factory() |
523 s.Register(m) | 560 s.Register(m) |
524 opts.RegistrationFinished(s) | 561 opts.RegistrationFinished(s) |
525 | 562 |
526 // Create a context with a different tar
get. | 563 // Create a context with a different tar
get. |
527 t := target.Task{} | 564 t := target.Task{} |
528 t.AsProto().ServiceName = proto.String("
foo") | 565 t.AsProto().ServiceName = proto.String("
foo") |
529 ctxWithTarget := target.Set(ctx, &t) | 566 ctxWithTarget := target.Set(ctx, &t) |
(...skipping 21 matching lines...) Expand all Loading... |
551 So(coll.Data[1].Task.GetServiceName(), S
houldEqual, t.AsProto().GetServiceName()) | 588 So(coll.Data[1].Task.GetServiceName(), S
houldEqual, t.AsProto().GetServiceName()) |
552 }) | 589 }) |
553 } | 590 } |
554 }) | 591 }) |
555 }) | 592 }) |
556 | 593 |
557 Convey("GetAll", t, func() { | 594 Convey("GetAll", t, func() { |
558 ctx, tc := testclock.UseTime(context.Background(), testclock.Tes
tTimeLocal) | 595 ctx, tc := testclock.UseTime(context.Background(), testclock.Tes
tTimeLocal) |
559 | 596 |
560 s := opts.Factory() | 597 s := opts.Factory() |
561 » » foo := &FakeMetric{"foo", "", []field.Field{}, types.NonCumulati
veIntType} | 598 » » foo := &FakeMetric{ |
562 » » bar := &FakeMetric{"bar", "", []field.Field{field.String("f")},
types.StringType} | 599 » » » types.MetricInfo{"foo", "", []field.Field{}, types.NonCu
mulativeIntType}, |
563 » » baz := &FakeMetric{"baz", "", []field.Field{field.String("f")},
types.NonCumulativeFloatType} | 600 » » » types.MetricMetadata{}} |
| 601 » » bar := &FakeMetric{ |
| 602 » » » types.MetricInfo{"bar", "", []field.Field{field.String("
f")}, types.StringType}, |
| 603 » » » types.MetricMetadata{}} |
| 604 » » baz := &FakeMetric{ |
| 605 » » » types.MetricInfo{"baz", "", []field.Field{field.String("
f")}, types.NonCumulativeFloatType}, |
| 606 » » » types.MetricMetadata{}} |
564 s.Register(foo) | 607 s.Register(foo) |
565 s.Register(bar) | 608 s.Register(bar) |
566 s.Register(baz) | 609 s.Register(baz) |
567 opts.RegistrationFinished(s) | 610 opts.RegistrationFinished(s) |
568 | 611 |
569 // Add test records. We increment the test clock each time so th
at the added | 612 // Add test records. We increment the test clock each time so th
at the added |
570 // records sort deterministically using sortableCellSlice. | 613 // records sort deterministically using sortableCellSlice. |
571 for _, m := range []struct { | 614 for _, m := range []struct { |
572 metric types.Metric | 615 metric types.Metric |
573 fieldvals []interface{} | 616 fieldvals []interface{} |
(...skipping 11 matching lines...) Expand all Loading... |
585 | 628 |
586 got := s.GetAll(ctx) | 629 got := s.GetAll(ctx) |
587 sort.Sort(sortableCellSlice(got)) | 630 sort.Sort(sortableCellSlice(got)) |
588 want := []types.Cell{ | 631 want := []types.Cell{ |
589 { | 632 { |
590 types.MetricInfo{ | 633 types.MetricInfo{ |
591 Name: "foo", | 634 Name: "foo", |
592 Fields: []field.Field{}, | 635 Fields: []field.Field{}, |
593 ValueType: types.NonCumulativeIntType, | 636 ValueType: types.NonCumulativeIntType, |
594 }, | 637 }, |
| 638 types.MetricMetadata{}, |
595 types.CellData{ | 639 types.CellData{ |
596 FieldVals: []interface{}{}, | 640 FieldVals: []interface{}{}, |
597 Value: int64(42), | 641 Value: int64(42), |
598 }, | 642 }, |
599 }, | 643 }, |
600 { | 644 { |
601 types.MetricInfo{ | 645 types.MetricInfo{ |
602 Name: "bar", | 646 Name: "bar", |
603 Fields: []field.Field{field.String("f
")}, | 647 Fields: []field.Field{field.String("f
")}, |
604 ValueType: types.StringType, | 648 ValueType: types.StringType, |
605 }, | 649 }, |
| 650 types.MetricMetadata{}, |
606 types.CellData{ | 651 types.CellData{ |
607 FieldVals: makeInterfaceSlice("one"), | 652 FieldVals: makeInterfaceSlice("one"), |
608 Value: "hello", | 653 Value: "hello", |
609 }, | 654 }, |
610 }, | 655 }, |
611 { | 656 { |
612 types.MetricInfo{ | 657 types.MetricInfo{ |
613 Name: "bar", | 658 Name: "bar", |
614 Fields: []field.Field{field.String("f
")}, | 659 Fields: []field.Field{field.String("f
")}, |
615 ValueType: types.StringType, | 660 ValueType: types.StringType, |
616 }, | 661 }, |
| 662 types.MetricMetadata{}, |
617 types.CellData{ | 663 types.CellData{ |
618 FieldVals: makeInterfaceSlice("two"), | 664 FieldVals: makeInterfaceSlice("two"), |
619 Value: "world", | 665 Value: "world", |
620 }, | 666 }, |
621 }, | 667 }, |
622 { | 668 { |
623 types.MetricInfo{ | 669 types.MetricInfo{ |
624 Name: "baz", | 670 Name: "baz", |
625 Fields: []field.Field{field.String("f
")}, | 671 Fields: []field.Field{field.String("f
")}, |
626 ValueType: types.NonCumulativeFloatType, | 672 ValueType: types.NonCumulativeFloatType, |
627 }, | 673 }, |
| 674 types.MetricMetadata{}, |
628 types.CellData{ | 675 types.CellData{ |
629 FieldVals: makeInterfaceSlice("three"), | 676 FieldVals: makeInterfaceSlice("three"), |
630 Value: 1.23, | 677 Value: 1.23, |
631 }, | 678 }, |
632 }, | 679 }, |
633 { | 680 { |
634 types.MetricInfo{ | 681 types.MetricInfo{ |
635 Name: "baz", | 682 Name: "baz", |
636 Fields: []field.Field{field.String("f
")}, | 683 Fields: []field.Field{field.String("f
")}, |
637 ValueType: types.NonCumulativeFloatType, | 684 ValueType: types.NonCumulativeFloatType, |
638 }, | 685 }, |
| 686 types.MetricMetadata{}, |
639 types.CellData{ | 687 types.CellData{ |
640 FieldVals: makeInterfaceSlice("four"), | 688 FieldVals: makeInterfaceSlice("four"), |
641 Value: 4.56, | 689 Value: 4.56, |
642 }, | 690 }, |
643 }, | 691 }, |
644 } | 692 } |
645 So(len(got), ShouldEqual, len(want)) | 693 So(len(got), ShouldEqual, len(want)) |
646 | 694 |
647 for i, g := range got { | 695 for i, g := range got { |
648 w := want[i] | 696 w := want[i] |
649 | 697 |
650 Convey(fmt.Sprintf("%d", i), func() { | 698 Convey(fmt.Sprintf("%d", i), func() { |
651 So(g.Name, ShouldEqual, w.Name) | 699 So(g.Name, ShouldEqual, w.Name) |
652 So(len(g.Fields), ShouldEqual, len(w.Fields)) | 700 So(len(g.Fields), ShouldEqual, len(w.Fields)) |
653 So(g.ValueType, ShouldEqual, w.ValueType) | 701 So(g.ValueType, ShouldEqual, w.ValueType) |
654 So(g.FieldVals, ShouldResemble, w.FieldVals) | 702 So(g.FieldVals, ShouldResemble, w.FieldVals) |
655 So(g.Value, ShouldEqual, w.Value) | 703 So(g.Value, ShouldEqual, w.Value) |
656 }) | 704 }) |
657 } | 705 } |
658 }) | 706 }) |
659 | 707 |
660 Convey("Concurrency", t, func() { | 708 Convey("Concurrency", t, func() { |
661 const numIterations = 100 | 709 const numIterations = 100 |
662 const numGoroutines = 32 | 710 const numGoroutines = 32 |
663 | 711 |
664 Convey("Incr", func(c C) { | 712 Convey("Incr", func(c C) { |
665 s := opts.Factory() | 713 s := opts.Factory() |
666 » » » m := &FakeMetric{"m", "", []field.Field{}, types.Cumulat
iveIntType} | 714 » » » m := &FakeMetric{ |
| 715 » » » » types.MetricInfo{"m", "", []field.Field{}, types
.CumulativeIntType}, |
| 716 » » » » types.MetricMetadata{}} |
667 s.Register(m) | 717 s.Register(m) |
668 | 718 |
669 wg := sync.WaitGroup{} | 719 wg := sync.WaitGroup{} |
670 f := func(n int) { | 720 f := func(n int) { |
671 defer wg.Done() | 721 defer wg.Done() |
672 for i := 0; i < numIterations; i++ { | 722 for i := 0; i < numIterations; i++ { |
673 c.So(s.Incr(ctx, m, time.Time{}, []inter
face{}{}, int64(1)), ShouldBeNil) | 723 c.So(s.Incr(ctx, m, time.Time{}, []inter
face{}{}, int64(1)), ShouldBeNil) |
674 } | 724 } |
675 } | 725 } |
676 | 726 |
677 for n := 0; n < numGoroutines; n++ { | 727 for n := 0; n < numGoroutines; n++ { |
678 wg.Add(1) | 728 wg.Add(1) |
679 go f(n) | 729 go f(n) |
680 } | 730 } |
681 wg.Wait() | 731 wg.Wait() |
682 | 732 |
683 val, err := s.Get(ctx, m, time.Time{}, []interface{}{}) | 733 val, err := s.Get(ctx, m, time.Time{}, []interface{}{}) |
684 So(val, ShouldEqual, numIterations*numGoroutines) | 734 So(val, ShouldEqual, numIterations*numGoroutines) |
685 So(err, ShouldBeNil) | 735 So(err, ShouldBeNil) |
686 }) | 736 }) |
687 }) | 737 }) |
688 | 738 |
689 Convey("Different targets", t, func() { | 739 Convey("Different targets", t, func() { |
690 Convey("Gets from context", func() { | 740 Convey("Gets from context", func() { |
691 s := opts.Factory() | 741 s := opts.Factory() |
692 » » » m := &FakeMetric{"m", "", []field.Field{}, types.NonCumu
lativeIntType} | 742 » » » m := &FakeMetric{ |
| 743 » » » » types.MetricInfo{"m", "", []field.Field{}, types
.NonCumulativeIntType}, |
| 744 » » » » types.MetricMetadata{}} |
693 s.Register(m) | 745 s.Register(m) |
694 opts.RegistrationFinished(s) | 746 opts.RegistrationFinished(s) |
695 | 747 |
696 t := target.Task{} | 748 t := target.Task{} |
697 t.AsProto().ServiceName = proto.String("foo") | 749 t.AsProto().ServiceName = proto.String("foo") |
698 ctxWithTarget := target.Set(ctx, &t) | 750 ctxWithTarget := target.Set(ctx, &t) |
699 | 751 |
700 So(s.Set(ctx, m, time.Time{}, []interface{}{}, int64(42)
), ShouldBeNil) | 752 So(s.Set(ctx, m, time.Time{}, []interface{}{}, int64(42)
), ShouldBeNil) |
701 So(s.Set(ctxWithTarget, m, time.Time{}, []interface{}{},
int64(43)), ShouldBeNil) | 753 So(s.Set(ctxWithTarget, m, time.Time{}, []interface{}{},
int64(43)), ShouldBeNil) |
702 | 754 |
(...skipping 18 matching lines...) Expand all Loading... |
721 } | 773 } |
722 }) | 774 }) |
723 }) | 775 }) |
724 } | 776 } |
725 | 777 |
726 func makeInterfaceSlice(v ...interface{}) []interface{} { | 778 func makeInterfaceSlice(v ...interface{}) []interface{} { |
727 return v | 779 return v |
728 } | 780 } |
729 | 781 |
730 // FakeMetric is a fake Metric implementation. | 782 // FakeMetric is a fake Metric implementation. |
731 type FakeMetric types.MetricInfo | 783 type FakeMetric struct { |
| 784 » types.MetricInfo |
| 785 » types.MetricMetadata |
| 786 } |
732 | 787 |
733 // Info implements Metric.Info. | 788 // Info implements Metric.Info |
734 func (m *FakeMetric) Info() types.MetricInfo { return types.MetricInfo(*m) } | 789 func (m *FakeMetric) Info() types.MetricInfo { return m.MetricInfo } |
| 790 |
| 791 // Metadata implements Metric.Metadata |
| 792 func (m *FakeMetric) Metadata() types.MetricMetadata { return m.MetricMetadata } |
735 | 793 |
736 // SetFixedResetTime implements Metric.SetFixedResetTime. | 794 // SetFixedResetTime implements Metric.SetFixedResetTime. |
737 func (m *FakeMetric) SetFixedResetTime(t time.Time) {} | 795 func (m *FakeMetric) SetFixedResetTime(t time.Time) {} |
738 | 796 |
739 type fakeDistributionMetric struct { | 797 type fakeDistributionMetric struct { |
740 FakeMetric | 798 FakeMetric |
741 | 799 |
742 bucketer *distribution.Bucketer | 800 bucketer *distribution.Bucketer |
743 } | 801 } |
744 | 802 |
745 func (m *fakeDistributionMetric) Bucketer() *distribution.Bucketer { return m.bu
cketer } | 803 func (m *fakeDistributionMetric) Bucketer() *distribution.Bucketer { return m.bu
cketer } |
746 | 804 |
747 type sortableCellSlice []types.Cell | 805 type sortableCellSlice []types.Cell |
748 | 806 |
749 func (s sortableCellSlice) Len() int { return len(s) } | 807 func (s sortableCellSlice) Len() int { return len(s) } |
750 func (s sortableCellSlice) Less(i, j int) bool { | 808 func (s sortableCellSlice) Less(i, j int) bool { |
751 return s[i].ResetTime.UnixNano() < s[j].ResetTime.UnixNano() | 809 return s[i].ResetTime.UnixNano() < s[j].ResetTime.UnixNano() |
752 } | 810 } |
753 func (s sortableCellSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } | 811 func (s sortableCellSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } |
754 | 812 |
755 type sortableDataSlice []*pb.MetricsData | 813 type sortableDataSlice []*pb.MetricsData |
756 | 814 |
757 func (s sortableDataSlice) Len() int { return len(s) } | 815 func (s sortableDataSlice) Len() int { return len(s) } |
758 func (s sortableDataSlice) Less(i, j int) bool { | 816 func (s sortableDataSlice) Less(i, j int) bool { |
759 a, _ := proto.Marshal(s[i]) | 817 a, _ := proto.Marshal(s[i]) |
760 b, _ := proto.Marshal(s[j]) | 818 b, _ := proto.Marshal(s[j]) |
761 return bytes.Compare(a, b) > 0 | 819 return bytes.Compare(a, b) > 0 |
762 } | 820 } |
763 func (s sortableDataSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } | 821 func (s sortableDataSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } |
OLD | NEW |