Package org.springframework.context.annotation

Examples of org.springframework.context.annotation.AnnotationConfigApplicationContext.refresh()


  @Test
  public void withExplicitScheduledTaskRegistrar() throws InterruptedException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ExplicitScheduledTaskRegistrarConfig.class);
    ctx.refresh();

    Thread.sleep(100);
    assertThat(ctx.getBean(AtomicInteger.class).get(), greaterThanOrEqualTo(10));
    assertThat(ctx.getBean(ExplicitScheduledTaskRegistrarConfig.class).threadName, startsWith("explicitScheduler1"));
    ctx.close();
View Full Code Here


  @Test
  public void withAmbiguousTaskSchedulers_butNoActualTasks() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(SchedulingEnabled_withAmbiguousTaskSchedulers_butNoActualTasks.class);
    ctx.refresh();
  }


  @Configuration
  @EnableScheduling
View Full Code Here

  @Test(expected=IllegalStateException.class)
  public void withAmbiguousTaskSchedulers_andSingleTask() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(SchedulingEnabled_withAmbiguousTaskSchedulers_andSingleTask.class);
    try {
      ctx.refresh();
    } catch (IllegalStateException ex) {
      assertThat(ex.getMessage(), startsWith("More than one TaskScheduler and/or"));
      throw ex;
    }
  }
View Full Code Here

  @Test
  public void withAmbiguousTaskSchedulers_andSingleTask_disambiguatedByScheduledTaskRegistrarBean() throws InterruptedException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(SchedulingEnabled_withAmbiguousTaskSchedulers_andSingleTask_disambiguatedByScheduledTaskRegistrar.class);
    ctx.refresh();
    Thread.sleep(20);
    ThreadAwareWorker worker = ctx.getBean(ThreadAwareWorker.class);
    ctx.close();
    assertThat(worker.executedByThread, startsWith("explicitScheduler2-"));
  }
View Full Code Here

  @Test
  public void withAmbiguousTaskSchedulers_andSingleTask_disambiguatedBySchedulerNameAttribute() throws InterruptedException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(SchedulingEnabled_withAmbiguousTaskSchedulers_andSingleTask_disambiguatedBySchedulerNameAttribute.class);
    ctx.refresh();
    Thread.sleep(20);
    ThreadAwareWorker worker = ctx.getBean(ThreadAwareWorker.class);
    ctx.close();
    assertThat(worker.executedByThread, startsWith("explicitScheduler2-"));
  }
View Full Code Here

  @Test
  public void withTaskAddedVia_configureTasks() throws InterruptedException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(SchedulingEnabled_withTaskAddedVia_configureTasks.class);
    ctx.refresh();
    Thread.sleep(20);
    ThreadAwareWorker worker = ctx.getBean(ThreadAwareWorker.class);
    ctx.close();
    assertThat(worker.executedByThread, startsWith("taskScheduler-"));
  }
View Full Code Here

  @Test
  public void withTriggerTask() throws InterruptedException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(TriggerTaskConfig.class);
    ctx.refresh();

    Thread.sleep(100);
    assertThat(ctx.getBean(AtomicInteger.class).get(), greaterThan(1));
    ctx.close();
  }
View Full Code Here

  @Test
  public void withInitiallyDelayedFixedRateTask() throws InterruptedException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(FixedRateTaskConfig_withInitialDelay.class);
    ctx.refresh();

    Thread.sleep(1950);
    AtomicInteger counter = ctx.getBean(AtomicInteger.class);
    ctx.close();
View Full Code Here

    ConfigurableApplicationContext parent = new GenericApplicationContext();
    parent.refresh();

    AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext();
    child.setParent(parent);
    child.refresh();

    ConfigurableEnvironment env = child.getBean(ConfigurableEnvironment.class);
    assertThat("unknown env", env, anyOf(
        sameInstance(parent.getEnvironment()),
        sameInstance(child.getEnvironment())));
View Full Code Here

  @Test
  public void proxyingOccurs() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(AsyncConfig.class);
    ctx.refresh();

    AsyncBean asyncBean = ctx.getBean(AsyncBean.class);
    assertThat(AopUtils.isAopProxy(asyncBean), is(true));
    asyncBean.work();
  }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.