Repository: incubator-usergrid Updated Branches: refs/heads/two-dot-o-dev 28a8590cd -> a58ccfa03
Adds Apache Header and restores content Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/a58ccfa0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/a58ccfa0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/a58ccfa0 Branch: refs/heads/two-dot-o-dev Commit: a58ccfa03d198bf59425bb9d0d2b78bb3b38a3f6 Parents: 28a8590 Author: Todd Nine <tn...@apigee.com> Authored: Tue Apr 21 14:17:26 2015 -0600 Committer: Todd Nine <tn...@apigee.com> Committed: Tue Apr 21 14:17:47 2015 -0600 ---------------------------------------------------------------------- .../corepersistence/index/PublishRxTest.java | 92 ++++++++++++++++++- .../corepersistence/index/PublishRxtest.java | 94 -------------------- 2 files changed, 90 insertions(+), 96 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a58ccfa0/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/PublishRxTest.java ---------------------------------------------------------------------- diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/PublishRxTest.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/PublishRxTest.java index 1d41286..973a42d 100644 --- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/PublishRxTest.java +++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/PublishRxTest.java @@ -1,7 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.apache.usergrid.corepersistence.index; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.junit.Ignore; +import org.junit.Test; + +import rx.Observable; +import rx.Subscription; +import rx.observables.ConnectableObservable; +import rx.schedulers.Schedulers; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + + /** - * Created by ApigeeCorporation on 4/21/15. + * Test to test some assumptions about RX behaviors */ -public class PublishRxTest {} +public class PublishRxTest { + + @Test + public void testPublish() throws InterruptedException { + + final int count = 10; + + final CountDownLatch latch = new CountDownLatch( count ); + + final Subscription connectedObservable = + Observable.range( 0, count ).doOnNext( integer -> latch.countDown() ).subscribeOn( Schedulers.io() ) + .subscribe(); + + + final boolean completed = latch.await( 5, TimeUnit.SECONDS ); + + assertTrue( "publish1 behaves as expected", completed ); + + final boolean completedSubscription = connectedObservable.isUnsubscribed(); + + assertTrue( "Subscription complete", completedSubscription ); + } + + + @Test + @Ignore("This seems like it should work, yet blocks forever") + public void testConnectableObserver() throws InterruptedException { + + final int count = 10; + + final CountDownLatch latch = new CountDownLatch( count ); + + final ConnectableObservable<Integer> connectedObservable = Observable.range( 0, count ).publish(); + + + //connect to our latch, which should run on it's own subscription + //start our latch running + connectedObservable.doOnNext( integer -> latch.countDown() ).subscribeOn( Schedulers.io() ).subscribe(); + + + final Observable<Integer> countObservable = connectedObservable.subscribeOn( Schedulers.io() ).count(); + + //start the sequence + connectedObservable.connect(); + + + final boolean completed = latch.await( 5, TimeUnit.SECONDS ); + + assertTrue( "publish1 behaves as expected", completed ); + + final int returnedCount = countObservable.toBlocking().last(); + + assertEquals( "Counts the same", count, returnedCount ); + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a58ccfa0/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/PublishRxtest.java ---------------------------------------------------------------------- diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/PublishRxtest.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/PublishRxtest.java deleted file mode 100644 index 6a49e80..0000000 --- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/PublishRxtest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.usergrid.corepersistence.index; - - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import org.junit.Ignore; -import org.junit.Test; - -import rx.Observable; -import rx.Subscription; -import rx.observables.ConnectableObservable; -import rx.schedulers.Schedulers; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - - -/** - * Test to test some assumptions about RX behaviors - */ -public class PublishRxTest { - - @Test - public void testPublish() throws InterruptedException { - - final int count = 10; - - final CountDownLatch latch = new CountDownLatch( count ); - - final Subscription connectedObservable = - Observable.range( 0, count ).doOnNext( integer -> latch.countDown() ).subscribeOn( Schedulers.io() ) - .subscribe(); - - - final boolean completed = latch.await( 5, TimeUnit.SECONDS ); - - assertTrue( "publish1 behaves as expected", completed ); - - final boolean completedSubscription = connectedObservable.isUnsubscribed(); - - assertTrue( "Subscription complete", completedSubscription ); - } - - - @Test - @Ignore("This seems like it should work, yet blocks forever") - public void testConnectableObserver() throws InterruptedException { - - final int count = 10; - - final CountDownLatch latch = new CountDownLatch( count ); - - final ConnectableObservable<Integer> connectedObservable = Observable.range( 0, count ).publish(); - - - //connect to our latch, which should run on it's own subscription - //start our latch running - connectedObservable.doOnNext( integer -> latch.countDown() ).subscribeOn( Schedulers.io() ).subscribe(); - - - final Observable<Integer> countObservable = connectedObservable.subscribeOn( Schedulers.io() ).count(); - - //start the sequence - connectedObservable.connect(); - - - final boolean completed = latch.await( 5, TimeUnit.SECONDS ); - - assertTrue( "publish1 behaves as expected", completed ); - - final int returnedCount = countObservable.toBlocking().last(); - - assertEquals( "Counts the same", count, returnedCount ); - } -}