NearestFit implements EventSubscriber { @Subscribe public synchronized void vetoed(Vetoed vetoEvent) { Objects.requireNonNull(vetoEvent); fitByGroupKey.getUnchecked(vetoEvent.getGroupKey()).maybeUpdate(vetoEvent.getVetoes()); } @VisibleForTesting  NearestFit(Ticker ticker); @Inject  NearestFit(); synchronized ImmutableSet<Veto> getNearestFit(TaskGroupKey groupKey); @Subscribe synchronized void remove(TasksDeleted deletedEvent); @Subscribe synchronized void stateChanged(TaskStateChange event); @Subscribe synchronized void vetoed(Vetoed vetoEvent);  }
@Test public void testScoring() { vetoed(SEVERITY_1); assertNearest(SEVERITY_1); vetoed(SEVERITY_2); assertNearest(SEVERITY_2); vetoed(SEVERITY_3); assertNearest(SEVERITY_3); vetoed(SEVERITY_4_CPU, SEVERITY_4_RAM, SEVERITY_4_DISK, SEVERITY_4_PORTS); assertNearest(SEVERITY_4_CPU, SEVERITY_4_RAM, SEVERITY_4_DISK, SEVERITY_4_PORTS); }
@Test public void testExpiration() { vetoed(SEVERITY_2); assertNearest(SEVERITY_2); ticker.advance(NearestFit.EXPIRATION); ticker.advance(Amount.of(1L, Time.SECONDS)); assertNearest(); }