|
| 1 | +/**************************************************************************** |
| 2 | + * Copyright 2019, Optimizely, Inc. and contributors * |
| 3 | + * * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); * |
| 5 | + * you may not use this file except in compliance with the License. * |
| 6 | + * You may obtain a copy of the License at * |
| 7 | + * * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 * |
| 9 | + * * |
| 10 | + * Unless required by applicable law or agreed to in writing, software * |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, * |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * |
| 13 | + * See the License for the specific language governing permissions and * |
| 14 | + * limitations under the License. * |
| 15 | + ***************************************************************************/ |
| 16 | + |
| 17 | +// Package event // |
| 18 | +package event |
| 19 | + |
| 20 | +import ( |
| 21 | + "testing" |
| 22 | + |
| 23 | + "github.com/stretchr/testify/assert" |
| 24 | +) |
| 25 | + |
| 26 | +func TestNewDefaultMetrics(t *testing.T) { |
| 27 | + |
| 28 | + metric := DefaultMetrics{} |
| 29 | + assert.Equal(t, 0, metric.QueueSize) |
| 30 | + assert.Equal(t, int64(0), metric.SuccessFlushCount) |
| 31 | + assert.Equal(t, int64(0), metric.FailFlushCount) |
| 32 | + assert.Equal(t, int64(0), metric.RetryFlushCount) |
| 33 | + |
| 34 | +} |
| 35 | + |
| 36 | +func TestSetQueueSize(t *testing.T) { |
| 37 | + |
| 38 | + metric := DefaultMetrics{} |
| 39 | + metric.SetQueueSize(24) |
| 40 | + assert.Equal(t, 24, metric.QueueSize) |
| 41 | + assert.Equal(t, int64(0), metric.SuccessFlushCount) |
| 42 | + assert.Equal(t, int64(0), metric.FailFlushCount) |
| 43 | + assert.Equal(t, int64(0), metric.RetryFlushCount) |
| 44 | + |
| 45 | +} |
| 46 | + |
| 47 | +func TestIncrSuccessFlushCount(t *testing.T) { |
| 48 | + |
| 49 | + metric := DefaultMetrics{} |
| 50 | + metric.IncrSuccessFlushCount() |
| 51 | + assert.Equal(t, 0, metric.QueueSize) |
| 52 | + assert.Equal(t, int64(1), metric.SuccessFlushCount) |
| 53 | + assert.Equal(t, int64(0), metric.FailFlushCount) |
| 54 | + assert.Equal(t, int64(0), metric.RetryFlushCount) |
| 55 | + |
| 56 | +} |
| 57 | + |
| 58 | +func TestIncrFailFlushCount(t *testing.T) { |
| 59 | + |
| 60 | + metric := DefaultMetrics{} |
| 61 | + metric.IncrFailFlushCount() |
| 62 | + assert.Equal(t, 0, metric.QueueSize) |
| 63 | + assert.Equal(t, int64(0), metric.SuccessFlushCount) |
| 64 | + assert.Equal(t, int64(1), metric.FailFlushCount) |
| 65 | + assert.Equal(t, int64(0), metric.RetryFlushCount) |
| 66 | + |
| 67 | +} |
| 68 | + |
| 69 | +func TestIncrRetryFlushCount(t *testing.T) { |
| 70 | + |
| 71 | + metric := DefaultMetrics{} |
| 72 | + metric.IncrRetryFlushCount() |
| 73 | + assert.Equal(t, 0, metric.QueueSize) |
| 74 | + assert.Equal(t, int64(0), metric.SuccessFlushCount) |
| 75 | + assert.Equal(t, int64(0), metric.FailFlushCount) |
| 76 | + assert.Equal(t, int64(1), metric.RetryFlushCount) |
| 77 | + |
| 78 | +} |
| 79 | + |
| 80 | +func TestAdd(t *testing.T) { |
| 81 | + |
| 82 | + metric := &DefaultMetrics{} |
| 83 | + metric.IncrRetryFlushCount() |
| 84 | + metric.IncrSuccessFlushCount() |
| 85 | + metric.IncrSuccessFlushCount() |
| 86 | + metric.IncrFailFlushCount() |
| 87 | + metric.SetQueueSize(24) |
| 88 | + |
| 89 | + metric.Add(metric) |
| 90 | + assert.Equal(t, 48, metric.QueueSize) |
| 91 | + assert.Equal(t, int64(4), metric.SuccessFlushCount) |
| 92 | + assert.Equal(t, int64(2), metric.FailFlushCount) |
| 93 | + assert.Equal(t, int64(2), metric.RetryFlushCount) |
| 94 | + |
| 95 | +} |
0 commit comments