Example usage for org.springframework.context ConfigurableApplicationContext close

List of usage examples for org.springframework.context ConfigurableApplicationContext close

Introduction

In this page you can find the example usage for org.springframework.context ConfigurableApplicationContext close.

Prototype

@Override
void close();

Source Link

Document

Close this application context, releasing all resources and locks that the implementation might hold.

Usage

From source file:samples.websocket.echo.SampleWebSocketsApplicationTests.java

@Test
public void runAndWait() throws Exception {
    ConfigurableApplicationContext context = SpringApplication.run(ClientConfiguration.class,
            "--spring.main.web_environment=false");
    long count = context.getBean(ClientConfiguration.class).latch.getCount();
    context.close();
    assertEquals(0, count);/*from   www .j  a  v  a  2s .co  m*/
}

From source file:guru.qas.martini.jmeter.config.MartiniSpringConfiguration.java

@Override
public void testStarted() {
    synchronized (contextRef) {
        ConfigurableApplicationContext context = initializeContext();
        ConfigurableApplicationContext previous = contextRef.getAndSet(context);
        if (null != previous) {
            previous.close();
        }// www  .  ja va2 s. c o  m

        String hostname = JMeterUtils.getLocalHostName();
        String ip = JMeterUtils.getLocalHostIP();
        String name = super.getName();
        String id = context.getId();
        long startupDate = context.getStartupDate();
        String username = System.getProperty("user.name");

        ConfigurableEnvironment environment = context.getEnvironment();
        String[] activeProfiles = environment.getActiveProfiles();
        ArrayList<String> profiles = Lists.newArrayList(activeProfiles);

        Map<String, String> environmentVariables = this.getEnvironmentProperties().getArgumentsAsMap();

        SuiteIdentifier identifier = DefaultSuiteIdentifier.builder().setId(id).setStartupTimestamp(startupDate)
                .setName(name).setHostname(hostname).setHostAddress(ip).setUsername(username)
                .setProfiles(profiles).setEnvironmentVariables(environmentVariables).build();

        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        beanFactory.registerSingleton(BEAN_SUITE_IDENTIFIER, identifier);

        EventManager eventManager = context.getBean(EventManager.class);
        eventManager.publishBeforeSuite(this, identifier);
    }
}

From source file:guru.qas.martini.jmeter.config.MartiniSpringConfiguration.java

@Override
public void testEnded() {
    synchronized (contextRef) {
        ConfigurableApplicationContext context = contextRef.getAndSet(null);
        if (null != context) {
            publishTestEnded(context);//w  ww .j a v  a  2  s  .  c  o  m
            context.close();
        }
    }
}

From source file:multibinder.RabbitAndKafkaBinderApplicationTests.java

@Test
public void contextLoads() throws Exception {
    // passing connection arguments arguments to the embedded Kafka instance
    ConfigurableApplicationContext context = SpringApplication.run(MultibinderApplication.class,
            "--spring.cloud.stream.kafka.binder.brokers=" + kafkaEmbedded.getBrokersAsString(),
            "--spring.cloud.stream.kafka.binder.zkNodes=" + kafkaEmbedded.getZookeeperConnectionString());
    context.close();
}

From source file:org.fcrepo.migration.LegacyFoxmlStorageMigratorTest.java

@Before
public synchronized void processFoxml() throws XMLStreamException, IOException {
    if (getResult() == null) {
        final ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
                "spring/stored-legacy-foxml.xml");
        this.result = (DummyHandler) context.getBean("dummyHandler");
        this.fetcher = (DummyURLFetcher) context.getBean("dummyFetcher");
        final Migrator m = (Migrator) context.getBean("migrator");
        m.run();/*from  ww  w.j a  v  a2  s  .c  o  m*/
        context.close();
    }
}

From source file:com.provenance.cloudprovenance.policyengine.cond.XPathProvenanceFunction.java

public void loadSpringBean() {

    ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "beans.xml" });
    xpathUtility = (XPathProvenanceConditionUtility) ctx.getBean("xPathProvenanceConditionUtility");
    ctx.close();
}

From source file:com.hellblazer.slp.anubis.EndToEndTest.java

@Override
protected void tearDown() throws Exception {
    if (controllerContext != null) {
        try {//from w  ww  .j a v a2s .co m
            controllerContext.close();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    controllerContext = null;
    if (memberContexts != null) {
        for (ConfigurableApplicationContext context : memberContexts) {
            try {
                context.close();
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }
    memberContexts = null;
    controller = null;
    partition = null;
    initialLatch = null;
    Thread.sleep(2000);
}

From source file:ro.contezi.websockets.main.SampleWebSocketsApplicationTest.java

@Test
public void reverseEndpoint() throws Exception {
    ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class)
                    .properties("websocket.uri:ws://localhost:" + this.port + "/reverse")
                    .run("--spring.main.web_environment=false");
    long count = context.getBean(ClientConfiguration.class).getLatch().getCount();
    AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class)
            .getMessagePayload();/*from  www . j  a v  a2s  .co m*/
    context.close();
    assertEquals(0, count);
    assertEquals("Reversed: !olleH", messagePayloadReference.get());
}

From source file:com.gaodashang.demo.SampleWebSocketsApplicationTests.java

@Test
public void reverseEndpoint() throws Exception {
    ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class)
                    .properties("websocket.uri:ws://localhost:" + this.port + "/reverse")
                    .run("--spring.main.web_environment=false");
    long count = context.getBean(ClientConfiguration.class).latch.getCount();
    AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
    context.close();
    assertEquals(0, count);/*from   w w  w  .  j av  a2 s  .c om*/
    assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get());
}