当前位置: 首页>>代码示例>>Java>>正文


Java LifecycleEnvironment类代码示例

本文整理汇总了Java中io.dropwizard.lifecycle.setup.LifecycleEnvironment的典型用法代码示例。如果您正苦于以下问题:Java LifecycleEnvironment类的具体用法?Java LifecycleEnvironment怎么用?Java LifecycleEnvironment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LifecycleEnvironment类属于io.dropwizard.lifecycle.setup包,在下文中一共展示了LifecycleEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import io.dropwizard.lifecycle.setup.LifecycleEnvironment; //导入依赖的package包/类
@Before
public void setUp() {
    this.petiteBundle = new PetiteBundle<PetiteBundleTest.TestConfiguration>() {
        @Override
        protected PetiteConfiguration getConfiguration(final TestConfiguration configuration) {
            final PetiteConfiguration petite = new PetiteConfiguration();
            petite.setAutomagicConfigurator(true);
            petite.setRegisterSelf(true);
            petite.setUseFullTypeNames(true);
            petite.setUseMetrics(false);
            return petite;
        }
    };

    when(this.environment.metrics()).thenReturn(this.metricRegistry);
    final Timer automagicTimer = mock(Timer.class);
    when(this.metricRegistry
            .timer(MetricRegistry.name(PetiteConfiguration.class, "automagicConfigurator")))
                    .thenReturn(automagicTimer);
    final Timer.Context automagicTimerContext = mock(Timer.Context.class);
    when(automagicTimer.time()).thenReturn(automagicTimerContext);
    final LifecycleEnvironment lifeCycle = mock(LifecycleEnvironment.class);
    when(this.environment.lifecycle()).thenReturn(lifeCycle);
}
 
开发者ID:mtakaki,项目名称:dropwizard-petite,代码行数:25,代码来源:PetiteBundleTest.java

示例2: run

import io.dropwizard.lifecycle.setup.LifecycleEnvironment; //导入依赖的package包/类
@Override
public void run(Environment environment) {
    ServiceLocatorUtilities.bind(serviceLocator, new EnvBinder(application, environment));

    LifecycleEnvironment lifecycle = environment.lifecycle();
    AdminEnvironment admin = environment.admin();

    listServices(HealthCheck.class).forEach(healthCheck -> {
        String name = healthCheck.getClass().getSimpleName();
        environment.healthChecks().register(name, healthCheck);
    });

    listServices(Managed.class).forEach(lifecycle::manage);
    listServices(LifeCycle.class).forEach(lifecycle::manage);
    listServices(LifeCycle.Listener.class).forEach(lifecycle::addLifeCycleListener);
    listServices(ServerLifecycleListener.class).forEach(lifecycle::addServerLifecycleListener);
    listServices(Task.class).forEach(admin::addTask);

    environment.jersey().register(HK2LifecycleListener.class);

    //Set service locator as parent for Jersey's service locator
    environment.getApplicationContext().setAttribute(ServletProperties.SERVICE_LOCATOR, serviceLocator);
    environment.getAdminContext().setAttribute(ServletProperties.SERVICE_LOCATOR, serviceLocator);

    serviceLocator.inject(application);
}
 
开发者ID:alex-shpak,项目名称:dropwizard-hk2bundle,代码行数:27,代码来源:HK2Bundle.java

示例3: shouldRegisterHealthCheck

import io.dropwizard.lifecycle.setup.LifecycleEnvironment; //导入依赖的package包/类
@Test
public void shouldRegisterHealthCheck() throws Exception {
    //GIVEN
    AmazonSQS sqs = mock(AmazonSQS.class);

    SqsBundle spiedBundle = spy(bundle);
    doReturn(sqs).when(spiedBundle).getAmazonSQS();

    LifecycleEnvironment lifecycle = mock(LifecycleEnvironment.class);
    doNothing().when(lifecycle).manage((Managed) anyObject());
    when(environment.lifecycle()).thenReturn(lifecycle);

    HealthCheckRegistry healthChecks = mock(HealthCheckRegistry.class);
    doNothing().when(healthChecks).register(anyObject(), anyObject());
    when(environment.healthChecks()).thenReturn(healthChecks);

    //WHEN
    spiedBundle.run(configurationHolder, environment);

    //THEN
    verify(healthChecks, times(1)).register(eq("SqsBundle"), any(SqsBundleHealthCheck.class));
}
 
开发者ID:sjarrin,项目名称:dropwizard-sqs-bundle,代码行数:23,代码来源:SqsBundleTest.java

示例4: testNewManagedCurator

