INTEXT-158: JavaConfig tests and upgrades

JIRA: https://jira.spring.io/browse/INTEXT-158

* Provide the test cases to demonstrate the Spring Integration Hazelcast adapters usage from the JavaConfig
* Upgrade to Hazelcast-3.6, SI-4.2.4, Gradle-2.5
* Fix Hazelcast-3.6 compatibility
* Fix failing tests
This commit is contained in:
erenavsarogullari
2016-01-24 23:02:52 +00:00
committed by Artem Bilan
parent 1759030fda
commit 0efd494337
29 changed files with 3361 additions and 1447 deletions

View File

@@ -19,7 +19,9 @@ It also provides event listeners in order to listen to the modifications perform
* com.hazelcast.core.ItemListener<E>
* com.hazelcast.core.MessageListener<E>
Hazelcast Event-Driven Inbound Channel Adapter listens related cache events and sends event messages to defined channel. Its basic definition is as follows :
Hazelcast Event-Driven Inbound Channel Adapter listens related cache events and sends event messages to defined channel. It supports both XML and JavaConfig driven configurations.
#### XML Driven Configuration :
```
<int-hazelcast:inbound-channel-adapter channel="mapChannel"
cache="map"
@@ -150,12 +152,46 @@ Sample definitions are as follows :
</constructor-arg>
</bean>
```
**Reference :** http://docs.hazelcast.org/docs/3.4/manual/html-single/hazelcast-documentation.html#distributed-data-structures
#### JavaConfig Driven Configuration :
The following sample shows Distributed Map configuration. Same configuration can be used for other distributed data structures(IMap, MultiMap, ReplicatedMap, IList, ISet, IQueue and ITopic).
```
@Bean
public PollableChannel distributedMapChannel() {
return new QueueChannel();
}
@Bean
public IMap<Integer, String> distributedMap() {
return hazelcastInstance().getMap("Distributed_Map");
}
@Bean
public HazelcastInstance hazelcastInstance() {
return Hazelcast.newHazelcastInstance();
}
@Bean
public HazelcastEventDrivenMessageProducer hazelcastEventDrivenMessageProducer() {
final HazelcastEventDrivenMessageProducer producer = new HazelcastEventDrivenMessageProducer(distributedMap());
producer.setOutputChannel(distributedMapChannel());
producer.setCacheEventTypes("ADDED,REMOVED,UPDATED,CLEAR_ALL");
producer.setCacheListeningPolicy(CacheListeningPolicyType.SINGLE);
return producer;
}
```
**Reference :** http://docs.hazelcast.org/docs/latest/manual/html/distributed-data-structures.html
## HAZELCAST CONTINUOUS QUERY INBOUND CHANNEL ADAPTER
## HAZELCAST CONTINUOUS QUERY INBOUND CHANNEL ADAPTER
Hazelcast Continuous Query enables to listen to the modifications performed on specific map entries. Hazelcast Continuous Query Inbound Channel Adapter is an event-driven channel adapter and listens to related distributed map events in the light of defined predicate. Its basic definition is as follows :
Hazelcast Continuous Query enables to listen to the modifications performed on specific map entries. Hazelcast Continuous Query Inbound Channel Adapter is an event-driven channel adapter and listens to related distributed map events in the light of defined predicate. It supports both XML and JavaConfig driven configurations.
#### XML Driven Configuration :
```
<int-hazelcast:cq-inbound-channel-adapter
channel="cqMapChannel"
@@ -197,12 +233,43 @@ Sample definition is as follows :
</constructor-arg>
</bean>
```
**Reference :** http://docs.hazelcast.org/docs/3.4/manual/html-single/hazelcast-documentation.html#continuous-query
#### JavaConfig Driven Configuration :
```
@Bean
public PollableChannel cqDistributedMapChannel() {
return new QueueChannel();
}
@Bean
public IMap<Integer, String> cqDistributedMap() {
return hazelcastInstance().getMap("CQ_Distributed_Map");
}
@Bean
public HazelcastInstance hazelcastInstance() {
return Hazelcast.newHazelcastInstance();
}
@Bean
public HazelcastContinuousQueryMessageProducer hazelcastContinuousQueryMessageProducer() {
final HazelcastContinuousQueryMessageProducer producer =
new HazelcastContinuousQueryMessageProducer(cqDistributedMap(), "surname=TestSurname");
producer.setOutputChannel(cqDistributedMapChannel());
producer.setCacheEventTypes("UPDATED");
producer.setIncludeValue(false);
return producer;
}
```
**Reference :** http://docs.hazelcast.org/docs/latest/manual/html/continuousquery.html
## HAZELCAST CLUSTER MONITOR INBOUND CHANNEL ADAPTER
Hazelcast Cluster Monitor enables to listen to the modifications performed on cluster. Hazelcast Cluster Monitor Inbound Channel Adapter is an event-driven channel adapter and listens to related Membership, Distributed Object, Migration, Lifecycle and Client events. Its basic definition is as follows :
Hazelcast Cluster Monitor enables to listen to the modifications performed on cluster. Hazelcast Cluster Monitor Inbound Channel Adapter is an event-driven channel adapter and listens to related Membership, Distributed Object, Migration, Lifecycle and Client events. It supports both XML and JavaConfig driven configurations.
#### XML Driven Configuration :
```
<int-hazelcast:cm-inbound-channel-adapter
channel="monitorChannel"
@@ -231,12 +298,36 @@ Sample definition is as follows :
</constructor-arg>
</bean>
```
#### JavaConfig Driven Configuration :
```
@Bean
public PollableChannel cmonChannel() {
return new QueueChannel();
}
@Bean
public HazelcastInstance hazelcastInstance() {
return Hazelcast.newHazelcastInstance();
}
@Bean
public HazelcastClusterMonitorMessageProducer hazelcastClusterMonitorMessageProducer() {
final HazelcastClusterMonitorMessageProducer producer = new HazelcastClusterMonitorMessageProducer(hazelcastInstance());
producer.setOutputChannel(cmonChannel());
producer.setMonitorEventTypes("DISTRIBUTED_OBJECT");
return producer;
}
```
**Reference :** http://docs.hazelcast.org/docs/latest/manual/html/distributedevents.html
## HAZELCAST DISTRIBUTED-SQL INBOUND CHANNEL ADAPTER
Hazelcast allows to run distributed queries on the distributed map. Hazelcast Distributed SQL Inbound Channel Adapter is a poller-driven inbound channel adapter. It runs defined distributed-sql and returns results in the light of iteration type. Its basic definition is as follows :
Hazelcast allows to run distributed queries on the distributed map. Hazelcast Distributed SQL Inbound Channel Adapter is a poller-driven inbound channel adapter. It runs defined distributed-sql and returns results in the light of iteration type. It supports both XML and JavaConfig driven configurations.
#### XML Driven Configuration :
```
<int-hazelcast:ds-inbound-channel-adapter
channel="dsMapChannel"
@@ -276,12 +367,43 @@ Sample definition is as follows :
</constructor-arg>
</bean>
```
**Reference :** http://docs.hazelcast.org/docs/3.4/manual/html-single/hazelcast-documentation.html#query-overview
#### JavaConfig Driven Configuration :
```
@Bean
public PollableChannel dsDistributedMapChannel() {
return new QueueChannel();
}
@Bean
public IMap<Integer, String> dsDistributedMap() {
return hazelcastInstance().getMap("DS_Distributed_Map");
}
@Bean
public HazelcastInstance hazelcastInstance() {
return Hazelcast.newHazelcastInstance();
}
@Bean
@InboundChannelAdapter(value = "dsDistributedMapChannel", poller = @Poller(maxMessagesPerPoll = "1"))
public HazelcastDistributedSQLMessageSource hazelcastDistributedSQLMessageSource() {
final HazelcastDistributedSQLMessageSource messageSource =
new HazelcastDistributedSQLMessageSource(dsDistributedMap(),
"name='TestName' AND surname='TestSurname'");
messageSource.setIterationType(DistributedSQLIterationType.ENTRY);
return messageSource;
}
```
**Reference :** http://docs.hazelcast.org/docs/latest/manual/html/distributedquery.html
## HAZELCAST OUTBOUND CHANNEL ADAPTER
Hazelcast Outbound Channel Adapter listens its defined channel and writes incoming messages to related distributed cache. It expects one of cache, cache-expression or HazelcastHeaders.CACHE_NAME for distributed object definition. Supported Distributed Objects : IMap, MultiMap, ReplicatedMap, IList, ISet, IQueue and ITopic. Its sample definition is as follows :
Hazelcast Outbound Channel Adapter listens its defined channel and writes incoming messages to related distributed cache. It expects one of cache, cache-expression or HazelcastHeaders.CACHE_NAME for distributed object definition. Supported Distributed Objects : IMap, MultiMap, ReplicatedMap, IList, ISet, IQueue and ITopic. It supports both XML and JavaConfig driven configurations.
#### XML Driven Configuration :
```
<int-hazelcast:outbound-channel-adapter channel="mapChannel" cache="distributedMap" key-expression="payload.id" extract-payload="false"/>
```
@@ -306,3 +428,33 @@ By setting distributed object name in the header, messages can be written to dif
**OR**
If **cache** or **cache-expression** attributes are not defined, HazelcastHeaders.CACHE_NAME has to be set in Message.
#### JavaConfig Driven Configuration :
```
@Bean
public MessageChannel distributedMapChannel() {
return new DirectChannel();
}
@Bean
public IMap<Integer, String> distributedMap() {
return hzInstance().getMap("Distributed_Map");
}
@Bean
public HazelcastInstance hzInstance() {
return Hazelcast.newHazelcastInstance();
}
@Bean
@ServiceActivator(inputChannel = "distributedMapChannel")
public HazelcastCacheWritingMessageHandler hazelcastCacheWritingMessageHandler() {
final HazelcastCacheWritingMessageHandler handler = new HazelcastCacheWritingMessageHandler();
handler.setDistributedObject(distributedMap());
handler.setKeyExpression(new SpelExpressionParser().parseExpression("payload.id"));
handler.setExtractPayload(true);
return handler;
}
```

View File

