github.com/galamsiva2020/kubernetes-heapster-monitoring@v0.0.0-20210823134957-3c1baa7c1e70/events/util/dummies.go (about)

     1  // Copyright 2015 Google Inc. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package util
    16  
    17  import (
    18  	"sync"
    19  	"time"
    20  
    21  	"k8s.io/heapster/events/core"
    22  )
    23  
    24  type DummySink struct {
    25  	name        string
    26  	mutex       sync.Mutex
    27  	exportCount int
    28  	stopped     bool
    29  	latency     time.Duration
    30  }
    31  
    32  func (this *DummySink) Name() string {
    33  	return this.name
    34  }
    35  func (this *DummySink) ExportEvents(*core.EventBatch) {
    36  	this.mutex.Lock()
    37  	this.exportCount++
    38  	this.mutex.Unlock()
    39  
    40  	time.Sleep(this.latency)
    41  }
    42  
    43  func (this *DummySink) Stop() {
    44  	this.mutex.Lock()
    45  	this.stopped = true
    46  	this.mutex.Unlock()
    47  
    48  	time.Sleep(this.latency)
    49  }
    50  
    51  func (this *DummySink) IsStopped() bool {
    52  	this.mutex.Lock()
    53  	defer this.mutex.Unlock()
    54  	return this.stopped
    55  }
    56  
    57  func (this *DummySink) GetExportCount() int {
    58  	this.mutex.Lock()
    59  	defer this.mutex.Unlock()
    60  	return this.exportCount
    61  }
    62  
    63  func NewDummySink(name string, latency time.Duration) *DummySink {
    64  	return &DummySink{
    65  		name:        name,
    66  		latency:     latency,
    67  		exportCount: 0,
    68  		stopped:     false,
    69  	}
    70  }
    71  
    72  type DummyEventSource struct {
    73  	eventBatch *core.EventBatch
    74  }
    75  
    76  func (this *DummyEventSource) GetNewEvents() *core.EventBatch {
    77  	return this.eventBatch
    78  }
    79  
    80  func NewDummySource(eventBatch *core.EventBatch) *DummyEventSource {
    81  	return &DummyEventSource{
    82  		eventBatch: eventBatch,
    83  	}
    84  }