~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/apiserver/metricsender/testing/mocksender.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
package testing
5
5
 
6
6
import (
 
7
        "fmt"
 
8
 
 
9
        "github.com/juju/juju/state"
 
10
 
7
11
        wireformat "github.com/juju/romulus/wireformat/metrics"
8
12
        "github.com/juju/utils"
9
13
)
10
14
 
11
15
// MockSender implements the metric sender interface.
12
16
type MockSender struct {
13
 
        Data [][]*wireformat.MetricBatch
 
17
        UnackedBatches map[string]struct{}
 
18
        Data           [][]*wireformat.MetricBatch
14
19
}
15
20
 
16
21
// Send implements the Send interface.
23
28
        var envResponses = make(wireformat.EnvironmentResponses)
24
29
 
25
30
        for _, batch := range d {
 
31
                if m.UnackedBatches != nil {
 
32
                        _, ok := m.UnackedBatches[fmt.Sprintf("%s/%s", batch.ModelUUID, batch.UUID)]
 
33
                        if ok {
 
34
                                continue
 
35
                        }
 
36
                }
26
37
                envResponses.Ack(batch.ModelUUID, batch.UUID)
27
38
        }
28
39
        return &wireformat.Response{
31
42
        }, nil
32
43
}
33
44
 
 
45
func (m *MockSender) IgnoreBatches(batches ...*state.MetricBatch) {
 
46
        if m.UnackedBatches == nil {
 
47
                m.UnackedBatches = make(map[string]struct{})
 
48
        }
 
49
        for _, batch := range batches {
 
50
                m.UnackedBatches[fmt.Sprintf("%s/%s", batch.ModelUUID(), batch.UUID())] = struct{}{}
 
51
        }
 
52
}
 
53
 
34
54
// ErrorSender implements the metric sender interface and is used
35
55
// to return errors during testing
36
56
type ErrorSender struct {