import io.dropwizard.lifecycle.setup.LifecycleEnvironment; //导入依赖的package包/类
@Test
public void testNewManagedCurator() {
    ZooKeeperConfiguration config = parse(ImmutableMap.of("retryPolicy",
            ImmutableMap.builder()
                    .put("type", "untilElapsed")
                    .put("maxElapsedTimeMs", 1000)
                    .put("sleepMsBetweenRetries", 50)
                    .build()));

    LifecycleEnvironment env = mock(LifecycleEnvironment.class);
    CuratorFramework curator = config.newManagedCurator(env);

    assertNotNull(curator);
    assertEquals(CuratorFrameworkState.LATENT, curator.getState());
    verify(env).manage(any(ManagedCuratorFramework.class));
}
 
开发者ID:bazaarvoice,项目名称:curator-extensions,代码行数:17,代码来源:ZooKeeperConfigurationTest.java

示例5: setUp

import io.dropwizard.lifecycle.setup.LifecycleEnvironment; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    final Environment environment = mock(Environment.class);
    when(environment.lifecycle()).thenReturn(mock(LifecycleEnvironment.class));
    when(environment.metrics()).thenReturn(new MetricRegistry());

    when(this.bundle.getSessionHolders()).thenReturn(this.sessionHolders);

    final DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setUrl("jdbc:hsqldb:mem:unit-of-work-" + UUID.randomUUID().toString());
    dataSourceFactory.setUser("sa");
    dataSourceFactory.setDriverClass("org.hsqldb.jdbcDriver");
    dataSourceFactory.setValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS");
    dataSourceFactory.setProperties(ImmutableMap.of("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"));
    dataSourceFactory.setMinSize(1);

    this.sessionFactory = new SessionFactoryFactory()
            .build(this.bundle, environment, dataSourceFactory, ImmutableList.<Class<?>>of(), RemoteCredentialHibernateBundle.DEFAULT_NAME);
    when(this.bundle.getSessionFactory()).thenReturn(this.sessionFactory);
    final Session session = this.sessionFactory.openSession();
    try {
        session.createSQLQuery("create table user_sessions (token varchar(64) primary key, username varchar(16))")
                .executeUpdate();
        session.createSQLQuery("insert into user_sessions values ('67ab89d', 'jeff_28')")
                .executeUpdate();
    } finally {
        session.close();
    }
}
 
开发者ID:mtakaki,项目名称:CredentialStorageService-dw-hibernate,代码行数:30,代码来源:UnitOfWorkAwareProxyFactoryTest.java

示例6: configure

import io.dropwizard.lifecycle.setup.LifecycleEnvironment; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void configure() {
    bind(environment).to(Environment.class);
    bind(environment.healthChecks()).to(HealthCheckRegistry.class);
    bind(environment.lifecycle()).to(LifecycleEnvironment.class);
    bind(environment.metrics()).to(MetricRegistry.class);
    bind(environment.getValidator()).to(Validator.class);
    bind(configuration).to(bootstrap.getApplication().getConfigurationClass()).to(Configuration.class);
    bind(environment.getObjectMapper()).to(ObjectMapper.class);
    bind(bootstrap.getApplication()).to((Class) bootstrap.getApplication().getClass()).to(Application.class);
}
 
开发者ID:baharclerode,项目名称:dropwizard-hk2,代码行数:13,代码来源:EnvironmentBinder.java

示例7: getClient

import io.dropwizard.lifecycle.setup.LifecycleEnvironment; //导入依赖的package包/类
private MongoClient getClient(LifecycleEnvironment lifecycle) {
  synchronized (this) {

    if (mongoClient != null) {
      return mongoClient;
    }

    logger.debug("Create client {}", connections);

    final MongoClientOptions options = MongoClientOptions.builder()
      .connectTimeout(5000)
      .serverSelectionTimeout(10000)
      .maxWaitTime(5000)
      .build();

    mongoClient = createClient(options);

    lifecycle.manage(new Managed() {

      @Override
      public void start() throws Exception {
      }

      @Override
      public void stop() throws Exception {
        mongoClient.close();
      }
    });
    return mongoClient;
  }
}
 
开发者ID:atgse,项目名称:sam,代码行数:32,代码来源:MongoDatabaseConnectionFactory.java

示例8: setUp

