use of com.yahoo.jdisc.ResourceReference in project vespa by vespa-engine.
the class ActiveContainerDeactivationWatchdogTest method watchdog_counts_deactivated_containers.
@Test
public void watchdog_counts_deactivated_containers() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ManualClock clock = new ManualClock(Instant.now());
ActiveContainerDeactivationWatchdog watchdog = new ActiveContainerDeactivationWatchdog(clock, Executors.newScheduledThreadPool(1));
MockMetric metric = new MockMetric();
ActiveContainer containerWithoutRetainedResources = new ActiveContainer(driver.newContainerBuilder());
watchdog.onContainerActivation(containerWithoutRetainedResources);
watchdog.emitMetrics(metric);
assertEquals(0, metric.totalCount);
assertEquals(0, metric.withRetainedReferencesCount);
watchdog.onContainerActivation(null);
containerWithoutRetainedResources.release();
clock.advance(ActiveContainerDeactivationWatchdog.REPORTING_GRACE_PERIOD);
watchdog.emitMetrics(metric);
assertEquals(0, metric.totalCount);
assertEquals(0, metric.withRetainedReferencesCount);
clock.advance(Duration.ofSeconds(1));
watchdog.emitMetrics(metric);
assertEquals(1, metric.totalCount);
assertEquals(0, metric.withRetainedReferencesCount);
ActiveContainer containerWithRetainedResources = new ActiveContainer(driver.newContainerBuilder());
try (ResourceReference ignoredRef = containerWithRetainedResources.refer()) {
watchdog.onContainerActivation(containerWithRetainedResources);
containerWithRetainedResources.release();
watchdog.onContainerActivation(null);
clock.advance(ActiveContainerDeactivationWatchdog.REPORTING_GRACE_PERIOD.plusSeconds(1));
watchdog.emitMetrics(metric);
assertEquals(2, metric.totalCount);
assertEquals(1, metric.withRetainedReferencesCount);
}
}
use of com.yahoo.jdisc.ResourceReference in project vespa by vespa-engine.
the class FilterTestCase method requireThatRequestFilterChainRetainsFilters.
@Test
public void requireThatRequestFilterChainRetainsFilters() {
final RequestFilter requestFilter1 = mock(RequestFilter.class);
final RequestFilter requestFilter2 = mock(RequestFilter.class);
verify(requestFilter1, never()).refer();
verify(requestFilter2, never()).refer();
final ResourceReference reference1 = mock(ResourceReference.class);
final ResourceReference reference2 = mock(ResourceReference.class);
when(requestFilter1.refer()).thenReturn(reference1);
when(requestFilter2.refer()).thenReturn(reference2);
final RequestFilter chain = RequestFilterChain.newInstance(requestFilter1, requestFilter2);
verify(requestFilter1, times(1)).refer();
verify(requestFilter2, times(1)).refer();
verify(reference1, never()).close();
verify(reference2, never()).close();
chain.release();
verify(reference1, times(1)).close();
verify(reference2, times(1)).close();
}
use of com.yahoo.jdisc.ResourceReference in project vespa by vespa-engine.
the class HttpRequestDispatch method handleRequest.
@SuppressWarnings("try")
private ServletRequestReader handleRequest() throws IOException {
HttpRequest jdiscRequest = HttpRequestFactory.newJDiscRequest(jDiscContext.container, servletRequest);
ContentChannel requestContentChannel;
try (ResourceReference ref = References.fromResource(jdiscRequest)) {
HttpRequestFactory.copyHeaders(servletRequest, jdiscRequest);
requestContentChannel = requestHandler.handleRequest(jdiscRequest, servletResponseController.responseHandler);
}
ServletInputStream servletInputStream = servletRequest.getInputStream();
ServletRequestReader servletRequestReader = new ServletRequestReader(servletInputStream, requestContentChannel, jDiscContext.janitor, metricReporter);
servletInputStream.setReadListener(servletRequestReader);
return servletRequestReader;
}
Aggregations