Java Code Examples for rx.subjects.Subject#subscribe()
The following examples show how to use
rx.subjects.Subject#subscribe() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewLocatorTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldFailWhenUsedAgainstMemcacheBucket() { Locator locator = new ViewLocator(0); ClusterConfig config = mock(ClusterConfig.class); when(config.bucketConfig("default")).thenReturn(mock(MemcachedBucketConfig.class)); CouchbaseRequest request = mock(ViewQueryRequest.class); Subject<CouchbaseResponse, CouchbaseResponse> response = AsyncSubject.create(); when(request.bucket()).thenReturn("default"); when(request.observable()).thenReturn(response); TestSubscriber<CouchbaseResponse> subscriber = new TestSubscriber<CouchbaseResponse>(); response.subscribe(subscriber); locator.locateAndDispatch(request, Collections.<Node>emptyList(), config, null, null); subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); List<Throwable> errors = subscriber.getOnErrorEvents(); assertEquals(1, errors.size()); assertTrue(errors.get(0) instanceof ServiceNotAvailableException); }
Example 2
Source File: ObservablesTest.java From couchbase-jvm-core with Apache License 2.0 | 5 votes |
/** * Heper method to test fail-safe functionality. * * @param scheduler the scheduler to test against. if null, it will be failed on the current thread. * @param threadName the part of a thread name to match against for additional verification. */ private static void testFailSafe(final Scheduler scheduler, final String threadName) { Subject<CouchbaseResponse, CouchbaseResponse> subject = AsyncSubject.create(); TestSubscriber<CouchbaseResponse> subscriber = TestSubscriber.create(); subject.subscribe(subscriber); Exception failure = new CouchbaseException("Some Error"); Observables.failSafe(scheduler, scheduler != null, subject, failure); subscriber.awaitTerminalEvent(); subscriber.assertError(failure); assertTrue(subscriber.getLastSeenThread().getName().contains(threadName)); }
Example 3
Source File: ViewHandlerTest.java From couchbase-jvm-core with Apache License 2.0 | 5 votes |
@Test public void shouldHavePipeliningDisabled() { Subject<CouchbaseResponse,CouchbaseResponse> obs1 = AsyncSubject.create(); ViewQueryRequest requestMock1 = mock(ViewQueryRequest.class); when(requestMock1.query()).thenReturn("{...}"); when(requestMock1.bucket()).thenReturn("foo"); when(requestMock1.username()).thenReturn("foo"); when(requestMock1.password()).thenReturn(""); when(requestMock1.observable()).thenReturn(obs1); when(requestMock1.isActive()).thenReturn(true); Subject<CouchbaseResponse,CouchbaseResponse> obs2 = AsyncSubject.create(); ViewQueryRequest requestMock2 = mock(ViewQueryRequest.class); when(requestMock2.query()).thenReturn("{...}"); when(requestMock2.bucket()).thenReturn("foo"); when(requestMock2.username()).thenReturn("foo"); when(requestMock2.password()).thenReturn(""); when(requestMock2.observable()).thenReturn(obs2); when(requestMock2.isActive()).thenReturn(true); TestSubscriber<CouchbaseResponse> t1 = TestSubscriber.create(); TestSubscriber<CouchbaseResponse> t2 = TestSubscriber.create(); obs1.subscribe(t1); obs2.subscribe(t2); channel.writeOutbound(requestMock1, requestMock2); t1.assertNotCompleted(); t2.assertError(RequestCancelledException.class); }
Example 4
Source File: QueryHandlerTest.java From couchbase-jvm-core with Apache License 2.0 | 5 votes |
@Test public void shouldHavePipeliningDisabled() { Subject<CouchbaseResponse,CouchbaseResponse> obs1 = AsyncSubject.create(); RawQueryRequest requestMock1 = mock(RawQueryRequest.class); when(requestMock1.query()).thenReturn("SELECT * FROM `foo`"); when(requestMock1.bucket()).thenReturn("foo"); when(requestMock1.username()).thenReturn("foo"); when(requestMock1.password()).thenReturn(""); when(requestMock1.observable()).thenReturn(obs1); when(requestMock1.isActive()).thenReturn(true); Subject<CouchbaseResponse,CouchbaseResponse> obs2 = AsyncSubject.create(); RawQueryRequest requestMock2 = mock(RawQueryRequest.class); when(requestMock2.query()).thenReturn("SELECT * FROM `foo`"); when(requestMock2.bucket()).thenReturn("foo"); when(requestMock2.username()).thenReturn("foo"); when(requestMock2.password()).thenReturn(""); when(requestMock2.observable()).thenReturn(obs2); when(requestMock2.isActive()).thenReturn(true); TestSubscriber<CouchbaseResponse> t1 = TestSubscriber.create(); TestSubscriber<CouchbaseResponse> t2 = TestSubscriber.create(); obs1.subscribe(t1); obs2.subscribe(t2); channel.writeOutbound(requestMock1, requestMock2); t1.assertNotCompleted(); t2.assertError(RequestCancelledException.class); }
Example 5
Source File: SearchHandlerTest.java From couchbase-jvm-core with Apache License 2.0 | 5 votes |
@Test public void shouldHavePipeliningDisabled() { Subject<CouchbaseResponse,CouchbaseResponse> obs1 = AsyncSubject.create(); SearchQueryRequest requestMock1 = mock(SearchQueryRequest.class); when(requestMock1.path()).thenReturn(""); when(requestMock1.payload()).thenReturn(""); when(requestMock1.bucket()).thenReturn("foo"); when(requestMock1.username()).thenReturn("foo"); when(requestMock1.password()).thenReturn(""); when(requestMock1.observable()).thenReturn(obs1); when(requestMock1.isActive()).thenReturn(true); Subject<CouchbaseResponse,CouchbaseResponse> obs2 = AsyncSubject.create(); SearchQueryRequest requestMock2 = mock(SearchQueryRequest.class); when(requestMock2.path()).thenReturn(""); when(requestMock2.payload()).thenReturn(""); when(requestMock2.bucket()).thenReturn("foo"); when(requestMock2.username()).thenReturn("foo"); when(requestMock2.password()).thenReturn(""); when(requestMock2.observable()).thenReturn(obs2); when(requestMock2.isActive()).thenReturn(true); TestSubscriber<CouchbaseResponse> t1 = TestSubscriber.create(); TestSubscriber<CouchbaseResponse> t2 = TestSubscriber.create(); obs1.subscribe(t1); obs2.subscribe(t2); channel.writeOutbound(requestMock1, requestMock2); t1.assertNotCompleted(); t2.assertError(RequestCancelledException.class); }
Example 6
Source File: ConfigHandlerTest.java From couchbase-jvm-core with Apache License 2.0 | 5 votes |
@Test public void shouldHavePipeliningDisabled() { Subject<CouchbaseResponse,CouchbaseResponse> obs1 = AsyncSubject.create(); GetDesignDocumentsRequest requestMock1 = mock(GetDesignDocumentsRequest.class); when(requestMock1.path()).thenReturn(""); when(requestMock1.bucket()).thenReturn("foo"); when(requestMock1.username()).thenReturn("foo"); when(requestMock1.password()).thenReturn(""); when(requestMock1.observable()).thenReturn(obs1); when(requestMock1.isActive()).thenReturn(true); Subject<CouchbaseResponse,CouchbaseResponse> obs2 = AsyncSubject.create(); GetDesignDocumentsRequest requestMock2 = mock(GetDesignDocumentsRequest.class); when(requestMock1.path()).thenReturn(""); when(requestMock2.bucket()).thenReturn("foo"); when(requestMock2.username()).thenReturn("foo"); when(requestMock2.password()).thenReturn(""); when(requestMock2.observable()).thenReturn(obs2); when(requestMock2.isActive()).thenReturn(true); TestSubscriber<CouchbaseResponse> t1 = TestSubscriber.create(); TestSubscriber<CouchbaseResponse> t2 = TestSubscriber.create(); obs1.subscribe(t1); obs2.subscribe(t2); channel.writeOutbound(requestMock1, requestMock2); t1.assertNotCompleted(); t2.assertError(RequestCancelledException.class); }
Example 7
Source File: KeyValueHandlerTest.java From couchbase-jvm-core with Apache License 2.0 | 5 votes |
@Test public void shouldHavePipeliningEnabled() { Subject<CouchbaseResponse,CouchbaseResponse> obs1 = AsyncSubject.create(); GetRequest requestMock1 = mock(GetRequest.class); when(requestMock1.keyBytes()).thenReturn("hello".getBytes()); when(requestMock1.bucket()).thenReturn("foo"); when(requestMock1.observable()).thenReturn(obs1); Subject<CouchbaseResponse,CouchbaseResponse> obs2 = AsyncSubject.create(); GetRequest requestMock2 = mock(GetRequest.class); when(requestMock2.keyBytes()).thenReturn("hello".getBytes()); when(requestMock2.bucket()).thenReturn("foo"); when(requestMock2.observable()).thenReturn(obs2); TestSubscriber<CouchbaseResponse> t1 = TestSubscriber.create(); TestSubscriber<CouchbaseResponse> t2 = TestSubscriber.create(); obs1.subscribe(t1); obs2.subscribe(t2); channel.writeOutbound(requestMock1, requestMock2); t1.assertNotCompleted(); t2.assertNotCompleted(); }