@Test public void testNext() { Subject<String, String> obs = PublishSubject.create(); Iterator<String> it = next(obs).iterator(); fireOnNextInNewThread(obs, "one"); assertTrue(it.hasNext()); assertEquals("one", it.next()); fireOnNextInNewThread(obs, "two"); assertTrue(it.hasNext()); assertEquals("two", it.next()); obs.onCompleted(); assertFalse(it.hasNext()); try { it.next(); fail("At the end of an iterator should throw a NoSuchElementException"); } catch (NoSuchElementException e) { } // If the observable is completed, hasNext always returns false and next always throw a // NoSuchElementException. assertFalse(it.hasNext()); try { it.next(); fail("At the end of an iterator should throw a NoSuchElementException"); } catch (NoSuchElementException e) { } }
@Test public void testNextWithOnlyUsingNextMethod() { Subject<String, String> obs = PublishSubject.create(); Iterator<String> it = next(obs).iterator(); fireOnNextInNewThread(obs, "one"); assertEquals("one", it.next()); fireOnNextInNewThread(obs, "two"); assertEquals("two", it.next()); obs.onCompleted(); try { it.next(); fail("At the end of an iterator should throw a NoSuchElementException"); } catch (NoSuchElementException e) { } }
@Override public void onCompleted() { publish.onCompleted(); }
@Override public void onCompleted() { subject.onCompleted(); }
public void init() { log.info("UpdateFX current version " + Version.PATCH_VERSION); // process.timeout() will cause an error state back but we don't want to break startup in case // of an timeout timeoutTimer = Utilities.setTimeout( 10000, () -> { log.error("Timeout reached for UpdateFX"); process.onCompleted(); }); String userAgent = environment.getProperty(BitsquareEnvironment.APP_NAME_KEY) + Version.VERSION; // Check if there is a new minor version release out. The release_url should be empty if no // release is available, otherwise the download url. try { releaseUrl = Utilities.readTextFileFromServer(UPDATES_BASE_URL + "/release_url", userAgent); if (releaseUrl != null && releaseUrl.length() > 0) { log.info("New release available at: " + releaseUrl); state.set(State.NEW_RELEASE); timeoutTimer.cancel(); return; } else { // All ok. Empty file if we have no new release. } } catch (IOException e) { // ignore. File might be missing } Updater updater = new Updater( UPDATES_BASE_URL, userAgent, Version.PATCH_VERSION, Paths.get(environment.getProperty(BitsquareEnvironment.APP_DATA_DIR_KEY)), ROOT_CLASS_PATH, UPDATE_SIGNING_KEYS, UPDATE_SIGNING_THRESHOLD) { @Override protected void updateProgress(long workDone, long max) { // log.trace("updateProgress " + workDone + "/" + max); super.updateProgress(workDone, max); } }; /* updater.progressProperty().addListener((observableValue, oldValue, newValue) -> { log.trace("progressProperty newValue = " + newValue); });*/ log.info("Checking for updates!"); updater.setOnSucceeded( event -> { try { UpdateSummary summary = updater.get(); log.info("summary " + summary.toString()); if (summary.descriptions != null && summary.descriptions.size() > 0) { log.info("One liner: {}", summary.descriptions.get(0).getOneLiner()); log.info("{}", summary.descriptions.get(0).getDescription()); } if (summary.highestVersion > Version.PATCH_VERSION) { log.info("UPDATE_AVAILABLE"); state.set(State.UPDATE_AVAILABLE); // We stop the timeout and treat it not completed. // The user should click the restart button manually if there are updates available. timeoutTimer.cancel(); } else if (summary.highestVersion == Version.PATCH_VERSION) { log.info("UP_TO_DATE"); state.set(State.UP_TO_DATE); timeoutTimer.cancel(); process.onCompleted(); } } catch (Throwable e) { log.error("Exception at processing UpdateSummary: " + e.getMessage()); // we treat errors as update not as critical errors to prevent startup, // so we use state.onCompleted() instead of state.onError() state.set(State.FAILURE); timeoutTimer.cancel(); process.onCompleted(); } }); updater.setOnFailed( event -> { log.error("Update failed: " + updater.getException()); updater.getException().printStackTrace(); // we treat errors as update not as critical errors to prevent startup, // so we use state.onCompleted() instead of state.onError() state.set(State.FAILURE); timeoutTimer.cancel(); process.onCompleted(); }); Thread thread = new Thread(updater, "Online update check"); thread.setDaemon(true); thread.start(); }