import io.dropwizard.lifecycle.setup.LifecycleEnvironment; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    mockConfiguration = mock(DummyConfiguration.class);
    mockEnvironment = mock(Environment.class);
    mockLifecycle = mock(LifecycleEnvironment.class);
    mockJersey = mock(JerseyEnvironment.class);
    mockHealthchecks = mock(HealthCheckRegistry.class);
    when(mockEnvironment.lifecycle()).thenReturn(mockLifecycle);
    when(mockEnvironment.healthChecks()).thenReturn(mockHealthchecks);
}
 
开发者ID:serhuz,项目名称:dropwizard-morphia,代码行数:11,代码来源:BaseBundleTest.java

示例9: shouldCorrectlyRegisterReceiver

import io.dropwizard.lifecycle.setup.LifecycleEnvironment; //导入依赖的package包/类
@Test
public void shouldCorrectlyRegisterReceiver() throws Exception {
    //GIVEN
    AmazonSQS sqs = mock(AmazonSQS.class);

    String queueUrl = "https://eu-central-1/queue.amazonaws.com/123456/test-queue";
    when(sqs.getQueueUrl("test-queue")).thenReturn(new GetQueueUrlResult()
            .withQueueUrl(queueUrl));

    LifecycleEnvironment lifecycle = mock(LifecycleEnvironment.class);
    doNothing().when(lifecycle).manage((Managed) anyObject());
    when(environment.lifecycle()).thenReturn(lifecycle);

    HealthCheckRegistry healthChecks = mock(HealthCheckRegistry.class);
    doNothing().when(healthChecks).register(anyObject(), anyObject());
    when(environment.healthChecks()).thenReturn(healthChecks);

    SqsBundle spiedBundle = spy(bundle);
    doReturn(sqs).when(spiedBundle).getAmazonSQS();

    spiedBundle.run(configurationHolder, environment);

    //WHEN
    spiedBundle.registerReceiver("test-queue", (m) -> process(m));

    //THEN
    verify(spiedBundle, times(1)).internalRegisterReceiver(eq("test-queue"), any(SqsReceiverHandler.class));
}
 
开发者ID:sjarrin,项目名称:dropwizard-sqs-bundle,代码行数:29,代码来源:SqsBundleTest.java

示例10: getEnvironment

import io.dropwizard.lifecycle.setup.LifecycleEnvironment; //导入依赖的package包/类
private Environment getEnvironment() {
    Environment environment = mock(Environment.class);
    JerseyEnvironment jersey = mock(JerseyEnvironment.class);
    when(environment.jersey()).thenReturn(jersey);
    LifecycleEnvironment lifecycle = mock(LifecycleEnvironment.class);
    when(environment.lifecycle()).thenReturn(lifecycle);
    HealthCheckRegistry healthchecks = mock(HealthCheckRegistry.class);
    when(environment.healthChecks()).thenReturn(healthchecks);
    return environment;
}
 
开发者ID:NLeSC,项目名称:ahn-pointcloud-viewer-ws,代码行数:11,代码来源:ViewerApplicationTest.java

示例11: setUp

import io.dropwizard.lifecycle.setup.LifecycleEnvironment; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
    final EntityManagerBundle<?> bundle = mock(EntityManagerBundle.class);
    final Environment environment = mock(Environment.class);
    when(bundle.name()).thenReturn("test-bundle");
    when(environment.lifecycle()).thenReturn(mock(LifecycleEnvironment.class));
    when(environment.metrics()).thenReturn(new MetricRegistry());

    final DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setUrl("jdbc:hsqldb:mem:unit-of-work-" + UUID.randomUUID().toString());
    dataSourceFactory.setUser("sa");
    dataSourceFactory.setDriverClass("org.hsqldb.jdbcDriver");
    dataSourceFactory.setValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS");
    dataSourceFactory.setProperties(ImmutableMap.of("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"));
    dataSourceFactory.setInitialSize(1);
    dataSourceFactory.setMinSize(1);

    entityManagerFactory = new EntityManagerFactoryFactory()
            .build(bundle, environment, dataSourceFactory, ImmutableList.<Class<?>>of());

    final EntityManager entityManager = entityManagerFactory.createEntityManager();
    try {
        EntityTransaction entityTransaction = entityManager.getTransaction();
        entityTransaction.begin();

        entityManager.createNativeQuery("create table user_sessions (token varchar(64) primary key, username varchar(16))")
                .executeUpdate();
        entityManager.createNativeQuery("insert into user_sessions values ('67ab89d', 'jeff_28')")
                .executeUpdate();

        entityTransaction.commit();
    } finally {
        entityManager.close();
    }

    final EntityManagerContext entityManagerContext = new EntityManagerContext(entityManagerFactory);
    sharedEntityManager = new SharedEntityManagerFactory().build(entityManagerContext);
}
 
