Search in sources :

Example 6 with ResourceReference

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);
    }
}
Also used : ManualClock(com.yahoo.test.ManualClock) ResourceReference(com.yahoo.jdisc.ResourceReference) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 7 with ResourceReference

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();
}
Also used : ResourceReference(com.yahoo.jdisc.ResourceReference) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) Test(org.testng.annotations.Test)

Example 8 with ResourceReference

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;
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) ServletInputStream(javax.servlet.ServletInputStream) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) ResourceReference(com.yahoo.jdisc.ResourceReference)

Aggregations

ResourceReference (com.yahoo.jdisc.ResourceReference)8 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)3 TestDriver (com.yahoo.jdisc.test.TestDriver)2 Test (org.junit.Test)2 Test (org.testng.annotations.Test)2 Request (com.yahoo.jdisc.Request)1 HttpRequest (com.yahoo.jdisc.http.HttpRequest)1 RequestFilter (com.yahoo.jdisc.http.filter.RequestFilter)1 ResponseFilter (com.yahoo.jdisc.http.filter.ResponseFilter)1 MbusRequest (com.yahoo.messagebus.jdisc.MbusRequest)1 ManualClock (com.yahoo.test.ManualClock)1 ByteBuffer (java.nio.ByteBuffer)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ServletInputStream (javax.servlet.ServletInputStream)1