示例#1
0
  private Throwable waitFor(final AtomicReference<Throwable> reference) {
    while (reference.get() == null) {
      yield();
    }

    return reference.get();
  }
示例#2
0
  public SelectionKey take() throws IOException, InterruptedException {
    if (this.current == null || !this.current.hasNext()) {

      while (this.selector.select() == 0) {
        if (interrupted()) {
          throw new InterruptedException();
        }

        yield();
      }

      this.current = this.selector.selectedKeys().iterator();
      assert this.current.hasNext();
    }

    final SelectionKey key = this.current.next();
    this.current.remove();
    return key;
  }
示例#3
0
  private void assertProducerReaches(
      final StubPublisher stubPublisher, final int expectedPublicationCount, boolean strict) {
    long loopStart = System.currentTimeMillis();
    while (stubPublisher.getPublicationCount() < expectedPublicationCount
        && System.currentTimeMillis() - loopStart < 5000) {
      yield();
    }

    if (strict) {
      assertThat(
          Integer.valueOf(stubPublisher.getPublicationCount()),
          equalTo(Integer.valueOf(expectedPublicationCount)));
    } else {
      final int actualPublicationCount = stubPublisher.getPublicationCount();
      assertTrue(
          "Producer reached unexpected count. Expected at least "
              + expectedPublicationCount
              + " but only reached "
              + actualPublicationCount,
          actualPublicationCount >= expectedPublicationCount);
    }
  }
示例#4
0
  void Delay() {

    for (int t = 0; t < 10000; t++) {
      Thread.yield();
    }
  }