INT-2075 - Added namespace support for cq-inbound-channel-adapter. Also some general cleanup and additional tests
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright 2002-2011 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. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.gemfire.inbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.gemfire.listener.QueryListenerContainer;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
|
||||
import com.gemstone.gemfire.cache.Operation;
|
||||
import com.gemstone.gemfire.cache.query.CqEvent;
|
||||
import com.gemstone.gemfire.cache.query.CqQuery;
|
||||
import com.gemstone.gemfire.cache.query.internal.CqQueryImpl;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ContinuousQueryMessageProducerTests {
|
||||
QueryListenerContainer queryListenerContainer;
|
||||
|
||||
ContinuousQueryMessageProducer cqMessageProducer;
|
||||
|
||||
CqMessageHandler handler;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
queryListenerContainer = mock(QueryListenerContainer.class);
|
||||
cqMessageProducer = new ContinuousQueryMessageProducer(queryListenerContainer, "");
|
||||
DirectChannel outputChannel = new DirectChannel();
|
||||
cqMessageProducer.setOutputChannel(outputChannel);
|
||||
handler = new CqMessageHandler();
|
||||
outputChannel.subscribe(handler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageProduced() {
|
||||
CqEvent cqEvent = event(Operation.CREATE, "hello");
|
||||
|
||||
cqMessageProducer.onEvent(cqEvent);
|
||||
|
||||
assertEquals(1, handler.count);
|
||||
assertEquals(cqEvent, handler.payload);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageNotProducedForUnsupportedEventType() {
|
||||
CqEvent cqEvent = event(Operation.DESTROY, "hello");
|
||||
|
||||
cqMessageProducer.onEvent(cqEvent);
|
||||
|
||||
assertEquals(0, handler.count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageProducedForAddedEventType() {
|
||||
|
||||
CqEvent cqEvent = event(Operation.DESTROY, null);
|
||||
|
||||
cqMessageProducer.setSupportedEventTypes(CqEventType.DESTROYED);
|
||||
cqMessageProducer.onEvent(cqEvent);
|
||||
|
||||
assertEquals(1, handler.count);
|
||||
assertEquals(cqEvent, handler.payload);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPayloadExpression() {
|
||||
CqEvent cqEvent = event(Operation.CREATE, "hello");
|
||||
cqMessageProducer.setPayloadExpression("newValue.toUpperCase() + ', WORLD'");
|
||||
cqMessageProducer.onEvent(cqEvent);
|
||||
assertEquals(1, handler.count);
|
||||
assertEquals("HELLO, WORLD", handler.payload);
|
||||
}
|
||||
|
||||
CqEvent event(final Operation operation, final Object value) {
|
||||
|
||||
CqEvent event = new CqEvent() {
|
||||
|
||||
final CqQuery cq = new CqQueryImpl();
|
||||
|
||||
final byte[] ba = new byte[0];
|
||||
|
||||
final Object key = new Object();
|
||||
|
||||
final Exception ex = new Exception();
|
||||
|
||||
public Operation getBaseOperation() {
|
||||
return operation;
|
||||
}
|
||||
|
||||
public CqQuery getCq() {
|
||||
return cq;
|
||||
}
|
||||
|
||||
public byte[] getDeltaValue() {
|
||||
return ba;
|
||||
}
|
||||
|
||||
public Object getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Object getNewValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Operation getQueryOperation() {
|
||||
return operation;
|
||||
}
|
||||
|
||||
public Throwable getThrowable() {
|
||||
return ex;
|
||||
}
|
||||
};
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
private static class CqMessageHandler implements MessageHandler {
|
||||
public int count;
|
||||
|
||||
public Object payload;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.integration.core.MessageHandler#handleMessage
|
||||
* (org.springframework.integration.Message)
|
||||
*/
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
count++;
|
||||
payload = message.getPayload();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,24 +23,17 @@
|
||||
<property name="cache" ref="client-cache"/>
|
||||
</bean>
|
||||
|
||||
<bean id="cqMessageProducer" class="org.springframework.integration.gemfire.inbound.ContinuousQueryMessageProducer">
|
||||
<constructor-arg ref="queryListenerContainer"/>
|
||||
<constructor-arg value="select * from /test"/>
|
||||
<property name="outputChannel" ref="outputChannel1"/>
|
||||
<property name="durable" value="true"/>
|
||||
</bean>
|
||||
<int-gfe:cq-inbound-channel-adapter query-listener-container="queryListenerContainer"
|
||||
query="select * from /test" channel="outputChannel1" durable="true"/>
|
||||
|
||||
<int:channel id="outputChannel1">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<bean id="spelCqMessageProducer" class="org.springframework.integration.gemfire.inbound.ContinuousQueryMessageProducer">
|
||||
<constructor-arg ref="queryListenerContainer"/>
|
||||
<constructor-arg value="select * from /test"/>
|
||||
<property name="outputChannel" ref="outputChannel2"/>
|
||||
<property name="payloadExpression" value="newValue"/>
|
||||
</bean>
|
||||
<int-gfe:cq-inbound-channel-adapter query-listener-container="queryListenerContainer"
|
||||
query="select * from /test" channel="outputChannel2" expression="newValue" query-events="CREATED"/>
|
||||
|
||||
|
||||
<int:channel id="outputChannel2">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
@@ -10,7 +10,7 @@
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.gemfire.inbound.cq;
|
||||
package org.springframework.integration.gemfire.inbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -37,12 +37,11 @@ import com.gemstone.gemfire.internal.cache.LocalRegion;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
* @since 2.1
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class ContinuousQueryMessageProducerTests {
|
||||
|
||||
public class CqInboundChannelAdapterTests {
|
||||
static ConfigurableApplicationContext staticCtx;
|
||||
|
||||
@Autowired
|
||||
@@ -82,9 +81,7 @@ public class ContinuousQueryMessageProducerTests {
|
||||
region.put("one",1);
|
||||
Message<?> msg = outputChannel2.receive(1000);
|
||||
assertNotNull(msg);
|
||||
assertEquals(1,msg.getPayload());
|
||||
|
||||
|
||||
assertEquals(1,msg.getPayload());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.gemfire.store.messagegroupstore;
|
||||
package org.springframework.integration.gemfire.store;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -9,9 +9,9 @@
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<bean class="org.springframework.integration.gemfire.store.messagegroupstore.GemfireMessageGroupStoreTestConfiguration"/>
|
||||
<bean class="org.springframework.integration.gemfire.store.GemfireMessageGroupStoreTestConfiguration"/>
|
||||
|
||||
<context:property-placeholder location="org/springframework/integration/gemfire/store/messagegroupstore/common.properties"/>
|
||||
<context:property-placeholder location="org/springframework/integration/gemfire/store/common.properties"/>
|
||||
|
||||
<int:channel id="i"/>
|
||||
|
||||
@@ -21,6 +21,6 @@
|
||||
|
||||
<int:service-activator input-channel="o" ref="messageGroupStoreActivator" />
|
||||
|
||||
<util:properties id="props" location="org/springframework/integration/gemfire/store/messagegroupstore/gfe-cache.properties"/>
|
||||
<util:properties id="props" location="org/springframework/integration/gemfire/store/gfe-cache.properties"/>
|
||||
|
||||
</beans>
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.gemfire.store.messagegroupstore;
|
||||
package org.springframework.integration.gemfire.store;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class GemfireMessageGroupStoreTest {
|
||||
public class GemfireMessageGroupStoreTests {
|
||||
|
||||
@Autowired
|
||||
private GemfireMessageGroupStoreTestConfiguration.FakeMessageConsumer consumer;
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
<context:property-placeholder location="org/springframework/integration/gemfire/inbound/cq/common.properties"/>
|
||||
|
||||
<context:component-scan base-package="org.springframework.integration.gemfire.store.messagegroupstore"/>
|
||||
<context:component-scan base-package="org.springframework.integration.gemfire.store"/>
|
||||
|
||||
<int:channel id="i"/>
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
|
||||
<!-- Loggers -->
|
||||
<logger name="org.springframework">
|
||||
<level value="debug" />
|
||||
<level value="warn" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.integration">
|
||||
<level value="debug" />
|
||||
<level value="warn" />
|
||||
</logger>
|
||||
|
||||
<!-- Root Logger -->
|
||||
|
||||
Reference in New Issue
Block a user