Examples of Closeable


Examples of java.io.Closeable

  }

  @Override
  public Closeable register(final Observer<? super T> observer) {
    // FIXME allow multiple registrations for the same observer instance?!
    final Closeable handler = new Closeable() {
      @Override
      public void close() throws IOException {
        unregister(this);
      }
    };
View Full Code Here

Examples of java.io.Closeable

   * @param token the token to the closeable handler
   */
  public void remove(Object token) {
    lock.lock();
    try {
      Closeable c = subObservers.remove(token);
      if (c != null) {
        try { c.close(); } catch (IOException ex) { }
      }
    } finally {
      lock.unlock();
    }
  }
View Full Code Here

Examples of java.io.Closeable

    }

    @Test
    public void close_success() throws Exception
    {
        Closeable c = newMock(Closeable.class);

        c.close();

        replay();

        InternalUtils.close(c);
View Full Code Here

Examples of java.io.Closeable

    }

    @Test
    public void close_ignores_exceptions() throws Exception
    {
        Closeable c = newMock(Closeable.class);

        c.close();
        setThrowable(new IOException());

        replay();

        InternalUtils.close(c);
View Full Code Here

Examples of java.io.Closeable

        ChangeDispatcher dispatcher = new ChangeDispatcher(store.getRoot());
        AtomicBoolean running = new AtomicBoolean(true);
        final CommitQueue queue = new CommitQueue(store, dispatcher);
        final List<Exception> exceptions = Collections.synchronizedList(new ArrayList<Exception>());

        Closeable observer = dispatcher.addObserver(new Observer() {
            private Revision before = new Revision(0, 0, store.getClusterId());

            @Override
            public void contentChanged(@Nonnull NodeState root, @Nullable CommitInfo info) {
                MongoNodeState after = (MongoNodeState) root;
                Revision r = after.getRevision();
//                System.out.println("seen: " + r);
                if (r.compareRevisionTime(before) < 0) {
                    exceptions.add(new Exception(
                            "Inconsistent revision sequence. Before: " +
                                    before + ", after: " + r));
                }
                before = r;
            }
        });

        // perform commits with multiple threads
        List<Thread> writers = new ArrayList<Thread>();
        for (int i = 0; i < NUM_WRITERS; i++) {
            final Random random = new Random(i);
            writers.add(new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        for (int i = 0; i < COMMITS_PER_WRITER; i++) {
                            Revision rev = queue.createRevision();
                            try {
                                Thread.sleep(0, random.nextInt(1000));
                            } catch (InterruptedException e) {
                                // ignore
                            }
                            if (random.nextInt(5) == 0) {
                                // cancel 20% of the commits
                                queue.canceled(rev);
                            } else {
                                boolean isBranch = random.nextInt(5) == 0;
                                queue.done(rev, isBranch, null);
                            }
                        }
                    } catch (Exception e) {
                        exceptions.add(e);
                    }
                }
            }));
        }
        for (Thread t : writers) {
            t.start();
        }
        for (Thread t : writers) {
            t.join();
        }
        running.set(false);
        observer.close();
        for (Exception e : exceptions) {
            throw e;
        }
    }
View Full Code Here

Examples of java.io.Closeable

    IOUtils.copy(in, out, buf, 10000);
  }

  @Test
  public void testCloseQuietlyCloseableOk() throws IOException {
    final Closeable c = context.mock(Closeable.class);

    context.checking(new Expectations() {
      {
        oneOf(c).close();
      }
View Full Code Here

Examples of java.io.Closeable

    IOUtils.closeQuietly(c);
  }

  @Test
  public void testCloseQuietlyCloseableThrows() throws IOException {
    final Closeable c = context.mock(Closeable.class);

    context.checking(new Expectations() {
      {
        oneOf(c).close(); will(throwException(new IOException()));
      }
View Full Code Here

Examples of java.io.Closeable

    }

    @Test
    public void close_success() throws Exception
    {
        Closeable c = newMock(Closeable.class);

        c.close();

        replay();

        TapestryInternalUtils.close(c);
View Full Code Here

Examples of java.io.Closeable

    }

    @Test
    public void close_ignores_exceptions() throws Exception
    {
        Closeable c = newMock(Closeable.class);

        c.close();
        setThrowable(new IOException());

        replay();

        TapestryInternalUtils.close(c);
View Full Code Here

Examples of java.io.Closeable

    }

    @Test
    public void close_success() throws Exception
    {
        Closeable c = newMock(Closeable.class);

        c.close();

        replay();

        TapestryInternalUtils.close(c);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.