Example #1
0
func TestAdd(t *testing.T) {
	store := New()
	newItem := item.New(time.Now(), []byte("payload"))
	store.Add(newItem)
	if store.items[0] != newItem {
		t.Fail()
	}
}
Example #2
0
func TestGet(t *testing.T) {
	store := New()
	newItem := item.New(time.Now(), []byte("payload"))
	store.Add(newItem)
	currentItem, err := store.Get()
	if err != nil {
		t.Fail()
	}
	if currentItem != newItem {
		t.Fail()
	}
}
Example #3
0
func TestAddFull(t *testing.T) {
	store := New()
	times := 10
	for i := 0; i < times; i++ {
		newItem := item.New(time.Now(), []byte(fmt.Sprintf("%d", i)))
		store.Add(newItem)
		sameItem, err := store.Get()
		if err != nil {
			t.Fail()
		}
		if sameItem != newItem {
			t.Fail()
		}
	}
}
Example #4
0
func (this *Service) Run() {
	dataCh := this.ext.DataChannel()
	defer this.ext.Close()
	go this.ext.Collect()
	go func() {
		for {
			select {
			case payload := <-dataCh:
				newItem := item.New(time.Now(), payload)
				this.Cache.Add(newItem)
			}
		}
	}()

	this.resourceManager.Run()
}