mirror of
https://github.com/reiseburo/rx-curator
synced 2024-09-15 06:41:58 +00:00
Start sketching out a simple API for observing PathChildrenCache
This commit is contained in:
parent
7d8d9c1ff9
commit
1bf5311770
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,3 +9,4 @@ gradle-app.setting
|
||||
|
||||
*.iml
|
||||
*.iw*
|
||||
.idea/
|
||||
|
39
build.gradle
39
build.gradle
@ -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
2
gradle.properties
Normal file
@ -0,0 +1,2 @@
|
||||
sourceCompatibility=1.7
|
||||
targetCompatibility=1.7
|
@ -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();
|
||||
}
|
||||
}
|
@ -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>
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user