SGF-57
+ fix some initilization problem with the container that triggered eager registration of cqs + added more integration tests
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.springframework.data.gemfire.listener;
|
package org.springframework.data.gemfire.listener;
|
||||||
|
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
@@ -91,6 +92,7 @@ public class ContinousQueryListenerContainer implements InitializingBean, Dispos
|
|||||||
private volatile boolean initialized = false;
|
private volatile boolean initialized = false;
|
||||||
private volatile boolean manageExecutor = false;
|
private volatile boolean manageExecutor = false;
|
||||||
|
|
||||||
|
private Set<ContinousQueryDefinition> defs = new LinkedHashSet<ContinousQueryDefinition>();
|
||||||
private Set<CqQuery> queries = new ConcurrentHashSet<CqQuery>();
|
private Set<CqQuery> queries = new ConcurrentHashSet<CqQuery>();
|
||||||
|
|
||||||
private QueryService queryService;
|
private QueryService queryService;
|
||||||
@@ -113,6 +115,7 @@ public class ContinousQueryListenerContainer implements InitializingBean, Dispos
|
|||||||
queryService = pool.getQueryService();
|
queryService = pool.getQueryService();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initMapping(defs);
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
|
||||||
start();
|
start();
|
||||||
@@ -333,7 +336,8 @@ public class ContinousQueryListenerContainer implements InitializingBean, Dispos
|
|||||||
* @param queries set of queries
|
* @param queries set of queries
|
||||||
*/
|
*/
|
||||||
public void setQueryListeners(Set<ContinousQueryDefinition> queries) {
|
public void setQueryListeners(Set<ContinousQueryDefinition> queries) {
|
||||||
initMapping(queries);
|
defs.clear();
|
||||||
|
defs.addAll(queries);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -355,7 +359,7 @@ public class ContinousQueryListenerContainer implements InitializingBean, Dispos
|
|||||||
closeQueries();
|
closeQueries();
|
||||||
|
|
||||||
for (ContinousQueryDefinition def : queryDefinitions) {
|
for (ContinousQueryDefinition def : queryDefinitions) {
|
||||||
doAddListener(def);
|
addCQuery(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
// resume activity
|
// resume activity
|
||||||
@@ -365,29 +369,35 @@ public class ContinousQueryListenerContainer implements InitializingBean, Dispos
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void doAddListener(ContinousQueryDefinition def) {
|
private void doAddListener(ContinousQueryDefinition def) {
|
||||||
CqQuery cq = null;
|
CqQuery cq = addCQuery(def);
|
||||||
|
|
||||||
|
if (isRunning()) {
|
||||||
|
executeQuery(cq);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private CqQuery addCQuery(ContinousQueryDefinition def) {
|
||||||
try {
|
try {
|
||||||
CqAttributesFactory caf = new CqAttributesFactory();
|
CqAttributesFactory caf = new CqAttributesFactory();
|
||||||
caf.addCqListener(new EventDispatcherAdapter(def.getListener()));
|
caf.addCqListener(new EventDispatcherAdapter(def.getListener()));
|
||||||
CqAttributes attr = caf.create();
|
CqAttributes attr = caf.create();
|
||||||
|
|
||||||
|
CqQuery cq = null;
|
||||||
|
|
||||||
if (StringUtils.hasText(def.getName())) {
|
if (StringUtils.hasText(def.getName())) {
|
||||||
cq = queryService.newCq(def.getName(), def.getQuery(), attr, def.isDurable());
|
cq = queryService.newCq(def.getName(), def.getQuery(), attr, def.isDurable());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cq = queryService.newCq(def.getQuery(), attr, def.isDurable());
|
cq = queryService.newCq(def.getQuery(), attr, def.isDurable());
|
||||||
}
|
}
|
||||||
|
|
||||||
queries.add(cq);
|
queries.add(cq);
|
||||||
|
return cq;
|
||||||
} catch (RuntimeException ex) {
|
} catch (RuntimeException ex) {
|
||||||
throw new GemfireQueryException("Cannot create query ", ex);
|
throw new GemfireQueryException("Cannot create query ", ex);
|
||||||
} catch (QueryException ex) {
|
} catch (QueryException ex) {
|
||||||
throw new GemfireQueryException("Cannot create query ", ex);
|
throw new GemfireQueryException("Cannot create query ", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRunning()) {
|
|
||||||
executeQuery(cq);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeQuery(CqQuery cq) {
|
private void executeQuery(CqQuery cq) {
|
||||||
|
|||||||
@@ -64,6 +64,11 @@ public class ListenerContainerTests {
|
|||||||
ccf.setPoolSubscriptionEnabled(true);
|
ccf.setPoolSubscriptionEnabled(true);
|
||||||
cache = ccf.create();
|
cache = ccf.create();
|
||||||
|
|
||||||
|
// not really used but here just for future tests :)
|
||||||
|
// PoolFactory pf = PoolManager.createFactory();
|
||||||
|
// pf.addServer("localhost", 40404);
|
||||||
|
// pf.setSubscriptionEnabled(true);
|
||||||
|
// Pool pool = pf.create("client");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -89,12 +94,12 @@ public class ListenerContainerTests {
|
|||||||
|
|
||||||
container = new ContinousQueryListenerContainer();
|
container = new ContinousQueryListenerContainer();
|
||||||
container.setCache(cache);
|
container.setCache(cache);
|
||||||
|
//container.setPoolName("client");
|
||||||
container.setBeanName("container");
|
container.setBeanName("container");
|
||||||
container.addListener(new ContinousQueryDefinition("test", query, adapter));
|
|
||||||
container.afterPropertiesSet();
|
container.afterPropertiesSet();
|
||||||
|
container.addListener(new ContinousQueryDefinition("test", query, adapter));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContainer() throws Exception {
|
public void testContainer() throws Exception {
|
||||||
ForkUtil.sendSignal();
|
ForkUtil.sendSignal();
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.springframework.data.gemfire.listener.adapter;
|
package org.springframework.data.gemfire.listener.adapter;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
@@ -26,8 +27,7 @@ import org.springframework.data.gemfire.ForkUtil;
|
|||||||
import org.springframework.data.gemfire.listener.ContinousQueryListenerContainer;
|
import org.springframework.data.gemfire.listener.ContinousQueryListenerContainer;
|
||||||
|
|
||||||
import com.gemstone.gemfire.cache.Cache;
|
import com.gemstone.gemfire.cache.Cache;
|
||||||
import com.gemstone.gemfire.cache.client.PoolFactory;
|
import com.gemstone.gemfire.cache.client.Pool;
|
||||||
import com.gemstone.gemfire.cache.client.PoolManager;
|
|
||||||
import com.gemstone.gemfire.cache.query.CqQuery;
|
import com.gemstone.gemfire.cache.query.CqQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,12 +54,15 @@ public class ContainerXmlSetupTest {
|
|||||||
ContinousQueryListenerContainer container = ctx.getBean(ContinousQueryListenerContainer.class);
|
ContinousQueryListenerContainer container = ctx.getBean(ContinousQueryListenerContainer.class);
|
||||||
assertTrue(container.isRunning());
|
assertTrue(container.isRunning());
|
||||||
|
|
||||||
ForkUtil.sendSignal();
|
|
||||||
Thread.sleep(3000);
|
|
||||||
Cache cache = ctx.getBean("gemfire-cache", Cache.class);
|
Cache cache = ctx.getBean("gemfire-cache", Cache.class);
|
||||||
|
Pool pool = ctx.getBean("client", Pool.class);
|
||||||
|
|
||||||
CqQuery[] cqs = cache.getQueryService().getCqs();
|
CqQuery[] cqs = cache.getQueryService().getCqs();
|
||||||
System.out.println("Cqs " + cqs.length);
|
CqQuery[] pcqs = pool.getQueryService().getCqs();
|
||||||
|
assertTrue(pool.getQueryService().getCq("test-bean-1") != null);
|
||||||
|
assertEquals(3, cqs.length);
|
||||||
|
assertEquals(3, pcqs.length);
|
||||||
ForkUtil.sendSignal();
|
ForkUtil.sendSignal();
|
||||||
|
Thread.sleep(3000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<prop key="log-level">warning</prop>
|
<prop key="log-level">warning</prop>
|
||||||
</util:properties>
|
</util:properties>
|
||||||
|
|
||||||
<gfe:client-cache use-bean-factory-locator="false" pool-name="client"/>
|
<gfe:client-cache use-bean-factory-locator="false"/>
|
||||||
|
|
||||||
<gfe:pool id="client" subscription-enabled="true">
|
<gfe:pool id="client" subscription-enabled="true">
|
||||||
<gfe:server host="localhost" port="40404"/>
|
<gfe:server host="localhost" port="40404"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user