Ejemplo n.º 1
0
 public static void main(String[] args) {
   System.out.println("Start spring container");
   System.out.println("=======================");
   ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
   System.out.println("Stop spring container");
   System.out.println("=======================");
   context.stop();
   context.close();
   context.destroy();
   System.out.println("Start spring container");
   System.out.println("=======================");
   context = new ClassPathXmlApplicationContext("beans.xml");
   context.close();
   context.destroy();
 }
  public int test(String contextConfig, final int offset) throws Exception {
    ActiveMqTestUtils.prepare();
    ClassPathXmlApplicationContext context =
        new ClassPathXmlApplicationContext(contextConfig, this.getClass());
    final AtomicInteger successCounter = new AtomicInteger();
    final AtomicInteger timeoutCounter = new AtomicInteger();
    final AtomicInteger failureCounter = new AtomicInteger();
    try {
      final RequestReplyExchanger gateway = context.getBean(RequestReplyExchanger.class);
      final CountDownLatch latch = new CountDownLatch(requests);

      for (int i = 0; i < requests; i++) {
        final int y = i;
        executor.execute(
            new Runnable() {
              public void run() {
                try {
                  assertEquals(
                      y + offset, gateway.exchange(new GenericMessage<Integer>(y)).getPayload());
                  successCounter.incrementAndGet();
                } catch (MessageTimeoutException e) {
                  timeoutCounter.incrementAndGet();
                } catch (Throwable t) {
                  t.printStackTrace();
                  failureCounter.incrementAndGet();
                } finally {
                  latch.countDown();
                }
              }
            });
      }
      assertTrue(latch.await(120, TimeUnit.SECONDS));
      // technically all we care that its > 0,
      // but reality of this test it has to be something more then 0
      assertTrue(successCounter.get() > 10);
      assertEquals(0, failureCounter.get());
      assertEquals(requests, successCounter.get() + timeoutCounter.get());
      return timeoutCounter.get();
    } finally {
      logger.info("Test config: " + contextConfig);
      logger.info("Success: " + successCounter.get());
      logger.info("Timeout: " + timeoutCounter.get());
      logger.info("Failure: " + failureCounter.get());
      context.destroy();
    }
  }
Ejemplo n.º 3
0
 @Override
 public void destroy() {
   super.destroy();
   context.destroy();
 }
Ejemplo n.º 4
0
 @Override
 public void contextDestroyed(ServletContextEvent arg0) {
   appContext.destroy();
   appContext.close();
 }
Ejemplo n.º 5
0
 @After
 public void closeContext() {
   context.destroy();
 }
 @After
 public void destroySpringContext() {
   log.info("destroy spring context");
   ctx.destroy();
 }