Search in sources :

Example 31 with ContainerBuilder

use of com.yahoo.jdisc.application.ContainerBuilder in project vespa by vespa-engine.

the class StateHandlerTest method startTestDriver.

@Before
public void startTestDriver() {
    Timer timer = this.currentTimeMillis::get;
    this.driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Timer.class).toInstance(timer);
        }
    });
    ContainerBuilder builder = driver.newContainerBuilder();
    HealthMonitorConfig healthMonitorConfig = new HealthMonitorConfig(new HealthMonitorConfig.Builder().snapshot_interval(TimeUnit.MILLISECONDS.toSeconds(SNAPSHOT_INTERVAL)));
    ThreadFactory threadFactory = ignored -> mock(Thread.class);
    this.monitor = new StateMonitor(healthMonitorConfig, timer, threadFactory);
    builder.guiceModules().install(new AbstractModule() {

        @Override
        protected void configure() {
            bind(StateMonitor.class).toInstance(monitor);
            bind(MetricConsumer.class).toProvider(MetricConsumerProviders.wrap(monitor));
            bind(ApplicationMetadataConfig.class).toInstance(new ApplicationMetadataConfig(new ApplicationMetadataConfig.Builder().generation(META_GENERATION)));
            bind(MetricsPresentationConfig.class).toInstance(new MetricsPresentationConfig(new MetricsPresentationConfig.Builder()));
        }
    });
    builder.serverBindings().bind("http://*/*", builder.getInstance(StateHandler.class));
    driver.activateContainer(builder);
    metric = builder.getInstance(Metric.class);
}
Also used : Metric(com.yahoo.jdisc.Metric) TestDriver(com.yahoo.jdisc.test.TestDriver) Defaults(com.yahoo.vespa.defaults.Defaults) ApplicationMetadataConfig(com.yahoo.container.core.ApplicationMetadataConfig) Vtag(com.yahoo.component.Vtag) HashMap(java.util.HashMap) After(org.junit.After) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) ThreadFactory(java.util.concurrent.ThreadFactory) Before(org.junit.Before) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Response(com.yahoo.jdisc.Response) Assert.assertNotNull(org.junit.Assert.assertNotNull) MetricConsumer(com.yahoo.jdisc.application.MetricConsumer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StandardCharsets(java.nio.charset.StandardCharsets) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) TreeMap(java.util.TreeMap) Assert.assertFalse(org.junit.Assert.assertFalse) Timer(com.yahoo.jdisc.Timer) BufferedContentChannel(com.yahoo.jdisc.handler.BufferedContentChannel) MetricsPresentationConfig(com.yahoo.metrics.MetricsPresentationConfig) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) AbstractModule(com.google.inject.AbstractModule) HealthMonitorConfig(com.yahoo.container.jdisc.config.HealthMonitorConfig) Mockito.mock(org.mockito.Mockito.mock) ThreadFactory(java.util.concurrent.ThreadFactory) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) HealthMonitorConfig(com.yahoo.container.jdisc.config.HealthMonitorConfig) AbstractModule(com.google.inject.AbstractModule) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Timer(com.yahoo.jdisc.Timer) ApplicationMetadataConfig(com.yahoo.container.core.ApplicationMetadataConfig) Metric(com.yahoo.jdisc.Metric) MetricsPresentationConfig(com.yahoo.metrics.MetricsPresentationConfig) Before(org.junit.Before)

Example 32 with ContainerBuilder

use of com.yahoo.jdisc.application.ContainerBuilder in project vespa by vespa-engine.

the class ThreadedRequestHandlerTestCase method requireThatRequestAndResponseReachHandlers.

@Test
public void requireThatRequestAndResponseReachHandlers() throws InterruptedException {
    Executor executor = Executors.newSingleThreadExecutor();
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    MyRequestHandler requestHandler = MyRequestHandler.newInstance(executor);
    builder.serverBindings().bind("http://localhost/", requestHandler);
    driver.activateContainer(builder);
    MyResponseHandler responseHandler = new MyResponseHandler();
    Request request = new Request(driver, URI.create("http://localhost/"));
    ContentChannel requestContent = request.connect(responseHandler);
    ByteBuffer buf = ByteBuffer.allocate(69);
    requestContent.write(buf, null);
    requestContent.close(null);
    request.release();
    requestHandler.entryLatch.countDown();
    assertTrue(requestHandler.exitLatch.await(60, TimeUnit.SECONDS));
    assertSame(request, requestHandler.request);
    assertSame(buf, requestHandler.content.read());
    assertNull(requestHandler.content.read());
    assertTrue(responseHandler.latch.await(60, TimeUnit.SECONDS));
    assertSame(requestHandler.response, responseHandler.response);
    assertNull(responseHandler.content.read());
    assertTrue(driver.close());
}
Also used : Executor(java.util.concurrent.Executor) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Request(com.yahoo.jdisc.Request) ByteBuffer(java.nio.ByteBuffer) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 33 with ContainerBuilder

