use of org.jboss.weld.environment.se.WeldContainer in project camel by apache.
the class CamelCdiDeployment method apply.
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
WeldContainer container = weld.initialize();
context.setBeanManager(container.getBeanManager());
try {
base.evaluate();
} finally {
container.shutdown();
context.unsetBeanManager();
}
}
};
}
use of org.jboss.weld.environment.se.WeldContainer in project indy by Commonjava.
the class DefaultIndyConfigFactoryTest method weldInjection_IterateIndyConfigurators.
@Test
public void weldInjection_IterateIndyConfigurators() {
Weld weld = new Weld();
WeldContainer container = weld.initialize();
List<String> sections = new ArrayList<>();
container.instance().select(IndyConfigInfo.class).iterator().forEachRemaining((instance) -> {
String section = ConfigUtils.getSectionName(instance);
System.out.printf("Got instance: %s with section: %s\n", instance, section);
sections.add(section);
});
System.out.println(sections);
assertThat(sections.contains(ConfigurationSectionListener.DEFAULT_SECTION), equalTo(true));
assertThat(sections.contains("flatfiles"), equalTo(true));
assertThat(sections.contains("ui"), equalTo(true));
assertThat(sections.contains("storage-default"), equalTo(true));
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class NotificationModeTest method testObserversNotifiedSerially.
@Test
public void testObserversNotifiedSerially() throws InterruptedException {
try (WeldContainer container = createWeld()) {
CountDownLatch latch = new CountDownLatch(4);
Set<String> threadNames = new CopyOnWriteArraySet<>();
List<String> observers = new CopyOnWriteArrayList<>();
container.event().select(PriorityMessage.class).fireAsync((id) -> {
threadNames.add(Thread.currentThread().getName());
observers.add(id);
latch.countDown();
}, NotificationOptions.builder().set(WeldNotificationOptions.MODE, NotificationMode.SERIAL).build());
assertTrue(latch.await(2, TimeUnit.SECONDS));
// Observers were notified using the same thread
assertEquals(1, threadNames.size());
assertEquals(4, observers.size());
assertEquals("1", observers.get(0));
assertEquals("20", observers.get(1));
assertEquals("300", observers.get(2));
assertEquals("last", observers.get(3));
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class NotificationModeTest method testAsyncEventExecutedInDifferentThread.
@Test
public void testAsyncEventExecutedInDifferentThread() throws InterruptedException {
try (WeldContainer container = createWeld()) {
BlockingQueue<Message> synchronizer = new LinkedBlockingQueue<>();
Set<String> threadNames = new CopyOnWriteArraySet<>();
container.event().select(Message.class).fireAsync(() -> threadNames.add(Thread.currentThread().getName()), WeldNotificationOptions.withParallelMode()).thenAccept(synchronizer::add);
Message message = synchronizer.poll(2, TimeUnit.SECONDS);
assertNotNull(message);
// Eeach observer was notified using a different thread
assertEquals(2, threadNames.size());
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class NotificationModeTest method testExceptionPropagated.
@Test
public void testExceptionPropagated() throws InterruptedException {
try (WeldContainer container = createWeld()) {
BlockingQueue<Throwable> synchronizer = new LinkedBlockingQueue<>();
container.event().select(Message.class).fireAsync(() -> {
throw new IllegalStateException(NotificationModeTest.class.getName());
}, WeldNotificationOptions.withParallelMode()).whenComplete((event, throwable) -> synchronizer.add(throwable));
Throwable materializedThrowable = synchronizer.poll(2, TimeUnit.SECONDS);
assertTrue(materializedThrowable instanceof CompletionException);
Throwable[] suppressed = ((CompletionException) materializedThrowable).getSuppressed();
assertEquals(2, suppressed.length);
assertTrue(suppressed[0] instanceof IllegalStateException);
assertEquals(NotificationModeTest.class.getName(), suppressed[0].getMessage());
assertTrue(suppressed[1] instanceof IllegalStateException);
assertEquals(NotificationModeTest.class.getName(), suppressed[1].getMessage());
}
}
Aggregations