From 1bf5311770ded9526b2d9abccb4a89add94fa0f9 Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Fri, 4 Sep 2015 11:05:45 -0700 Subject: [PATCH] Start sketching out a simple API for observing PathChildrenCache --- .gitignore | 1 + build.gradle | 39 +++++++++++++++++- gradle.properties | 2 + .../reiseburo/rx/curator/PathChildren.java | 41 +++++++++++++++++++ .../rx/curator/PathChildrenSpec.groovy | 26 ++++++++++++ 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 gradle.properties create mode 100644 src/main/java/com/github/reiseburo/rx/curator/PathChildren.java create mode 100644 src/test/groovy/com/github/reiseburo/rx/curator/PathChildrenSpec.groovy diff --git a/.gitignore b/.gitignore index 93c23b1..409ce11 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ gradle-app.setting *.iml *.iw* +.idea/ diff --git a/build.gradle b/build.gradle index 3e17748..67ebab8 100644 --- a/build.gradle +++ b/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 + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..a52a6fa --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +sourceCompatibility=1.7 +targetCompatibility=1.7 diff --git a/src/main/java/com/github/reiseburo/rx/curator/PathChildren.java b/src/main/java/com/github/reiseburo/rx/curator/PathChildren.java new file mode 100644 index 0000000..5b18391 --- /dev/null +++ b/src/main/java/com/github/reiseburo/rx/curator/PathChildren.java @@ -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 watch(String znodePath) { + return Observable.never(); + } +} diff --git a/src/test/groovy/com/github/reiseburo/rx/curator/PathChildrenSpec.groovy b/src/test/groovy/com/github/reiseburo/rx/curator/PathChildrenSpec.groovy new file mode 100644 index 0000000..26fe2b5 --- /dev/null +++ b/src/test/groovy/com/github/reiseburo/rx/curator/PathChildrenSpec.groovy @@ -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"() { + expect: + PathChildren.with(curatorFramework).watch('/brokers') instanceof Observable + } +}