@Test public void testOverflow() throws IOException { AbstractWatchService.Key key = watcher.register(new StubWatchable(), ImmutableSet.of(ENTRY_CREATE)); for (int i = 0; i < AbstractWatchService.Key.MAX_QUEUE_SIZE + 10; i++) { key.post(new AbstractWatchService.Event<>(ENTRY_CREATE, 1, null)); } key.signal(); List<WatchEvent<?>> events = key.pollEvents(); assertThat(events).hasSize(AbstractWatchService.Key.MAX_QUEUE_SIZE + 1); for (int i = 0; i < AbstractWatchService.Key.MAX_QUEUE_SIZE; i++) { assertThat(events.get(i).kind()).isEqualTo(ENTRY_CREATE); } WatchEvent<?> lastEvent = events.get(AbstractWatchService.Key.MAX_QUEUE_SIZE); assertThat(lastEvent.kind()).isEqualTo(OVERFLOW); assertThat(lastEvent.count()).isEqualTo(10); }
public Key register(Watchable watchable, Iterable<? extends WatchEvent.Kind<?>> eventTypes) throws IOException { checkOpen(); return new Key(this, watchable, eventTypes); }
AbstractWatchService implements WatchService { public Key register(Watchable watchable, Iterable<? extends WatchEvent.Kind<?>> eventTypes) throws IOException { checkOpen(); return new Key(this, watchable, eventTypes); } }
AbstractWatchService implements WatchService { public Key register(Watchable watchable, Iterable<? extends WatchEvent.Kind<?>> eventTypes) throws IOException { checkOpen(); return new Key(this, watchable, eventTypes); }  }
AbstractWatchService implements WatchService { public Key register(Watchable watchable, Iterable<? extends WatchEvent.Kind<?>> eventTypes) throws IOException { checkOpen(); return new Key(this, watchable, eventTypes); }  Key register(Watchable watchable, Iterable<? extends WatchEvent.Kind<?>> eventTypes); @VisibleForTesting boolean isOpen(); void cancelled(Key key); @NullableDecl @Override WatchKey poll(); @NullableDecl @Override WatchKey poll(long timeout, TimeUnit unit); @Override WatchKey take(); @Override void close(); }
AbstractWatchService implements WatchService { public Key register(Watchable watchable, Iterable<? extends WatchEvent.Kind<?>> eventTypes) throws IOException { checkOpen(); return new Key(this, watchable, eventTypes); }  Key register(Watchable watchable, Iterable<? extends WatchEvent.Kind<?>> eventTypes); @VisibleForTesting boolean isOpen(); void cancelled(Key key); @NullableDecl @Override WatchKey poll(); @NullableDecl @Override WatchKey poll(long timeout, TimeUnit unit); @Override WatchKey take(); @Override void close();  }