-
Notifications
You must be signed in to change notification settings - Fork 13
/
stub.go
55 lines (41 loc) · 1.19 KB
/
stub.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Package stub is used for testing
package stub
import (
"fmt"
"sync/atomic"
"github.com/blind-oracle/psql-streamer/common"
"github.com/blind-oracle/psql-streamer/event"
"github.com/spf13/viper"
)
type evf func([]event.Event) error
// Stub is a stub sink
type Stub struct {
name string
f evf
events uint64
*common.Logger
}
// New creates a new Stub sink
func New(name string, v *viper.Viper, f evf) (*Stub, error) {
return &Stub{name: name, f: f}, nil
}
// ProcessEventsBatch processess the events batch
func (k *Stub) ProcessEventsBatch(events []event.Event) (err error) {
atomic.AddUint64(&k.events, uint64(len(events)))
if k.f != nil {
return k.f(events)
}
return
}
// Name returns Sink's name
func (k *Stub) Name() string { return k.name }
// Type returns Sink's type
func (k *Stub) Type() string { return "Sink-Stub" }
// SetLogger sets a logger
func (k *Stub) SetLogger(l *common.Logger) {}
// Stats returns statistics
func (k *Stub) Stats() string { return fmt.Sprintf("events: %d", atomic.LoadUint64(&k.events)) }
// Status returns the current healthcheck state
func (k *Stub) Status() error { return nil }
// Close shuts down sink
func (k *Stub) Close() error { return nil }