SGF-571 - Remove explicit call to start() in ContinuousQueryListenerContainer.afterPropertiesSet().
This commit is contained in:
@@ -77,7 +77,7 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
|
||||
InitializingBean, DisposableBean, SmartLifecycle {
|
||||
|
||||
// Default Thread name prefix is "ContinuousQueryListenerContainer-".
|
||||
public static final String DEFAULT_THREAD_NAME_PREFIX = String.format("%1$s-", ClassUtils.getShortName(
|
||||
public static final String DEFAULT_THREAD_NAME_PREFIX = String.format("%s-", ClassUtils.getShortName(
|
||||
ContinuousQueryListenerContainer.class));
|
||||
|
||||
private boolean autoStartup = true;
|
||||
@@ -96,11 +96,11 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private Queue<CqQuery> continuousQueries = new ConcurrentLinkedQueue<CqQuery>();
|
||||
private Queue<CqQuery> continuousQueries = new ConcurrentLinkedQueue<>();
|
||||
|
||||
private QueryService queryService;
|
||||
|
||||
private Set<ContinuousQueryDefinition> continuousQueryDefinitions = new LinkedHashSet<ContinuousQueryDefinition>();
|
||||
private Set<ContinuousQueryDefinition> continuousQueryDefinitions = new LinkedHashSet<>();
|
||||
|
||||
private String beanName;
|
||||
private String poolName;
|
||||
@@ -113,10 +113,6 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
|
||||
Assert.state(queryService != null, "QueryService was not properly initialized");
|
||||
|
||||
initialized = true;
|
||||
|
||||
if (isAutoStartup()) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@@ -140,7 +136,7 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
|
||||
}
|
||||
}
|
||||
catch (BeansException ignore) {
|
||||
Assert.notNull(PoolManager.find(poolName), String.format("No GemFire Pool with name [%1$s] was found",
|
||||
Assert.notNull(PoolManager.find(poolName), String.format("No GemFire Pool with name [%s] was found",
|
||||
poolName));
|
||||
}
|
||||
|
||||
@@ -176,7 +172,7 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
|
||||
* @see org.springframework.core.task.SimpleAsyncTaskExecutor#SimpleAsyncTaskExecutor(String)
|
||||
*/
|
||||
protected TaskExecutor createDefaultTaskExecutor() {
|
||||
return new SimpleAsyncTaskExecutor(beanName != null ? String.format("%1$s-", beanName)
|
||||
return new SimpleAsyncTaskExecutor(beanName != null ? String.format("%s-", beanName)
|
||||
: DEFAULT_THREAD_NAME_PREFIX);
|
||||
}
|
||||
|
||||
@@ -216,16 +212,19 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
|
||||
try {
|
||||
cq.execute();
|
||||
}
|
||||
catch (QueryException ex) {
|
||||
catch (QueryException e) {
|
||||
throw new GemfireQueryException(String.format("Could not execute query [%1$s]; state is [%2$s].",
|
||||
cq.getName(), cq.getState()), ex);
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
throw new GemfireQueryException(String.format("Could not execute query [%1$s]; state is [%2$s].",
|
||||
cq.getName(), cq.getState()), ex);
|
||||
cq.getName(), cq.getState()), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(Runnable callback) {
|
||||
stop();
|
||||
callback.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void stop() {
|
||||
if (isRunning()) {
|
||||
doStop();
|
||||
@@ -237,11 +236,6 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
|
||||
}
|
||||
}
|
||||
|
||||
public void stop(final Runnable callback) {
|
||||
stop();
|
||||
callback.run();
|
||||
}
|
||||
|
||||
private void doStop() {
|
||||
for (CqQuery cq : continuousQueries) {
|
||||
try {
|
||||
@@ -253,6 +247,7 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
stop();
|
||||
closeQueries();
|
||||
@@ -313,6 +308,7 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
|
||||
* @return a boolean value indicating whether this CQ listener container automatically starts.
|
||||
* @see org.springframework.context.SmartLifecycle#isAutoStartup()
|
||||
*/
|
||||
@Override
|
||||
public boolean isAutoStartup() {
|
||||
return autoStartup;
|
||||
}
|
||||
@@ -345,6 +341,7 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
|
||||
*
|
||||
* @param name the name of the bean in the factory.
|
||||
*/
|
||||
@Override
|
||||
public void setBeanName(String name) {
|
||||
this.beanName = name;
|
||||
}
|
||||
@@ -467,11 +464,8 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
|
||||
|
||||
return cq;
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
throw new GemfireQueryException("Cannot create query ", ex);
|
||||
}
|
||||
catch (QueryException ex) {
|
||||
throw new GemfireQueryException("Cannot create query ", ex);
|
||||
catch (QueryException e) {
|
||||
throw new GemfireQueryException("Cannot create query ", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -553,5 +547,4 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
|
||||
public void close() {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,21 +50,17 @@ import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.config.xml.GemfireConstants;
|
||||
|
||||
/**
|
||||
* The ContinuousQueryListenerContainerTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the {@link ContinuousQueryListenerContainer} class.
|
||||
* Unit tests for {@link ContinuousQueryListenerContainer}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Rule
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.rules.ExpectedException
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.mockito.Mock
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.mockito.runners.MockitoJUnitRunner
|
||||
* @see org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public class ContinuousQueryListenerContainerTest {
|
||||
public class ContinuousQueryListenerContainerTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
@@ -77,7 +73,7 @@ public class ContinuousQueryListenerContainerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void afterPropertiesSetAutoStarts() throws Exception {
|
||||
public void afterPropertiesSetIsAutoStart() throws Exception {
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||
Pool mockPool = mock(Pool.class);
|
||||
QueryService mockQueryService = mock(QueryService.class);
|
||||
@@ -96,11 +92,11 @@ public class ContinuousQueryListenerContainerTest {
|
||||
}
|
||||
finally {
|
||||
assertThat(PoolManagerImpl.getPMI().unregister(mockPool), is(true));
|
||||
assertThat(listenerContainer.isAutoStartup(), is(true));
|
||||
assertThat((QueryService) TestUtils.readField("queryService", listenerContainer), is(equalTo(mockQueryService)));
|
||||
assertThat(TestUtils.readField("taskExecutor", listenerContainer), is(instanceOf(Executor.class)));
|
||||
assertThat(listenerContainer.isActive(), is(true));
|
||||
assertThat(listenerContainer.isRunning(), is(true));
|
||||
assertThat(listenerContainer.isAutoStartup(), is(true));
|
||||
assertThat(listenerContainer.isRunning(), is(false));
|
||||
assertThat(TestUtils.readField("queryService", listenerContainer), is(equalTo(mockQueryService)));
|
||||
assertThat(TestUtils.readField("taskExecutor", listenerContainer), is(instanceOf(Executor.class)));
|
||||
|
||||
verify(mockBeanFactory, times(1)).containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME));
|
||||
verify(mockBeanFactory, times(1)).isTypeMatch(eq(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME), eq(Pool.class));
|
||||
@@ -112,7 +108,7 @@ public class ContinuousQueryListenerContainerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void afterPropertiesSetStartsManually() {
|
||||
public void afterPropertiesSetIsManualStart() {
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||
QueryService mockQueryService = mock(QueryService.class);
|
||||
|
||||
@@ -130,6 +126,7 @@ public class ContinuousQueryListenerContainerTest {
|
||||
assertThat(listenerContainer.isAutoStartup(), is(false));
|
||||
assertThat(listenerContainer.isRunning(), is(false));
|
||||
|
||||
verify(mockBeanFactory, never()).containsBean(eq("TestPool"));
|
||||
verify(mockBeanFactory, times(1)).isTypeMatch(eq("TestPool"), eq(Pool.class));
|
||||
verify(mockBeanFactory, times(1)).getBean(eq("TestPool"), eq(Pool.class));
|
||||
verify(poolManagerSpy, never()).find(anyString());
|
||||
@@ -361,5 +358,4 @@ public class ContinuousQueryListenerContainerTest {
|
||||
|
||||
assertThat(listenerContainer.isAutoStartup(), is(true));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user