SGF-571 - Remove explicit call to start() in ContinuousQueryListenerContainer.afterPropertiesSet().

This commit is contained in:
John Blum
2016-11-22 00:30:20 -08:00
parent 1b9e65cdc1
commit 632801677e
2 changed files with 26 additions and 37 deletions

View File

@@ -78,7 +78,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;
@@ -114,10 +114,6 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
Assert.state(queryService != null, "QueryService was not properly initialized");
initialized = true;
if (isAutoStartup()) {
start();
}
}
/* (non-Javadoc) */
@@ -141,7 +137,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));
}
@@ -177,7 +173,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);
}
@@ -217,16 +213,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();
@@ -238,11 +237,6 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
}
}
public void stop(final Runnable callback) {
stop();
callback.run();
}
private void doStop() {
for (CqQuery cq : continuousQueries) {
try {
@@ -254,6 +248,7 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
}
}
@Override
public void destroy() throws Exception {
stop();
closeQueries();
@@ -314,6 +309,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;
}
@@ -346,6 +342,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;
}
@@ -468,11 +465,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);
}
}
@@ -554,5 +548,4 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
public void close() {
}
}
}

View File

@@ -51,21 +51,17 @@ import com.gemstone.gemfire.cache.query.QueryService;
import com.gemstone.gemfire.internal.cache.PoolManagerImpl;
/**
* 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();
@@ -78,7 +74,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);
@@ -97,11 +93,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((QueryService) TestUtils.readField("queryService", listenerContainer), is(equalTo(mockQueryService)));
assertThat((Executor) 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));
@@ -113,7 +109,7 @@ public class ContinuousQueryListenerContainerTest {
}
@Test
public void afterPropertiesSetStartsManually() {
public void afterPropertiesSetIsManualStart() {
BeanFactory mockBeanFactory = mock(BeanFactory.class);
QueryService mockQueryService = mock(QueryService.class);
@@ -131,6 +127,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());
@@ -362,5 +359,4 @@ public class ContinuousQueryListenerContainerTest {
assertThat(listenerContainer.isAutoStartup(), is(true));
}
}