Start sketching out a simple API for observing PathChildrenCache

This commit is contained in:
R. Tyler Croy 2015-09-04 11:05:45 -07:00
parent 7d8d9c1ff9
commit 1bf5311770
No known key found for this signature in database
GPG Key ID: 1426C7DC3F51E16F
5 changed files with 108 additions and 1 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ gradle-app.setting
*.iml
*.iw*
.idea/

View File

@ -18,6 +18,7 @@ dependencies {
}
compile 'io.reactivex:rxjava:[1.0.14,2.0)'
testCompile 'org.apache.curator:curator-test:[2.7.1,2.8)'
testCompile "org.spockframework:spock-core:1.0-groovy-2.4"
testCompile 'cglib:cglib-nodep:3.1'
}
@ -36,5 +37,41 @@ test {
}
}
assemble.dependsOn check
task sourcesJar(type: Jar) {
classifier = 'sources'
dependsOn classes
from sourceSets.main.allSource
}
task javadocJar(type: Jar) {
dependsOn javadoc
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
assemble.dependsOn check, javadocJar, sourcesJar
install.dependsOn assemble
plugins.withType(JavaPlugin) {
sourceCompatibility = 1.7
targetCompatibility = 1.7
project.tasks.withType(JavaCompile) { task ->
task.sourceCompatibility = project.sourceCompatibility
task.targetCompatibility = project.targetCompatibility
}
project.tasks.withType(GroovyCompile) { task ->
task.sourceCompatibility = project.sourceCompatibility
task.targetCompatibility = project.targetCompatibility
}
}

2
gradle.properties Normal file
View File

@ -0,0 +1,2 @@
sourceCompatibility=1.7
targetCompatibility=1.7

View File

@ -0,0 +1,41 @@
package com.github.reiseburo.rx.curator;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
import rx.Observable;
/**
* PathChildren is an {@code Observable} which takes events from a {@code PathChildrenCache}
* and emits them for subscription
*/
public class PathChildren {
protected CuratorFramework curatorFramework;
public CuratorFramework getCuratorFramework() {
return curatorFramework;
}
public void setCuratorFramework(CuratorFramework curatorFramework) {
this.curatorFramework = curatorFramework;
}
/**
* Create an instance of PathChildren configured with the provided
* {@code CuratorFramework} instance. This assumes that {@code curatorFramework}
* has already been started
*
* @param curatorFramework
* @return
*/
public static PathChildren with(CuratorFramework curatorFramework) {
PathChildren instance = new PathChildren();
instance.setCuratorFramework(curatorFramework);
return instance;
}
public Observable<PathChildrenCacheEvent> watch(String znodePath) {
return Observable.never();
}
}

View File

@ -0,0 +1,26 @@
package com.github.reiseburo.rx.curator
import org.apache.curator.framework.CuratorFramework
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent
import rx.Observable
import spock.lang.*
/**
*/
class PathChildrenSpec extends Specification {
CuratorFramework curatorFramework
def setup() {
curatorFramework = Mock(CuratorFramework)
}
def "PathChildren.with(curator) returns an instance"() {
expect:
PathChildren.with(curatorFramework) instanceof PathChildren
}
def ".watch(String) should return an Observable<T>"() {
expect:
PathChildren.with(curatorFramework).watch('/brokers') instanceof Observable<PathChildrenCacheEvent>
}
}