开发者ID:scottescue,项目名称:dropwizard-entitymanager,代码行数:39,代码来源:UnitOfWorkAwareProxyFactoryTest.java

示例12: register

import io.dropwizard.lifecycle.setup.LifecycleEnvironment; //导入依赖的package包/类
private void register(LifecycleEnvironment lifecycle, Collection<Class<? extends Managed>> managed) {
    LOGGER.info("managing lifecycle of {} services", managed.size());
    managed.forEach(managedClass -> lifecycle.manage(injector.getInstance(managedClass)));
}
 
开发者ID:MineboxOS,项目名称:minebox,代码行数:5,代码来源:MinebdApplication.java

示例13: configure

import io.dropwizard.lifecycle.setup.LifecycleEnvironment; //导入依赖的package包/类
@Override
protected Application configure() {
    this.forceSet(TestProperties.CONTAINER_PORT, "0");

    final MetricRegistry metricRegistry = new MetricRegistry();
    final SessionFactoryFactory factory = new SessionFactoryFactory();
    final DataSourceFactory dbConfig = new DataSourceFactory();
    this.bundle = mock(RemoteCredentialHibernateBundle.class);

    final SessionHolders sessionHolders = mock(SessionHolders.class);
    when(this.bundle.getSessionHolders()).thenReturn(sessionHolders);

    final Environment environment = mock(Environment.class);
    final LifecycleEnvironment lifecycleEnvironment = mock(LifecycleEnvironment.class);
    when(environment.lifecycle()).thenReturn(lifecycleEnvironment);
    when(environment.metrics()).thenReturn(metricRegistry);

    dbConfig.setUrl("jdbc:hsqldb:mem:DbTest-" + System.nanoTime()
            + "?hsqldb.translate_dti_types=false");
    dbConfig.setUser("sa");
    dbConfig.setDriverClass("org.hsqldb.jdbcDriver");
    dbConfig.setValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS");

    this.sessionFactory = factory.build(this.bundle,
            environment,
            dbConfig,
            ImmutableList.<Class<?>> of(Person.class),
            RemoteCredentialHibernateBundle.DEFAULT_NAME);
    when(this.bundle.getSessionFactory()).thenReturn(this.sessionFactory);
    when(this.bundle.getCurrentThreadSessionFactory()).thenReturn(this.sessionFactory);

    final Session session = this.sessionFactory.openSession();
    try {
        session.createSQLQuery("DROP TABLE people IF EXISTS").executeUpdate();
        session.createSQLQuery(
                "CREATE TABLE people (name varchar(100) primary key, email varchar(16), birthday timestamp with time zone)")
                .executeUpdate();
        session.createSQLQuery(
                "INSERT INTO people VALUES ('Coda', '[email protected]', '1979-01-02 00:22:00+0:00')")
                .executeUpdate();
    } finally {
        session.close();
    }

    final DropwizardResourceConfig config = DropwizardResourceConfig
            .forTesting(new MetricRegistry());
    config.register(new UnitOfWorkApplicationListener("hr-db", this.bundle));
    config.register(new PersonResource(new PersonDAO(this.bundle)));
    config.register(new JacksonMessageBodyProvider(Jackson.newObjectMapper(),
            Validators.newValidator()));
    config.register(new DataExceptionMapper());

    return config;
}
 
开发者ID:mtakaki,项目名称:CredentialStorageService-dw-hibernate,代码行数:55,代码来源:JerseyIntegrationTest.java

示例14: testLifecycleEnvironmentBound

import io.dropwizard.lifecycle.setup.LifecycleEnvironment; //导入依赖的package包/类
@Test
public void testLifecycleEnvironmentBound() {
    assertThat(jerseyLocator.getService(LifecycleEnvironment.class)).isSameAs(RULE.getEnvironment().lifecycle());
}
 
开发者ID:baharclerode,项目名称:dropwizard-hk2,代码行数:5,代码来源:HK2BundleTest.java

示例15: getDatabase

import io.dropwizard.lifecycle.setup.LifecycleEnvironment; //导入依赖的package包/类
public MongoDatabase getDatabase(LifecycleEnvironment lifecycle) {

    logger.debug("Create database {}", name);
    final MongoClient client = getClient(lifecycle);
    return client.getDatabase(name);
  }
 
开发者ID:atgse,项目名称:sam,代码行数:7,代码来源:MongoDatabaseConnectionFactory.java


注:本文中的io.dropwizard.lifecycle.setup.LifecycleEnvironment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。