@@ -4,6 +4,7 @@ apply plugin: 'java'
apply from: "${rootProject.projectDir}/publish-maven.gradle"
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'jacoco'
group = 'org.springframework.integration'
@@ -38,10 +39,9 @@ if (project.hasProperty('platformVersion')) {
sourceCompatibility = targetCompatibility = 1.7
ext {
hazelcastVersion = '3.5'
jacocoVersion = '0.7.5.201505241946'
slf4jVersion = '1.7.12'
springIntegrationVersion = '4.1.5.RELEASE'
hazelcastVersion = '3.6'
slf4jVersion = '1.7.13'
springIntegrationVersion = '4.2.4.RELEASE'
idPrefix = 'hazelcast'
@@ -63,8 +63,8 @@ sourceSets {
}
}
configurations {
jacoco //Configuration Group used by Sonar to provide Code Coverage using JaCoCo
jacoco {
toolVersion = "0.7.5.201505241946"
}
dependencies {
@@ -76,8 +76,6 @@ dependencies {
testCompile "org.springframework.integration:spring-integration-test:$springIntegrationVersion"
testRuntime "org.slf4j:slf4j-log4j12:$slf4jVersion"
jacoco "org.jacoco:org.jacoco.agent:$jacocoVersion:runtime"
}
// enable all compiler warnings; individual projects may customize further
@@ -86,8 +84,21 @@ dependencies {
test {
// suppress all console output during testing unless running `gradle -i`
logging.captureStandardOutput(LogLevel.INFO)
jvmArgs "-javaagent:${configurations.jacoco.asPath}=destfile=${buildDir}/jacoco.exec,includes=*",
"-Dhazelcast.logging.type=slf4j"
jvmArgs "-Dhazelcast.logging.type=slf4j"
maxHeapSize = "1024m"
jacoco {
append = false
destinationFile = file("$buildDir/jacoco.exec")
}
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.destination "${buildDir}/reports/jacoco/html"
}
}
task sourcesJar(type: Jar) {
@@ -244,9 +255,3 @@ task dist(dependsOn: assemble) {
group = 'Distribution'
description = 'Builds -dist, -docs and -schema distribution archives.'
}
task wrapper(type: Wrapper) {
description = 'Generates gradlew[.bat] scripts'
gradleVersion = '2.4'
distributionUrl = "http://services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"
}

View File

@@ -1,6 +1,6 @@
#Tue Jun 23 21:21:28 EDT 2015
#Tue Jan 26 14:22:37 EST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-bin.zip

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@@ -41,7 +41,7 @@ import com.hazelcast.core.ReplicatedMap;
public class HazelcastIntegrationDefinitionValidator {
public static <E extends Enum<E>> Set<String> validateEnumType(final Class<E> enumType, final String types) {
Set<String> typeSet = StringUtils.commaDelimitedListToSet(types);
Set<String> typeSet = StringUtils.commaDelimitedListToSet(StringUtils.trimAllWhitespace(types));
for (String type : typeSet) {
Enum.valueOf(enumType, type);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@@ -28,7 +28,7 @@ import org.springframework.util.StringUtils;
/**
* Hazelcast Distributed SQL Inbound Channel Adapter Parser parses
* {@code <int-hazelcast:cq-inbound-channel-adapter/>} configuration.
* {@code <int-hazelcast:ds-inbound-channel-adapter/>} configuration.
*
* @author Eren Avsarogullari
* @since 1.0.0

View File

@@ -1,56 +0,0 @@
/*
* Copyright 2015 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.hazelcast;
import org.junit.Assert;
import org.springframework.integration.hazelcast.message.EntryEventMessagePayload;
import org.springframework.messaging.Message;
import com.hazelcast.core.EntryEventType;
/**
* Base Class for Hazelcast Test Support
*
* @author Eren Avsarogullari
* @since 1.0.0
*/
public class AbstractHazelcastTestSupport {
protected void verifyEntryEvent(Message<?> msg, String cacheName, EntryEventType event) {
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
if (event == EntryEventType.CLEAR_ALL || event == EntryEventType.EVICT_ALL) {
Assert.assertTrue(msg.getPayload() instanceof Integer);
}
else {
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
}
Assert.assertEquals(cacheName, msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
Assert.assertEquals(event.name(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
}
protected void verifyItemEvent(Message<?> msg, EntryEventType event) {
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(event.toString(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString());
}
}

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="distList" factory-bean="hzInstance" factory-method="getList">
<constructor-arg value="distList"/>
</bean>
<bean id="hzInstance" class="com.hazelcast.core.Hazelcast" factory-method="newHazelcastInstance"
destroy-method="shutdown">
<constructor-arg>
<bean class="com.hazelcast.config.Config">
<property name="instanceName" value="Test_Hazelcast_Instance"/>
</bean>
</constructor-arg>
</bean>
</beans>

View File

@@ -0,0 +1,119 @@
/*
* Copyright 2015-2016 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.hazelcast;
import static org.junit.Assert.assertTrue;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.hazelcast.core.DistributedObject;
import com.hazelcast.core.IList;
/**
* Hazelcast Integration Definition Validator Test Class
* @author Eren Avsarogullari
* @since 1.0.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@DirtiesContext
public class HazelcastIntegrationDefinitionValidatorTests {
@Resource
private IList<HazelcastIntegrationTestUser> distList;
@Test
public void testValidateEnumType() {
final String cacheEventTypes =
" ADDED, REMOVED, UPDATED, EVICTED, EVICT_ALL, CLEAR_ALL ";
final Set<String> typeSet = HazelcastIntegrationDefinitionValidator
.validateEnumType(CacheEventType.class, cacheEventTypes);
assertTrue(typeSet.size() == 6);
for (String type : typeSet) {
Enum.valueOf(CacheEventType.class, type);
}
}
@Test(expected = IllegalArgumentException.class)
public void testValidateEnumTypeWithInvalidValue() {
final String cacheEventTypes = "Invalid_Enum_Type";
HazelcastIntegrationDefinitionValidator
.validateEnumType(CacheEventType.class, cacheEventTypes);
}
@Test
public void testValidateCacheEventsByDistributedObject() {
Set<String> cacheEventTypeSet = new HashSet<>(2);
cacheEventTypeSet.add(CacheEventType.ADDED.toString());
cacheEventTypeSet.add(CacheEventType.REMOVED.toString());
HazelcastIntegrationDefinitionValidator
.validateCacheEventsByDistributedObject(this.distList, cacheEventTypeSet);
}
@Test(expected = IllegalArgumentException.class)
public void testValidateCacheEventsByDistributedObjectWithInvalidValue() {
Set<String> cacheEventTypeSet = new HashSet<>(1);
cacheEventTypeSet.add("Invalid_Cache_Event_Type");
HazelcastIntegrationDefinitionValidator
.validateCacheEventsByDistributedObject(this.distList, cacheEventTypeSet);
}
@Test
public void testValidateCacheTypeForEventDrivenMessageProducer() {
HazelcastIntegrationDefinitionValidator
.validateCacheTypeForEventDrivenMessageProducer(this.distList);
}
@Test(expected = IllegalArgumentException.class)
public void testValidateCacheTypeForEventDrivenMessageProducerWithUnexpectedDistObject() {
HazelcastIntegrationDefinitionValidator
.validateCacheTypeForEventDrivenMessageProducer(new DistributedObject() {
@Override
public String getPartitionKey() {
return null;
}
@Override
public String getName() {
return null;
}
@Override
public String getServiceName() {
return null;
}
@Override
public void destroy() {
}
});
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@@ -16,10 +16,9 @@
package org.springframework.integration.hazelcast.inbound;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import javax.annotation.Resource;
@@ -27,9 +26,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.hazelcast.AbstractHazelcastTestSupport;
import org.springframework.integration.hazelcast.HazelcastHeaders;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.integration.hazelcast.inbound.util.HazelcastInboundChannelAdapterTestUtils;
import org.springframework.integration.hazelcast.message.EntryEventMessagePayload;
import org.springframework.messaging.Message;
import org.springframework.messaging.PollableChannel;
@@ -50,166 +49,129 @@ import com.hazelcast.core.IMap;
@ContextConfiguration
@DirtiesContext
@SuppressWarnings("unchecked")
public class HazelcastCQDistributedMapInboundChannelAdapterTests extends AbstractHazelcastTestSupport {
public class HazelcastCQDistributedMapInboundChannelAdapterTests {
@Autowired
private PollableChannel cqMapChannel1;
@Autowired
private PollableChannel cqMapChannel1;
@Autowired
private PollableChannel cqMapChannel2;
@Autowired
private PollableChannel cqMapChannel2;
@Autowired
private PollableChannel cqMapChannel3;
@Autowired
private PollableChannel cqMapChannel3;
@Autowired
private PollableChannel cqMapChannel4;
@Autowired
private PollableChannel cqMapChannel4;
@Autowired
private PollableChannel cqMapChannel5;
@Autowired
private PollableChannel cqMapChannel5;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> cqDistributedMap1;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> cqDistributedMap1;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> cqDistributedMap2;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> cqDistributedMap2;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> cqDistributedMap3;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> cqDistributedMap3;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> cqDistributedMap4;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> cqDistributedMap4;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> cqDistributedMap5;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> cqDistributedMap5;
@Test
public void testContinuousQueryForOnlyADDEDEntryEvent() {
cqDistributedMap1.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
cqDistributedMap1.remove(1);
cqDistributedMap1.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
Message<?> msg = cqMapChannel1.receive(2_000);
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
assertEquals(EntryEventType.ADDED.name(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
assertEquals("cqDistributedMap1", msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
@Test
public void testContinuousQueryForOnlyADDEDEntryEvent() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForADDEDDistributedMapEntryEvent(cqDistributedMap1,
cqMapChannel1, "cqDistributedMap1");
}
assertEquals(Integer.valueOf(1),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
assertEquals(1,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId());
assertEquals("TestName1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName());
assertEquals("TestSurname1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname());
}
@Test
public void testContinuousQueryForOnlyREMOVEDEntryEvent() {
cqDistributedMap2
.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
cqDistributedMap2
.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
cqDistributedMap2.remove(2);
Message<?> msg =
cqMapChannel2.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
assertEquals(EntryEventType.REMOVED.name(),
msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
assertEquals("cqDistributedMap2",
msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
@Test
public void testContinuousQueryForOnlyREMOVEDEntryEvent() {
cqDistributedMap2.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
cqDistributedMap2.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
cqDistributedMap2.remove(2);
Message<?> msg = cqMapChannel2.receive(2_000);
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
assertEquals(EntryEventType.REMOVED.name(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
assertEquals("cqDistributedMap2", msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
assertEquals(Integer.valueOf(2),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
assertEquals(2,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId());
assertEquals("TestName2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName());
assertEquals("TestSurname2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname());
}
assertEquals(Integer.valueOf(2),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
assertEquals(2,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId());
assertEquals("TestName2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName());
assertEquals("TestSurname2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname());
}
@Test
public void testContinuousQueryForALLEntryEvent() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForDistributedMapEntryEvents(cqDistributedMap3,
cqMapChannel3, "cqDistributedMap3");
}
@Test
public void testContinuousQueryForALLEntryEvent() {
cqDistributedMap3.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg = cqMapChannel3.receive(2_000);
verifyEntryEvent(msg, "cqDistributedMap3", EntryEventType.ADDED);
@Test
public void testContinuousQueryForOnlyUPDATEDEntryEvent() {
cqDistributedMap4
.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
cqDistributedMap4
.put(1, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
Message<?> msg =
cqMapChannel4.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
assertEquals(EntryEventType.UPDATED.name(),
msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
assertEquals("cqDistributedMap4",
msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
cqDistributedMap3.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurnameUpdated"));
msg = cqMapChannel3.receive(2_000);
verifyEntryEvent(msg, "cqDistributedMap3", EntryEventType.UPDATED);
assertEquals(Integer.valueOf(1),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
assertEquals(1,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId());
assertEquals("TestName1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName());
assertEquals("TestSurname1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname());
assertEquals(2,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId());
assertEquals("TestName2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName());
assertEquals("TestSurname2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname());
}
cqDistributedMap3.remove(1);
msg = cqMapChannel3.receive(2_000);
verifyEntryEvent(msg, "cqDistributedMap3", EntryEventType.REMOVED);
cqDistributedMap3.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
msg = cqMapChannel3.receive(2_000);
verifyEntryEvent(msg, "cqDistributedMap3", EntryEventType.ADDED);
cqDistributedMap3.clear();
msg = cqMapChannel3.receive(2_000);
verifyEntryEvent(msg, "cqDistributedMap3", EntryEventType.CLEAR_ALL);
}
@Test
public void testContinuousQueryForOnlyUPDATEDEntryEvent() {
cqDistributedMap4.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
cqDistributedMap4.put(1, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
Message<?> msg = cqMapChannel4.receive(2_000);
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
assertEquals(EntryEventType.UPDATED.name(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
assertEquals("cqDistributedMap4", msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
assertEquals(Integer.valueOf(1),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
assertEquals(1,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId());
assertEquals("TestName1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName());
assertEquals("TestSurname1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname());
assertEquals(2,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId());
assertEquals("TestName2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName());
assertEquals("TestSurname2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname());
}
@Test
public void testContinuousQueryForOnlyUPDATEDEntryEventWhenIncludeValueIsFalse() {
cqDistributedMap5.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
cqDistributedMap5.put(1, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
Message<?> msg = cqMapChannel5.receive(2_000);
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
assertEquals(EntryEventType.UPDATED.name(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
assertEquals("cqDistributedMap5", msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
assertEquals(Integer.valueOf(1),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg.getPayload()).key);
assertNull(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg.getPayload()).oldValue);
assertNull(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg.getPayload()).value);
}
@Test
public void testContinuousQueryForOnlyUPDATEDEntryEventWhenIncludeValueIsFalse() {
HazelcastInboundChannelAdapterTestUtils
.testContinuousQueryForUPDATEDEntryEventWhenIncludeValueIsFalse(
cqDistributedMap5, cqMapChannel5, "cqDistributedMap5");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@@ -16,14 +16,15 @@
package org.springframework.integration.hazelcast.inbound;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.hazelcast.inbound.util.HazelcastInboundChannelAdapterTestUtils;
import org.springframework.messaging.Message;
import org.springframework.messaging.PollableChannel;
import org.springframework.test.annotation.DirtiesContext;
@@ -35,13 +36,10 @@ import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.config.GroupConfig;
import com.hazelcast.core.Client;
import com.hazelcast.core.ClientType;
import com.hazelcast.core.DistributedObjectEvent;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.core.LifecycleEvent;
import com.hazelcast.core.Member;
import com.hazelcast.core.LifecycleEvent.LifecycleState;
import com.hazelcast.core.MembershipEvent;
import com.hazelcast.core.MigrationEvent;
/**
@@ -55,179 +53,135 @@ import com.hazelcast.core.MigrationEvent;
@DirtiesContext
public class HazelcastClusterMonitorInboundChannelAdapterTests {
private static final String TEST_GROUP_NAME1 = "Test_Group_Name1";
private static final String TEST_GROUP_NAME1 = "Test_Group_Name1";
private static final int TIMEOUT = 10_000;
@Autowired
private PollableChannel cmChannel1;
@Autowired
private PollableChannel cmChannel1;
@Autowired
private PollableChannel cmChannel2;
@Autowired
private PollableChannel cmChannel2;
@Autowired
private PollableChannel cmChannel3;
@Autowired
private PollableChannel cmChannel3;
@Autowired
private PollableChannel cmChannel4;
@Autowired
private PollableChannel cmChannel4;
@Autowired
private PollableChannel cmChannel5;
@Autowired
private PollableChannel cmChannel5;
@Autowired
private PollableChannel cmChannel6;
@Autowired
private PollableChannel cmChannel6;
@Autowired
private HazelcastInstance hazelcastInstance;
@Autowired
private HazelcastInstance hazelcastInstance;
@Autowired
private HazelcastInstance hazelcastInstance2;
@Autowired
private HazelcastInstance hazelcastInstance2;
@Autowired
private HazelcastInstance hazelcastInstance3;
@Autowired
private HazelcastInstance hazelcastInstance3;
@Test
public void testMembershipEvent() {
HazelcastInboundChannelAdapterTestUtils
.testMembershipEvent(hazelcastInstance, cmChannel1, "testKey1", "testValue1");
}
@Test
public void testMembershipEvent() {
testMembershipEvent(hazelcastInstance, cmChannel1, "testKey1", "testValue1");
}
@Test
public void testDistributedObjectEvent() {
HazelcastInboundChannelAdapterTestUtils
.testDistributedObjectEventByChannelAndHazelcastInstance(cmChannel2,
hazelcastInstance, "Test_Distributed_Map4");
}
@Test
public void testDistributedObjectEvent() {
testDistributedObjectEventByChannelAndHazelcastInstance(cmChannel2,
hazelcastInstance);
}
@Test
public void testMigrationEvent() {
final IMap<Integer, String> distributedMap =
hazelcastInstance3.getMap("Test_Distributed_Map2");
distributedMap.put(1, "TestValue1");
distributedMap.put(2, "TestValue2");
@Test
public void testMigrationEvent() {
final IMap<Integer, String> distributedMap = hazelcastInstance3
.getMap("Test_Distributed_Map2");
distributedMap.put(1, "TestValue1");
distributedMap.put(2, "TestValue2");
hazelcastInstance3.getLifecycleService().terminate();
final Message<?> msg =
cmChannel3.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
verifyMigrationEvent(msg);
}
hazelcastInstance3.getLifecycleService().terminate();
final Message<?> msg = cmChannel3.receive(TIMEOUT);
verifyMigrationEvent(msg);
}
@Test
public void testLifecycleEvent() throws InterruptedException {
hazelcastInstance2.getLifecycleService().terminate();
@Test
public void testLifecycleEvent() throws InterruptedException {
hazelcastInstance2.getLifecycleService().terminate();
Message<?> msg =
cmChannel4.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
verifyLifecycleEvent(msg, LifecycleState.SHUTTING_DOWN);
Message<?> msg = cmChannel4.receive(TIMEOUT);
verifyLifecycleEvent(msg, LifecycleState.SHUTTING_DOWN);
msg = cmChannel4.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
verifyLifecycleEvent(msg, LifecycleState.SHUTDOWN);
}
msg = cmChannel4.receive(TIMEOUT);
verifyLifecycleEvent(msg, LifecycleState.SHUTDOWN);
}
@Test
public void testClientEvent() {
testClientEventByChannelAndGroupName(cmChannel5, TEST_GROUP_NAME1);
}
@Test
public void testClientEvent() {
testClientEventByChannelAndGroupName(cmChannel5, TEST_GROUP_NAME1);
}
@Test
public void testMultipleMonitorTypes() {
HazelcastInboundChannelAdapterTestUtils
.testDistributedObjectEventByChannelAndHazelcastInstance(cmChannel6,
hazelcastInstance, "Test_Distributed_Map5");
@Test
public void testMultipleMonitorTypes() {
testDistributedObjectEventByChannelAndHazelcastInstance(cmChannel6,
hazelcastInstance);
HazelcastInboundChannelAdapterTestUtils
.testMembershipEvent(hazelcastInstance, cmChannel6, "testKey2", "testValue2");
}
testMembershipEvent(hazelcastInstance, cmChannel6, "testKey2", "testValue2");
}
private void testClientEventByChannelAndGroupName(final PollableChannel channel,
final String groupName) {
final HazelcastInstance client = getHazelcastClientByGroupName(groupName);
private void testMembershipEvent(
final HazelcastInstance instance, final PollableChannel channel,
final String key, final String value) {
Member member = instance.getCluster().getMembers().iterator().next();
member.setStringAttribute(key, value);
Message<?> msg = channel.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
verifyClientEvent(msg);
Message<?> msg = channel.receive(TIMEOUT);
verifyMembershipEvent(msg, MembershipEvent.MEMBER_ATTRIBUTE_CHANGED);
}
client.getLifecycleService().terminate();
private void testClientEventByChannelAndGroupName(final PollableChannel channel,
final String groupName) {
final HazelcastInstance client = getHazelcastClientByGroupName(groupName);
msg = channel.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
verifyClientEvent(msg);
}
Message<?> msg = channel.receive(TIMEOUT);
verifyClientEvent(msg);
private HazelcastInstance getHazelcastClientByGroupName(final String groupName) {
final GroupConfig groupConfig = new GroupConfig();
groupConfig.setName(groupName);
groupConfig.setPassword("dev-pass");
final ClientConfig cfg = new ClientConfig();
cfg.setGroupConfig(groupConfig);
cfg.getNetworkConfig().addAddress("127.0.0.1:5701");
client.getLifecycleService().terminate();
return HazelcastClient.newHazelcastClient(cfg);
}
msg = channel.receive(TIMEOUT);
verifyClientEvent(msg);
}
private void verifyMigrationEvent(final Message<?> msg) {
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof MigrationEvent);
assertNotNull(((MigrationEvent) msg.getPayload()).getStatus());
assertNotNull(((MigrationEvent) msg.getPayload()).getNewOwner());
assertNotNull(((MigrationEvent) msg.getPayload()).getOldOwner());
}
private void testDistributedObjectEventByChannelAndHazelcastInstance(
final PollableChannel channel, final HazelcastInstance hazelcastInstance) {
final String distributedObjectName = "Test_Distributed_Map";
final IMap<Integer, String> distributedMap = hazelcastInstance
.getMap(distributedObjectName);
private void verifyLifecycleEvent(final Message<?> msg,
final LifecycleState lifecycleState) {
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof LifecycleEvent);
assertEquals(lifecycleState, ((LifecycleEvent) msg.getPayload()).getState());
}
Message<?> msg = channel.receive(TIMEOUT);
verifyDistributedObjectEvent(msg, DistributedObjectEvent.EventType.CREATED,
distributedObjectName);
distributedMap.destroy();
msg = channel.receive(TIMEOUT);
verifyDistributedObjectEvent(msg, DistributedObjectEvent.EventType.DESTROYED,
distributedObjectName);
}
private HazelcastInstance getHazelcastClientByGroupName(final String groupName) {
final GroupConfig groupConfig = new GroupConfig();
groupConfig.setName(groupName);
groupConfig.setPassword("dev-pass");
final ClientConfig cfg = new ClientConfig();
cfg.setGroupConfig(groupConfig);
cfg.getNetworkConfig().addAddress("127.0.0.1:5701");
return HazelcastClient.newHazelcastClient(cfg);
}
private void verifyMembershipEvent(final Message<?> msg, final int membershipEvent) {
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof MembershipEvent);
assertEquals(membershipEvent, ((MembershipEvent) msg.getPayload()).getEventType());
assertNotNull(((MembershipEvent) msg.getPayload()).getMember());
}
private void verifyDistributedObjectEvent(final Message<?> msg,
final DistributedObjectEvent.EventType eventType,
final String distributedObjectName) {
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof DistributedObjectEvent);
assertEquals(eventType, ((DistributedObjectEvent) msg.getPayload()).getEventType());
assertNotNull(
(((DistributedObjectEvent) msg.getPayload()).getDistributedObject())
.getName(),
distributedObjectName);
}
private void verifyMigrationEvent(final Message<?> msg) {
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof MigrationEvent);
assertNotNull(((MigrationEvent) msg.getPayload()).getStatus());
assertNotNull(((MigrationEvent) msg.getPayload()).getNewOwner());
assertNotNull(((MigrationEvent) msg.getPayload()).getOldOwner());
}
private void verifyLifecycleEvent(final Message<?> msg,
final LifecycleState lifecycleState) {
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof LifecycleEvent);
assertEquals(lifecycleState, ((LifecycleEvent) msg.getPayload()).getState());
}
private void verifyClientEvent(final Message<?> msg) {
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof Client);
assertEquals(ClientType.JAVA, ((Client) msg.getPayload()).getClientType());
assertNotNull(((Client) msg.getPayload()).getSocketAddress());
}
private void verifyClientEvent(final Message<?> msg) {
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof Client);
assertEquals(ClientType.JAVA, ((Client) msg.getPayload()).getClientType());
assertNotNull(((Client) msg.getPayload()).getSocketAddress());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@@ -25,9 +25,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.hazelcast.AbstractHazelcastTestSupport;
import org.springframework.integration.hazelcast.HazelcastHeaders;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.integration.hazelcast.inbound.util.HazelcastInboundChannelAdapterTestUtils;
import org.springframework.messaging.Message;
import org.springframework.messaging.PollableChannel;
import org.springframework.test.annotation.DirtiesContext;
@@ -46,69 +46,58 @@ import com.hazelcast.core.IList;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@DirtiesContext
public class HazelcastDistributedListEventDrivenInboundChannelAdapterTests extends AbstractHazelcastTestSupport {
public class HazelcastDistributedListEventDrivenInboundChannelAdapterTests {
@Autowired
private PollableChannel edListChannel1;
@Autowired
private PollableChannel edListChannel1;
@Autowired
private PollableChannel edListChannel2;
@Autowired
private PollableChannel edListChannel2;
@Autowired
private PollableChannel edListChannel3;
@Autowired
private PollableChannel edListChannel3;
@Resource
private IList<HazelcastIntegrationTestUser> edDistributedList1;
@Resource
private IList<HazelcastIntegrationTestUser> edDistributedList1;
@Resource
private IList<HazelcastIntegrationTestUser> edDistributedList2;
@Resource
private IList<HazelcastIntegrationTestUser> edDistributedList2;
@Resource
private IList<HazelcastIntegrationTestUser> edDistributedList3;
@Resource
private IList<HazelcastIntegrationTestUser> edDistributedList3;
@Test
public void testEventDrivenForOnlyADDEDEntryEvent() {
edDistributedList1.add(new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg = edListChannel1.receive(2_000);
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
assertEquals(EntryEventType.ADDED.toString(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString());
assertEquals(1, ((HazelcastIntegrationTestUser) msg.getPayload()).getId());
assertEquals("TestName1", ((HazelcastIntegrationTestUser) msg.getPayload()).getName());
assertEquals("TestSurname1", ((HazelcastIntegrationTestUser) msg.getPayload()).getSurname());
}
@Test
public void testEventDrivenForOnlyADDEDEntryEvent() {
edDistributedList1.add(new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg = edListChannel1.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
assertEquals(EntryEventType.ADDED.toString(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString());
assertEquals(1, ((HazelcastIntegrationTestUser) msg.getPayload()).getId());
assertEquals("TestName1", ((HazelcastIntegrationTestUser) msg.getPayload()).getName());
assertEquals("TestSurname1", ((HazelcastIntegrationTestUser) msg.getPayload()).getSurname());
}
@Test
public void testEventDrivenForOnlyREMOVEDEntryEvent() {
HazelcastIntegrationTestUser user = new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2");
edDistributedList2.add(user);
edDistributedList2.remove(user);
Message<?> msg = edListChannel2.receive(2_000);
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
assertEquals(EntryEventType.REMOVED.toString(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString());
assertEquals(2, ((HazelcastIntegrationTestUser) msg.getPayload()).getId());
assertEquals("TestName2", ((HazelcastIntegrationTestUser) msg.getPayload()).getName());
assertEquals("TestSurname2", ((HazelcastIntegrationTestUser) msg.getPayload()).getSurname());
}
@Test
public void testEventDrivenForOnlyREMOVEDEntryEvent() {
HazelcastIntegrationTestUser user = new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2");
edDistributedList2.add(user);
edDistributedList2.remove(user);
Message<?> msg = edListChannel2.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
assertEquals(EntryEventType.REMOVED.toString(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString());
assertEquals(2, ((HazelcastIntegrationTestUser) msg.getPayload()).getId());
assertEquals("TestName2", ((HazelcastIntegrationTestUser) msg.getPayload()).getName());
assertEquals("TestSurname2", ((HazelcastIntegrationTestUser) msg.getPayload()).getSurname());
}
@Test
public void testEventDrivenForALLEntryEvent() {
HazelcastIntegrationTestUser user = new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1");
edDistributedList3.add(user);
Message<?> msg = edListChannel3.receive(2_000);
verifyItemEvent(msg, EntryEventType.ADDED);
edDistributedList3.remove(user);
msg = edListChannel3.receive(2_000);
verifyItemEvent(msg, EntryEventType.REMOVED);
user = new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2");
edDistributedList3.add(user);
msg = edListChannel3.receive(2_000);
verifyItemEvent(msg, EntryEventType.ADDED);
}
@Test
public void testEventDrivenForALLEntryEvent() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForDistributedCollectionItemEvents(edDistributedList3, edListChannel3);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@@ -23,9 +23,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.hazelcast.AbstractHazelcastTestSupport;
import org.springframework.integration.hazelcast.HazelcastHeaders;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.integration.hazelcast.inbound.util.HazelcastInboundChannelAdapterTestUtils;
import org.springframework.integration.hazelcast.message.EntryEventMessagePayload;
import org.springframework.messaging.Message;
import org.springframework.messaging.PollableChannel;
@@ -46,139 +46,116 @@ import com.hazelcast.core.IMap;
@ContextConfiguration
@DirtiesContext
@SuppressWarnings("unchecked")
public class HazelcastDistributedMapEventDrivenInboundChannelAdapterTests extends AbstractHazelcastTestSupport {
public class HazelcastDistributedMapEventDrivenInboundChannelAdapterTests {
@Autowired
private PollableChannel edMapChannel1;
@Autowired
private PollableChannel edMapChannel1;
@Autowired
private PollableChannel edMapChannel2;
@Autowired
private PollableChannel edMapChannel2;
@Autowired
private PollableChannel edMapChannel3;
@Autowired
private PollableChannel edMapChannel3;
@Autowired
private PollableChannel edMapChannel4;
@Autowired
private PollableChannel edMapChannel4;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> edDistributedMap1;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> edDistributedMap1;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> edDistributedMap2;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> edDistributedMap2;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> edDistributedMap3;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> edDistributedMap3;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> edDistributedMap4;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> edDistributedMap4;
@Test
public void testEventDrivenForOnlyADDEDEntryEvent() {
edDistributedMap1.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg = edMapChannel1.receive(2_000);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.ADDED.name(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertEquals("edDistributedMap1", msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
@Test
public void testEventDrivenForOnlyADDEDEntryEvent() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForADDEDDistributedMapEntryEvent(edDistributedMap1,
edMapChannel1, "edDistributedMap1");
}
Assert.assertEquals(Integer.valueOf(1),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg.getPayload()).key);
Assert.assertEquals(1,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId());
Assert.assertEquals("TestName1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName());
Assert.assertEquals("TestSurname1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname());
}
@Test
public void testEventDrivenForOnlyUPDATEDEntryEvent() {
edDistributedMap2
.put(2, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
edDistributedMap2
.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
Message<?> msg =
edMapChannel2.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.UPDATED.name(),
msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertEquals("edDistributedMap2",
msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
@Test
public void testEventDrivenForOnlyUPDATEDEntryEvent() {
edDistributedMap2.put(2, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
edDistributedMap2.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
Message<?> msg = edMapChannel2.receive(2_000);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.UPDATED.name(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertEquals("edDistributedMap2", msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
Assert.assertEquals(Integer.valueOf(2),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
Assert.assertEquals(1,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId());
Assert.assertEquals("TestName1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName());
Assert.assertEquals("TestSurname1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname());
Assert.assertEquals(2,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId());
Assert.assertEquals("TestName2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName());
Assert.assertEquals("TestSurname2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname());
}
Assert.assertEquals(Integer.valueOf(2),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
Assert.assertEquals(1,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId());
Assert.assertEquals("TestName1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName());
Assert.assertEquals("TestSurname1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname());
Assert.assertEquals(2,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId());
Assert.assertEquals("TestName2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName());
Assert.assertEquals("TestSurname2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname());
}
@Test
public void testEventDrivenForOnlyREMOVEDEntryEvent() {
edDistributedMap3
.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
edDistributedMap3
.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
edDistributedMap3.remove(2);
Message<?> msg =
edMapChannel3.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.REMOVED.name(),
msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertEquals("edDistributedMap3",
msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
@Test
public void testEventDrivenForOnlyREMOVEDEntryEvent() {
edDistributedMap3.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
edDistributedMap3.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
edDistributedMap3.remove(2);
Message<?> msg = edMapChannel3.receive(2_000);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.REMOVED.name(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertEquals("edDistributedMap3", msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
Assert.assertEquals(Integer.valueOf(2),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
Assert.assertEquals(2,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId());
Assert.assertEquals("TestName2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName());
Assert.assertEquals("TestSurname2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname());
}
Assert.assertEquals(Integer.valueOf(2),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
Assert.assertEquals(2,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId());
Assert.assertEquals("TestName2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName());
Assert.assertEquals("TestSurname2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname());
}
@Test
public void testEventDrivenForALLEntryEvent() {
edDistributedMap4.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg = edMapChannel4.receive(2_000);
verifyEntryEvent(msg, "edDistributedMap4", EntryEventType.ADDED);
edDistributedMap4.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurnameUpdated"));
msg = edMapChannel4.receive(2_000);
verifyEntryEvent(msg, "edDistributedMap4", EntryEventType.UPDATED);
edDistributedMap4.remove(1);
msg = edMapChannel4.receive(2_000);
verifyEntryEvent(msg, "edDistributedMap4", EntryEventType.REMOVED);
edDistributedMap4.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
msg = edMapChannel4.receive(2_000);
verifyEntryEvent(msg, "edDistributedMap4", EntryEventType.ADDED);
edDistributedMap4.clear();
msg = edMapChannel4.receive(2_000);
verifyEntryEvent(msg, "edDistributedMap4", EntryEventType.CLEAR_ALL);
}
@Test
public void testEventDrivenForALLEntryEvent() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForDistributedMapEntryEvents(edDistributedMap4, edMapChannel4,
"edDistributedMap4");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@@ -23,9 +23,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.hazelcast.AbstractHazelcastTestSupport;
import org.springframework.integration.hazelcast.HazelcastHeaders;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.integration.hazelcast.inbound.util.HazelcastInboundChannelAdapterTestUtils;
import org.springframework.messaging.Message;
import org.springframework.messaging.PollableChannel;
import org.springframework.test.annotation.DirtiesContext;
@@ -44,69 +44,71 @@ import com.hazelcast.core.IQueue;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@DirtiesContext
public class HazelcastDistributedQueueEventDrivenInboundChannelAdapterTests extends AbstractHazelcastTestSupport {
public class HazelcastDistributedQueueEventDrivenInboundChannelAdapterTests {
@Autowired
private PollableChannel edQueueChannel1;
@Autowired
private PollableChannel edQueueChannel1;
@Autowired
private PollableChannel edQueueChannel2;
@Autowired
private PollableChannel edQueueChannel2;
@Autowired
private PollableChannel edQueueChannel3;
@Autowired
private PollableChannel edQueueChannel3;
@Resource
private IQueue<HazelcastIntegrationTestUser> edDistributedQueue1;
@Resource
private IQueue<HazelcastIntegrationTestUser> edDistributedQueue1;
@Resource
private IQueue<HazelcastIntegrationTestUser> edDistributedQueue2;
@Resource
private IQueue<HazelcastIntegrationTestUser> edDistributedQueue2;
@Resource
private IQueue<HazelcastIntegrationTestUser> edDistributedQueue3;
@Resource
private IQueue<HazelcastIntegrationTestUser> edDistributedQueue3;
@Test
public void testEventDrivenForOnlyADDEDEntryEvent() {
edDistributedQueue1.add(new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg = edQueueChannel1.receive(2_000);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.ADDED.toString(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString());
Assert.assertEquals(1, (((HazelcastIntegrationTestUser) msg.getPayload()).getId()));
Assert.assertEquals("TestName1", (((HazelcastIntegrationTestUser) msg.getPayload()).getName()));
Assert.assertEquals("TestSurname1", (((HazelcastIntegrationTestUser) msg.getPayload()).getSurname()));
}
@Test
public void testEventDrivenForOnlyADDEDEntryEvent() {
edDistributedQueue1
.add(new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg =
edQueueChannel1.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.ADDED.toString(),
msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString());
Assert
.assertEquals(1, (((HazelcastIntegrationTestUser) msg.getPayload()).getId()));
Assert.assertEquals("TestName1",
(((HazelcastIntegrationTestUser) msg.getPayload()).getName()));
Assert.assertEquals("TestSurname1",
(((HazelcastIntegrationTestUser) msg.getPayload()).getSurname()));
}
@Test
public void testEventDrivenForOnlyREMOVEDEntryEvent() {
HazelcastIntegrationTestUser user = new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2");
edDistributedQueue2.add(user);
edDistributedQueue2.remove(user);
Message<?> msg = edQueueChannel2.receive(2_000);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.REMOVED.toString(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString());
Assert.assertEquals(2, (((HazelcastIntegrationTestUser) msg.getPayload()).getId()));
Assert.assertEquals("TestName2", (((HazelcastIntegrationTestUser) msg.getPayload()).getName()));
Assert.assertEquals("TestSurname2", (((HazelcastIntegrationTestUser) msg.getPayload()).getSurname()));
}
@Test
public void testEventDrivenForOnlyREMOVEDEntryEvent() {
HazelcastIntegrationTestUser user =
new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2");
edDistributedQueue2.add(user);
edDistributedQueue2.remove(user);
Message<?> msg =
edQueueChannel2.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.REMOVED.toString(),
msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString());
Assert
.assertEquals(2, (((HazelcastIntegrationTestUser) msg.getPayload()).getId()));
Assert.assertEquals("TestName2",
(((HazelcastIntegrationTestUser) msg.getPayload()).getName()));
Assert.assertEquals("TestSurname2",
(((HazelcastIntegrationTestUser) msg.getPayload()).getSurname()));
}
@Test
public void testEventDrivenForALLEntryEvent() {
HazelcastIntegrationTestUser user = new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1");
edDistributedQueue3.add(user);
Message<?> msg = edQueueChannel3.receive(2_000);
verifyItemEvent(msg, EntryEventType.ADDED);
edDistributedQueue3.remove(user);
msg = edQueueChannel3.receive(2_000);
verifyItemEvent(msg, EntryEventType.REMOVED);
user = new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2");
edDistributedQueue3.add(user);
msg = edQueueChannel3.receive(2_000);
verifyItemEvent(msg, EntryEventType.ADDED);
}
@Test
public void testEventDrivenForALLEntryEvent() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForDistributedCollectionItemEvents(edDistributedQueue3,
edQueueChannel3);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@@ -16,18 +16,14 @@
package org.springframework.integration.hazelcast.inbound;
import java.util.Collection;
import java.util.Map;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.messaging.Message;
import org.springframework.integration.hazelcast.inbound.util.HazelcastInboundChannelAdapterTestUtils;
import org.springframework.messaging.PollableChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
@@ -46,101 +42,52 @@ import com.hazelcast.core.IMap;
@DirtiesContext
public class HazelcastDistributedSQLInboundChannelAdapterTests {
@Autowired
private PollableChannel dsMapChannel1;
@Autowired
private PollableChannel dsMapChannel1;
@Autowired
private PollableChannel dsMapChannel2;
@Autowired
private PollableChannel dsMapChannel2;
@Autowired
private PollableChannel dsMapChannel3;
@Autowired
private PollableChannel dsMapChannel3;
@Autowired
private PollableChannel dsMapChannel4;
@Autowired
private PollableChannel dsMapChannel4;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> dsDistributedMap1;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> dsDistributedMap1;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> dsDistributedMap2;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> dsDistributedMap2;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> dsDistributedMap3;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> dsDistributedMap3;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> dsDistributedMap4;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> dsDistributedMap4;
@Test
public void testDistributedSQLForOnlyENTRYIterationType() throws InterruptedException {
dsDistributedMap1.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1", 10));
dsDistributedMap1.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2", 20));
dsDistributedMap1.put(3, new HazelcastIntegrationTestUser(3, "TestName3", "TestSurname3", 30));
dsDistributedMap1.put(4, new HazelcastIntegrationTestUser(4, "TestName4", "TestSurname4", 40));
dsDistributedMap1.put(5, new HazelcastIntegrationTestUser(5, "TestName5", "TestSurname5", 50));
@Test
public void testDistributedSQLForOnlyENTRYIterationType() {
HazelcastInboundChannelAdapterTestUtils
.testDistributedSQLForENTRYIterationType(dsDistributedMap1, dsMapChannel1);
}
Message<?> msg = dsMapChannel1.receive(2_000);
@Test
public void testDistributedSQLForOnlyKEYIterationType() {
HazelcastInboundChannelAdapterTestUtils
.testDistributedSQLForKEYIterationType(dsDistributedMap2, dsMapChannel2);
}
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof Collection);
Assert.assertEquals(4, (((Map.Entry<?, ?>) ((Collection<?>) msg.getPayload()).iterator()
.next()).getKey()));
Assert.assertEquals(4, ((HazelcastIntegrationTestUser) ((Map.Entry<?, ?>) ((Collection<?>) msg.getPayload())
.iterator().next()).getValue()).getId());
Assert.assertEquals("TestName4", ((HazelcastIntegrationTestUser) ((Map.Entry<?, ?>) ((Collection<?>) msg
.getPayload()).iterator().next()).getValue()).getName());
Assert.assertEquals("TestSurname4", ((HazelcastIntegrationTestUser) ((Map.Entry<?, ?>) ((Collection<?>) msg
.getPayload()).iterator().next()).getValue()).getSurname());
}
@Test
public void testDistributedSQLForOnlyLOCAL_KEYIterationType() {
HazelcastInboundChannelAdapterTestUtils
.testDistributedSQLForLOCAL_KEYIterationType(dsDistributedMap3, dsMapChannel3);
}
@Test
public void testDistributedSQLForOnlyKEYIterationType() throws InterruptedException {
dsDistributedMap2.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1", 10));
dsDistributedMap2.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2", 20));
dsDistributedMap2.put(3, new HazelcastIntegrationTestUser(3, "TestName3", "TestSurname3", 30));
Message<?> msg = dsMapChannel2.receive(2_000);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof Collection);
Assert.assertEquals(1, ((Collection<?>) msg.getPayload()).iterator().next());
}
@Test
public void testDistributedSQLForOnlyLOCAL_KEYIterationType()
throws InterruptedException {
dsDistributedMap3.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1", 10));
dsDistributedMap3.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2", 20));
dsDistributedMap3.put(3, new HazelcastIntegrationTestUser(3, "TestName3", "TestSurname3", 30));
Message<?> msg = dsMapChannel3.receive(2_000);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof Collection);
Assert.assertEquals(2, ((Collection<?>) msg.getPayload()).iterator().next());
}
@Test
public void testDistributedSQLForOnlyVALUEIterationType() throws InterruptedException {
dsDistributedMap4.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1", 10));
dsDistributedMap4.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2", 20));
dsDistributedMap4.put(3, new HazelcastIntegrationTestUser(3, "TestName3", "TestSurname3", 30));
dsDistributedMap4.put(4, new HazelcastIntegrationTestUser(4, "TestName4", "TestSurname4", 40));
dsDistributedMap4.put(5, new HazelcastIntegrationTestUser(5, "TestName5", "TestSurname5", 50));
Message<?> msg = dsMapChannel4.receive(2_000);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof Collection);
Assert.assertEquals(3,
((HazelcastIntegrationTestUser) (((Collection<?>) msg.getPayload()).iterator().next())).getId());
Assert.assertEquals("TestName3",
((HazelcastIntegrationTestUser) (((Collection<?>) msg.getPayload()).iterator().next())).getName());
Assert.assertEquals("TestSurname3",
((HazelcastIntegrationTestUser) (((Collection<?>) msg.getPayload()).iterator().next())).getSurname());
}
@Test
public void testDistributedSQLForOnlyVALUEIterationType() {
HazelcastInboundChannelAdapterTestUtils
.testDistributedSQLForVALUEIterationType(dsDistributedMap4, dsMapChannel4);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@@ -23,9 +23,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.hazelcast.AbstractHazelcastTestSupport;
import org.springframework.integration.hazelcast.HazelcastHeaders;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.integration.hazelcast.inbound.util.HazelcastInboundChannelAdapterTestUtils;
import org.springframework.messaging.Message;
import org.springframework.messaging.PollableChannel;
import org.springframework.test.annotation.DirtiesContext;
@@ -44,69 +44,71 @@ import com.hazelcast.core.ISet;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@DirtiesContext
public class HazelcastDistributedSetEventDrivenInboundChannelAdapterTests extends AbstractHazelcastTestSupport {
public class HazelcastDistributedSetEventDrivenInboundChannelAdapterTests {
@Autowired
private PollableChannel edSetChannel1;
@Autowired
private PollableChannel edSetChannel1;
@Autowired
private PollableChannel edSetChannel2;
@Autowired
private PollableChannel edSetChannel2;
@Autowired
private PollableChannel edSetChannel3;
@Autowired
private PollableChannel edSetChannel3;
@Resource
private ISet<HazelcastIntegrationTestUser> edDistributedSet1;
@Resource
private ISet<HazelcastIntegrationTestUser> edDistributedSet1;
@Resource
private ISet<HazelcastIntegrationTestUser> edDistributedSet2;
@Resource
private ISet<HazelcastIntegrationTestUser> edDistributedSet2;
@Resource
private ISet<HazelcastIntegrationTestUser> edDistributedSet3;
@Resource
private ISet<HazelcastIntegrationTestUser> edDistributedSet3;
@Test
public void testEventDrivenForOnlyADDEDEntryEvent() {
edDistributedSet1.add(new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg = edSetChannel1.receive(2_000);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.ADDED.toString(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString());
Assert.assertEquals(1, (((HazelcastIntegrationTestUser) msg.getPayload()).getId()));
Assert.assertEquals("TestName1", (((HazelcastIntegrationTestUser) msg.getPayload()).getName()));
Assert.assertEquals("TestSurname1", (((HazelcastIntegrationTestUser) msg.getPayload()).getSurname()));
}
@Test
public void testEventDrivenForOnlyADDEDEntryEvent() {
edDistributedSet1
.add(new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg =
edSetChannel1.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.ADDED.toString(),
msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString());
Assert
.assertEquals(1, (((HazelcastIntegrationTestUser) msg.getPayload()).getId()));
Assert.assertEquals("TestName1",
(((HazelcastIntegrationTestUser) msg.getPayload()).getName()));
Assert.assertEquals("TestSurname1",
(((HazelcastIntegrationTestUser) msg.getPayload()).getSurname()));
}
@Test
public void testEventDrivenForOnlyREMOVEDEntryEvent() {
HazelcastIntegrationTestUser user = new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2");
edDistributedSet2.add(user);
edDistributedSet2.remove(user);
Message<?> msg = edSetChannel2.receive(2_000);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.REMOVED.toString(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString());
Assert.assertEquals(2, (((HazelcastIntegrationTestUser) msg.getPayload()).getId()));
Assert.assertEquals("TestName2", (((HazelcastIntegrationTestUser) msg.getPayload()).getName()));
Assert.assertEquals("TestSurname2", (((HazelcastIntegrationTestUser) msg.getPayload()).getSurname()));
}
@Test
public void testEventDrivenForOnlyREMOVEDEntryEvent() {
HazelcastIntegrationTestUser user =
new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2");
edDistributedSet2.add(user);
edDistributedSet2.remove(user);
Message<?> msg =
edSetChannel2.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.REMOVED.toString(),
msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString());
Assert
.assertEquals(2, (((HazelcastIntegrationTestUser) msg.getPayload()).getId()));
Assert.assertEquals("TestName2",
(((HazelcastIntegrationTestUser) msg.getPayload()).getName()));
Assert.assertEquals("TestSurname2",
(((HazelcastIntegrationTestUser) msg.getPayload()).getSurname()));
}
@Test
public void testEventDrivenForALLEntryEvent() {
HazelcastIntegrationTestUser user = new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1");
edDistributedSet3.add(user);
Message<?> msg = edSetChannel3.receive(2_000);
verifyItemEvent(msg, EntryEventType.ADDED);
edDistributedSet3.remove(user);
msg = edSetChannel3.receive(2_000);
verifyItemEvent(msg, EntryEventType.REMOVED);
user = new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2");
edDistributedSet3.add(user);
msg = edSetChannel3.receive(2_000);
verifyItemEvent(msg, EntryEventType.ADDED);
}
@Test
public void testEventDrivenForALLEntryEvent() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForDistributedCollectionItemEvents(edDistributedSet3,
edSetChannel3);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@@ -18,14 +18,12 @@ package org.springframework.integration.hazelcast.inbound;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.hazelcast.HazelcastHeaders;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.messaging.Message;
import org.springframework.integration.hazelcast.inbound.util.HazelcastInboundChannelAdapterTestUtils;
import org.springframework.messaging.PollableChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
@@ -44,24 +42,16 @@ import com.hazelcast.core.ITopic;
@DirtiesContext
public class HazelcastDistributedTopicEventDrivenInboundChannelAdapterTests {
@Autowired
private PollableChannel edTopicChannel1;
@Autowired
private PollableChannel edTopicChannel1;
@Resource
private ITopic<HazelcastIntegrationTestUser> edDistributedTopic1;
@Resource
private ITopic<HazelcastIntegrationTestUser> edDistributedTopic1;
@Test
public void testEventDrivenForOnlyADDEDEntryEvent() {
edDistributedTopic1.publish(new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg = edTopicChannel1.receive(2_000);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.PUBLISHING_TIME));
Assert.assertEquals("edDistributedTopic1", msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
Assert.assertEquals(1, ((HazelcastIntegrationTestUser) msg.getPayload()).getId());
Assert.assertEquals("TestName1", ((HazelcastIntegrationTestUser) msg.getPayload()).getName());
Assert.assertEquals("TestSurname1", ((HazelcastIntegrationTestUser) msg.getPayload()).getSurname());
}
@Test
public void testEventDrivenForOnlyADDEDEntryEvent() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForTopicMessageEvent(edDistributedTopic1, edTopicChannel1);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@@ -23,9 +23,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.hazelcast.AbstractHazelcastTestSupport;
import org.springframework.integration.hazelcast.HazelcastHeaders;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.integration.hazelcast.inbound.util.HazelcastInboundChannelAdapterTestUtils;
import org.springframework.integration.hazelcast.message.EntryEventMessagePayload;
import org.springframework.messaging.Message;
import org.springframework.messaging.PollableChannel;
@@ -47,102 +47,93 @@ import com.hazelcast.core.MultiMap;
@ContextConfiguration
@DirtiesContext
@SuppressWarnings("unchecked")
public class HazelcastMultiMapEventDrivenInboundChannelAdapterTests extends AbstractHazelcastTestSupport {
public class HazelcastMultiMapEventDrivenInboundChannelAdapterTests {
@Autowired
private PollableChannel edMultiMapChannel1;
@Autowired
private PollableChannel edMultiMapChannel1;
@Autowired
private PollableChannel edMultiMapChannel2;
@Autowired
private PollableChannel edMultiMapChannel2;
@Autowired
private PollableChannel edMultiMapChannel3;
@Autowired
private PollableChannel edMultiMapChannel3;
@Resource
private MultiMap<Integer, HazelcastIntegrationTestUser> edMultiMap1;
@Resource
private MultiMap<Integer, HazelcastIntegrationTestUser> edMultiMap1;
@Resource
private MultiMap<Integer, HazelcastIntegrationTestUser> edMultiMap2;
@Resource
private MultiMap<Integer, HazelcastIntegrationTestUser> edMultiMap2;
@Resource
private MultiMap<Integer, HazelcastIntegrationTestUser> edMultiMap3;
@Resource
private MultiMap<Integer, HazelcastIntegrationTestUser> edMultiMap3;
@Test
public void testEventDrivenForOnlyADDEDEntryEvent() {
edMultiMap1.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg = edMultiMapChannel1.receive(2_000);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.ADDED.name(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertEquals("edMultiMap1", msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
@Test
public void testEventDrivenForOnlyADDEDEntryEvent() {
edMultiMap1
.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg =
edMultiMapChannel1.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.ADDED.name(),
msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertEquals("edMultiMap1",
msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
Assert.assertEquals(Integer.valueOf(1),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
Assert.assertEquals(1,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId());
Assert.assertEquals("TestName1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName());
Assert.assertEquals("TestSurname1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname());
}
Assert.assertEquals(Integer.valueOf(1),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
Assert.assertEquals(1,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId());
Assert.assertEquals("TestName1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName());
Assert.assertEquals("TestSurname1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname());
}
@Test
public void testEventDrivenForOnlyREMOVEDEntryEvent() {
edMultiMap2.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
edMultiMap2.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
edMultiMap2.remove(2);
Message<?> msg = edMultiMapChannel2.receive(2_000);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.REMOVED.name(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertEquals("edMultiMap2", msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
@Test
public void testEventDrivenForOnlyREMOVEDEntryEvent() {
edMultiMap2
.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
edMultiMap2
.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
edMultiMap2.remove(2);
Message<?> msg =
edMultiMapChannel2.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.REMOVED.name(),
msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertEquals("edMultiMap2",
msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
Assert.assertEquals(Integer.valueOf(2),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
Assert.assertNull(((EntryEventMessagePayload<?, ?>) msg.getPayload()).value);
Assert.assertEquals(2,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId());
Assert.assertEquals("TestName2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName());
Assert.assertEquals("TestSurname2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname());
}
Assert.assertEquals(Integer.valueOf(2),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
Assert.assertNull(((EntryEventMessagePayload<?, ?>) msg.getPayload()).value);
Assert.assertEquals(2,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId());
Assert.assertEquals("TestName2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName());
Assert.assertEquals("TestSurname2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname());
}
@Test
public void testEventDrivenForALLEntryEvent() {
edMultiMap3.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg = edMultiMapChannel3.receive(2_000);
verifyEntryEvent(msg, "edMultiMap3", EntryEventType.ADDED);
edMultiMap3.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurnameUpdated"));
msg = edMultiMapChannel3.receive(2_000);
verifyEntryEvent(msg, "edMultiMap3", EntryEventType.ADDED);
edMultiMap3.remove(1);
msg = edMultiMapChannel3.receive(2_000);
verifyEntryEvent(msg, "edMultiMap3", EntryEventType.REMOVED);
msg = edMultiMapChannel3.receive(2_000);
verifyEntryEvent(msg, "edMultiMap3", EntryEventType.REMOVED);
edMultiMap3.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
msg = edMultiMapChannel3.receive(2_000);
verifyEntryEvent(msg, "edMultiMap3", EntryEventType.ADDED);
edMultiMap3.clear();
msg = edMultiMapChannel3.receive(2_000);
verifyEntryEvent(msg, "edMultiMap3", EntryEventType.CLEAR_ALL);
}
@Test
public void testEventDrivenForALLEntryEvent() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForMultiMapEntryEvents(edMultiMap3, edMultiMapChannel3,
"edMultiMap3");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@@ -23,9 +23,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.hazelcast.AbstractHazelcastTestSupport;
import org.springframework.integration.hazelcast.HazelcastHeaders;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.integration.hazelcast.inbound.util.HazelcastInboundChannelAdapterTestUtils;
import org.springframework.integration.hazelcast.message.EntryEventMessagePayload;
import org.springframework.messaging.Message;
import org.springframework.messaging.PollableChannel;
@@ -46,138 +46,139 @@ import com.hazelcast.core.ReplicatedMap;
@ContextConfiguration
@DirtiesContext
@SuppressWarnings("unchecked")
public class HazelcastReplicatedMapEventDrivenInboundChannelAdapterTests extends AbstractHazelcastTestSupport {
public class HazelcastReplicatedMapEventDrivenInboundChannelAdapterTests {
@Autowired
private PollableChannel edReplicatedMapChannel1;
@Autowired
private PollableChannel edReplicatedMapChannel1;
@Autowired
private PollableChannel edReplicatedMapChannel2;
@Autowired
private PollableChannel edReplicatedMapChannel2;
@Autowired
private PollableChannel edReplicatedMapChannel3;
@Autowired
private PollableChannel edReplicatedMapChannel3;
@Autowired
private PollableChannel edReplicatedMapChannel4;
@Autowired
private PollableChannel edReplicatedMapChannel4;
@Resource
private ReplicatedMap<Integer, HazelcastIntegrationTestUser> edReplicatedMap1;
@Resource
private ReplicatedMap<Integer, HazelcastIntegrationTestUser> edReplicatedMap1;
@Resource
private ReplicatedMap<Integer, HazelcastIntegrationTestUser> edReplicatedMap2;
@Resource
private ReplicatedMap<Integer, HazelcastIntegrationTestUser> edReplicatedMap2;
@Resource
private ReplicatedMap<Integer, HazelcastIntegrationTestUser> edReplicatedMap3;
@Resource
private ReplicatedMap<Integer, HazelcastIntegrationTestUser> edReplicatedMap3;
@Resource
private ReplicatedMap<Integer, HazelcastIntegrationTestUser> edReplicatedMap4;
@Resource
private ReplicatedMap<Integer, HazelcastIntegrationTestUser> edReplicatedMap4;
@Test
public void testEventDrivenForOnlyADDEDEntryEvent() {
edReplicatedMap1.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg = edReplicatedMapChannel1.receive(2_000);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.ADDED.name(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertEquals("edReplicatedMap1", msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
@Test
public void testEventDrivenForOnlyADDEDEntryEvent() {
edReplicatedMap1
.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg = edReplicatedMapChannel1
.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.ADDED.name(),
msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertEquals("edReplicatedMap1",
msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
Assert.assertEquals(Integer.valueOf(1),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
Assert.assertEquals(1,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId());
Assert.assertEquals("TestName1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName());
Assert.assertEquals("TestSurname1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname());
}
Assert.assertEquals(Integer.valueOf(1),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
Assert.assertEquals(1,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId());
Assert.assertEquals("TestName1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName());
Assert.assertEquals("TestSurname1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname());
}
@Test
public void testEventDrivenForOnlyUPDATEDEntryEvent() {
edReplicatedMap2.put(2, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
edReplicatedMap2.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
Message<?> msg = edReplicatedMapChannel2.receive(2_000);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
@Test
public void testEventDrivenForOnlyUPDATEDEntryEvent() {
edReplicatedMap2
.put(2, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
edReplicatedMap2
.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
Message<?> msg = edReplicatedMapChannel2
.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.UPDATED.name(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertEquals("edReplicatedMap2", msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.UPDATED.name(),
msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertEquals("edReplicatedMap2",
msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
Assert.assertEquals(Integer.valueOf(2),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
Assert.assertEquals(1,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId());
Assert.assertEquals("TestName1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName());
Assert.assertEquals("TestSurname1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname());
Assert.assertEquals(2,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId());
Assert.assertEquals("TestName2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName());
Assert.assertEquals("TestSurname2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname());
}
Assert.assertEquals(Integer.valueOf(2),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
Assert.assertEquals(1,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId());
Assert.assertEquals("TestName1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName());
Assert.assertEquals("TestSurname1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname());
Assert.assertEquals(2,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId());
Assert.assertEquals("TestName2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName());
Assert.assertEquals("TestSurname2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname());
}
@Test
public void testEventDrivenForOnlyREMOVEDEntryEvent() {
edReplicatedMap3.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
edReplicatedMap3.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
edReplicatedMap3.remove(2);
Message<?> msg = edReplicatedMapChannel3.receive(2_000);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.REMOVED.name(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertEquals("edReplicatedMap3", msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
@Test
public void testEventDrivenForOnlyREMOVEDEntryEvent() {
edReplicatedMap3
.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
edReplicatedMap3
.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
edReplicatedMap3.remove(2);
Message<?> msg = edReplicatedMapChannel3
.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.REMOVED.name(),
msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertEquals("edReplicatedMap3",
msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
Assert.assertEquals(Integer.valueOf(2),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
Assert.assertEquals(2,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId());
Assert.assertEquals("TestName2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName());
Assert.assertEquals("TestSurname2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname());
}
Assert.assertEquals(Integer.valueOf(2),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
Assert.assertEquals(2,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId());
Assert.assertEquals("TestName2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName());
Assert.assertEquals("TestSurname2",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname());
}
@Test
public void testEventDrivenForALLEntryEvent() {
edReplicatedMap4.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg = edReplicatedMapChannel4.receive(2_000);
verifyEntryEvent(msg, "edReplicatedMap4", EntryEventType.ADDED);
edReplicatedMap4.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurnameUpdated"));
msg = edReplicatedMapChannel4.receive(2_000);
verifyEntryEvent(msg, "edReplicatedMap4", EntryEventType.UPDATED);
edReplicatedMap4.remove(1);
msg = edReplicatedMapChannel4.receive(2_000);
verifyEntryEvent(msg, "edReplicatedMap4", EntryEventType.REMOVED);
edReplicatedMap4.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
msg = edReplicatedMapChannel4.receive(2_000);
verifyEntryEvent(msg, "edReplicatedMap4", EntryEventType.ADDED);
}
@Test
public void testEventDrivenForALLEntryEvent() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForReplicatedMapEntryEvents(edReplicatedMap4,
edReplicatedMapChannel4, "edReplicatedMap4");
}
}

View File

@@ -0,0 +1,87 @@
/*
* Copyright 2015-2016 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.hazelcast.inbound.config;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.integration.hazelcast.inbound.util.HazelcastInboundChannelAdapterTestUtils;
import org.springframework.messaging.PollableChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.hazelcast.core.IMap;
/**
* Hazelcast Continuous Query Inbound Channel Adapter JavaConfig driven Unit Test Class
*
* @author Eren Avsarogullari
* @since 1.0.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = HazelcastIntegrationInboundTestConfiguration.class,
loader = AnnotationConfigContextLoader.class)
@DirtiesContext
public class HazelcastCQDistributedMapInboundChannelAdapterConfigTests {
@Autowired
private PollableChannel cqDistributedMapChannel1;
@Autowired
private PollableChannel cqDistributedMapChannel2;
@Autowired
private PollableChannel cqDistributedMapChannel3;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> testCQDistributedMap1;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> testCQDistributedMap2;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> testCQDistributedMap3;
@Test
public void testContinuousQueryForADDEDEntryEvent() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForADDEDDistributedMapEntryEvent(testCQDistributedMap1,
cqDistributedMapChannel1, "Test_CQ_Distributed_Map1");
}
@Test
public void testContinuousQueryForALLEntryEvent() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForDistributedMapEntryEvents(testCQDistributedMap2,
cqDistributedMapChannel2, "Test_CQ_Distributed_Map2");
}
@Test
public void testContinuousQueryForUPDATEDEntryEventWhenIncludeValueIsFalse() {
HazelcastInboundChannelAdapterTestUtils
.testContinuousQueryForUPDATEDEntryEventWhenIncludeValueIsFalse(
testCQDistributedMap3, cqDistributedMapChannel3,
"Test_CQ_Distributed_Map3");
}
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright 2015-2016 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.hazelcast.inbound.config;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.hazelcast.inbound.util.HazelcastInboundChannelAdapterTestUtils;
import org.springframework.messaging.PollableChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.hazelcast.core.HazelcastInstance;
/**
* Hazelcast Cluster Monitor Inbound Channel Adapter JavaConfig driven Unit Test Class
*
* @author Eren Avsarogullari
* @since 1.0.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = HazelcastIntegrationInboundTestConfiguration.class)
@DirtiesContext
public class HazelcastClusterMonitorInboundChannelAdapterConfigTests {
@Autowired
private PollableChannel cmonChannel;
@Autowired
private PollableChannel cmonChannel2;
@Autowired
private HazelcastInstance testHazelcastInstance;
@Test
public void testConfigDrivenMembershipEvent() {
HazelcastInboundChannelAdapterTestUtils
.testMembershipEvent(testHazelcastInstance, cmonChannel, "testKey1",
"testValue1");
}
@Test
public void testConfigDrivenDistributedObjectEvent() {
HazelcastInboundChannelAdapterTestUtils
.testDistributedObjectEventByChannelAndHazelcastInstance(cmonChannel2,
testHazelcastInstance, "Test_Distributed_Map3");
}
}

View File

@@ -0,0 +1,99 @@
/*
* Copyright 2015-2016 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.hazelcast.inbound.config;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.integration.hazelcast.inbound.util.HazelcastInboundChannelAdapterTestUtils;
import org.springframework.messaging.PollableChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.hazelcast.core.IMap;
/**
* Hazelcast Distributed SQL Inbound Channel Adapter JavaConfig driven Unit Test Class
*
* @author Eren Avsarogullari
* @since 1.0.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = HazelcastIntegrationInboundTestConfiguration.class,
loader = AnnotationConfigContextLoader.class)
@DirtiesContext
public class HazelcastDistributedSQLInboundChannelAdapterConfigTests {
@Autowired
private PollableChannel dsDistributedMapChannel;
@Autowired
private PollableChannel dsDistributedMapChannel2;
@Autowired
private PollableChannel dsDistributedMapChannel3;
@Autowired
private PollableChannel dsDistributedMapChannel4;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> testDSDistributedMap;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> testDSDistributedMap2;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> testDSDistributedMap3;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> testDSDistributedMap4;
@Test
public void testDistributedSQLForENTRYIterationType() {
HazelcastInboundChannelAdapterTestUtils
.testDistributedSQLForENTRYIterationType(testDSDistributedMap,
dsDistributedMapChannel);
}
@Test
public void testDistributedSQLForKEYIterationType() {
HazelcastInboundChannelAdapterTestUtils
.testDistributedSQLForKEYIterationType(testDSDistributedMap2,
dsDistributedMapChannel2);
}
@Test
public void testDistributedSQLForLOCAL_KEYIterationType() {
HazelcastInboundChannelAdapterTestUtils
.testDistributedSQLForLOCAL_KEYIterationType(testDSDistributedMap3,
dsDistributedMapChannel3);
}
@Test
public void testDistributedSQLForVALUEIterationType() {
HazelcastInboundChannelAdapterTestUtils
.testDistributedSQLForVALUEIterationType(testDSDistributedMap4,
dsDistributedMapChannel4);
}
}

View File

@@ -0,0 +1,156 @@
/*
* Copyright 2015-2016 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.hazelcast.inbound.config;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.integration.hazelcast.inbound.util.HazelcastInboundChannelAdapterTestUtils;
import org.springframework.messaging.PollableChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.hazelcast.core.IList;
import com.hazelcast.core.IMap;
import com.hazelcast.core.IQueue;
import com.hazelcast.core.ISet;
import com.hazelcast.core.ITopic;
import com.hazelcast.core.MultiMap;
import com.hazelcast.core.ReplicatedMap;
/**
* Hazelcast Event Driven Inbound Channel Adapter JavaConfig driven Unit Test Class
*
* @author Eren Avsarogullari
* @since 1.0.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = HazelcastIntegrationInboundTestConfiguration.class,
loader = AnnotationConfigContextLoader.class)
@DirtiesContext
public class HazelcastEventDrivenInboundChannelAdapterConfigTests {
@Autowired
private PollableChannel distributedMapChannel;
@Autowired
private PollableChannel distributedMapChannel2;
@Autowired
private PollableChannel distributedListChannel;
@Autowired
private PollableChannel distributedSetChannel;
@Autowired
private PollableChannel distributedQueueChannel;
@Autowired
private PollableChannel topicChannel;
@Autowired
private PollableChannel replicatedMapChannel;
@Autowired
private PollableChannel multiMapChannel;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> testDistributedMap;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> testDistributedMap2;
@Resource
private IList<HazelcastIntegrationTestUser> testDistributedList;
@Resource
private ISet<HazelcastIntegrationTestUser> testDistributedSet;
@Resource
private IQueue<HazelcastIntegrationTestUser> testDistributedQueue;
@Resource
private ITopic<HazelcastIntegrationTestUser> testTopic;
@Resource
private ReplicatedMap<Integer, HazelcastIntegrationTestUser> testReplicatedMap;
@Resource
private MultiMap<Integer, HazelcastIntegrationTestUser> testMultiMap;
@Test
public void testEventDrivenForADDEDEntryEvent() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForADDEDDistributedMapEntryEvent(testDistributedMap,
distributedMapChannel, "Test_Distributed_Map");
}
@Test
public void testEventDrivenForEntryEvents() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForDistributedMapEntryEvents(testDistributedMap2,
distributedMapChannel2, "Test_Distributed_Map2");
}
@Test
public void testEventDrivenForDistributedListItemEvents() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForDistributedCollectionItemEvents(testDistributedList,
distributedListChannel);
}
@Test
public void testEventDrivenForDistributedSetItemEvents() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForDistributedCollectionItemEvents(testDistributedSet,
distributedSetChannel);
}
@Test
public void testEventDrivenForDistributedQueueItemEvents() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForDistributedCollectionItemEvents(testDistributedQueue,
distributedQueueChannel);
}
@Test
public void testEventDrivenForADDEDMessageEvent() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForTopicMessageEvent(testTopic, topicChannel);
}
@Test
public void testEventDrivenForReplicatedMapEntryEvents() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForReplicatedMapEntryEvents(testReplicatedMap,
replicatedMapChannel, "Test_Replicated_Map");
}
@Test
public void testEventDrivenForMultiMapEntryEvents() {
HazelcastInboundChannelAdapterTestUtils
.testEventDrivenForMultiMapEntryEvents(testMultiMap, multiMapChannel,
"Test_Multi_Map");
}
}

View File

@@ -0,0 +1,379 @@
/*
* Copyright 2015-2016 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.hazelcast.inbound.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.InboundChannelAdapter;
import org.springframework.integration.annotation.Poller;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.hazelcast.DistributedSQLIterationType;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.integration.hazelcast.inbound.HazelcastClusterMonitorMessageProducer;
import org.springframework.integration.hazelcast.inbound.HazelcastContinuousQueryMessageProducer;
import org.springframework.integration.hazelcast.inbound.HazelcastDistributedSQLMessageSource;
import org.springframework.integration.hazelcast.inbound.HazelcastEventDrivenMessageProducer;
import org.springframework.messaging.PollableChannel;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IList;
import com.hazelcast.core.IMap;
import com.hazelcast.core.IQueue;
import com.hazelcast.core.ISet;
import com.hazelcast.core.ITopic;
import com.hazelcast.core.MultiMap;
import com.hazelcast.core.ReplicatedMap;
/**
* Configuration Class for Hazelcast Integration Inbound Test
*
* @author Eren Avsarogullari
* @since 1.0.0
*/
@Configuration
@EnableIntegration
public class HazelcastIntegrationInboundTestConfiguration {
@Bean
public PollableChannel distributedMapChannel() {
return new QueueChannel();
}
@Bean
public PollableChannel distributedMapChannel2() {
return new QueueChannel();
}
@Bean
public PollableChannel distributedListChannel() {
return new QueueChannel();
}
@Bean
public PollableChannel distributedSetChannel() {
return new QueueChannel();
}
@Bean
public PollableChannel distributedQueueChannel() {
return new QueueChannel();
}
@Bean
public PollableChannel topicChannel() {
return new QueueChannel();
}
@Bean
public PollableChannel multiMapChannel() {
return new QueueChannel();
}
@Bean
public PollableChannel replicatedMapChannel() {
return new QueueChannel();
}
@Bean
public PollableChannel cqDistributedMapChannel1() {
return new QueueChannel();
}
@Bean
public PollableChannel cqDistributedMapChannel2() {
return new QueueChannel();
}
@Bean
public PollableChannel cqDistributedMapChannel3() {
return new QueueChannel();
}
@Bean
public PollableChannel dsDistributedMapChannel() {
return new QueueChannel();
}
@Bean
public PollableChannel dsDistributedMapChannel2() {
return new QueueChannel();
}
@Bean
public PollableChannel dsDistributedMapChannel3() {
return new QueueChannel();
}
@Bean
public PollableChannel dsDistributedMapChannel4() {
return new QueueChannel();
}
@Bean
public PollableChannel cmonChannel() {
return new QueueChannel();
}
@Bean
public PollableChannel cmonChannel2() {
return new QueueChannel();
}
@Bean
public IMap<Integer, HazelcastIntegrationTestUser> testDistributedMap() {
return testHazelcastInstance().getMap("Test_Distributed_Map");
}
@Bean
public IMap<Integer, HazelcastIntegrationTestUser> testDistributedMap2() {
return testHazelcastInstance().getMap("Test_Distributed_Map2");
}
@Bean
public IList<HazelcastIntegrationTestUser> testDistributedList() {
return testHazelcastInstance().getList("Test_Distributed_List");
}
@Bean
public ISet<HazelcastIntegrationTestUser> testDistributedSet() {
return testHazelcastInstance().getSet("Test_Distributed_Set");
}
@Bean
public IQueue<HazelcastIntegrationTestUser> testDistributedQueue() {
return testHazelcastInstance().getQueue("Test_Distributed_Queue");
}
@Bean
public ITopic<HazelcastIntegrationTestUser> testTopic() {
return testHazelcastInstance().getTopic("Test_Topic");
}
@Bean
public MultiMap<Integer, HazelcastIntegrationTestUser> testMultiMap() {
return testHazelcastInstance().getMultiMap("Test_Multi_Map");
}
@Bean
public ReplicatedMap<Integer, HazelcastIntegrationTestUser> testReplicatedMap() {
return testHazelcastInstance().getReplicatedMap("Test_Replicated_Map");
}
@Bean
public IMap<Integer, HazelcastIntegrationTestUser> testCQDistributedMap1() {
return testHazelcastInstance().getMap("Test_CQ_Distributed_Map1");
}
@Bean
public IMap<Integer, HazelcastIntegrationTestUser> testCQDistributedMap2() {
return testHazelcastInstance().getMap("Test_CQ_Distributed_Map2");
}
@Bean
public IMap<Integer, HazelcastIntegrationTestUser> testCQDistributedMap3() {
return testHazelcastInstance().getMap("Test_CQ_Distributed_Map3");
}
@Bean
public IMap<Integer, HazelcastIntegrationTestUser> testDSDistributedMap() {
return testHazelcastInstance().getMap("Test_DS_Distributed_Map");
}
@Bean
public IMap<Integer, HazelcastIntegrationTestUser> testDSDistributedMap2() {
return testHazelcastInstance().getMap("Test_DS_Distributed_Map2");
}
@Bean
public IMap<Integer, HazelcastIntegrationTestUser> testDSDistributedMap3() {
return testHazelcastInstance().getMap("Test_DS_Distributed_Map3");
}
@Bean
public IMap<Integer, HazelcastIntegrationTestUser> testDSDistributedMap4() {
return testHazelcastInstance().getMap("Test_DS_Distributed_Map4");
}
@Bean
public HazelcastInstance testHazelcastInstance() {
return Hazelcast.newHazelcastInstance();
}
@Bean
public HazelcastEventDrivenMessageProducer hazelcastEventDrivenMessageProducer() {
final HazelcastEventDrivenMessageProducer producer =
new HazelcastEventDrivenMessageProducer(testDistributedMap());
producer.setOutputChannel(distributedMapChannel());
return producer;
}
@Bean
public HazelcastEventDrivenMessageProducer hazelcastEventDrivenMessageProducer2() {
final HazelcastEventDrivenMessageProducer producer =
new HazelcastEventDrivenMessageProducer(testDistributedMap2());
producer.setOutputChannel(distributedMapChannel2());
producer.setCacheEventTypes("ADDED,REMOVED,UPDATED,CLEAR_ALL");
return producer;
}
@Bean
public HazelcastEventDrivenMessageProducer hazelcastEventDrivenMessageProducer3() {
final HazelcastEventDrivenMessageProducer producer =
new HazelcastEventDrivenMessageProducer(testDistributedList());
producer.setOutputChannel(distributedListChannel());
producer.setCacheEventTypes("ADDED,REMOVED");
return producer;
}
@Bean
public HazelcastEventDrivenMessageProducer hazelcastEventDrivenMessageProducer4() {
final HazelcastEventDrivenMessageProducer producer =
new HazelcastEventDrivenMessageProducer(testDistributedSet());
producer.setOutputChannel(distributedSetChannel());
producer.setCacheEventTypes("ADDED,REMOVED");
return producer;
}
@Bean
public HazelcastEventDrivenMessageProducer hazelcastEventDrivenMessageProducer5() {
final HazelcastEventDrivenMessageProducer producer =
new HazelcastEventDrivenMessageProducer(testDistributedQueue());
producer.setOutputChannel(distributedQueueChannel());
producer.setCacheEventTypes("ADDED,REMOVED");
return producer;
}
@Bean
public HazelcastEventDrivenMessageProducer hazelcastEventDrivenMessageProducer6() {
final HazelcastEventDrivenMessageProducer producer =
new HazelcastEventDrivenMessageProducer(testTopic());
producer.setOutputChannel(topicChannel());
return producer;
}
@Bean
public HazelcastEventDrivenMessageProducer hazelcastEventDrivenMessageProducer7() {
final HazelcastEventDrivenMessageProducer producer =
new HazelcastEventDrivenMessageProducer(testReplicatedMap());
producer.setOutputChannel(replicatedMapChannel());
producer.setCacheEventTypes("ADDED,REMOVED,UPDATED");
return producer;
}
@Bean
public HazelcastEventDrivenMessageProducer hazelcastEventDrivenMessageProducer8() {
final HazelcastEventDrivenMessageProducer producer =
new HazelcastEventDrivenMessageProducer(testMultiMap());
producer.setOutputChannel(multiMapChannel());
producer.setCacheEventTypes("ADDED,REMOVED,CLEAR_ALL");
return producer;
}
@Bean
public HazelcastContinuousQueryMessageProducer hazelcastContinuousQueryMessageProducer() {
final HazelcastContinuousQueryMessageProducer producer =
new HazelcastContinuousQueryMessageProducer(testCQDistributedMap1(),
"name=TestName1");
producer.setOutputChannel(cqDistributedMapChannel1());
return producer;
}
@Bean
public HazelcastContinuousQueryMessageProducer hazelcastContinuousQueryMessageProducer2() {
final HazelcastContinuousQueryMessageProducer producer =
new HazelcastContinuousQueryMessageProducer(testCQDistributedMap2(),
"name=TestName1 OR name=TestName2");
producer.setOutputChannel(cqDistributedMapChannel2());
producer.setCacheEventTypes("ADDED,REMOVED,UPDATED,CLEAR_ALL");
return producer;
}
@Bean
public HazelcastContinuousQueryMessageProducer hazelcastContinuousQueryMessageProducer3() {
final HazelcastContinuousQueryMessageProducer producer =
new HazelcastContinuousQueryMessageProducer(testCQDistributedMap3(),
"surname=TestSurname2");
producer.setOutputChannel(cqDistributedMapChannel3());
producer.setCacheEventTypes("UPDATED");
producer.setIncludeValue(false);
return producer;
}
@Bean
public HazelcastClusterMonitorMessageProducer hazelcastClusterMonitorMessageProducer() {
final HazelcastClusterMonitorMessageProducer producer =
new HazelcastClusterMonitorMessageProducer(testHazelcastInstance());
producer.setOutputChannel(cmonChannel());
return producer;
}
@Bean
public HazelcastClusterMonitorMessageProducer hazelcastClusterMonitorMessageProducer2() {
final HazelcastClusterMonitorMessageProducer producer =
new HazelcastClusterMonitorMessageProducer(testHazelcastInstance());
producer.setOutputChannel(cmonChannel2());
producer.setMonitorEventTypes("DISTRIBUTED_OBJECT");
return producer;
}
@Bean
@InboundChannelAdapter(value = "dsDistributedMapChannel",
poller = @Poller(maxMessagesPerPoll = "1"))
public HazelcastDistributedSQLMessageSource hazelcastDistributedSQLMessageSource() {
final HazelcastDistributedSQLMessageSource messageSource =
new HazelcastDistributedSQLMessageSource(testDSDistributedMap(),
"name='TestName4' AND surname='TestSurname4'");
messageSource.setIterationType(DistributedSQLIterationType.ENTRY);
return messageSource;
}
@Bean
@InboundChannelAdapter(value = "dsDistributedMapChannel2",
poller = @Poller(maxMessagesPerPoll = "1"))
public HazelcastDistributedSQLMessageSource hazelcastDistributedSQLMessageSource2() {
final HazelcastDistributedSQLMessageSource messageSource =
new HazelcastDistributedSQLMessageSource(testDSDistributedMap2(),
"name='TestName1' AND surname='TestSurname1'");
messageSource.setIterationType(DistributedSQLIterationType.KEY);
return messageSource;
}
@Bean
@InboundChannelAdapter(value = "dsDistributedMapChannel3",
poller = @Poller(maxMessagesPerPoll = "1"))
public HazelcastDistributedSQLMessageSource hazelcastDistributedSQLMessageSource3() {
final HazelcastDistributedSQLMessageSource messageSource =
new HazelcastDistributedSQLMessageSource(testDSDistributedMap3(),
"age > 5");
messageSource.setIterationType(DistributedSQLIterationType.LOCAL_KEY);
return messageSource;
}
@Bean
@InboundChannelAdapter(value = "dsDistributedMapChannel4",
poller = @Poller(maxMessagesPerPoll = "1"))
public HazelcastDistributedSQLMessageSource hazelcastDistributedSQLMessageSource4() {
final HazelcastDistributedSQLMessageSource messageSource =
new HazelcastDistributedSQLMessageSource(testDSDistributedMap4(),
"name='TestName3' AND surname='TestSurname3'");
messageSource.setIterationType(DistributedSQLIterationType.VALUE);
return messageSource;
}
}

View File

@@ -0,0 +1,404 @@
/*
* Copyright 2015-2016 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.hazelcast.inbound.util;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Collection;
import java.util.Map;
import org.junit.Assert;
import org.springframework.integration.hazelcast.HazelcastHeaders;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.integration.hazelcast.message.EntryEventMessagePayload;
import org.springframework.messaging.Message;
import org.springframework.messaging.PollableChannel;
import com.hazelcast.core.DistributedObjectEvent;
import com.hazelcast.core.EntryEventType;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.ICollection;
import com.hazelcast.core.IMap;
import com.hazelcast.core.ITopic;
import com.hazelcast.core.Member;
import com.hazelcast.core.MembershipEvent;
import com.hazelcast.core.MultiMap;
import com.hazelcast.core.ReplicatedMap;
import com.hazelcast.spi.exception.DistributedObjectDestroyedException;
/**
* Util Class for Hazelcast Inbound Channel Adapters Test Support
* @author Eren Avsarogullari
* @since 1.0.0
*/
@SuppressWarnings("unchecked")
public class HazelcastInboundChannelAdapterTestUtils {
public static final int TIMEOUT = 20_000;
public static void verifyEntryEvent(Message<?> msg, String cacheName,
EntryEventType event) {
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
if (event == EntryEventType.CLEAR_ALL || event == EntryEventType.EVICT_ALL) {
Assert.assertTrue(msg.getPayload() instanceof Integer);
}
else {
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
}
Assert.assertEquals(cacheName, msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
Assert.assertEquals(event.name(),
msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
}
public static void verifyItemEvent(Message<?> msg, EntryEventType event) {
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(event.toString(),
msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString());
}
public static void testEventDrivenForADDEDDistributedMapEntryEvent(
final IMap<Integer, HazelcastIntegrationTestUser> distributedMap,
final PollableChannel channel, final String cacheName) {
HazelcastIntegrationTestUser hazelcastIntegrationTestUser =
new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1");
distributedMap.put(1, hazelcastIntegrationTestUser);
Message<?> msg = channel.receive(TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertEquals(EntryEventType.ADDED.name(),
msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
Assert.assertEquals(cacheName, msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
Assert.assertEquals(Integer.valueOf(1),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
Assert.assertEquals(1,
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId());
Assert.assertEquals("TestName1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName());
Assert.assertEquals("TestSurname1",
(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname());
}
public static void testEventDrivenForDistributedMapEntryEvents(
final IMap<Integer, HazelcastIntegrationTestUser> distributedMap,
final PollableChannel channel, final String cacheName) {
distributedMap
.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg = channel.receive(TIMEOUT);
verifyEntryEvent(msg, cacheName, EntryEventType.ADDED);
distributedMap.put(1,
new HazelcastIntegrationTestUser(1, "TestName1", "TestSurnameUpdated"));
msg = channel.receive(TIMEOUT);
verifyEntryEvent(msg, cacheName, EntryEventType.UPDATED);
distributedMap.remove(1);
msg = channel.receive(TIMEOUT);
verifyEntryEvent(msg, cacheName, EntryEventType.REMOVED);
distributedMap
.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
msg = channel.receive(TIMEOUT);
verifyEntryEvent(msg, cacheName, EntryEventType.ADDED);
distributedMap.clear();
msg = channel.receive(TIMEOUT);
verifyEntryEvent(msg, cacheName, EntryEventType.CLEAR_ALL);
}
public static void testEventDrivenForDistributedCollectionItemEvents(
final ICollection<HazelcastIntegrationTestUser> distributedObject,
final PollableChannel channel) {
HazelcastIntegrationTestUser user =
new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1");
distributedObject.add(user);
Message<?> msg = channel.receive(TIMEOUT);
verifyItemEvent(msg, EntryEventType.ADDED);
distributedObject.remove(user);
msg = channel.receive(TIMEOUT);
verifyItemEvent(msg, EntryEventType.REMOVED);
user = new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2");
distributedObject.add(user);
msg = channel.receive(TIMEOUT);
verifyItemEvent(msg, EntryEventType.ADDED);
}
public static void testEventDrivenForReplicatedMapEntryEvents(
final ReplicatedMap<Integer, HazelcastIntegrationTestUser> replicatedMap,
final PollableChannel channel, final String cacheName) {
replicatedMap
.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg = channel.receive(TIMEOUT);
verifyEntryEvent(msg, cacheName, EntryEventType.ADDED);
replicatedMap.put(1,
new HazelcastIntegrationTestUser(1, "TestName1", "TestSurnameUpdated"));
msg = channel.receive(TIMEOUT);
verifyEntryEvent(msg, cacheName, EntryEventType.UPDATED);
replicatedMap.remove(1);
msg = channel.receive(TIMEOUT);
verifyEntryEvent(msg, cacheName, EntryEventType.REMOVED);
replicatedMap
.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
msg = channel.receive(TIMEOUT);
verifyEntryEvent(msg, cacheName, EntryEventType.ADDED);
}
public static void testEventDrivenForTopicMessageEvent(
final ITopic<HazelcastIntegrationTestUser> topic, final PollableChannel channel) {
topic.publish(new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg = channel.receive(TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.PUBLISHING_TIME));
Assert.assertEquals(topic.getName(),
msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
Assert.assertEquals(1, ((HazelcastIntegrationTestUser) msg.getPayload()).getId());
Assert.assertEquals("TestName1",
((HazelcastIntegrationTestUser) msg.getPayload()).getName());
Assert.assertEquals("TestSurname1",
((HazelcastIntegrationTestUser) msg.getPayload()).getSurname());
}
public static void testEventDrivenForMultiMapEntryEvents(
final MultiMap<Integer, HazelcastIntegrationTestUser> multiMap,
final PollableChannel channel, final String cacheName) {
multiMap.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
Message<?> msg = channel.receive(TIMEOUT);
verifyEntryEvent(msg, cacheName, EntryEventType.ADDED);
multiMap.put(1,
new HazelcastIntegrationTestUser(1, "TestName1", "TestSurnameUpdated"));
msg = channel.receive(TIMEOUT);
verifyEntryEvent(msg, cacheName, EntryEventType.ADDED);
multiMap.remove(1);
msg = channel.receive(TIMEOUT);
verifyEntryEvent(msg, cacheName, EntryEventType.REMOVED);
msg = channel.receive(TIMEOUT);
verifyEntryEvent(msg, cacheName, EntryEventType.REMOVED);
multiMap.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
msg = channel.receive(TIMEOUT);
verifyEntryEvent(msg, cacheName, EntryEventType.ADDED);
multiMap.clear();
msg = channel.receive(TIMEOUT);
verifyEntryEvent(msg, cacheName, EntryEventType.CLEAR_ALL);
}
public static void testContinuousQueryForUPDATEDEntryEventWhenIncludeValueIsFalse(
final IMap<Integer, HazelcastIntegrationTestUser> cqDistributedMap,
final PollableChannel channel, final String cacheName) {
cqDistributedMap
.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1"));
cqDistributedMap
.put(1, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
Message<?> msg = channel.receive(TIMEOUT);
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER));
assertEquals(EntryEventType.UPDATED.name(),
msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE));
assertEquals(cacheName, msg.getHeaders().get(HazelcastHeaders.CACHE_NAME));
assertEquals(Integer.valueOf(1),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
assertNull(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue);
assertNull(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value);
}
public static void testDistributedSQLForENTRYIterationType(
final IMap<Integer, HazelcastIntegrationTestUser> dsDistributedMap,
final PollableChannel channel) {
dsDistributedMap
.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1", 10));
dsDistributedMap
.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2", 20));
dsDistributedMap
.put(3, new HazelcastIntegrationTestUser(3, "TestName3", "TestSurname3", 30));
dsDistributedMap
.put(4, new HazelcastIntegrationTestUser(4, "TestName4", "TestSurname4", 40));
dsDistributedMap
.put(5, new HazelcastIntegrationTestUser(5, "TestName5", "TestSurname5", 50));
Message<?> msg = channel.receive(TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof Collection);
Assert.assertEquals(4,
(((Map.Entry<?, ?>) ((Collection<?>) msg.getPayload()).iterator().next())
.getKey()));
Assert.assertEquals(4,
((HazelcastIntegrationTestUser) ((Map.Entry<?, ?>) ((Collection<?>) msg
.getPayload()).iterator().next()).getValue()).getId());
Assert.assertEquals("TestName4",
((HazelcastIntegrationTestUser) ((Map.Entry<?, ?>) ((Collection<?>) msg
.getPayload()).iterator().next()).getValue()).getName());
Assert.assertEquals("TestSurname4",
((HazelcastIntegrationTestUser) ((Map.Entry<?, ?>) ((Collection<?>) msg
.getPayload()).iterator().next()).getValue()).getSurname());
}
public static void testDistributedSQLForKEYIterationType(
final IMap<Integer, HazelcastIntegrationTestUser> dsDistributedMap,
final PollableChannel channel) {
dsDistributedMap
.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1", 10));
dsDistributedMap
.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2", 20));
dsDistributedMap
.put(3, new HazelcastIntegrationTestUser(3, "TestName3", "TestSurname3", 30));
Message<?> msg = channel.receive(TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof Collection);
Assert.assertEquals(1, ((Collection<?>) msg.getPayload()).iterator().next());
}
public static void testDistributedSQLForLOCAL_KEYIterationType(
final IMap<Integer, HazelcastIntegrationTestUser> dsDistributedMap,
final PollableChannel channel) {
dsDistributedMap
.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1", 10));
dsDistributedMap
.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2", 20));
dsDistributedMap
.put(3, new HazelcastIntegrationTestUser(3, "TestName3", "TestSurname3", 30));
Message<?> msg = channel.receive(TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof Collection);
}
public static void testDistributedSQLForVALUEIterationType(
final IMap<Integer, HazelcastIntegrationTestUser> dsDistributedMap,
final PollableChannel channel) {
dsDistributedMap
.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1", 10));
dsDistributedMap
.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2", 20));
dsDistributedMap
.put(3, new HazelcastIntegrationTestUser(3, "TestName3", "TestSurname3", 30));
dsDistributedMap
.put(4, new HazelcastIntegrationTestUser(4, "TestName4", "TestSurname4", 40));
dsDistributedMap
.put(5, new HazelcastIntegrationTestUser(5, "TestName5", "TestSurname5", 50));
Message<?> msg = channel.receive(TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof Collection);
Assert.assertEquals(3,
((HazelcastIntegrationTestUser) (((Collection<?>) msg.getPayload()).iterator()
.next())).getId());
Assert.assertEquals("TestName3",
((HazelcastIntegrationTestUser) (((Collection<?>) msg.getPayload()).iterator()
.next())).getName());
Assert.assertEquals("TestSurname3",
((HazelcastIntegrationTestUser) (((Collection<?>) msg.getPayload()).iterator()
.next())).getSurname());
}
public static void testMembershipEvent(final HazelcastInstance instance,
final PollableChannel channel, final String key, final String value) {
Member member = instance.getCluster().getMembers().iterator().next();
member.setStringAttribute(key, value);
Message<?> msg = channel.receive(TIMEOUT);
verifyMembershipEvent(msg, MembershipEvent.MEMBER_ATTRIBUTE_CHANGED);
}
public static void testDistributedObjectEventByChannelAndHazelcastInstance(
final PollableChannel channel, final HazelcastInstance hazelcastInstance,
final String distributedObjectName) {
final IMap<Integer, String> distributedMap =
hazelcastInstance.getMap(distributedObjectName);
Message<?> msg = channel.receive(TIMEOUT);
verifyDistributedObjectEvent(msg, DistributedObjectEvent.EventType.CREATED,
distributedObjectName);
distributedMap.destroy();
msg = channel.receive(TIMEOUT);
try {
// Since Hazelcast 3.6 we can use DistributedObjectEvent.getDistributedObject() for DESTROYED objects.
verifyDistributedObjectEvent(msg, DistributedObjectEvent.EventType.DESTROYED, distributedObjectName);
fail("DistributedObjectDestroyedException expected");
}
catch (Exception e) {
assertThat(e, instanceOf(DistributedObjectDestroyedException.class));
}
}
private static void verifyMembershipEvent(final Message<?> msg,
final int membershipEvent) {
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof MembershipEvent);
assertEquals(membershipEvent,
((MembershipEvent) msg.getPayload()).getEventType());
assertNotNull(((MembershipEvent) msg.getPayload()).getMember());
}
private static void verifyDistributedObjectEvent(final Message<?> msg,
final DistributedObjectEvent.EventType eventType,
final String distributedObjectName) {
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof DistributedObjectEvent);
assertEquals(eventType,
((DistributedObjectEvent) msg.getPayload()).getEventType());
assertNotNull((((DistributedObjectEvent) msg.getPayload()).getDistributedObject())
.getName(), distributedObjectName);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@@ -21,7 +21,6 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -30,9 +29,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;
@@ -47,6 +44,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.hazelcast.HazelcastHeaders;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.integration.hazelcast.HazelcastTestRequestHandlerAdvice;
import org.springframework.integration.hazelcast.outbound.util.HazelcastOutboundChannelAdapterTestUtils;
import org.springframework.integration.support.DefaultMessageBuilderFactory;
import org.springframework.integration.support.MessageBuilderFactory;
import org.springframework.messaging.Message;
@@ -58,7 +56,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.hazelcast.core.ITopic;
import com.hazelcast.core.MessageListener;
import com.hazelcast.core.MultiMap;
import com.hazelcast.core.ReplicatedMap;
@@ -72,479 +69,405 @@ import com.hazelcast.core.ReplicatedMap;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@DirtiesContext
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public class HazelcastOutboundChannelAdapterTests {
private static final int DATA_COUNT = 100;
private static final String DISTRIBUTED_MAP = "distributedMap";
private static final int DEFAULT_AGE = 5;
private static final String CACHE_HEADER = "CACHE_HEADER";
private static final String TEST_NAME = "Test_Name";
private final MessageBuilderFactory messageBuilderFactory =
new DefaultMessageBuilderFactory();
private static final String TEST_SURNAME = "Test_Surname";
@Autowired
@Qualifier("firstMapChannel")
private MessageChannel firstMapChannel;
private static final String DISTRIBUTED_MAP = "distributedMap";
@Autowired
@Qualifier("secondMapChannel")
private MessageChannel secondMapChannel;
private static final String CACHE_HEADER = "CACHE_HEADER";
@Autowired
@Qualifier("thirdMapChannel")
private MessageChannel thirdMapChannel;
private final MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory();
@Autowired
@Qualifier("fourthMapChannel")
private MessageChannel fourthMapChannel;
@Autowired
@Qualifier("firstMapChannel")
private MessageChannel firstMapChannel;
@Autowired
@Qualifier("fifthMapChannel")
private MessageChannel fifthMapChannel;
@Autowired
@Qualifier("secondMapChannel")
private MessageChannel secondMapChannel;
@Autowired
@Qualifier("sixthMapChannel")
private MessageChannel sixthMapChannel;
@Autowired
@Qualifier("thirdMapChannel")
private MessageChannel thirdMapChannel;
@Autowired
@Qualifier("bulkMapChannel")
private MessageChannel bulkMapChannel;
@Autowired
@Qualifier("fourthMapChannel")
private MessageChannel fourthMapChannel;
@Autowired
@Qualifier("multiMapChannel")
private MessageChannel multiMapChannel;
@Autowired
@Qualifier("fifthMapChannel")
private MessageChannel fifthMapChannel;
@Autowired
@Qualifier("replicatedMapChannel")
private MessageChannel replicatedMapChannel;
@Autowired
@Qualifier("sixthMapChannel")
private MessageChannel sixthMapChannel;
@Autowired
@Qualifier("bulkReplicatedMapChannel")
private MessageChannel bulkReplicatedMapChannel;
@Autowired
@Qualifier("bulkMapChannel")
private MessageChannel bulkMapChannel;
@Autowired
@Qualifier("listChannel")
private MessageChannel listChannel;
@Autowired
@Qualifier("multiMapChannel")
private MessageChannel multiMapChannel;
@Autowired
@Qualifier("bulkListChannel")
private MessageChannel bulkListChannel;
@Autowired
@Qualifier("replicatedMapChannel")
private MessageChannel replicatedMapChannel;
@Autowired
@Qualifier("setChannel")
private MessageChannel setChannel;
@Autowired
@Qualifier("bulkReplicatedMapChannel")
private MessageChannel bulkReplicatedMapChannel;
@Autowired
@Qualifier("bulkSetChannel")
private MessageChannel bulkSetChannel;
@Autowired
@Qualifier("listChannel")
private MessageChannel listChannel;
@Autowired
@Qualifier("queueChannel")
private MessageChannel queueChannel;
@Autowired
@Qualifier("bulkListChannel")
private MessageChannel bulkListChannel;
@Autowired
@Qualifier("bulkQueueChannel")
private MessageChannel bulkQueueChannel;
@Autowired
@Qualifier("setChannel")
private MessageChannel setChannel;
@Autowired
@Qualifier("topicChannel")
private MessageChannel topicChannel;
@Autowired
@Qualifier("bulkSetChannel")
private MessageChannel bulkSetChannel;
@Autowired
@Qualifier("lockChannel")
private MessageChannel lockChannel;
@Autowired
@Qualifier("queueChannel")
private MessageChannel queueChannel;
@Resource
private Map<?, ?> distributedMap;
@Autowired
@Qualifier("bulkQueueChannel")
private MessageChannel bulkQueueChannel;
@Resource
private Map<?, ?> distributedBulkMap;
@Autowired
@Qualifier("topicChannel")
private MessageChannel topicChannel;
@Resource
private MultiMap<Integer, HazelcastIntegrationTestUser> multiMap;
@Autowired
@Qualifier("lockChannel")
private MessageChannel lockChannel;
@Resource
private ReplicatedMap<Integer, HazelcastIntegrationTestUser> replicatedMap;
@Resource
private Map<?, ?> distributedMap;
@Resource
private ReplicatedMap<Integer, HazelcastIntegrationTestUser> bulkReplicatedMap;
@Resource
private Map<?, ?> distributedBulkMap;
@Resource
private List<HazelcastIntegrationTestUser> distributedList;
@Resource
private MultiMap<Integer, HazelcastIntegrationTestUser> multiMap;
@Resource
private List<HazelcastIntegrationTestUser> distributedBulkList;
@Resource
private ReplicatedMap<Integer, HazelcastIntegrationTestUser> replicatedMap;
@Resource
private ReplicatedMap<Integer, HazelcastIntegrationTestUser> bulkReplicatedMap;
@Resource
private List<HazelcastIntegrationTestUser> distributedList;
@Resource
private List<HazelcastIntegrationTestUser> distributedBulkList;
@Resource
private Set<HazelcastIntegrationTestUser> distributedSet;
@Resource
private Set<HazelcastIntegrationTestUser> distributedBulkSet;
@Resource
private Queue<HazelcastIntegrationTestUser> distributedQueue;
@Resource
private Queue<HazelcastIntegrationTestUser> distributedBulkQueue;
@Resource
private ITopic<HazelcastIntegrationTestUser> topic;
@Autowired
@Qualifier("testFirstMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testFirstMapRequestHandlerAdvice;
@Autowired
@Qualifier("testSecondMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testSecondMapRequestHandlerAdvice;
@Autowired
@Qualifier("testThirdMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testThirdMapRequestHandlerAdvice;
@Autowired
@Qualifier("testFourthMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testFourthMapRequestHandlerAdvice;
@Autowired
@Qualifier("testBulkMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testBulkMapRequestHandlerAdvice;
@Autowired
@Qualifier("testMultiMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testMultiMapRequestHandlerAdvice;
@Autowired
@Qualifier("testReplicatedMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testReplicatedMapRequestHandlerAdvice;
@Autowired
@Qualifier("testBulkReplicatedMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testBulkReplicatedMapRequestHandlerAdvice;
@Autowired
@Qualifier("testListRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testListRequestHandlerAdvice;
@Autowired
@Qualifier("testBulkListRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testBulkListRequestHandlerAdvice;
@Autowired
@Qualifier("testSetRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testSetRequestHandlerAdvice;
@Autowired
@Qualifier("testBulkSetRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testBulkSetRequestHandlerAdvice;
@Autowired
@Qualifier("testQueueRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testQueueRequestHandlerAdvice;
@Autowired
@Qualifier("testBulkQueueRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testBulkQueueRequestHandlerAdvice;
@Autowired
@Qualifier("testTopicRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testTopicRequestHandlerAdvice;
@Before
public void setUp() {
this.distributedMap.clear();
this.distributedBulkMap.clear();
this.distributedList.clear();
this.distributedBulkList.clear();
this.distributedSet.clear();
this.distributedBulkSet.clear();
this.distributedQueue.clear();
this.distributedBulkQueue.clear();
this.multiMap.clear();
this.replicatedMap.clear();
this.bulkReplicatedMap.clear();
}
@Test
public void testWriteToDistributedMap() throws InterruptedException {
sendMessageToChannel(this.firstMapChannel);
assertTrue(this.testFirstMapRequestHandlerAdvice.executeLatch.await(10,
TimeUnit.SECONDS));
verifyMapForPayload(new TreeMap(this.distributedMap));
}
@Test
public void testBulkWriteToDistributedMap() throws InterruptedException {
Map<Integer, HazelcastIntegrationTestUser> userMap = new HashMap<>(DATA_COUNT);
for (int index = 1; index <= DATA_COUNT; index++) {
userMap.put(index, getTestUser(index));
}
this.bulkMapChannel.send(new GenericMessage<>(userMap));
assertTrue(this.testBulkMapRequestHandlerAdvice.executeLatch.await(10,
TimeUnit.SECONDS));
verifyMapForPayload(new TreeMap(this.distributedBulkMap));
}
@Test
public void testWriteToDistributedMapWhenCacheExpressionIsSet()
throws InterruptedException {
sendMessageWithCacheHeaderToChannel(this.secondMapChannel, CACHE_HEADER,
DISTRIBUTED_MAP);
assertTrue(this.testSecondMapRequestHandlerAdvice.executeLatch.await(10,
TimeUnit.SECONDS));
verifyMapForPayload(new TreeMap(this.distributedMap));
}
@Test
public void testWriteToDistributedMapWhenHazelcastHeaderIsSet()
throws InterruptedException {
sendMessageWithCacheHeaderToChannel(this.thirdMapChannel,
HazelcastHeaders.CACHE_NAME, DISTRIBUTED_MAP);
assertTrue(this.testThirdMapRequestHandlerAdvice.executeLatch.await(10,
TimeUnit.SECONDS));
verifyMapForPayload(new TreeMap(this.distributedMap));
}
@Test
public void testWriteToDistributedMapWhenExtractPayloadIsFalse()
throws InterruptedException {
sendMessageWithCacheHeaderToChannel(this.fourthMapChannel,
HazelcastHeaders.CACHE_NAME, DISTRIBUTED_MAP);
assertTrue(this.testFourthMapRequestHandlerAdvice.executeLatch.await(10,
TimeUnit.SECONDS));
verifyMapForMessage(new TreeMap(this.distributedMap));
}
@Test
public void testWriteToMultiMap() throws InterruptedException {
sendMessageToChannel(this.multiMapChannel);
assertTrue(this.testMultiMapRequestHandlerAdvice.executeLatch.await(10,
TimeUnit.SECONDS));
verifyMultiMapForPayload(this.multiMap);
}
@Test
public void testWriteToReplicatedMap() throws InterruptedException {
sendMessageToChannel(this.replicatedMapChannel);
assertTrue(this.testReplicatedMapRequestHandlerAdvice.executeLatch.await(10,
TimeUnit.SECONDS));
verifyMapForPayload(new TreeMap(this.replicatedMap));
}
@Test
public void testBulkWriteToReplicatedMap() throws InterruptedException {
Map<Integer, HazelcastIntegrationTestUser> userMap = new HashMap<>(DATA_COUNT);
for (int index = 1; index <= DATA_COUNT; index++) {
userMap.put(index, getTestUser(index));
}
this.bulkReplicatedMapChannel.send(new GenericMessage<>(userMap));
assertTrue(this.testBulkReplicatedMapRequestHandlerAdvice.executeLatch.await(10,
TimeUnit.SECONDS));
verifyMapForPayload(new TreeMap(this.bulkReplicatedMap));
}
@Test
public void testWriteToDistributedList() throws InterruptedException {
sendMessageToChannel(this.listChannel);
assertTrue(this.testListRequestHandlerAdvice.executeLatch.await(10,
TimeUnit.SECONDS));
verifyCollection(this.distributedList, DATA_COUNT);
}
@Test
public void testBulkWriteToDistributedList() throws InterruptedException {
List<HazelcastIntegrationTestUser> userList = new ArrayList<>(DATA_COUNT);
for (int index = 1; index <= DATA_COUNT; index++) {
userList.add(getTestUser(index));
}
this.bulkListChannel.send(new GenericMessage<>(userList));
assertTrue(this.testBulkListRequestHandlerAdvice.executeLatch.await(10,
TimeUnit.SECONDS));
verifyCollection(this.distributedBulkList, DATA_COUNT);
}
@Test
public void testWriteToDistributedSet() throws InterruptedException {
sendMessageToChannel(this.setChannel);
assertTrue(this.testSetRequestHandlerAdvice.executeLatch.await(10,
TimeUnit.SECONDS));
final List<HazelcastIntegrationTestUser> list = new ArrayList(this.distributedSet);
Collections.sort(list);
verifyCollection(list, DATA_COUNT);
}
@Test
public void testBulkWriteToDistributedSet() throws InterruptedException {
Set<HazelcastIntegrationTestUser> userSet = new HashSet<>(DATA_COUNT);
for (int index = 1; index <= DATA_COUNT; index++) {
userSet.add(getTestUser(index));
}
this.bulkSetChannel.send(new GenericMessage<>(userSet));
assertTrue(this.testBulkSetRequestHandlerAdvice.executeLatch.await(10,
TimeUnit.SECONDS));
final List<HazelcastIntegrationTestUser> list = new ArrayList(this.distributedBulkSet);
Collections.sort(list);
verifyCollection(list, DATA_COUNT);
}
@Test
public void testWriteToDistributedQueue() throws InterruptedException {
sendMessageToChannel(this.queueChannel);
assertTrue(this.testQueueRequestHandlerAdvice.executeLatch.await(10,
TimeUnit.SECONDS));
verifyCollection(this.distributedQueue, DATA_COUNT);
}
@Test
public void testBulkWriteToDistributedQueue() throws InterruptedException {
Queue<HazelcastIntegrationTestUser> userQueue = new ArrayBlockingQueue(DATA_COUNT);
for (int index = 1; index <= DATA_COUNT; index++) {
userQueue.add(getTestUser(index));
}
this.bulkQueueChannel.send(new GenericMessage<>(userQueue));
assertTrue(this.testBulkQueueRequestHandlerAdvice.executeLatch.await(10,
TimeUnit.SECONDS));
verifyCollection(this.distributedBulkQueue, DATA_COUNT);
}
@Test
public void testWriteToTopic() throws InterruptedException {
this.topic.addMessageListener(new TestTopicMessageListener());
sendMessageToChannel(this.topicChannel);
assertTrue(this.testTopicRequestHandlerAdvice.executeLatch.await(10,
TimeUnit.SECONDS));
}
@Test(expected = MessageHandlingException.class)
public void testWriteToDistributedMapWhenCacheIsNotSet() {
this.fifthMapChannel.send(new GenericMessage<>(getTestUser(1)));
}
@Test(expected = MessageHandlingException.class)
public void testWriteToDistributedMapWhenKeyExpressionIsNotSet() {
Message<HazelcastIntegrationTestUser> message = this.messageBuilderFactory
.withPayload(getTestUser(1))
.setHeader(HazelcastHeaders.CACHE_NAME, DISTRIBUTED_MAP).build();
this.sixthMapChannel.send(message);
}
@Test(expected = MessageHandlingException.class)
public void testWriteToLock() {
this.lockChannel.send(new GenericMessage<>("foo"));
}
private void sendMessageToChannel(final MessageChannel channel) {
for (int index = 1; index <= DATA_COUNT; index++) {
channel.send(new GenericMessage<>(getTestUser(index)));
}
}
private void sendMessageWithCacheHeaderToChannel(final MessageChannel channel,
final String headerName, final String distributedObjectName) {
for (int index = 1; index <= DATA_COUNT; index++) {
Message<HazelcastIntegrationTestUser> message = this.messageBuilderFactory
.withPayload(getTestUser(index))
.setHeader(headerName, distributedObjectName).build();
channel.send(message);
}
}
private void verifyMapForPayload(final Map<Integer, HazelcastIntegrationTestUser> map) {
int index = 1;
assertNotNull(map);
assertEquals(true, map.size() == DATA_COUNT);
for (Entry<Integer, HazelcastIntegrationTestUser> entry : map.entrySet()) {
assertNotNull(entry);
assertEquals(index, entry.getKey().intValue());
verifyHazelcastIntegrationTestUser(entry.getValue(), index);
index++;
}
}
private void verifyMultiMapForPayload(
final MultiMap<Integer, HazelcastIntegrationTestUser> multiMap) {
int index = 1;
assertNotNull(multiMap);
assertEquals(true, multiMap.size() == DATA_COUNT);
SortedSet<Integer> keys = new TreeSet<>(multiMap.keySet());
for (Integer key : keys) {
assertNotNull(key);
assertEquals(index, key.intValue());
HazelcastIntegrationTestUser user = multiMap.get(key).iterator().next();
verifyHazelcastIntegrationTestUser(user, index);
index++;
}
}
private void verifyMapForMessage(
final Map<Integer, Message<HazelcastIntegrationTestUser>> map) {
int index = 1;
assertNotNull(map);
assertEquals(true, map.size() == DATA_COUNT);
for (Entry<Integer, Message<HazelcastIntegrationTestUser>> entry : map.entrySet()) {
assertNotNull(entry);
assertEquals(index, entry.getKey().intValue());
assertTrue(entry.getValue().getHeaders().size() > 0);
verifyHazelcastIntegrationTestUser(entry.getValue().getPayload(), index);
index++;
}
}
private void verifyCollection(final Collection<HazelcastIntegrationTestUser> coll,
final int dataCount) {
int index = 1;
assertNotNull(coll);
assertEquals(true, coll.size() == dataCount);
for (HazelcastIntegrationTestUser user : coll) {
verifyHazelcastIntegrationTestUser(user, index);
index++;
}
}
private void verifyHazelcastIntegrationTestUser(HazelcastIntegrationTestUser user,
int index) {
assertNotNull(user);
assertEquals(index, user.getId());
assertEquals(TEST_NAME, user.getName());
assertEquals(TEST_SURNAME, user.getSurname());
assertEquals(index + DEFAULT_AGE, user.getAge());
}
private HazelcastIntegrationTestUser getTestUser(int index) {
return new HazelcastIntegrationTestUser(index, TEST_NAME, TEST_SURNAME, index
+ DEFAULT_AGE);
}
private class TestTopicMessageListener implements MessageListener {
private int index = 1;
@Override
public void onMessage(com.hazelcast.core.Message message) {
HazelcastIntegrationTestUser user = (HazelcastIntegrationTestUser) message
.getMessageObject();
verifyHazelcastIntegrationTestUser(user, index);
index++;
}
}
@Resource
private Set<HazelcastIntegrationTestUser> distributedSet;
@Resource
private Set<HazelcastIntegrationTestUser> distributedBulkSet;
@Resource
private Queue<HazelcastIntegrationTestUser> distributedQueue;
@Resource
private Queue<HazelcastIntegrationTestUser> distributedBulkQueue;
@Resource
private ITopic<HazelcastIntegrationTestUser> topic;
@Autowired
@Qualifier("testFirstMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testFirstMapRequestHandlerAdvice;
@Autowired
@Qualifier("testSecondMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testSecondMapRequestHandlerAdvice;
@Autowired
@Qualifier("testThirdMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testThirdMapRequestHandlerAdvice;
@Autowired
@Qualifier("testFourthMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testFourthMapRequestHandlerAdvice;
@Autowired
@Qualifier("testBulkMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testBulkMapRequestHandlerAdvice;
@Autowired
@Qualifier("testMultiMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testMultiMapRequestHandlerAdvice;
@Autowired
@Qualifier("testReplicatedMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testReplicatedMapRequestHandlerAdvice;
@Autowired
@Qualifier("testBulkReplicatedMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testBulkReplicatedMapRequestHandlerAdvice;
@Autowired
@Qualifier("testListRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testListRequestHandlerAdvice;
@Autowired
@Qualifier("testBulkListRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testBulkListRequestHandlerAdvice;
@Autowired
@Qualifier("testSetRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testSetRequestHandlerAdvice;
@Autowired
@Qualifier("testBulkSetRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testBulkSetRequestHandlerAdvice;
@Autowired
@Qualifier("testQueueRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testQueueRequestHandlerAdvice;
@Autowired
@Qualifier("testBulkQueueRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testBulkQueueRequestHandlerAdvice;
@Autowired
@Qualifier("testTopicRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice testTopicRequestHandlerAdvice;
@Before
public void setUp() {
this.distributedMap.clear();
this.distributedBulkMap.clear();
this.distributedList.clear();
this.distributedBulkList.clear();
this.distributedSet.clear();
this.distributedBulkSet.clear();
this.distributedQueue.clear();
this.distributedBulkQueue.clear();
this.multiMap.clear();
this.replicatedMap.clear();
this.bulkReplicatedMap.clear();
}
@Test
public void testWriteToDistributedMap() throws InterruptedException {
HazelcastOutboundChannelAdapterTestUtils
.testWriteToDistributedMap(this.firstMapChannel, this.distributedMap,
this.testFirstMapRequestHandlerAdvice);
}
@Test
public void testBulkWriteToDistributedMap() {
HazelcastOutboundChannelAdapterTestUtils
.testBulkWriteToDistributedMap(this.bulkMapChannel, this.distributedBulkMap,
this.testBulkMapRequestHandlerAdvice);
}
@Test
public void testWriteToDistributedMapWhenCacheExpressionIsSet()
throws InterruptedException {
sendMessageWithCacheHeaderToChannel(this.secondMapChannel, CACHE_HEADER,
DISTRIBUTED_MAP);
assertTrue(this.testSecondMapRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS));
HazelcastOutboundChannelAdapterTestUtils
.verifyMapForPayload(new TreeMap(this.distributedMap));
}
@Test
public void testWriteToDistributedMapWhenHazelcastHeaderIsSet()
throws InterruptedException {
sendMessageWithCacheHeaderToChannel(this.thirdMapChannel,
HazelcastHeaders.CACHE_NAME, DISTRIBUTED_MAP);
assertTrue(this.testThirdMapRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS));
HazelcastOutboundChannelAdapterTestUtils
.verifyMapForPayload(new TreeMap(this.distributedMap));
}
@Test
public void testWriteToDistributedMapWhenExtractPayloadIsFalse()
throws InterruptedException {
sendMessageWithCacheHeaderToChannel(this.fourthMapChannel,
HazelcastHeaders.CACHE_NAME, DISTRIBUTED_MAP);
assertTrue(this.testFourthMapRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS));
verifyMapForMessage(new TreeMap(this.distributedMap));
}
@Test
public void testWriteToMultiMap() {
HazelcastOutboundChannelAdapterTestUtils
.testWriteToMultiMap(this.multiMapChannel, this.multiMap,
this.testMultiMapRequestHandlerAdvice);
}
@Test
public void testWriteToReplicatedMap() {
HazelcastOutboundChannelAdapterTestUtils
.testWriteToReplicatedMap(this.replicatedMapChannel, this.replicatedMap,
this.testReplicatedMapRequestHandlerAdvice);
}
@Test
public void testBulkWriteToReplicatedMap() throws InterruptedException {
Map<Integer, HazelcastIntegrationTestUser> userMap =
new HashMap<>(HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
for (int index = 1;
index <= HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT; index++) {
userMap
.put(index, HazelcastOutboundChannelAdapterTestUtils.getTestUser(index));
}
this.bulkReplicatedMapChannel.send(new GenericMessage<>(userMap));
assertTrue(this.testBulkReplicatedMapRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS));
HazelcastOutboundChannelAdapterTestUtils
.verifyMapForPayload(new TreeMap(this.bulkReplicatedMap));
}
@Test
public void testWriteToDistributedList() {
HazelcastOutboundChannelAdapterTestUtils
.testWriteToDistributedList(this.listChannel, this.distributedList,
this.testListRequestHandlerAdvice);
}
@Test
public void testBulkWriteToDistributedList() throws InterruptedException {
List<HazelcastIntegrationTestUser> userList =
new ArrayList<>(HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
for (int index = 1;
index <= HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT; index++) {
userList.add(HazelcastOutboundChannelAdapterTestUtils.getTestUser(index));
}
this.bulkListChannel.send(new GenericMessage<>(userList));
assertTrue(this.testBulkListRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS));
HazelcastOutboundChannelAdapterTestUtils
.verifyCollection(this.distributedBulkList,
HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
}
@Test
public void testWriteToDistributedSet() {
HazelcastOutboundChannelAdapterTestUtils
.testWriteToDistributedSet(this.setChannel, this.distributedSet,
this.testSetRequestHandlerAdvice);
}
@Test
public void testBulkWriteToDistributedSet() throws InterruptedException {
Set<HazelcastIntegrationTestUser> userSet =
new HashSet<>(HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
for (int index = 1;
index <= HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT; index++) {
userSet.add(HazelcastOutboundChannelAdapterTestUtils.getTestUser(index));
}
this.bulkSetChannel.send(new GenericMessage<>(userSet));
assertTrue(this.testBulkSetRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS));
final List<HazelcastIntegrationTestUser> list =
new ArrayList(this.distributedBulkSet);
Collections.sort(list);
HazelcastOutboundChannelAdapterTestUtils
.verifyCollection(list, HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
}
@Test
public void testWriteToDistributedQueue() {
HazelcastOutboundChannelAdapterTestUtils
.testWriteToDistributedQueue(this.queueChannel, this.distributedQueue,
this.testQueueRequestHandlerAdvice);
}
@Test
public void testBulkWriteToDistributedQueue() throws InterruptedException {
Queue<HazelcastIntegrationTestUser> userQueue =
new ArrayBlockingQueue(HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
for (int index = 1;
index <= HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT; index++) {
userQueue.add(HazelcastOutboundChannelAdapterTestUtils.getTestUser(index));
}
this.bulkQueueChannel.send(new GenericMessage<>(userQueue));
assertTrue(this.testBulkQueueRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS));
HazelcastOutboundChannelAdapterTestUtils
.verifyCollection(this.distributedBulkQueue,
HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
}
@Test
public void testWriteToTopic() {
HazelcastOutboundChannelAdapterTestUtils
.testWriteToTopic(this.topicChannel, this.topic,
this.testTopicRequestHandlerAdvice);
}
@Test(expected = MessageHandlingException.class)
public void testWriteToDistributedMapWhenCacheIsNotSet() {
this.fifthMapChannel.send(new GenericMessage<>(
HazelcastOutboundChannelAdapterTestUtils.getTestUser(1)));
}
@Test(expected = MessageHandlingException.class)
public void testWriteToDistributedMapWhenKeyExpressionIsNotSet() {
Message<HazelcastIntegrationTestUser> message = this.messageBuilderFactory
.withPayload(HazelcastOutboundChannelAdapterTestUtils.getTestUser(1))
.setHeader(HazelcastHeaders.CACHE_NAME, DISTRIBUTED_MAP).build();
this.sixthMapChannel.send(message);
}
@Test(expected = MessageHandlingException.class)
public void testWriteToLock() {
this.lockChannel.send(new GenericMessage<>("foo"));
}
private void sendMessageWithCacheHeaderToChannel(final MessageChannel channel,
final String headerName, final String distributedObjectName) {
for (int index = 1;
index <= HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT; index++) {
Message<HazelcastIntegrationTestUser> message = this.messageBuilderFactory
.withPayload(HazelcastOutboundChannelAdapterTestUtils.getTestUser(index))
.setHeader(headerName, distributedObjectName).build();
channel.send(message);
}
}
private void verifyMapForMessage(
final Map<Integer, Message<HazelcastIntegrationTestUser>> map) {
int index = 1;
assertNotNull(map);
assertEquals(true, map.size() == HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
for (Entry<Integer, Message<HazelcastIntegrationTestUser>> entry : map.entrySet()) {
assertNotNull(entry);
assertEquals(index, entry.getKey().intValue());
assertTrue(entry.getValue().getHeaders().size() > 0);
HazelcastOutboundChannelAdapterTestUtils
.verifyHazelcastIntegrationTestUser(entry.getValue().getPayload(), index);
index++;
}
}
}

View File

@@ -0,0 +1,300 @@
/*
* Copyright 2015-2016 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.hazelcast.outbound.config;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.annotation.IntegrationComponentScan;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.integration.hazelcast.HazelcastTestRequestHandlerAdvice;
import org.springframework.integration.hazelcast.outbound.HazelcastCacheWritingMessageHandler;
import org.springframework.integration.hazelcast.outbound.util.HazelcastOutboundChannelAdapterTestUtils;
import org.springframework.messaging.MessageChannel;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.core.ITopic;
import com.hazelcast.core.MultiMap;
import com.hazelcast.core.ReplicatedMap;
import com.hazelcast.core.DistributedObject;
/**
* Configuration Class for Hazelcast Integration Outbound Test
*
* @author Eren Avsarogullari
* @since 1.0.0
*/
@Configuration
@ComponentScan(basePackages = {"org.springframework.integration.hazelcast.*"})
@EnableIntegration
@IntegrationComponentScan("org.springframework.integration.hazelcast.outbound")
public class HazelcastIntegrationOutboundTestConfiguration {
@Bean
public MessageChannel distMapChannel() {
return new DirectChannel();
}
@Bean
public MessageChannel distMapBulkChannel() {
return new DirectChannel();
}
@Bean
public MessageChannel distListChannel() {
return new DirectChannel();
}
@Bean
public MessageChannel distSetChannel() {
return new DirectChannel();
}
@Bean
public MessageChannel distQueueChannel() {
return new DirectChannel();
}
@Bean
public MessageChannel topicChannel2() {
return new DirectChannel();
}
@Bean
public MessageChannel multiMapChannel2() {
return new DirectChannel();
}
@Bean
public MessageChannel replicatedMapChannel2() {
return new DirectChannel();
}
@Bean
public IMap<Integer, HazelcastIntegrationTestUser> distMap() {
return testHzInstance().getMap("Distributed_Map1");
}
@Bean
public IMap<Integer, HazelcastIntegrationTestUser> distBulkMap() {
return testHzInstance().getMap("Distributed_Bulk_Map1");
}
@Bean
public List<HazelcastIntegrationTestUser> distList() {
return testHzInstance().getList("Distributed_List1");
}
@Bean
public Set<HazelcastIntegrationTestUser> distSet() {
return testHzInstance().getSet("Distributed_Set1");
}
@Bean
public Queue<HazelcastIntegrationTestUser> distQueue() {
return testHzInstance().getQueue("Distributed_Queue1");
}
@Bean
public ITopic<HazelcastIntegrationTestUser> topic() {
return testHzInstance().getTopic("Topic1");
}
@Bean
public MultiMap<Integer, HazelcastIntegrationTestUser> multiMap() {
return testHzInstance().getMultiMap("Multi_Map1");
}
@Bean
public ReplicatedMap<Integer, HazelcastIntegrationTestUser> replicatedMap() {
return testHzInstance().getReplicatedMap("Replicated_Map1");
}
@Bean
public HazelcastInstance testHzInstance() {
return Hazelcast.newHazelcastInstance();
}
@Bean
public HazelcastTestRequestHandlerAdvice distMapRequestHandlerAdvice() {
return new HazelcastTestRequestHandlerAdvice(
HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
}
@Bean
public HazelcastTestRequestHandlerAdvice distBulkMapRequestHandlerAdvice() {
return new HazelcastTestRequestHandlerAdvice(1);
}
@Bean
public HazelcastTestRequestHandlerAdvice distListRequestHandlerAdvice() {
return new HazelcastTestRequestHandlerAdvice(
HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
}
@Bean
public HazelcastTestRequestHandlerAdvice distSetRequestHandlerAdvice() {
return new HazelcastTestRequestHandlerAdvice(
HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
}
@Bean
public HazelcastTestRequestHandlerAdvice distQueueRequestHandlerAdvice() {
return new HazelcastTestRequestHandlerAdvice(
HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
}
@Bean
public HazelcastTestRequestHandlerAdvice topicRequestHandlerAdvice() {
return new HazelcastTestRequestHandlerAdvice(
HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
}
@Bean
public HazelcastTestRequestHandlerAdvice multiMapRequestHandlerAdvice() {
return new HazelcastTestRequestHandlerAdvice(
HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
}
@Bean
public HazelcastTestRequestHandlerAdvice replicatedMapRequestHandlerAdvice() {
return new HazelcastTestRequestHandlerAdvice(
HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
}
@Bean
@ServiceActivator(inputChannel = "distMapChannel", adviceChain = "distMapRequestHandlerAdvice")
public HazelcastCacheWritingMessageHandler hazelcastCacheWritingMessageHandler() {
final HazelcastCacheWritingMessageHandler handler =
new HazelcastCacheWritingMessageHandler();
handler.setDistributedObject(distMap());
handler
.setKeyExpression(new SpelExpressionParser().parseExpression("payload.id"));
handler.setExtractPayload(true);
return handler;
}
@Bean
@ServiceActivator(inputChannel = "distMapBulkChannel",
adviceChain = "distBulkMapRequestHandlerAdvice")
public HazelcastCacheWritingMessageHandler hazelcastCacheWritingMessageHandler2() {
final HazelcastCacheWritingMessageHandler handler =
new HazelcastCacheWritingMessageHandler();
handler.setDistributedObject(distBulkMap());
handler
.setKeyExpression(new SpelExpressionParser().parseExpression("payload.id"));
handler.setExtractPayload(true);
return handler;
}
@Bean
@ServiceActivator(inputChannel = "distListChannel",
adviceChain = "distListRequestHandlerAdvice")
public HazelcastCacheWritingMessageHandler hazelcastCacheWritingMessageHandler3() {
final HazelcastCacheWritingMessageHandler handler =
new HazelcastCacheWritingMessageHandler();
handler.setDistributedObject((DistributedObject) distList());
handler
.setKeyExpression(new SpelExpressionParser().parseExpression("payload.id"));
handler.setExtractPayload(true);
return handler;
}
@Bean
@ServiceActivator(inputChannel = "distSetChannel",
adviceChain = "distSetRequestHandlerAdvice")
public HazelcastCacheWritingMessageHandler hazelcastCacheWritingMessageHandler4() {
final HazelcastCacheWritingMessageHandler handler =
new HazelcastCacheWritingMessageHandler();
handler.setDistributedObject((DistributedObject) distSet());
handler
.setKeyExpression(new SpelExpressionParser().parseExpression("payload.id"));
handler.setExtractPayload(true);
return handler;
}
@Bean
@ServiceActivator(inputChannel = "distQueueChannel",
adviceChain = "distQueueRequestHandlerAdvice")
public HazelcastCacheWritingMessageHandler hazelcastCacheWritingMessageHandler5() {
final HazelcastCacheWritingMessageHandler handler =
new HazelcastCacheWritingMessageHandler();
handler.setDistributedObject((DistributedObject) distQueue());
handler
.setKeyExpression(new SpelExpressionParser().parseExpression("payload.id"));
handler.setExtractPayload(true);
return handler;
}
@Bean
@ServiceActivator(inputChannel = "topicChannel2",
adviceChain = "topicRequestHandlerAdvice")
public HazelcastCacheWritingMessageHandler hazelcastCacheWritingMessageHandler6() {
final HazelcastCacheWritingMessageHandler handler =
new HazelcastCacheWritingMessageHandler();
handler.setDistributedObject(topic());
handler
.setKeyExpression(new SpelExpressionParser().parseExpression("payload.id"));
handler.setExtractPayload(true);
return handler;
}
@Bean
@ServiceActivator(inputChannel = "multiMapChannel2",
adviceChain = "multiMapRequestHandlerAdvice")
public HazelcastCacheWritingMessageHandler hazelcastCacheWritingMessageHandler7() {
final HazelcastCacheWritingMessageHandler handler =
new HazelcastCacheWritingMessageHandler();
handler.setDistributedObject(multiMap());
handler
.setKeyExpression(new SpelExpressionParser().parseExpression("payload.id"));
handler.setExtractPayload(true);
return handler;
}
@Bean
@ServiceActivator(inputChannel = "replicatedMapChannel2",
adviceChain = "replicatedMapRequestHandlerAdvice")
public HazelcastCacheWritingMessageHandler hazelcastCacheWritingMessageHandler8() {
final HazelcastCacheWritingMessageHandler handler =
new HazelcastCacheWritingMessageHandler();
handler.setDistributedObject(replicatedMap());
handler
.setKeyExpression(new SpelExpressionParser().parseExpression("payload.id"));
handler.setExtractPayload(true);
return handler;
}
}

View File

@@ -0,0 +1,199 @@
/*
* Copyright 2015-2016 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.hazelcast.outbound.config;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.integration.hazelcast.HazelcastTestRequestHandlerAdvice;
import org.springframework.integration.hazelcast.outbound.util.HazelcastOutboundChannelAdapterTestUtils;
import org.springframework.messaging.MessageChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.hazelcast.core.IMap;
import com.hazelcast.core.ITopic;
import com.hazelcast.core.MultiMap;
import com.hazelcast.core.ReplicatedMap;
/**
* Hazelcast Outbound Channel Adapter JavaConfig driven Unit Test Class
*
* @author Eren Avsarogullari
* @since 1.0.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = HazelcastIntegrationOutboundTestConfiguration.class,
loader = AnnotationConfigContextLoader.class)
@DirtiesContext
public class HazelcastOutboundChannelAdapterConfigTests {
@Autowired
@Qualifier("distMapChannel")
private MessageChannel distMapChannel;
@Autowired
@Qualifier("distMapBulkChannel")
private MessageChannel distMapBulkChannel;
@Autowired
@Qualifier("distListChannel")
private MessageChannel distListChannel;
@Autowired
@Qualifier("distSetChannel")
private MessageChannel distSetChannel;
@Autowired
@Qualifier("distQueueChannel")
private MessageChannel distQueueChannel;
@Autowired
@Qualifier("topicChannel2")
private MessageChannel topicChannel2;
@Autowired
@Qualifier("multiMapChannel2")
private MessageChannel multiMapChannel2;
@Autowired
@Qualifier("replicatedMapChannel2")
private MessageChannel replicatedMapChannel2;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> distMap;
@Resource
private IMap<Integer, HazelcastIntegrationTestUser> distBulkMap;
@Resource
private List<HazelcastIntegrationTestUser> distList;
@Resource
private Set<HazelcastIntegrationTestUser> distSet;
@Resource
private Queue<HazelcastIntegrationTestUser> distQueue;
@Resource
private ITopic<HazelcastIntegrationTestUser> topic;
@Resource
private MultiMap<Integer, HazelcastIntegrationTestUser> multiMap;
@Resource
private ReplicatedMap<Integer, HazelcastIntegrationTestUser> replicatedMap;
@Autowired
@Qualifier("distMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice distMapRequestHandlerAdvice;
@Autowired
@Qualifier("distBulkMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice distBulkMapRequestHandlerAdvice;
@Autowired
@Qualifier("distListRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice distListRequestHandlerAdvice;
@Autowired
@Qualifier("distSetRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice distSetRequestHandlerAdvice;
@Autowired
@Qualifier("distQueueRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice distQueueRequestHandlerAdvice;
@Autowired
@Qualifier("topicRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice topicRequestHandlerAdvice;
@Autowired
@Qualifier("multiMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice multiMapRequestHandlerAdvice;
@Autowired
@Qualifier("replicatedMapRequestHandlerAdvice")
private HazelcastTestRequestHandlerAdvice replicatedMapRequestHandlerAdvice;
@Test
public void testWriteToDistributedMap() {
HazelcastOutboundChannelAdapterTestUtils
.testWriteToDistributedMap(this.distMapChannel, this.distMap,
this.distMapRequestHandlerAdvice);
}
@Test
public void testBulkWriteToDistributedMap() {
HazelcastOutboundChannelAdapterTestUtils
.testBulkWriteToDistributedMap(this.distMapBulkChannel, this.distBulkMap,
this.distBulkMapRequestHandlerAdvice);
}
@Test
public void testWriteToDistributedList() {
HazelcastOutboundChannelAdapterTestUtils
.testWriteToDistributedList(this.distListChannel, this.distList,
this.distListRequestHandlerAdvice);
}
@Test
public void testWriteToDistributedSet() {
HazelcastOutboundChannelAdapterTestUtils
.testWriteToDistributedSet(this.distSetChannel, this.distSet,
this.distSetRequestHandlerAdvice);
}
@Test
public void testWriteToDistributedQueue() {
HazelcastOutboundChannelAdapterTestUtils
.testWriteToDistributedQueue(this.distQueueChannel, this.distQueue,
this.distQueueRequestHandlerAdvice);
}
@Test
public void testWriteToTopic() {
HazelcastOutboundChannelAdapterTestUtils
.testWriteToTopic(this.topicChannel2, this.topic, this.topicRequestHandlerAdvice);
}
@Test
public void testWriteToMultiMap() {
HazelcastOutboundChannelAdapterTestUtils
.testWriteToMultiMap(this.multiMapChannel2, this.multiMap,
this.multiMapRequestHandlerAdvice);
}
@Test
public void testWriteToReplicatedMap() {
HazelcastOutboundChannelAdapterTestUtils
.testWriteToReplicatedMap(this.replicatedMapChannel2, this.replicatedMap,
this.replicatedMapRequestHandlerAdvice);
}
}

View File

@@ -0,0 +1,247 @@
/*
* Copyright 2016 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.hazelcast.outbound.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
import org.springframework.integration.hazelcast.HazelcastIntegrationTestUser;
import org.springframework.integration.hazelcast.HazelcastTestRequestHandlerAdvice;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.GenericMessage;
import com.hazelcast.core.ITopic;
import com.hazelcast.core.MessageListener;
import com.hazelcast.core.MultiMap;
import com.hazelcast.core.ReplicatedMap;
/**
* Util Class for Hazelcast Outbound Channel Adapter Test Support
*
* @author Eren Avsarogullari
*
* @since 1.0.0
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public class HazelcastOutboundChannelAdapterTestUtils {
public static final int DATA_COUNT = 100;
public static final int DEFAULT_AGE = 5;
public static final String TEST_NAME = "Test_Name";
public static final String TEST_SURNAME = "Test_Surname";
public static void testWriteToDistributedMap(MessageChannel channel,
Map<?, ?> distributedMap,
HazelcastTestRequestHandlerAdvice requestHandlerAdvice) {
testWriteToMap(channel, distributedMap, requestHandlerAdvice);
}
private static void testWriteToMap(MessageChannel channel,
Map<?, ?> distributedMap,
HazelcastTestRequestHandlerAdvice requestHandlerAdvice) {
try {
sendMessageToChannel(channel);
assertTrue(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS));
verifyMapForPayload(new TreeMap(distributedMap));
}
catch (InterruptedException e) {
fail("Test has been failed due to " + e.getMessage());
}
}
public static void testBulkWriteToDistributedMap(MessageChannel channel,
Map<?, ?> distributedMap,
HazelcastTestRequestHandlerAdvice requestHandlerAdvice) {
try {
Map<Integer, HazelcastIntegrationTestUser> userMap =
new HashMap<>(DATA_COUNT);
for (int index = 1; index <= DATA_COUNT; index++) {
userMap.put(index, getTestUser(index));
}
channel.send(new GenericMessage<>(userMap));
assertTrue(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS));
verifyMapForPayload(new TreeMap(distributedMap));
}
catch (InterruptedException e) {
fail("Test has been failed due to " + e.getMessage());
}
}
public static void testWriteToMultiMap(MessageChannel channel,
MultiMap<Integer, HazelcastIntegrationTestUser> multiMap,
HazelcastTestRequestHandlerAdvice requestHandlerAdvice) {
try {
sendMessageToChannel(channel);
assertTrue(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS));
verifyMultiMapForPayload(multiMap);
}
catch (InterruptedException e) {
fail("Test has been failed due to " + e.getMessage());
}
}
public static void testWriteToReplicatedMap(MessageChannel channel,
ReplicatedMap<Integer, HazelcastIntegrationTestUser> replicatedMap,
HazelcastTestRequestHandlerAdvice requestHandlerAdvice) {
testWriteToMap(channel, replicatedMap, requestHandlerAdvice);
}
public static void testWriteToDistributedList(MessageChannel channel,
List<HazelcastIntegrationTestUser> distributedList,
HazelcastTestRequestHandlerAdvice requestHandlerAdvice) {
testWriteToDistributedCollection(channel, distributedList, requestHandlerAdvice);
}
private static void testWriteToDistributedCollection(MessageChannel channel,
Collection<HazelcastIntegrationTestUser> distributedList,
HazelcastTestRequestHandlerAdvice requestHandlerAdvice) {
try {
sendMessageToChannel(channel);
assertTrue(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS));
verifyCollection(distributedList, DATA_COUNT);
}
catch (InterruptedException e) {
fail("Test has been failed due to " + e.getMessage());
}
}
public static void testWriteToDistributedSet(MessageChannel channel,
Set<HazelcastIntegrationTestUser> distributedSet,
HazelcastTestRequestHandlerAdvice requestHandlerAdvice) {
try {
sendMessageToChannel(channel);
assertTrue(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS));
final List<HazelcastIntegrationTestUser> list = new ArrayList(distributedSet);
Collections.sort(list);
verifyCollection(list, DATA_COUNT);
}
catch (InterruptedException e) {
fail("Test has been failed due to " + e.getMessage());
}
}
public static void testWriteToDistributedQueue(MessageChannel channel,
Queue<HazelcastIntegrationTestUser> distributedQueue,
HazelcastTestRequestHandlerAdvice requestHandlerAdvice) {
testWriteToDistributedCollection(channel, distributedQueue, requestHandlerAdvice);
}
public static void testWriteToTopic(MessageChannel channel,
ITopic<HazelcastIntegrationTestUser> topic,
HazelcastTestRequestHandlerAdvice requestHandlerAdvice) {
try {
topic.addMessageListener(new MessageListener() {
private int index = 1;
@Override
public void onMessage(com.hazelcast.core.Message message) {
HazelcastIntegrationTestUser user =
(HazelcastIntegrationTestUser) message.getMessageObject();
verifyHazelcastIntegrationTestUser(user, index);
index++;
}
});
sendMessageToChannel(channel);
assertTrue(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS));
}
catch (InterruptedException e) {
fail("Test has been failed due to " + e.getMessage());
}
}
public static HazelcastIntegrationTestUser getTestUser(int index) {
return new HazelcastIntegrationTestUser(index, TEST_NAME, TEST_SURNAME,
index + DEFAULT_AGE);
}
public static void verifyMapForPayload(
final Map<Integer, HazelcastIntegrationTestUser> map) {
int index = 1;
assertNotNull(map);
assertEquals(true, map.size() == DATA_COUNT);
for (Map.Entry<Integer, HazelcastIntegrationTestUser> entry : map.entrySet()) {
assertNotNull(entry);
assertEquals(index, entry.getKey().intValue());
verifyHazelcastIntegrationTestUser(entry.getValue(), index);
index++;
}
}
public static void verifyCollection(
final Collection<HazelcastIntegrationTestUser> coll, final int dataCount) {
int index = 1;
assertNotNull(coll);
assertEquals(true, coll.size() == dataCount);
for (HazelcastIntegrationTestUser user : coll) {
verifyHazelcastIntegrationTestUser(user, index);
index++;
}
}
public static void verifyHazelcastIntegrationTestUser(
HazelcastIntegrationTestUser user, int index) {
assertNotNull(user);
assertEquals(index, user.getId());
assertEquals(TEST_NAME, user.getName());
assertEquals(TEST_SURNAME, user.getSurname());
assertEquals(index + DEFAULT_AGE, user.getAge());
}
private static void sendMessageToChannel(final MessageChannel channel) {
for (int index = 1; index <= DATA_COUNT; index++) {
channel.send(new GenericMessage<>(getTestUser(index)));
}
}
private static void verifyMultiMapForPayload(
final MultiMap<Integer, HazelcastIntegrationTestUser> multiMap) {
int index = 1;
assertNotNull(multiMap);
assertEquals(true, multiMap.size() == DATA_COUNT);
SortedSet<Integer> keys = new TreeSet<>(multiMap.keySet());
for (Integer key : keys) {
assertNotNull(key);
assertEquals(index, key.intValue());
HazelcastIntegrationTestUser user = multiMap.get(key).iterator().next();
verifyHazelcastIntegrationTestUser(user, index);
index++;
}
}
}