Clean up warnings across code base
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -130,68 +130,69 @@ public class SimpleTransactionScopeTests {
|
||||
|
||||
@Test
|
||||
public void getWithTransactionManager() throws Exception {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.getBeanFactory().registerScope("tx", new SimpleTransactionScope());
|
||||
try (GenericApplicationContext context = new GenericApplicationContext()) {
|
||||
context.getBeanFactory().registerScope("tx", new SimpleTransactionScope());
|
||||
|
||||
GenericBeanDefinition bd1 = new GenericBeanDefinition();
|
||||
bd1.setBeanClass(TestBean.class);
|
||||
bd1.setScope("tx");
|
||||
bd1.setPrimary(true);
|
||||
context.registerBeanDefinition("txScopedObject1", bd1);
|
||||
GenericBeanDefinition bd1 = new GenericBeanDefinition();
|
||||
bd1.setBeanClass(TestBean.class);
|
||||
bd1.setScope("tx");
|
||||
bd1.setPrimary(true);
|
||||
context.registerBeanDefinition("txScopedObject1", bd1);
|
||||
|
||||
GenericBeanDefinition bd2 = new GenericBeanDefinition();
|
||||
bd2.setBeanClass(DerivedTestBean.class);
|
||||
bd2.setScope("tx");
|
||||
context.registerBeanDefinition("txScopedObject2", bd2);
|
||||
GenericBeanDefinition bd2 = new GenericBeanDefinition();
|
||||
bd2.setBeanClass(DerivedTestBean.class);
|
||||
bd2.setScope("tx");
|
||||
context.registerBeanDefinition("txScopedObject2", bd2);
|
||||
|
||||
context.refresh();
|
||||
context.refresh();
|
||||
|
||||
CallCountingTransactionManager tm = new CallCountingTransactionManager();
|
||||
TransactionTemplate tt = new TransactionTemplate(tm);
|
||||
Set<DerivedTestBean> finallyDestroy = new HashSet<>();
|
||||
CallCountingTransactionManager tm = new CallCountingTransactionManager();
|
||||
TransactionTemplate tt = new TransactionTemplate(tm);
|
||||
Set<DerivedTestBean> finallyDestroy = new HashSet<>();
|
||||
|
||||
tt.execute(status -> {
|
||||
TestBean bean1 = context.getBean(TestBean.class);
|
||||
assertSame(bean1, context.getBean(TestBean.class));
|
||||
tt.execute(status -> {
|
||||
TestBean bean1 = context.getBean(TestBean.class);
|
||||
assertSame(bean1, context.getBean(TestBean.class));
|
||||
|
||||
DerivedTestBean bean2 = context.getBean(DerivedTestBean.class);
|
||||
assertSame(bean2, context.getBean(DerivedTestBean.class));
|
||||
context.getBeanFactory().destroyScopedBean("txScopedObject2");
|
||||
assertFalse(TransactionSynchronizationManager.hasResource("txScopedObject2"));
|
||||
assertTrue(bean2.wasDestroyed());
|
||||
DerivedTestBean bean2 = context.getBean(DerivedTestBean.class);
|
||||
assertSame(bean2, context.getBean(DerivedTestBean.class));
|
||||
context.getBeanFactory().destroyScopedBean("txScopedObject2");
|
||||
assertFalse(TransactionSynchronizationManager.hasResource("txScopedObject2"));
|
||||
assertTrue(bean2.wasDestroyed());
|
||||
|
||||
DerivedTestBean bean2a = context.getBean(DerivedTestBean.class);
|
||||
assertSame(bean2a, context.getBean(DerivedTestBean.class));
|
||||
assertNotSame(bean2, bean2a);
|
||||
context.getBeanFactory().getRegisteredScope("tx").remove("txScopedObject2");
|
||||
assertFalse(TransactionSynchronizationManager.hasResource("txScopedObject2"));
|
||||
assertFalse(bean2a.wasDestroyed());
|
||||
DerivedTestBean bean2a = context.getBean(DerivedTestBean.class);
|
||||
assertSame(bean2a, context.getBean(DerivedTestBean.class));
|
||||
assertNotSame(bean2, bean2a);
|
||||
context.getBeanFactory().getRegisteredScope("tx").remove("txScopedObject2");
|
||||
assertFalse(TransactionSynchronizationManager.hasResource("txScopedObject2"));
|
||||
assertFalse(bean2a.wasDestroyed());
|
||||
|
||||
DerivedTestBean bean2b = context.getBean(DerivedTestBean.class);
|
||||
finallyDestroy.add(bean2b);
|
||||
assertSame(bean2b, context.getBean(DerivedTestBean.class));
|
||||
assertNotSame(bean2, bean2b);
|
||||
assertNotSame(bean2a, bean2b);
|
||||
DerivedTestBean bean2b = context.getBean(DerivedTestBean.class);
|
||||
finallyDestroy.add(bean2b);
|
||||
assertSame(bean2b, context.getBean(DerivedTestBean.class));
|
||||
assertNotSame(bean2, bean2b);
|
||||
assertNotSame(bean2a, bean2b);
|
||||
|
||||
Set<DerivedTestBean> immediatelyDestroy = new HashSet<>();
|
||||
TransactionTemplate tt2 = new TransactionTemplate(tm);
|
||||
tt2.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRED);
|
||||
tt2.execute(status2 -> {
|
||||
DerivedTestBean bean2c = context.getBean(DerivedTestBean.class);
|
||||
immediatelyDestroy.add(bean2c);
|
||||
assertSame(bean2c, context.getBean(DerivedTestBean.class));
|
||||
assertNotSame(bean2, bean2c);
|
||||
assertNotSame(bean2a, bean2c);
|
||||
assertNotSame(bean2b, bean2c);
|
||||
return null;
|
||||
});
|
||||
assertTrue(immediatelyDestroy.iterator().next().wasDestroyed());
|
||||
assertFalse(bean2b.wasDestroyed());
|
||||
|
||||
Set<DerivedTestBean> immediatelyDestroy = new HashSet<>();
|
||||
TransactionTemplate tt2 = new TransactionTemplate(tm);
|
||||
tt2.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRED);
|
||||
tt2.execute(status2 -> {
|
||||
DerivedTestBean bean2c = context.getBean(DerivedTestBean.class);
|
||||
immediatelyDestroy.add(bean2c);
|
||||
assertSame(bean2c, context.getBean(DerivedTestBean.class));
|
||||
assertNotSame(bean2, bean2c);
|
||||
assertNotSame(bean2a, bean2c);
|
||||
assertNotSame(bean2b, bean2c);
|
||||
return null;
|
||||
});
|
||||
assertTrue(immediatelyDestroy.iterator().next().wasDestroyed());
|
||||
assertFalse(bean2b.wasDestroyed());
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
assertTrue(finallyDestroy.iterator().next().wasDestroyed());
|
||||
assertTrue(finallyDestroy.iterator().next().wasDestroyed());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user