@Test public void testFactoryExceptionIsPropagated() { NullPointerException exception = mock(NullPointerException.class); when(_factory.create(any(ServiceEndPoint.class))).thenThrow(exception); SingleThreadedClientServiceCache<Service> cache = newCache(); try { cache.checkOut(END_POINT); fail(); } catch (Exception caught) { assertSame(exception, caught); } }
public ServiceHandle<S> checkOut(ServiceEndPoint endPoint) throws Exception { checkNotNull(endPoint); _requestCount.incrementAndGet(); try { long revision = _revisionNumber.incrementAndGet(); S service = _pool.borrowObject(endPoint); ServiceHandle<S> handle = new ServiceHandle<>(service, endPoint); _checkedOutRevisions.put(handle, revision); return handle; } catch (NoSuchElementException e) { _missCount.incrementAndGet(); throw new NoCachedInstancesAvailableException(String.format("No cached instances available for endpoint: %s", endPoint)); } }
SingleThreadedClientServiceCache implements ServiceCache<S> { public ServiceHandle<S> checkOut(ServiceEndPoint endPoint) throws Exception { checkNotNull(endPoint); _requestCount.incrementAndGet(); try { long revision = _revisionNumber.incrementAndGet(); S service = _pool.borrowObject(endPoint); ServiceHandle<S> handle = new ServiceHandle<>(service, endPoint); _checkedOutRevisions.put(handle, revision); return handle; } catch (NoSuchElementException e) { _missCount.incrementAndGet(); throw new NoCachedInstancesAvailableException(String.format("No cached instances available for endpoint: %s", endPoint)); } } }
SingleThreadedClientServiceCache implements ServiceCache<S> { public ServiceHandle<S> checkOut(ServiceEndPoint endPoint) throws Exception { checkNotNull(endPoint); _requestCount.incrementAndGet(); try { long revision = _revisionNumber.incrementAndGet(); S service = _pool.borrowObject(endPoint); ServiceHandle<S> handle = new ServiceHandle<>(service, endPoint); _checkedOutRevisions.put(handle, revision); return handle; } catch (NoSuchElementException e) { _missCount.incrementAndGet(); throw new NoCachedInstancesAvailableException(String.format("No cached instances available for endpoint: %s", endPoint)); } } SingleThreadedClientServiceCache(ServiceCachingPolicy policy, ServiceFactory<S> serviceFactory, MetricRegistry metrics); @VisibleForTesting  SingleThreadedClientServiceCache(ServiceCachingPolicy policy, ServiceFactory<S> serviceFactory, ScheduledExecutorService executor,
                                     MetricRegistry metrics); }
SingleThreadedClientServiceCache implements ServiceCache<S> { public ServiceHandle<S> checkOut(ServiceEndPoint endPoint) throws Exception { checkNotNull(endPoint); _requestCount.incrementAndGet(); try { long revision = _revisionNumber.incrementAndGet(); S service = _pool.borrowObject(endPoint); ServiceHandle<S> handle = new ServiceHandle<>(service, endPoint); _checkedOutRevisions.put(handle, revision); return handle; } catch (NoSuchElementException e) { _missCount.incrementAndGet(); throw new NoCachedInstancesAvailableException(String.format("No cached instances available for endpoint: %s", endPoint)); } } SingleThreadedClientServiceCache(ServiceCachingPolicy policy, ServiceFactory<S> serviceFactory, MetricRegistry metrics); @VisibleForTesting  SingleThreadedClientServiceCache(ServiceCachingPolicy policy, ServiceFactory<S> serviceFactory, ScheduledExecutorService executor,
                                     MetricRegistry metrics); ServiceHandle<S> checkOut(ServiceEndPoint endPoint); @Override void checkIn(ServiceHandle<S> handle); @Override int getNumIdleInstances(ServiceEndPoint endPoint); @Override int getNumActiveInstances(ServiceEndPoint endPoint); @Override void close(); @Override void register(ServiceEndPoint endPoint); @Override void evict(ServiceEndPoint endPoint); }
SingleThreadedClientServiceCache implements ServiceCache<S> { public ServiceHandle<S> checkOut(ServiceEndPoint endPoint) throws Exception { checkNotNull(endPoint); _requestCount.incrementAndGet(); try { long revision = _revisionNumber.incrementAndGet(); S service = _pool.borrowObject(endPoint); ServiceHandle<S> handle = new ServiceHandle<>(service, endPoint); _checkedOutRevisions.put(handle, revision); return handle; } catch (NoSuchElementException e) { _missCount.incrementAndGet(); throw new NoCachedInstancesAvailableException(String.format("No cached instances available for endpoint: %s", endPoint)); } } SingleThreadedClientServiceCache(ServiceCachingPolicy policy, ServiceFactory<S> serviceFactory, MetricRegistry metrics); @VisibleForTesting  SingleThreadedClientServiceCache(ServiceCachingPolicy policy, ServiceFactory<S> serviceFactory, ScheduledExecutorService executor,
                                     MetricRegistry metrics); ServiceHandle<S> checkOut(ServiceEndPoint endPoint); @Override void checkIn(ServiceHandle<S> handle); @Override int getNumIdleInstances(ServiceEndPoint endPoint); @Override int getNumActiveInstances(ServiceEndPoint endPoint); @Override void close(); @Override void register(ServiceEndPoint endPoint); @Override void evict(ServiceEndPoint endPoint);  }