Adding some more basic test cases
This commit is contained in:
parent
3699f00042
commit
7119b5d653
|
@ -44,7 +44,6 @@ public class PathChildren {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Observable<PathChildrenCacheEvent> watch(final String znodePath) {
|
public Observable<PathChildrenCacheEvent> watch(final String znodePath) {
|
||||||
return Observable.create(new Observable.OnSubscribe<PathChildrenCacheEvent>() {
|
return Observable.create(new Observable.OnSubscribe<PathChildrenCacheEvent>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -41,35 +41,68 @@ class PathChildrenIntegrationSpec extends Specification {
|
||||||
TestingServer server
|
TestingServer server
|
||||||
TestSubscriber subscriber
|
TestSubscriber subscriber
|
||||||
PollingConditions pollingConditions
|
PollingConditions pollingConditions
|
||||||
|
boolean eventReceived = false
|
||||||
|
|
||||||
def setup() {
|
def setup() {
|
||||||
server = new TestingServer(true)
|
server = new TestingServer(true)
|
||||||
curator = CuratorFrameworkFactory.newClient(server.connectString, new RetryOneTime(1000))
|
curator = CuratorFrameworkFactory.newClient(server.connectString, new RetryOneTime(1000))
|
||||||
curator.start()
|
curator.start()
|
||||||
subscriber = new TestSubscriber()
|
subscriber = new TestSubscriber()
|
||||||
pollingConditions = new PollingConditions(timeout: 3)
|
pollingConditions = new PollingConditions(timeout: 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
def cleanup() {
|
def cleanup() {
|
||||||
|
eventReceived = false
|
||||||
curator?.close()
|
curator?.close()
|
||||||
server?.close()
|
server?.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
def "an initialization event should be received"() {
|
Observable<PathChildrenCacheEvent> createObservableFor(CuratorFramework curator, String path) {
|
||||||
given:
|
return PathChildren.with(curator).watch(path)
|
||||||
boolean received = false
|
}
|
||||||
Subscription subscription
|
|
||||||
Observable<PathChildrenCacheEvent> observable = PathChildren.with(curator).watch('/')
|
|
||||||
|
|
||||||
|
def "an initialization event should be received"() {
|
||||||
when:
|
when:
|
||||||
subscription = observable.subscribe { PathChildrenCacheEvent ev ->
|
createObservableFor(curator, '/').subscribe { PathChildrenCacheEvent ev ->
|
||||||
if (ev.type == PathChildrenCacheEvent.Type.INITIALIZED) {
|
if (ev.type == PathChildrenCacheEvent.Type.INITIALIZED) {
|
||||||
received = true
|
eventReceived = true
|
||||||
subscription.unsubscribe()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
then:
|
then:
|
||||||
pollingConditions.eventually { assert received }
|
pollingConditions.eventually { assert eventReceived }
|
||||||
|
}
|
||||||
|
|
||||||
|
def "receive normal add events"() {
|
||||||
|
given:
|
||||||
|
createObservableFor(curator, '/').subscribe { PathChildrenCacheEvent ev ->
|
||||||
|
if (ev.type == PathChildrenCacheEvent.Type.CHILD_ADDED) {
|
||||||
|
eventReceived = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
when:
|
||||||
|
curator.create().forPath('/spock')
|
||||||
|
|
||||||
|
then:
|
||||||
|
pollingConditions.eventually { assert eventReceived }
|
||||||
|
}
|
||||||
|
|
||||||
|
def "receive delete events"() {
|
||||||
|
given:
|
||||||
|
final String znode = '/spock'
|
||||||
|
curator.create().forPath(znode)
|
||||||
|
|
||||||
|
createObservableFor(curator, '/').subscribe { PathChildrenCacheEvent ev ->
|
||||||
|
if (ev.type == PathChildrenCacheEvent.Type.CHILD_REMOVED) {
|
||||||
|
eventReceived = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
when:
|
||||||
|
curator.delete().forPath(znode)
|
||||||
|
|
||||||
|
then:
|
||||||
|
pollingConditions.eventually { assert eventReceived }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue