@Override public int size() { return host.size(); }
@Override public void onComplete() { counter.active.decrementAndGet(); counter.subscription.remove(subscription); if (queue != null && counter.active.get() == 0) { if (counter.completable) { if(counter.closing.compareAndSet(false,true)) { counter.closed = true; queue.addContinuation(new Continuation( () -> { final List current = new ArrayList(); while (queue.size() > 0) { try { current.add(queue.get()); }catch(ClosedQueueException e){ break; } } throw new ClosedQueueException( current); })); queue.close(); } } } }
@Test public void publishTest() { for (int k = 0; k < ITERATIONS; k++) { Queue<Integer> queue = QueueFactories.<Integer>boundedNonBlockingQueue(10) .build(); Thread t = new Thread(() -> { try { System.out.println("Sleeping!"); Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Waking!"); System.out.println("Closing! " + queue.size()); queue.close(); }); t.start(); of(1, 2, 3).peek(i -> System.out.println("publishing " + i)) .publishTo(queue) .forEach(System.out::println); assertThat(queue.stream().collect(Collectors.toList()), equalTo(Arrays.asList(1, 2, 3))); t = null; System.gc(); } }
@Test public void mergeAdapterTest() { for (int k = 0; k < ITERATIONS; k++) { Queue<Integer> queue = QueueFactories.<Integer>boundedNonBlockingQueue(10) .build(); Thread t = new Thread(() -> { queue.add(1); queue.add(2); queue.add(3); try { System.out.println("Sleeping!"); Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Waking!"); System.out.println("Closing! " + queue.size()); queue.close(); }); t.start(); assertThat(this.<Integer>of().peek(i -> System.out.println("publishing " + i)) .merge(queue).collect(Collectors.toList()), equalTo(Arrays.asList(1, 2, 3))); t = null; System.gc(); } }
s.request(1000-queue.size()); }finally { wip.set(false);
@Test public void publishToAndMerge() { for (int k = 0; k < ITERATIONS; k++) { System.out.println("Publish toNested and zip iteration " + k); com.oath.cyclops.async.adapters.Queue<Integer> queue = QueueFactories.<Integer>boundedNonBlockingQueue(10) .build(); Thread t = new Thread(() -> { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Closing! " + queue.size()); queue.close(); }); t.start(); AtomicBoolean complete = new AtomicBoolean(false); AtomicBoolean start = new AtomicBoolean(false); List<Integer> list = of(1, 2, 3) .publishTo(queue) .peek(System.out::println) .merge(queue) .toList(); assertThat(list, hasItems(1, 2, 3)); assertThat(list.size(), equalTo(6)); System.gc(); } }
@Override public int size() { return host.size(); }
@Override public void onComplete() { counter.active.decrementAndGet(); counter.subscription.remove(subscription); if (queue != null && counter.active.get() == 0) { if (counter.completable) { if(counter.closing.compareAndSet(false,true)) { counter.closed = true; queue.addContinuation(new Continuation( () -> { final List current = new ArrayList(); while (queue.size() > 0) { try { current.add(queue.get()); }catch(ClosedQueueException e){ break; } } throw new ClosedQueueException( current); })); queue.close(); } } } }
@Override public void onComplete() { counter.active.decrementAndGet(); counter.subscription.removeValue(subscription); if (queue != null && counter.active.get() == 0) { if (counter.completable) { if(counter.closing.compareAndSet(false,true)) { counter.closed = true; queue.addContinuation(new Continuation( () -> { final List current = new ArrayList(); while (queue.size() > 0) { try { current.add(queue.get()); }catch(ClosedQueueException e){ break; } } throw new ClosedQueueException( current); })); queue.close(); } } } }
s.request(1000-queue.size()); }finally { wip.set(false);