public Observable() { this.observers = new CopyOnWriteArrayList<>(); }
public AbstractEventBusTest(boolean collectEventsReceived) { if (collectEventsReceived) { eventsReceived = new CopyOnWriteArrayList<Object>(); } else { eventsReceived = null; } }
@Override public List<String> create(String[] elements) { return new CopyOnWriteArrayList<>(MinimalCollection.of(elements)); } })
@Override public <T> List<T> createList(Class<T> listType, Collection<? extends T> contents) { return new CopyOnWriteArrayList<>(contents); } }
/** * the resident routers must being initialized before address notification. * FIXME: this method should not be public */ public void initWithRouters(List<Router> builtinRouters) { this.builtinRouters = builtinRouters; this.routers = new CopyOnWriteArrayList<>(builtinRouters); this.sort(); }
/** * the resident routers must being initialized before address notification. * FIXME: this method should not be public */ public void initWithRouters(List<Router> builtinRouters) { this.builtinRouters = builtinRouters; this.routers = new CopyOnWriteArrayList<>(builtinRouters); this.sort(); }
/** * Creates an empty {@code CopyOnWriteArrayList} instance. * * <p><b>Note:</b> if you need an immutable empty {@link List}, use {@link Collections#emptyList} * instead. * * @return a new, empty {@code CopyOnWriteArrayList} * @since 12.0 */ @GwtIncompatible // CopyOnWriteArrayList public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList() { return new CopyOnWriteArrayList<>(); }
public AbstractEventBusTest(boolean collectEventsReceived) { if (collectEventsReceived) { eventsReceived = new CopyOnWriteArrayList<Object>(); } else { eventsReceived = null; } }
public void setFlashMaps(List<FlashMap> flashMaps) { this.flashMaps = new CopyOnWriteArrayList<>(flashMaps); }
/** * If we use route:// protocol in version before 2.7.0, each URL will generate a Router instance, so we should * keep the routers up to date, that is, each time router URLs changes, we should update the routers list, only * keep the builtinRouters which are available all the time and the latest notified routers which are generated * from URLs. * * @param routers routers from 'router://' rules in 2.6.x or before. */ public void addRouters(List<Router> routers) { List<Router> newRouters = new CopyOnWriteArrayList<>(); newRouters.addAll(builtinRouters); newRouters.addAll(routers); CollectionUtils.sort(routers); this.routers = newRouters; }
/** * If we use route:// protocol in version before 2.7.0, each URL will generate a Router instance, so we should * keep the routers up to date, that is, each time router URLs changes, we should update the routers list, only * keep the builtinRouters which are available all the time and the latest notified routers which are generated * from URLs. * * @param routers routers from 'router://' rules in 2.6.x or before. */ public void addRouters(List<Router> routers) { List<Router> newRouters = new CopyOnWriteArrayList<>(); newRouters.addAll(builtinRouters); newRouters.addAll(routers); CollectionUtils.sort(routers); this.routers = newRouters; }
/** * Creates a {@code CopyOnWriteArrayList} instance containing the given elements. * * @param elements the elements that the list should contain, in order * @return a new {@code CopyOnWriteArrayList} containing those elements * @since 12.0 */ @GwtIncompatible // CopyOnWriteArrayList public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList( Iterable<? extends E> elements) { // We copy elements to an ArrayList first, rather than incurring the // quadratic cost of adding them to the COWAL directly. Collection<? extends E> elementsCollection = (elements instanceof Collection) ? Collections2.cast(elements) : newArrayList(elements); return new CopyOnWriteArrayList<>(elementsCollection); }
@Test public void testCollectorFailureDoesNotResultInTwoErrorEmissions() { try { final List<Throwable> list = new CopyOnWriteArrayList<Throwable>(); RxJavaPlugins.setErrorHandler(addToList(list)); final RuntimeException e1 = new RuntimeException(); final RuntimeException e2 = new RuntimeException(); Burst.items(1).error(e2) // .collect(callableListCreator(), biConsumerThrows(e1)) // .test() // .assertError(e1) // .assertNotComplete(); assertEquals(1, list.size()); assertEquals(e2, list.get(0).getCause()); } finally { RxJavaPlugins.reset(); } }
@Test public void testCollectorFailureDoesNotResultInTwoErrorEmissions() { try { final List<Throwable> list = new CopyOnWriteArrayList<Throwable>(); RxJavaPlugins.setErrorHandler(addToList(list)); final RuntimeException e1 = new RuntimeException(); final RuntimeException e2 = new RuntimeException(); Burst.items(1).error(e2) // .collect(callableListCreator(), biConsumerThrows(e1)) // .test() // .assertError(e1) // .assertNotComplete(); assertEquals(1, list.size()); assertEquals(e2, list.get(0).getCause()); } finally { RxJavaPlugins.reset(); } }
@Test public void testCollectorFailureDoesNotResultInTwoErrorEmissionsObservable() { try { final List<Throwable> list = new CopyOnWriteArrayList<Throwable>(); RxJavaPlugins.setErrorHandler(addToList(list)); final RuntimeException e1 = new RuntimeException(); final RuntimeException e2 = new RuntimeException(); Burst.items(1).error(e2) // .collect(callableListCreator(), biConsumerThrows(e1)) // .toObservable() .test() // .assertError(e1) // .assertNotComplete(); assertEquals(1, list.size()); assertEquals(e2, list.get(0).getCause()); } finally { RxJavaPlugins.reset(); } }
@Test public void singleSmartLifecycleWithoutAutoStartup() throws Exception { CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>(); TestSmartLifecycleBean bean = TestSmartLifecycleBean.forStartupTests(1, startedBeans); bean.setAutoStartup(false); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("bean", bean); assertFalse(bean.isRunning()); context.refresh(); assertFalse(bean.isRunning()); assertEquals(0, startedBeans.size()); context.start(); assertTrue(bean.isRunning()); assertEquals(1, startedBeans.size()); context.stop(); }
@Test public void singleSmartLifecycleShutdown() throws Exception { Assume.group(TestGroup.PERFORMANCE); CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>(); TestSmartLifecycleBean bean = TestSmartLifecycleBean.forShutdownTests(99, 300, stoppedBeans); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("bean", bean); context.refresh(); assertTrue(bean.isRunning()); context.stop(); assertEquals(1, stoppedBeans.size()); assertFalse(bean.isRunning()); assertEquals(bean, stoppedBeans.get(0)); }
@Test public void singleSmartLifecycleAutoStartup() throws Exception { CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>(); TestSmartLifecycleBean bean = TestSmartLifecycleBean.forStartupTests(1, startedBeans); bean.setAutoStartup(true); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("bean", bean); assertFalse(bean.isRunning()); context.refresh(); assertTrue(bean.isRunning()); context.stop(); assertFalse(bean.isRunning()); assertEquals(1, startedBeans.size()); }
@Test public void mapFactoryWithExpiringGuavaCacheDemonstrationCodeForUseInJavadoc() { //javadoc will be a version of this using lambdas and without assertions final List<Integer> completed = new CopyOnWriteArrayList<Integer>(); //size should be less than 5 to notice the effect Function<Consumer<Object>, Map<Integer, Object>> evictingMapFactory = createEvictingMapFactoryGuava(3); int numValues = 1000; TestSubscriber<Integer> ts = Flowable.range(1, numValues) .groupBy(mod5, Functions.<Integer>identity(), true, 16, evictingMapFactory) .flatMap(addCompletedKey(completed)) .test() .assertComplete(); ts.assertValueCount(numValues); //the exact eviction behaviour of the guava cache is not specified so we make some approximate tests assertTrue(completed.size() > numValues * 0.9); }
@Test public void singleLifecycleShutdown() throws Exception { CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>(); Lifecycle bean = new TestLifecycleBean(null, stoppedBeans); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("bean", bean); context.refresh(); assertFalse(bean.isRunning()); bean.start(); assertTrue(bean.isRunning()); context.stop(); assertEquals(1, stoppedBeans.size()); assertFalse(bean.isRunning()); assertEquals(bean, stoppedBeans.get(0)); }