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);
}
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());
}
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());
}
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();
}
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;
}
Aggregations