Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
Use fake store adapter from storeadapter package
Browse files Browse the repository at this point in the history
Signed-off-by: John Tuley <jtuley@pivotal.io>
  • Loading branch information
Johannes Petzold authored and John Tuley committed Aug 19, 2014
1 parent 3d1def3 commit b8f5328
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 56 deletions.
13 changes: 10 additions & 3 deletions store/app_service_store_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ import (
"github.com/cloudfoundry/loggregatorlib/appservice"
. "github.com/cloudfoundry/loggregatorlib/store"
"github.com/cloudfoundry/loggregatorlib/store/cache"
"github.com/cloudfoundry/storeadapter"
"github.com/cloudfoundry/storeadapter/fakestoreadapter"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"path"
)

var _ = Describe("AppServiceUnit", func() {
Context("when the store has data", func() {
var store *AppServiceStore
var adapter *FakeAdapter
var adapter *fakestoreadapter.FakeStoreAdapter
var incomingChan chan appservice.AppServices
var app1Service1 appservice.AppService

BeforeEach(func() {
adapter = &FakeAdapter{}
adapter = fakestoreadapter.New()
c := cache.NewAppServiceCache()
incomingChan = make(chan appservice.AppServices)
app1Service1 = appservice.AppService{AppId: "app-1", Url: "syslog://example.com:12345"}
Expand All @@ -26,6 +29,8 @@ var _ = Describe("AppServiceUnit", func() {
})

It("does not modify the store, when deleting data that doesn't exist", func() {
key := path.Join("/loggregator/services", app1Service1.AppId, app1Service1.Id())

incomingChan <- appservice.AppServices{
AppId: app1Service1.AppId,
Urls: []string{app1Service1.Url},
Expand All @@ -40,7 +45,9 @@ var _ = Describe("AppServiceUnit", func() {
AppId: app1Service1.AppId,
Urls: []string{},
}
Expect(adapter.DeleteCount).To(Equal(1))

_, err := adapter.Get(key)
Expect(err).To(Equal(storeadapter.ErrorKeyNotFound))
})
})
})
1 change: 0 additions & 1 deletion store/app_service_store_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func appServiceFromStoreNode(node storeadapter.StoreNode) appservice.AppService
appId := path.Base(path.Dir(key))
serviceUrl := string(node.Value)
appService := appservice.AppService{AppId: appId, Url: serviceUrl}

return appService
}

Expand Down
36 changes: 34 additions & 2 deletions store/app_service_store_watcher_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import (
"errors"
. "github.com/cloudfoundry/loggregatorlib/store"
"github.com/cloudfoundry/loggregatorlib/store/cache"
"github.com/cloudfoundry/storeadapter"
"github.com/cloudfoundry/storeadapter/fakestoreadapter"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"sync"
)

var _ = Describe("AppServiceStoreWatcherUnit", func() {
Context("when there is an error", func() {
var adapter *FakeAdapter
var adapter *fakeStoreAdapter

BeforeEach(func() {
adapter = &FakeAdapter{}
adapter = newFSA()
watcher, _, _ := NewAppServiceStoreWatcher(adapter, cache.NewAppServiceCache())

go watcher.Run()
Expand All @@ -26,3 +29,32 @@ var _ = Describe("AppServiceStoreWatcherUnit", func() {
})
})
})

type fakeStoreAdapter struct {
*fakestoreadapter.FakeStoreAdapter
watchCounter int
sync.Mutex
}

func (fsa *fakeStoreAdapter) Watch(key string) (events <-chan storeadapter.WatchEvent, stop chan<- bool, errors <-chan error) {
events, _, errors = fsa.FakeStoreAdapter.Watch(key)

fsa.Lock()
defer fsa.Unlock()
fsa.watchCounter++

return events, make(chan bool), errors
}

func (fsa *fakeStoreAdapter) GetWatchCounter() int {
fsa.Lock()
defer fsa.Unlock()

return fsa.watchCounter
}

func newFSA() *fakeStoreAdapter {
return &fakeStoreAdapter{
FakeStoreAdapter: fakestoreadapter.New(),
}
}
50 changes: 0 additions & 50 deletions store/store_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"os/exec"
"os/signal"
"path"
"sync"
"testing"
"time"
)
Expand Down Expand Up @@ -67,52 +66,3 @@ func buildNode(appService appservice.AppService) storeadapter.StoreNode {
Value: []byte(appService.Url),
}
}

type FakeAdapter struct {
DeleteCount int
WatchErrChannel chan error
WatchCounter int
sync.Mutex
}

func (adapter *FakeAdapter) GetWatchCounter() int {
adapter.Lock()
defer adapter.Unlock()
return adapter.WatchCounter
}

func (adapter *FakeAdapter) Connect() error { return nil }
func (adapter *FakeAdapter) Create(storeadapter.StoreNode) error { return nil }
func (adapter *FakeAdapter) Update(storeadapter.StoreNode) error { return nil }
func (adapter *FakeAdapter) CompareAndSwap(storeadapter.StoreNode, storeadapter.StoreNode) error {
return nil
}
func (adapter *FakeAdapter) CompareAndSwapByIndex(uint64, storeadapter.StoreNode) error {
return nil
}

func (adapter *FakeAdapter) SetMulti(nodes []storeadapter.StoreNode) error { return nil }
func (adapter *FakeAdapter) Get(key string) (storeadapter.StoreNode, error) {
return storeadapter.StoreNode{}, nil
}
func (adapter *FakeAdapter) ListRecursively(key string) (storeadapter.StoreNode, error) {
return storeadapter.StoreNode{}, nil
}
func (adapter *FakeAdapter) Delete(keys ...string) error {
adapter.DeleteCount++
return nil
}
func (adapter *FakeAdapter) CompareAndDelete(storeadapter.StoreNode) error { return nil }
func (adapter *FakeAdapter) UpdateDirTTL(key string, ttl uint64) error { return nil }
func (adapter *FakeAdapter) Watch(key string) (events <-chan storeadapter.WatchEvent, stop chan<- bool, errors <-chan error) {
adapter.Lock()
defer adapter.Unlock()
adapter.WatchCounter++
adapter.WatchErrChannel = make(chan error, 1)

return nil, make(chan bool), adapter.WatchErrChannel
}
func (adapter *FakeAdapter) Disconnect() error { return nil }
func (adapter *FakeAdapter) MaintainNode(storeNode storeadapter.StoreNode) (lostNode <-chan bool, releaseNode chan chan bool, err error) {
return nil, nil, nil
}

0 comments on commit b8f5328

Please sign in to comment.