use of com.yahoo.jdisc.application.ContainerBuilder in project vespa by vespa-engine.

the class ThreadedRequestHandlerTestCase method requireThatRequestContentIsClosedIfHandlerIgnoresIt.

@Test
public void requireThatRequestContentIsClosedIfHandlerIgnoresIt() throws InterruptedException {
    Executor executor = Executors.newSingleThreadExecutor();
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    MyRequestHandler requestHandler = MyRequestHandler.newIgnoreContent(executor);
    builder.serverBindings().bind("http://localhost/", requestHandler);
    driver.activateContainer(builder);
    MyResponseHandler responseHandler = new MyResponseHandler();
    ContentChannel content = driver.connectRequest("http://localhost/", responseHandler);
    MyCompletion writeCompletion = new MyCompletion();
    content.write(ByteBuffer.allocate(69), writeCompletion);
    MyCompletion closeCompletion = new MyCompletion();
    content.close(closeCompletion);
    requestHandler.entryLatch.countDown();
    assertTrue(requestHandler.exitLatch.await(60, TimeUnit.SECONDS));
    assertTrue(writeCompletion.latch.await(60, TimeUnit.SECONDS));
    assertTrue(writeCompletion.completed);
    assertTrue(closeCompletion.latch.await(60, TimeUnit.SECONDS));
    assertTrue(writeCompletion.completed);
    assertTrue(responseHandler.latch.await(60, TimeUnit.SECONDS));
    assertSame(requestHandler.response, responseHandler.response);
    assertNull(responseHandler.content.read());
    assertTrue(driver.close());
}
Also used : Executor(java.util.concurrent.Executor) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 34 with ContainerBuilder

use of com.yahoo.jdisc.application.ContainerBuilder in project vespa by vespa-engine.

the class ConfiguredApplication method start.

@Override
public void start() {
    qrConfig = getConfig(QrConfig.class);
    ContainerDiscApplication.hackToInitializeServer(qrConfig);
    ContainerBuilder builder = createBuilderWithGuiceBindings();
    configureComponents(builder.guiceModules().activate());
    intitializeAndActivateContainer(builder);
    startReconfigurerThread();
    portWatcher = new Thread(this::watchPortChange);
    portWatcher.setDaemon(true);
    portWatcher.start();
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) QrConfig(com.yahoo.container.QrConfig)

Example 35 with ContainerBuilder

use of com.yahoo.jdisc.application.ContainerBuilder in project vespa by vespa-engine.

the class ConfiguredApplication method createBuilderWithGuiceBindings.

private ContainerBuilder createBuilderWithGuiceBindings() {
    ContainerBuilder builder = activator.newContainerBuilder();
    setupGuiceBindings(builder.guiceModules());
    return builder;
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder)

Aggregations

ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)53 Test (org.junit.Test)41 TestDriver (com.yahoo.jdisc.test.TestDriver)40 Request (com.yahoo.jdisc.Request)16 Response (com.yahoo.jdisc.Response)12 ByteBuffer (java.nio.ByteBuffer)7 Executor (java.util.concurrent.Executor)6 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)4 AbstractModule (com.google.inject.AbstractModule)3 BindingSet (com.yahoo.jdisc.application.BindingSet)3 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)3 NonWorkingRequestHandler (com.yahoo.jdisc.test.NonWorkingRequestHandler)3 Container (com.yahoo.jdisc.Container)2 UriPattern (com.yahoo.jdisc.application.UriPattern)2 Map (java.util.Map)2 ThreadFactory (java.util.concurrent.ThreadFactory)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Module (com.google.inject.Module)1 Pair (com.yahoo.collections.Pair)1