List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext close
@Override public void close()
From source file:org.springframework.boot.actuate.autoconfigure.metrics.PublicMetricsAutoConfigurationTests.java
@Test public void richGaugePublicMetrics() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( RichGaugeReaderConfig.class, MetricRepositoryAutoConfiguration.class, PublicMetricsAutoConfiguration.class); RichGaugeReader richGaugeReader = context.getBean(RichGaugeReader.class); assertThat(richGaugeReader).isNotNull(); given(richGaugeReader.findAll()).willReturn(Collections.singletonList(new RichGauge("bar", 3.7d))); RichGaugeReaderPublicMetrics publicMetrics = context.getBean(RichGaugeReaderPublicMetrics.class); assertThat(publicMetrics).isNotNull(); Collection<Metric<?>> metrics = publicMetrics.metrics(); assertThat(metrics).isNotNull();//from ww w . j a v a 2 s . co m assertThat(6).isEqualTo(metrics.size()); assertHasMetric(metrics, new Metric<>("bar.val", 3.7d)); assertHasMetric(metrics, new Metric<>("bar.avg", 3.7d)); assertHasMetric(metrics, new Metric<>("bar.min", 3.7d)); assertHasMetric(metrics, new Metric<>("bar.max", 3.7d)); assertHasMetric(metrics, new Metric<>("bar.alpha", -1.d)); assertHasMetric(metrics, new Metric<>("bar.count", 1L)); context.close(); }
From source file:org.springframework.boot.actuate.autoconfigure.PublicMetricsAutoConfigurationTests.java
@Test public void richGaugePublicMetrics() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( RichGaugeReaderConfig.class, MetricRepositoryAutoConfiguration.class, PublicMetricsAutoConfiguration.class); RichGaugeReader richGaugeReader = context.getBean(RichGaugeReader.class); assertNotNull(richGaugeReader);// w w w . ja va 2 s. co m given(richGaugeReader.findAll()).willReturn(Collections.singletonList(new RichGauge("bar", 3.7d))); RichGaugeReaderPublicMetrics publicMetrics = context.getBean(RichGaugeReaderPublicMetrics.class); assertNotNull(publicMetrics); Collection<Metric<?>> metrics = publicMetrics.metrics(); assertNotNull(metrics); assertEquals(metrics.size(), 6); assertHasMetric(metrics, new Metric<Double>("bar.val", 3.7d)); assertHasMetric(metrics, new Metric<Double>("bar.avg", 3.7d)); assertHasMetric(metrics, new Metric<Double>("bar.min", 3.7d)); assertHasMetric(metrics, new Metric<Double>("bar.max", 3.7d)); assertHasMetric(metrics, new Metric<Double>("bar.alpha", -1.d)); assertHasMetric(metrics, new Metric<Long>("bar.count", 1L)); context.close(); }
From source file:org.springframework.integration.configuration.EnableIntegrationTests.java
@Test public void testParentChildAnnotationConfiguration() { AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext(); child.register(ChildConfiguration.class); child.setParent(this.context); child.refresh();/*from www .j a va2s.co m*/ AbstractMessageChannel foo = child.getBean("foo", AbstractMessageChannel.class); ChannelInterceptor baz = child.getBean("baz", ChannelInterceptor.class); assertTrue(foo.getChannelInterceptors().contains(baz)); assertFalse(this.output.getChannelInterceptors().contains(baz)); child.close(); }
From source file:org.springframework.integration.configuration.EnableIntegrationTests.java
@Test public void testParentChildAnnotationConfigurationFromAnotherPackage() { AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext(); child.register(org.springframework.integration.configuration2.ChildConfiguration.class); child.setParent(this.context); child.refresh();/*w ww .ja v a 2 s . c om*/ AbstractMessageChannel foo = child.getBean("foo", AbstractMessageChannel.class); ChannelInterceptor baz = child.getBean("baz", ChannelInterceptor.class); assertTrue(foo.getChannelInterceptors().contains(baz)); assertFalse(this.output.getChannelInterceptors().contains(baz)); child.close(); }
From source file:org.springframework.integration.etcd.leader.EtcdTests.java
@Test public void testSimpleLeader() throws InterruptedException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SimpleTestConfig.class); TestCandidate candidate = ctx.getBean(TestCandidate.class); TestEventListener listener = ctx.getBean(TestEventListener.class); assertThat(candidate.onGrantedLatch.await(5, TimeUnit.SECONDS), is(true)); assertThat(listener.onEventLatch.await(5, TimeUnit.SECONDS), is(true)); assertThat(listener.events.size(), is(1)); ctx.close(); }
From source file:org.springframework.integration.etcd.leader.EtcdTests.java
@Test public void testLeaderYield() throws InterruptedException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(YieldTestConfig.class); YieldTestCandidate candidate = ctx.getBean(YieldTestCandidate.class); YieldTestEventListener listener = ctx.getBean(YieldTestEventListener.class); assertThat(candidate.onGrantedLatch.await(5, TimeUnit.SECONDS), is(true)); assertThat(candidate.onRevokedLatch.await(10, TimeUnit.SECONDS), is(true)); assertThat(listener.onEventsLatch.await(1, TimeUnit.MILLISECONDS), is(true)); assertThat(listener.events.size(), is(2)); ctx.close(); }
From source file:org.springframework.integration.etcd.leader.EtcdTests.java
@Test public void testBlockingThreadLeader() throws InterruptedException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext( BlockingThreadTestConfig.class); BlockingThreadTestCandidate candidate = ctx.getBean(BlockingThreadTestCandidate.class); YieldTestEventListener listener = ctx.getBean(YieldTestEventListener.class); assertThat(candidate.onGrantedLatch.await(5, TimeUnit.SECONDS), is(true)); Thread.sleep(2000); // Let the grant-notification thread run for a while candidate.ctx.yield(); // Internally interrupts the grant notification thread assertThat(candidate.onRevokedLatch.await(10, TimeUnit.SECONDS), is(true)); assertThat(listener.onEventsLatch.await(1, TimeUnit.MILLISECONDS), is(true)); assertThat(listener.events.size(), is(2)); ctx.close(); }
From source file:org.springframework.integration.etcd.leader.EtcdTests.java
@Test public void testFailingCandidateGrantCallback() throws InterruptedException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext( FailingCandidateTestConfig.class); FailingTestCandidate candidate = ctx.getBean(FailingTestCandidate.class); YieldTestEventListener listener = ctx.getBean(YieldTestEventListener.class); assertThat(candidate.onGrantedLatch.await(5, TimeUnit.SECONDS), is(true)); assertThat(candidate.onRevokedLatch.await(10, TimeUnit.SECONDS), is(true)); assertThat(listener.onEventsLatch.await(10, TimeUnit.SECONDS), is(true)); assertThat(listener.events.size(), is(2)); ctx.close(); }
From source file:org.springframework.integration.ftp.inbound.RotatingServersTests.java
@Test public void testStandard() throws Exception { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(StandardConfig.class); StandardConfig config = ctx.getBean(StandardConfig.class); ctx.getBean(StandardIntegrationFlow.class).stop(); assertThat(config.latch.await(10, TimeUnit.SECONDS)).isTrue(); List<Integer> sfCalls = config.sessionSources.stream().limit(17).collect(Collectors.toList()); assertThat(sfCalls).containsExactly(1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 2, 2, 3, 3, 1, 1); File f1 = new File(tmpDir + File.separator + "standard" + File.separator + "f1"); assertThat(f1.exists()).isTrue();/*from w w w . ja va 2 s . c o m*/ File f2 = new File(tmpDir + File.separator + "standard" + File.separator + "f2"); assertThat(f2.exists()).isTrue(); File f3 = new File(tmpDir + File.separator + "standard" + File.separator + "f3"); assertThat(f3.exists()).isTrue(); assertThat(ctx.getBean("files", QueueChannel.class).getQueueSize()).isEqualTo(3); ctx.close(); }
From source file:org.springframework.integration.ftp.inbound.RotatingServersTests.java
@Test public void testFair() throws Exception { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(FairConfig.class); StandardConfig config = ctx.getBean(StandardConfig.class); ctx.getBean(StandardIntegrationFlow.class).stop(); assertThat(config.latch.await(10, TimeUnit.SECONDS)).isTrue(); List<Integer> sfCalls = config.sessionSources.stream().limit(17).collect(Collectors.toList()); assertThat(sfCalls).containsExactly(1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3); File f1 = new File(tmpDir + File.separator + "fair" + File.separator + "f1"); assertThat(f1.exists()).isTrue();//w w w. j a va2 s .c o m File f2 = new File(tmpDir + File.separator + "fair" + File.separator + "f2"); assertThat(f2.exists()).isTrue(); File f3 = new File(tmpDir + File.separator + "fair" + File.separator + "f3"); assertThat(f3.exists()).isTrue(); assertThat(ctx.getBean("files", QueueChannel.class).getQueueSize()).isEqualTo(3); ctx.close(); }