Java Code Examples for rx.observers.TestSubscriber#getOnNextEvents()
The following examples show how to use
rx.observers.TestSubscriber#getOnNextEvents() .
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: VwapServerTest.java From MarketData with Apache License 2.0 | 6 votes |
/** * Test 10 */ @Test @Ignore public void should_generate_one_google_vwap_event_when_a_google_trade_is_done() { // given TestSubscriber<Vwap> testSubscriber = new TestSubscriber<>(); HttpRequest request = createRequest("code", "GOOGL"); vwapServer.getEvents(request).subscribe(testSubscriber); // when tradeSourceSubject.onNext(new Trade("GOOGL", 10, 7058.673).toJson()); tradeSourceSubject.onNext(new Trade("APPLE", 10, 981.8).toJson()); scheduler.advanceTimeBy(1, TimeUnit.SECONDS); // then List<Vwap> events = testSubscriber.getOnNextEvents(); assertThat(events).hasSize(1); Vwap vwap = events.get(0); assertThat(vwap.code).isEqualTo("GOOGL"); assertThat(vwap.vwap).isEqualTo(705.8673); assertThat(vwap.volume).isEqualTo(10); }
Example 2
Source File: VwapServerTest.java From MarketData with Apache License 2.0 | 6 votes |
/** * Test 11 */ @Test @Ignore public void should_add_all_google_trades_to_generate_vwap_events() { // given TestSubscriber<Vwap> testSubscriber = new TestSubscriber<>(); HttpRequest request = createRequest("code", "GOOGL"); vwapServer.getEvents(request).subscribe(testSubscriber); // when tradeSourceSubject.onNext(new Trade("GOOGL", 10, 7058).toJson()); tradeSourceSubject.onNext(new Trade("GOOGL", 10, 7062).toJson()); scheduler.advanceTimeBy(1, TimeUnit.SECONDS); // then List<Vwap> events = testSubscriber.getOnNextEvents(); assertThat(events).isNotEmpty(); Vwap vwap = events.get(events.size()-1); assertThat(vwap.code).isEqualTo("GOOGL"); assertThat(vwap.vwap).isEqualTo(706); assertThat(vwap.volume).isEqualTo(20); }
Example 3
Source File: RxPaperBookTest.java From RxPaper with MIT License | 6 votes |
@Test public void testGetAllKeys() throws Exception { RxPaperBook book = RxPaperBook.with("KEYS", Schedulers.immediate()); final String key = "hello"; final String key2 = "you"; final ComplexObject value = ComplexObject.random(); book.write(key, value).subscribe(); book.write(key2, value).subscribe(); final TestSubscriber<List<String>> foundSubscriber = TestSubscriber.create(); book.keys().subscribe(foundSubscriber); foundSubscriber.awaitTerminalEvent(); foundSubscriber.assertNoErrors(); foundSubscriber.assertValueCount(1); final List<List<String>> onNextEvents = foundSubscriber.getOnNextEvents(); foundSubscriber.assertValueCount(1); Assert.assertEquals(book.book.getAllKeys(), onNextEvents.get(0)); }
Example 4
Source File: FontInstallerTest.java From fontster with Apache License 2.0 | 5 votes |
@Test public void testGenerateCommands_systemMountedFirst() throws Exception { downloadFontPack(); TestSubscriber<String> testSubscriber = new TestSubscriber<>(); FontInstaller.generateCommands(MOCK_FONT_PACK, null).subscribe(testSubscriber); List<String> commands = testSubscriber.getOnNextEvents(); assertEquals(SystemConstants.MOUNT_SYSTEM_COMMAND, commands.get(0)); deleteDownloadFolder(); }
Example 5
Source File: CompressDataJobITest.java From hawkular-metrics with Apache License 2.0 | 5 votes |
private <T> void testCompressResults(MetricType<T> type, Metric<T> metric, DateTime start) throws Exception { if (metric.getDataPoints() != null && !metric.getDataPoints().isEmpty()) { doAction(() -> metricsService.addDataPoints(type, Observable.just(metric))); } CountDownLatch latch = new CountDownLatch(1); jobScheduler.onJobFinished(jobDetails -> { if(jobDetails.getJobName().equals(JOB_NAME)) { latch.countDown(); } }); jobScheduler.advanceTimeBy(1); assertTrue(latch.await(TIMEOUT, TimeUnit.SECONDS)); long startSlice = DateTimeService.getTimeSlice(start.getMillis(), Duration.standardHours(2)); long endSlice = DateTimeService.getTimeSlice(start.plusHours(1).plusMinutes(59).getMillis(), Duration .standardHours(2)); DataPointDecompressTransformer<T> decompressor = new DataPointDecompressTransformer<>(type, Order.ASC, 0, start .getMillis(), start.plusMinutes(30).getMillis()); Observable<DataPoint<T>> dataPoints = dataAccess.findCompressedData(metric.getMetricId(), startSlice, endSlice, 0, Order.ASC).compose(decompressor); TestSubscriber<DataPoint<T>> pointTestSubscriber = new TestSubscriber<>(); dataPoints.subscribe(pointTestSubscriber); pointTestSubscriber.awaitTerminalEvent(5, TimeUnit.SECONDS); pointTestSubscriber.assertCompleted(); List<DataPoint<T>> compressedPoints = pointTestSubscriber.getOnNextEvents(); assertEquals(metric.getDataPoints(), compressedPoints); }
Example 6
Source File: BaseITest.java From hawkular-metrics with Apache License 2.0 | 5 votes |
/** * This method takes a function that produces an Observable. The method blocks up to * five seconds until the Observable emits a terminal event. The items that the * Observable emits are then returned. * * @param fn A function that produces an Observable * @param <T> The type of items emitted by the Observable * @return A list of the items emitted by the Observable */ protected <T> List<T> getOnNextEvents(Supplier<Observable<T>> fn) { TestSubscriber<T> subscriber = new TestSubscriber<>(); Observable<T> observable = fn.get(); observable.doOnError(Throwable::printStackTrace) .subscribe(subscriber); subscriber.awaitTerminalEvent(5, SECONDS); subscriber.assertNoErrors(); subscriber.assertCompleted(); return subscriber.getOnNextEvents(); }
Example 7
Source File: PrayerManagerTest.java From android with Apache License 2.0 | 5 votes |
@Test public void manualLocationButNotSet() { when(mHiddenPreferences.getLocationDistanceLimit()) .thenReturn(5000L); when(mLocationPreferences.isUsingAutomaticLocation()) .thenReturn(false); when(mLocationPreferences.getPreferredLocation()) .thenReturn(null); when(mLocationPreferences.hasPreferredLocation()) .thenReturn(false); when(mLocationRepository.getLocation(anyBoolean())) .thenReturn(Observable.just(mLocation)); when(mPrayerDownloader.getPrayerTimes(eq(mLocation))) .thenReturn(Observable.just(mPrayerContext1)); PrayerManager prayerManager = new PrayerManager( mPrayerDownloader, mLocationRepository, mPrayerBroadcaster, mHiddenPreferences, mLocationPreferences ); TestSubscriber<PrayerContext> testSubscriber = new TestSubscriber<>(); prayerManager.getPrayerContext(false).subscribe(testSubscriber); testSubscriber.assertNoErrors(); List<PrayerContext> prayers = testSubscriber.getOnNextEvents(); assertThat(prayers).hasSize(1); assertThat(prayers.get(0)).isEqualTo(mPrayerContext1); }
Example 8
Source File: CompressionTest.java From hawkular-metrics with Apache License 2.0 | 5 votes |
@Test public void testNonExistantCompression() throws Exception { // Write to past .. should go to data_0 table long start = now().minusDays(2).getMillis(); createAndInsertMetrics(start, 100, 1); compressData(start); // Try to compress table in the past // Verify that the out of order table was not dropped TableMetadata table = session.getCluster().getMetadata().getKeyspace(getKeyspace()) .getTable(DataAccessImpl.OUT_OF_ORDER_TABLE_NAME); assertNotNull(table, "data_0 should not have been dropped"); TestSubscriber<Long> ts = new TestSubscriber<>(); // Verify that the out of order table was not compressed rxSession.executeAndFetch(String.format("SELECT COUNT(*) FROM %s", DataAccessImpl.OUT_OF_ORDER_TABLE_NAME)) .map(r -> r.getLong(0)) .subscribe(ts); ts.awaitTerminalEvent(2, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertCompleted(); List<Long> onNextEvents = ts.getOnNextEvents(); assertEquals(onNextEvents.size(), 1); assertEquals(onNextEvents.get(0).longValue(), 100); }
Example 9
Source File: FontInstallerTest.java From fontster with Apache License 2.0 | 5 votes |
@Test public void testGenerateCommands_containsInstallCommands() throws Exception { downloadFontPack(); TestSubscriber<String> testSubscriber = new TestSubscriber<>(); FontInstaller.generateCommands(MOCK_FONT_PACK, null).subscribe(testSubscriber); List<String> commands = testSubscriber.getOnNextEvents(); assertTrue(commands.containsAll(EXPECTED_COMMANDS)); deleteDownloadFolder(); }
Example 10
Source File: RunApplicationTest.java From vertx-deploy-tools with Apache License 2.0 | 5 votes |
private List<DeployApplicationRequest> execute() { RunApplication command = new RunApplication(Vertx.vertx(), config); Observable<DeployApplicationRequest> observable = command.readServiceDefaults(request); TestSubscriber<DeployApplicationRequest> testSubscriber = new TestSubscriber<>(); observable.subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); testSubscriber.assertNoErrors(); testSubscriber.assertCompleted(); return testSubscriber.getOnNextEvents(); }
Example 11
Source File: TestSubscriberAssertionsWrapper.java From rxassertions with Apache License 2.0 | 5 votes |
TestSubscriberAssertionsWrapper(BlockingObservable<T> actual) { super(actual, TestSubscriberAssertionsWrapper.class); TestSubscriber<T> subscriber = new TestSubscriber<>(); actual.subscribe(subscriber); onErrorEvents = subscriber.getOnErrorEvents(); onNextEvents = subscriber.getOnNextEvents(); onCompletedEvents = subscriber.getOnCompletedEvents(); }
Example 12
Source File: PrayerDownloaderTest.java From android with Apache License 2.0 | 4 votes |
@Test public void getPrayerContextCodeSameYear() { String code = "ext-157"; PrayerDownloader d = new PrayerDownloader( mDateHelper, mPrayerClient, mPrayerCache, mInterfacePreferences ); when(mDateHelper.getCurrentMonth()) .thenReturn(3); when(mDateHelper.getCurrentYear()) .thenReturn(2016); when(mDateHelper.getNextMonth()) .thenReturn(4); when(mDateHelper.isNextMonthNewYear()) .thenReturn(false); when(mPrayerCache.get(anyInt(), anyInt(), eq(code))) .thenReturn(Observable.<PrayerData>empty()); when(mPrayerClient.getPrayerTimesByCode(eq(code), anyInt(), eq(4))) .thenReturn(Observable.just(mPrayerData1)); when(mPrayerClient.getPrayerTimesByCode(eq(code), anyInt(), eq(5))) .thenReturn(Observable.just(mPrayerData2)); TestSubscriber<PrayerContext> testSubscriber = new TestSubscriber<>(); d.getPrayerTimes(code).subscribe(testSubscriber); testSubscriber.assertNoErrors(); List<PrayerContext> prayers = testSubscriber.getOnNextEvents(); assertThat(prayers).hasSize(1); verify(mPrayerCache, times(1)).get(eq(2016), eq(4), eq(code)); verify(mPrayerCache, times(1)).get(eq(2016), eq(5), eq(code)); verify(mPrayerClient, times(1)).getPrayerTimesByCode(eq(code), eq(2016), eq(4)); verify(mPrayerClient, times(1)).getPrayerTimesByCode(eq(code), eq(2016), eq(5)); verify(mPrayerCache, times(1)).save(eq(mPrayerData1)); verify(mPrayerCache, times(1)).save(eq(mPrayerData2)); }
Example 13
Source File: PrayerDownloaderTest.java From android with Apache License 2.0 | 4 votes |
@Test public void prayerContextCodeCache() { PrayerDownloader d = new PrayerDownloader( mDateHelper, mPrayerClient, mPrayerCache, mInterfacePreferences ); when(mDateHelper.getCurrentMonth()) .thenReturn(11); when(mDateHelper.getCurrentYear()) .thenReturn(2016); when(mDateHelper.getNextYear()) .thenReturn(2017); when(mDateHelper.getNextMonth()) .thenReturn(0); when(mDateHelper.isNextMonthNewYear()) .thenReturn(true); when(mPrayerCache.get(eq(2016), eq(12), eq("ext-157"))) .thenReturn(Observable.just(mPrayerData1)); when(mPrayerCache.get(eq(2017), eq(1), eq("ext-157"))) .thenReturn(Observable.just(mPrayerData2)); when(mPrayerClient.getPrayerTimesByCode(anyString(), anyInt(), eq(12))) .thenReturn(Observable.just(mPrayerData3)); when(mPrayerClient.getPrayerTimesByCode(anyString(), anyInt(), eq(1))) .thenReturn(Observable.just(mPrayerData4)); TestSubscriber<PrayerContext> testSubscriber = new TestSubscriber<>(); d.getPrayerTimes("ext-157").subscribe(testSubscriber); testSubscriber.assertNoErrors(); List<PrayerContext> prayers = testSubscriber.getOnNextEvents(); assertThat(prayers).hasSize(1); PrayerContextImpl pc = (PrayerContextImpl) prayers.get(0); assertThat(pc.getCurrentPrayerData()).isEqualTo(mPrayerData1); assertThat(pc.getNextPrayerData()).isEqualTo(mPrayerData2); }
Example 14
Source File: PrayerDownloaderTest.java From android with Apache License 2.0 | 4 votes |
@Test public void prayerContextCoordinateCache() { PrayerDownloader d = new PrayerDownloader( mDateHelper, mPrayerClient, mPrayerCache, mInterfacePreferences ); when(mLocation.getLatitude()) .thenReturn(3.28011); when(mLocation.getLongitude()) .thenReturn(101.556); when(mLocation.distanceTo(any(Location.class))) .thenReturn(0f); when(mDateHelper.getCurrentMonth()) .thenReturn(11); when(mDateHelper.getCurrentYear()) .thenReturn(2016); when(mDateHelper.getNextYear()) .thenReturn(2017); when(mDateHelper.getNextMonth()) .thenReturn(0); when(mDateHelper.isNextMonthNewYear()) .thenReturn(true); when(mPrayerCache.get(eq(2016), eq(12), eq(mLocation))) .thenReturn(Observable.just(mPrayerData1)); when(mPrayerCache.get(eq(2017), eq(1), eq(mLocation))) .thenReturn(Observable.just(mPrayerData2)); when(mPrayerClient.getPrayerTimesByCoordinates(anyDouble(), anyDouble(), anyInt(), eq(12))) .thenReturn(Observable.just(mPrayerData3)); when(mPrayerClient.getPrayerTimesByCoordinates(anyDouble(), anyDouble(), anyInt(), eq(1))) .thenReturn(Observable.just(mPrayerData4)); TestSubscriber<PrayerContext> testSubscriber = new TestSubscriber<>(); d.getPrayerTimes(mLocation).subscribe(testSubscriber); testSubscriber.assertNoErrors(); List<PrayerContext> prayers = testSubscriber.getOnNextEvents(); assertThat(prayers).hasSize(1); PrayerContextImpl pc = (PrayerContextImpl) prayers.get(0); assertThat(pc.getCurrentPrayerData()).isEqualTo(mPrayerData1); assertThat(pc.getNextPrayerData()).isEqualTo(mPrayerData2); }
Example 15
Source File: PrayerDownloaderTest.java From android with Apache License 2.0 | 4 votes |
@Test public void getPrayerContextCodeNextYear() { String code = "ext-157"; PrayerDownloader d = new PrayerDownloader( mDateHelper, mPrayerClient, mPrayerCache, mInterfacePreferences ); when(mDateHelper.getCurrentMonth()) .thenReturn(11); when(mDateHelper.getCurrentYear()) .thenReturn(2016); when(mDateHelper.getNextYear()) .thenReturn(2017); when(mDateHelper.getNextMonth()) .thenReturn(0); when(mDateHelper.isNextMonthNewYear()) .thenReturn(true); when(mPrayerCache.get(anyInt(), anyInt(), eq(code))) .thenReturn(Observable.<PrayerData>empty()); when(mPrayerClient.getPrayerTimesByCode(eq(code), anyInt(), eq(12))) .thenReturn(Observable.just(mPrayerData1)); when(mPrayerClient.getPrayerTimesByCode(eq(code), anyInt(), eq(1))) .thenReturn(Observable.just(mPrayerData2)); TestSubscriber<PrayerContext> testSubscriber = new TestSubscriber<>(); d.getPrayerTimes(code).subscribe(testSubscriber); testSubscriber.assertNoErrors(); List<PrayerContext> prayers = testSubscriber.getOnNextEvents(); assertThat(prayers).hasSize(1); verify(mPrayerCache, times(1)).get(eq(2016), eq(12), eq(code)); verify(mPrayerCache, times(1)).get(eq(2017), eq(1), eq(code)); verify(mPrayerClient, times(1)).getPrayerTimesByCode(eq(code), eq(2016), eq(12)); verify(mPrayerClient, times(1)).getPrayerTimesByCode(eq(code), eq(2017), eq(1)); verify(mPrayerCache, times(1)).save(eq(mPrayerData1)); verify(mPrayerCache, times(1)).save(eq(mPrayerData2)); }
Example 16
Source File: SimpleUploadDataStoreTest.java From RxUploader with Apache License 2.0 | 4 votes |
@SuppressLint("ApplySharedPref") @Test public void testGetAll() throws Exception { final Job job1 = Job.builder() .setId("job_id_1") .setFilepath("test/file/path/1") .setMetadata(Collections.emptyMap()) .setMimeType("text/plain") .setStatus(Status.createQueued("job_id_1")) .build(); final Job job2 = Job.builder() .setId("job_id_2") .setFilepath("test/file/path/2") .setMetadata(Collections.emptyMap()) .setMimeType("text/plain") .setStatus(Status.createCompleted("job_id_2", null)) .build(); final Job job3 = Job.builder() .setId("job_id_3") .setFilepath("test/file/path/3") .setMetadata(Collections.emptyMap()) .setMimeType("text/plain") .setStatus(Status.createFailed("job_id_3", ErrorType.SERVICE)) .build(); final Set<String> keys = new HashSet<>(); keys.add(SimpleUploadDataStore.jobIdKey(job1.id())); keys.add(SimpleUploadDataStore.jobIdKey(job2.id())); keys.add(SimpleUploadDataStore.jobIdKey(job3.id())); final SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putStringSet(SimpleUploadDataStore.KEY_JOB_IDS, keys); editor.putString(SimpleUploadDataStore.jobIdKey(job1.id()), gson.toJson(job1)); editor.putString(SimpleUploadDataStore.jobIdKey(job2.id()), gson.toJson(job2)); editor.putString(SimpleUploadDataStore.jobIdKey(job3.id()), gson.toJson(job3)); editor.commit(); final TestSubscriber<Job> ts = TestSubscriber.create(); dataStore.getAll().subscribe(ts); ts.awaitTerminalEvent(1, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertCompleted(); ts.assertValueCount(3); final List<Job> jobs = ts.getOnNextEvents(); assertThat(jobs, containsInAnyOrder(job1, job2, job3)); }
Example 17
Source File: PrayerDownloaderTest.java From android with Apache License 2.0 | 4 votes |
@Test public void getPrayerContextDifferentYear() { PrayerDownloader d = new PrayerDownloader( mDateHelper, mPrayerClient, mPrayerCache, mInterfacePreferences ); when(mLocation.getLatitude()) .thenReturn(3.28011); when(mLocation.getLongitude()) .thenReturn(101.556); when(mLocation.distanceTo(any(Location.class))) .thenReturn(0f); when(mDateHelper.getCurrentMonth()) .thenReturn(11); when(mDateHelper.getCurrentYear()) .thenReturn(2016); when(mDateHelper.getNextYear()) .thenReturn(2017); when(mDateHelper.getNextMonth()) .thenReturn(0); when(mDateHelper.isNextMonthNewYear()) .thenReturn(true); when(mPrayerCache.get(anyInt(), anyInt(), eq(mLocation))) .thenReturn(Observable.<PrayerData>empty()); when(mPrayerClient.getPrayerTimesByCoordinates(anyDouble(), anyDouble(), anyInt(), eq(12))) .thenReturn(Observable.just(mPrayerData1)); when(mPrayerClient.getPrayerTimesByCoordinates(anyDouble(), anyDouble(), anyInt(), eq(1))) .thenReturn(Observable.just(mPrayerData2)); TestSubscriber<PrayerContext> testSubscriber = new TestSubscriber<>(); d.getPrayerTimes(mLocation).subscribe(testSubscriber); testSubscriber.assertNoErrors(); List<PrayerContext> prayers = testSubscriber.getOnNextEvents(); assertThat(prayers).hasSize(1); verify(mPrayerCache, times(1)).get(eq(2016), eq(12), eq(mLocation)); verify(mPrayerCache, times(1)).get(eq(2017), eq(1), eq(mLocation)); verify(mPrayerClient, times(1)).getPrayerTimesByCoordinates(eq(3.28011), eq(101.556), eq(2016), eq(12)); verify(mPrayerClient, times(1)).getPrayerTimesByCoordinates(eq(3.28011), eq(101.556), eq(2017), eq(1)); verify(mPrayerCache, times(1)).save(eq(mPrayerData1), eq(mLocation)); verify(mPrayerCache, times(1)).save(eq(mPrayerData2), eq(mLocation)); }
Example 18
Source File: PrayerDownloaderTest.java From android with Apache License 2.0 | 4 votes |
@Test public void getPrayerContextSameYear() { PrayerDownloader d = new PrayerDownloader( mDateHelper, mPrayerClient, mPrayerCache, mInterfacePreferences ); when(mLocation.getLatitude()) .thenReturn(3.28011); when(mLocation.getLongitude()) .thenReturn(101.556); when(mLocation.distanceTo(any(Location.class))) .thenReturn(0f); when(mDateHelper.getCurrentMonth()) .thenReturn(3); when(mDateHelper.getCurrentYear()) .thenReturn(2016); when(mDateHelper.getNextMonth()) .thenReturn(4); when(mDateHelper.isNextMonthNewYear()) .thenReturn(false); when(mPrayerCache.get(anyInt(), anyInt(), eq(mLocation))) .thenReturn(Observable.<PrayerData>empty()); when(mPrayerClient.getPrayerTimesByCoordinates(anyDouble(), anyDouble(), anyInt(), eq(4))) .thenReturn(Observable.just(mPrayerData1)); when(mPrayerClient.getPrayerTimesByCoordinates(anyDouble(), anyDouble(), anyInt(), eq(5))) .thenReturn(Observable.just(mPrayerData2)); TestSubscriber<PrayerContext> testSubscriber = new TestSubscriber<>(); d.getPrayerTimes(mLocation).subscribe(testSubscriber); testSubscriber.assertNoErrors(); List<PrayerContext> prayers = testSubscriber.getOnNextEvents(); assertThat(prayers).hasSize(1); verify(mPrayerCache, times(1)).get(eq(2016), eq(4), eq(mLocation)); verify(mPrayerCache, times(1)).get(eq(2016), eq(5), eq(mLocation)); verify(mPrayerClient, times(1)).getPrayerTimesByCoordinates(eq(3.28011), eq(101.556), eq(2016), eq(4)); verify(mPrayerClient, times(1)).getPrayerTimesByCoordinates(eq(3.28011), eq(101.556), eq(2016), eq(5)); verify(mPrayerCache, times(1)).save(eq(mPrayerData1), eq(mLocation)); verify(mPrayerCache, times(1)).save(eq(mPrayerData2), eq(mLocation)); }
Example 19
Source File: PrayerManagerTest.java From android with Apache License 2.0 | 4 votes |
@Test public void manualLocation() { PrayerCode pc = new PrayerCode.Builder() .setCode("ext-153") .setCity("Jitra") .build(); when(mHiddenPreferences.getLocationDistanceLimit()) .thenReturn(5000L); when(mLocationPreferences.isUsingAutomaticLocation()) .thenReturn(false); when(mLocationPreferences.getPreferredLocation()) .thenReturn(pc); when(mLocationPreferences.hasPreferredLocation()) .thenReturn(true); when(mPrayerDownloader.getPrayerTimes(eq(mLocation))) .thenReturn(Observable.just(mPrayerContext1)); when(mPrayerDownloader.getPrayerTimes(eq(pc.getCode()))) .thenReturn(Observable.just(mPrayerContext2)); PrayerManager prayerManager = new PrayerManager( mPrayerDownloader, mLocationRepository, mPrayerBroadcaster, mHiddenPreferences, mLocationPreferences ); TestSubscriber<PrayerContext> testSubscriber = new TestSubscriber<>(); prayerManager.getPrayerContext(false).subscribe(testSubscriber); testSubscriber.assertNoErrors(); List<PrayerContext> prayers = testSubscriber.getOnNextEvents(); assertThat(prayers).hasSize(1); assertThat(prayers.get(0)).isEqualTo(mPrayerContext2); }
Example 20
Source File: CompressionTest.java From hawkular-metrics with Apache License 2.0 | 4 votes |
@Test void addAndCompressData() throws Exception { long start = now().getMillis(); int amountOfMetrics = 1000; int datapointsPerMetric = 10; createAndInsertMetrics(start, amountOfMetrics, datapointsPerMetric); CountDownLatch latch = new CountDownLatch(1); latchingSchemaChangeListener(latch); compressData(start); // Verify the count from the data_compressed table TestSubscriber<Long> ts = new TestSubscriber<>(); rxSession.executeAndFetch("SELECT COUNT(*) FROM data_compressed") .map(r -> r.getLong(0)) .subscribe(ts); ts.awaitTerminalEvent(2, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertCompleted(); List<Long> onNextEvents = ts.getOnNextEvents(); assertEquals(onNextEvents.size(), 1); assertEquals(onNextEvents.get(0).longValue(), amountOfMetrics); // Now read it through findDataPoints also assertTrue(latch.await(5, TimeUnit.SECONDS)); for (int i = 0; i < amountOfMetrics; i++) { String metricName = String.format("m%d", i); MetricId<Double> mId = new MetricId<>(tenantId, GAUGE, metricName); Observable<DataPoint<Double>> dataPoints = metricsService.findDataPoints(mId, start, start + datapointsPerMetric + 1, 0, Order.ASC); TestSubscriber<DataPoint<Double>> tsrD = new TestSubscriber<>(); dataPoints.subscribe(tsrD); tsrD.awaitTerminalEvent(10, TimeUnit.SECONDS); tsrD.assertCompleted(); tsrD.assertNoErrors(); tsrD.assertValueCount(datapointsPerMetric); List<DataPoint<Double>> datapoints = tsrD.getOnNextEvents(); for(int h = 0; h < datapoints.size(); h++) { assertEquals(datapoints.get(h).getValue(), startValue + h); } } }