diff --git a/spring-integration-hazelcast/README.md b/spring-integration-hazelcast/README.md index 42bf802..4eed970 100644 --- a/spring-integration-hazelcast/README.md +++ b/spring-integration-hazelcast/README.md @@ -535,4 +535,6 @@ public LockRegistry lockRegistry() { } ``` -When used with a shared `MessageGroupStore` (e.g. `Aggregator` store management), the `HazelcastLockRegistry` can be use to provide this functionality across multiple application instances, such that only one instance can manipulate the group at a time. +When used with a shared `MessageGroupStore` (e.g. `Aggregator` store management), the `HazelcastLockRegistry` can be use to provide this functionality across multiple application instances, such that only one instance can manipulate the group at a time. + +NOTE: For all the distributed operations the CP Subsystem must be enabled on `HazelcastInstance`. diff --git a/spring-integration-hazelcast/build.gradle b/spring-integration-hazelcast/build.gradle index e69bb7f..9b282bf 100644 --- a/spring-integration-hazelcast/build.gradle +++ b/spring-integration-hazelcast/build.gradle @@ -1,22 +1,13 @@ -buildscript { - repositories { - maven { url 'https://repo.spring.io/plugins-release' } - } - dependencies { - classpath 'io.spring.gradle:dependency-management-plugin:1.0.2.RELEASE' - classpath 'io.spring.gradle:spring-io-plugin:0.0.8.RELEASE' - } -} - plugins { id 'java' id 'eclipse' id 'idea' id 'jacoco' + id 'org.sonarqube' version '2.8' id 'checkstyle' - id 'org.sonarqube' version '2.5' + id 'org.ajoberstar.grgit' version '3.1.1' + id "io.spring.dependency-management" version '1.0.8.RELEASE' } - description = 'Spring Integration Hazelcast Support' apply from: "${rootProject.projectDir}/publish-maven.gradle" @@ -30,32 +21,15 @@ repositories { maven { url 'https://repo.spring.io/libs-milestone' } } -if (project.hasProperty('platformVersion')) { - apply plugin: 'spring-io' - - dependencyManagement { - springIoTestRuntime { - imports { - mavenBom "io.spring.platform:platform-bom:${platformVersion}" - } - } - } -} - compileJava { - sourceCompatibility = 1.7 - targetCompatibility = 1.7 -} - -compileTestJava { sourceCompatibility = 1.8 targetCompatibility = 1.8 } ext { - hazelcastVersion = '3.8.9' - slf4jVersion = '1.7.25' - springIntegrationVersion = '4.3.20.BUILD-SNAPSHOT' + hazelcastVersion = '3.12.4' + slf4jVersion = '1.7.28' + springIntegrationVersion = '5.2.1.RELEASE' idPrefix = 'hazelcast' @@ -78,12 +52,12 @@ sourceSets { } jacoco { - toolVersion = "0.7.9" + toolVersion = '0.8.4' } checkstyle { configFile = file("$rootDir/src/checkstyle/checkstyle.xml") - toolVersion = "8.0" + toolVersion = '8.25' } // enable all compiler warnings; individual projects may customize further @@ -103,9 +77,9 @@ dependencies { test { // suppress all console output during testing unless running `gradle -i` logging.captureStandardOutput(LogLevel.INFO) - jvmArgs "-Dhazelcast.logging.type=slf4j" + jvmArgs '-Dhazelcast.logging.type=slf4j' - maxHeapSize = "1024m" + maxHeapSize = '1024m' jacoco { append = false destinationFile = file("$buildDir/jacoco.exec") @@ -121,12 +95,12 @@ jacocoTestReport { } task sourcesJar(type: Jar) { - classifier = 'sources' + archiveClassifier = 'sources' from sourceSets.main.allJava } task javadocJar(type: Jar) { - classifier = 'javadoc' + archiveClassifier = 'javadoc' from javadoc } @@ -137,13 +111,13 @@ artifacts { sonarqube { properties { - property "sonar.jacoco.reportPath", "${buildDir.name}/jacoco.exec" - property "sonar.links.homepage", linkHomepage - property "sonar.links.ci", linkCi - property "sonar.links.issue", linkIssue - property "sonar.links.scm", linkScmUrl - property "sonar.links.scm_dev", linkScmDevConnection - property "sonar.java.coveragePlugin", "jacoco" + property 'sonar.jacoco.reportPath', "${buildDir.name}/jacoco.exec" + property 'sonar.links.homepage', linkHomepage + property 'sonar.links.ci', linkCi + property 'sonar.links.issue', linkIssue + property 'sonar.links.scm', linkScmUrl + property 'sonar.links.scm_dev', linkScmDevConnection + property 'sonar.java.coveragePlugin', 'jacoco' } } @@ -155,17 +129,17 @@ task api(type: Javadoc) { options.author = true options.header = rootProject.description options.overview = 'src/api/overview.html' - options.stylesheetFile = file("src/api/stylesheet.css") + options.stylesheetFile = file('src/api/stylesheet.css') source = sourceSets.main.allJava classpath = project.sourceSets.main.compileClasspath - destinationDir = new File(buildDir, "api") + destinationDir = new File(buildDir, 'api') } task schemaZip(type: Zip) { group = 'Distribution' - classifier = 'schema' - description = "Builds -${classifier} archive containing all " + + archiveClassifier = 'schema' + description = "Builds -${archiveClassifier} archive containing all " + "XSDs for deployment at static.springframework.org/schema." duplicatesStrategy = 'exclude' @@ -190,8 +164,8 @@ task schemaZip(type: Zip) { task docsZip(type: Zip) { group = 'Distribution' - classifier = 'docs' - description = "Builds -${classifier} archive containing api " + + archiveClassifier = 'docs' + description = "Builds -${archiveClassifier} archive containing api " + "for deployment at static.spring.io/spring-integration/docs." from('src/dist') { @@ -205,8 +179,8 @@ task docsZip(type: Zip) { task distZip(type: Zip, dependsOn: [docsZip, schemaZip]) { group = 'Distribution' - classifier = 'dist' - description = "Builds -${classifier} archive, containing all jars and docs, " + + archiveClassifier = 'dist' + description = "Builds -${archiveClassifier} archive, containing all jars and docs, " + "suitable for community download page." ext.baseDir = "${project.name}-${project.version}"; @@ -218,11 +192,11 @@ task distZip(type: Zip, dependsOn: [docsZip, schemaZip]) { into "${baseDir}" } - from(zipTree(docsZip.archivePath)) { + from(zipTree(docsZip.archiveFile)) { into "${baseDir}/docs" } - from(zipTree(schemaZip.archivePath)) { + from(zipTree(schemaZip.archiveFile)) { into "${baseDir}/schema" } @@ -237,11 +211,11 @@ task distZip(type: Zip, dependsOn: [docsZip, schemaZip]) { // Not published by default; only for use when building from source. task depsZip(type: Zip, dependsOn: distZip) { zipTask -> group = 'Distribution' - classifier = 'dist-with-deps' - description = "Builds -${classifier} archive, containing everything " + - "in the -${distZip.classifier} archive plus all dependencies." + archiveClassifier = 'dist-with-deps' + description = "Builds -${archiveClassifier} archive, containing everything " + + "in the -${distZip.archiveClassifier} archive plus all dependencies." - from zipTree(distZip.archivePath) + from zipTree(distZip.archiveFile) gradle.taskGraph.whenReady { taskGraph -> if (taskGraph.hasTask(":${zipTask.name}")) { diff --git a/spring-integration-hazelcast/gradle.properties b/spring-integration-hazelcast/gradle.properties index 9733f28..dfe1192 100644 --- a/spring-integration-hazelcast/gradle.properties +++ b/spring-integration-hazelcast/gradle.properties @@ -1,2 +1 @@ -version=1.0.1.BUILD-SNAPSHOT -org.gradle.daemon=true +version=2.0.0.BUILD-SNAPSHOT diff --git a/spring-integration-hazelcast/gradle/wrapper/gradle-wrapper.jar b/spring-integration-hazelcast/gradle/wrapper/gradle-wrapper.jar index e27d71c..5c2d1cf 100644 Binary files a/spring-integration-hazelcast/gradle/wrapper/gradle-wrapper.jar and b/spring-integration-hazelcast/gradle/wrapper/gradle-wrapper.jar differ diff --git a/spring-integration-hazelcast/gradle/wrapper/gradle-wrapper.properties b/spring-integration-hazelcast/gradle/wrapper/gradle-wrapper.properties index e5af7b4..5028f28 100644 --- a/spring-integration-hazelcast/gradle/wrapper/gradle-wrapper.properties +++ b/spring-integration-hazelcast/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Fri Jul 07 17:27:53 EDT 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip diff --git a/spring-integration-hazelcast/gradlew b/spring-integration-hazelcast/gradlew index cccdd3d..83f2acf 100755 --- a/spring-integration-hazelcast/gradlew +++ b/spring-integration-hazelcast/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# 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 +# +# https://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. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -109,8 +125,8 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` diff --git a/spring-integration-hazelcast/gradlew.bat b/spring-integration-hazelcast/gradlew.bat index e95643d..24467a1 100644 --- a/spring-integration-hazelcast/gradlew.bat +++ b/spring-integration-hazelcast/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome diff --git a/spring-integration-hazelcast/publish-maven.gradle b/spring-integration-hazelcast/publish-maven.gradle index f1444f0..72a61b1 100644 --- a/spring-integration-hazelcast/publish-maven.gradle +++ b/spring-integration-hazelcast/publish-maven.gradle @@ -14,6 +14,17 @@ install { def customizePom(pom, gradleProject) { pom.whenConfigured { generatedPom -> + + // sort to make pom dependencies order consistent to ease comparison of older poms + generatedPom.dependencies = generatedPom.dependencies.sort { dep -> + "$dep.scope:$dep.groupId:$dep.artifactId" + } + + def managedVersions = dependencyManagement.managedVersions + generatedPom.dependencies.findAll{dep -> !dep.version }.each { dep -> + dep.version = managedVersions["${dep.groupId}:${dep.artifactId}"] + } + // respect 'optional' and 'provided' dependencies gradleProject.optionalDeps.each { dep -> generatedPom.dependencies.find { it.artifactId == dep.name }?.optional = true @@ -31,7 +42,7 @@ def customizePom(pom, gradleProject) { generatedPom.project { name = gradleProject.description description = gradleProject.description - url = linkHomepage + url = 'https://github.com/spring-projects/spring-integration-aws' organization { name = 'SpringIO' url = 'https://spring.io' @@ -43,18 +54,27 @@ def customizePom(pom, gradleProject) { distribution 'repo' } } - scm { - url = linkScmUrl - connection = 'scm:git:' + linkScmConnection - developerConnection = 'scm:git:' + linkScmDevConnection + url = 'https://github.com/spring-projects/spring-integration-aws' + connection = 'scm:git:git://github.com/spring-projects/spring-integration-aws' + developerConnection = 'scm:git:git://github.com/spring-projects/spring-integration-aws' } developers { developer { - id = 'erenavsarogullari' - name = 'Eren Avsarogullari' - email = 'erenavsarogullari@gmail.com' + id = 'amolnayak311' + name = 'Amol Nayak' + email = 'amolnayak311@gmail.com' + } + developer { + id = 'ghillert' + name = 'Gunnar Hillert' + email = 'ghillert@pivotal.io' + } + developer { + id = 'abilan' + name = 'Artem Bilan' + email = 'abilan@pivotal.io' } } } diff --git a/spring-integration-hazelcast/src/checkstyle/checkstyle.xml b/spring-integration-hazelcast/src/checkstyle/checkstyle.xml index 4b7a81e..c262bf5 100644 --- a/spring-integration-hazelcast/src/checkstyle/checkstyle.xml +++ b/spring-integration-hazelcast/src/checkstyle/checkstyle.xml @@ -103,9 +103,7 @@ - - - + diff --git a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/HazelcastLocalInstanceRegistrar.java b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/HazelcastLocalInstanceRegistrar.java index 03d104b..b1e6ad4 100644 --- a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/HazelcastLocalInstanceRegistrar.java +++ b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/HazelcastLocalInstanceRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2019 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. @@ -96,7 +96,7 @@ public class HazelcastLocalInstanceRegistrar implements SmartInitializingSinglet } private void syncConfigurationMultiMap(HazelcastInstance hazelcastInstance) { - Lock lock = hazelcastInstance.getLock(SPRING_INTEGRATION_INTERNAL_CLUSTER_LOCK); + Lock lock = hazelcastInstance.getCPSubsystem().getLock(SPRING_INTEGRATION_INTERNAL_CLUSTER_LOCK); lock.lock(); try { MultiMap multiMap = hazelcastInstance diff --git a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/inbound/AbstractHazelcastMessageProducer.java b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/inbound/AbstractHazelcastMessageProducer.java index cf79723..009cd54 100644 --- a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/inbound/AbstractHazelcastMessageProducer.java +++ b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/inbound/AbstractHazelcastMessageProducer.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2019 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. @@ -42,6 +42,7 @@ import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.MapEvent; import com.hazelcast.core.MultiMap; +import com.hazelcast.instance.EndpointQualifier; /** * Hazelcast Base Event-Driven Message Producer. @@ -118,10 +119,9 @@ public abstract class AbstractHazelcastMessageProducer extends MessageProducerSu final Set hazelcastInstanceSet = Hazelcast.getAllHazelcastInstances(); final Set localSocketAddressesSet = getLocalSocketAddresses(hazelcastInstanceSet); return localSocketAddressesSet.isEmpty() || - (!localSocketAddressesSet.isEmpty() - && (localSocketAddressesSet.contains(socketAddress) || - isEventComingFromNonRegisteredHazelcastInstance(hazelcastInstanceSet.iterator().next(), - localSocketAddressesSet, socketAddress))); + localSocketAddressesSet.contains(socketAddress) + || isEventComingFromNonRegisteredHazelcastInstance(hazelcastInstanceSet.iterator().next(), + localSocketAddressesSet, socketAddress); } @@ -193,19 +193,20 @@ public abstract class AbstractHazelcastMessageProducer extends MessageProducerSu if (AbstractHazelcastMessageProducer.this.logger.isDebugEnabled()) { AbstractHazelcastMessageProducer.this.logger.debug("Received Event : " + event); } - sendMessage(event, event.getMember().getSocketAddress(), getCacheListeningPolicy()); + sendMessage(event, + event.getMember().getSocketAddress(EndpointQualifier.MEMBER), getCacheListeningPolicy()); } } @Override - @SuppressWarnings("unchecked") protected Message toMessage(AbstractIMapEvent event) { - final Map headers = new HashMap(); + final Map headers = new HashMap<>(); headers.put(HazelcastHeaders.EVENT_TYPE, event.getEventType().name()); - headers.put(HazelcastHeaders.MEMBER, event.getMember().getSocketAddress()); + headers.put(HazelcastHeaders.MEMBER, event.getMember().getSocketAddress(EndpointQualifier.MEMBER)); headers.put(HazelcastHeaders.CACHE_NAME, event.getName()); if (event instanceof EntryEvent) { + @SuppressWarnings("unchecked") EntryEvent entryEvent = (EntryEvent) event; EntryEventMessagePayload messagePayload = new EntryEventMessagePayload<>(entryEvent.getKey(), entryEvent.getValue(), entryEvent.getOldValue()); diff --git a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/inbound/HazelcastEventDrivenMessageProducer.java b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/inbound/HazelcastEventDrivenMessageProducer.java index 3dcc11e..f873b5b 100644 --- a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/inbound/HazelcastEventDrivenMessageProducer.java +++ b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/inbound/HazelcastEventDrivenMessageProducer.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2018 the original author or authors. + * Copyright 2015-2019 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. @@ -35,6 +35,7 @@ import com.hazelcast.core.Message; import com.hazelcast.core.MessageListener; import com.hazelcast.core.MultiMap; import com.hazelcast.core.ReplicatedMap; +import com.hazelcast.instance.EndpointQualifier; import com.hazelcast.map.listener.MapListener; /** @@ -140,7 +141,8 @@ public class HazelcastEventDrivenMessageProducer extends AbstractHazelcastMessag @Override protected void processEvent(ItemEvent event) { if (getCacheEvents().contains(event.getEventType().toString())) { - sendMessage(event, event.getMember().getSocketAddress(), getCacheListeningPolicy()); + sendMessage(event, + event.getMember().getSocketAddress(EndpointQualifier.MEMBER), getCacheListeningPolicy()); } if (logger.isDebugEnabled()) { @@ -152,7 +154,7 @@ public class HazelcastEventDrivenMessageProducer extends AbstractHazelcastMessag protected org.springframework.messaging.Message toMessage(ItemEvent event) { final Map headers = new HashMap<>(); headers.put(HazelcastHeaders.EVENT_TYPE, event.getEventType().name()); - headers.put(HazelcastHeaders.MEMBER, event.getMember().getSocketAddress()); + headers.put(HazelcastHeaders.MEMBER, event.getMember().getSocketAddress(EndpointQualifier.MEMBER)); return getMessageBuilderFactory().withPayload(event.getItem()).copyHeaders(headers).build(); } @@ -169,7 +171,8 @@ public class HazelcastEventDrivenMessageProducer extends AbstractHazelcastMessag @Override protected void processEvent(Message event) { - sendMessage(event, event.getPublishingMember().getSocketAddress(), getCacheListeningPolicy()); + sendMessage(event, + event.getPublishingMember().getSocketAddress(EndpointQualifier.MEMBER), getCacheListeningPolicy()); if (logger.isDebugEnabled()) { logger.debug("Received Message : " + event); @@ -181,7 +184,8 @@ public class HazelcastEventDrivenMessageProducer extends AbstractHazelcastMessag Assert.notNull(event.getMessageObject(), "message must not be null"); final Map headers = new HashMap<>(); - headers.put(HazelcastHeaders.MEMBER, event.getPublishingMember().getSocketAddress()); + headers.put(HazelcastHeaders.MEMBER, + event.getPublishingMember().getSocketAddress(EndpointQualifier.MEMBER)); headers.put(HazelcastHeaders.CACHE_NAME, event.getSource()); headers.put(HazelcastHeaders.PUBLISHING_TIME, event.getPublishTime()); diff --git a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/leader/LeaderInitiator.java b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/leader/LeaderInitiator.java index 674bd2a..54f5dc8 100644 --- a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/leader/LeaderInitiator.java +++ b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/leader/LeaderInitiator.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2018 the original author or authors. + * Copyright 2015-2019 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. @@ -39,7 +39,7 @@ import org.springframework.integration.support.leader.LockRegistryLeaderInitiato import org.springframework.util.Assert; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.ILock; +import com.hazelcast.cp.lock.FencedLock; /** * Bootstrap leadership {@link org.springframework.integration.leader.Candidate candidates} @@ -106,7 +106,7 @@ public class LeaderInitiator implements SmartLifecycle, DisposableBean, Applicat /** * Hazelcast distributed lock. */ - private volatile ILock lock; + private volatile FencedLock lock; private boolean customPublisher = false; @@ -210,7 +210,7 @@ public class LeaderInitiator implements SmartLifecycle, DisposableBean, Applicat @Override public synchronized void start() { if (!this.running) { - this.lock = this.client.getLock(this.candidate.getRole()); + this.lock = this.client.getCPSubsystem().getLock(this.candidate.getRole()); this.leaderSelector = new LeaderSelector(); this.running = true; this.future = this.executorService.submit(this.leaderSelector); diff --git a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/listener/HazelcastMembershipListener.java b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/listener/HazelcastMembershipListener.java index 3db4061..4630bd9 100644 --- a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/listener/HazelcastMembershipListener.java +++ b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/listener/HazelcastMembershipListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2019 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. @@ -27,23 +27,28 @@ import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.MembershipAdapter; import com.hazelcast.core.MembershipEvent; import com.hazelcast.core.MultiMap; +import com.hazelcast.instance.EndpointQualifier; /** * Hazelcast {@link MembershipAdapter} in order to listen for membership updates in the cluster. * * @author Eren Avsarogullari + * @author Artem Bilan + * * @since 1.0.0 */ public class HazelcastMembershipListener extends MembershipAdapter { @Override public void memberRemoved(MembershipEvent membershipEvent) { - SocketAddress removedMemberSocketAddress = membershipEvent.getMember().getSocketAddress(); + SocketAddress removedMemberSocketAddress = + membershipEvent.getMember().getSocketAddress(EndpointQualifier.MEMBER); Set hazelcastLocalInstanceSet = Hazelcast.getAllHazelcastInstances(); if (!hazelcastLocalInstanceSet.isEmpty()) { HazelcastInstance hazelcastInstance = hazelcastLocalInstanceSet.iterator().next(); - Lock lock = hazelcastInstance - .getLock(HazelcastLocalInstanceRegistrar.SPRING_INTEGRATION_INTERNAL_CLUSTER_LOCK); + Lock lock = + hazelcastInstance.getCPSubsystem() + .getLock(HazelcastLocalInstanceRegistrar.SPRING_INTEGRATION_INTERNAL_CLUSTER_LOCK); lock.lock(); try { MultiMap configMultiMap = hazelcastInstance diff --git a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/lock/HazelcastLockRegistry.java b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/lock/HazelcastLockRegistry.java index 559a635..d010947 100644 --- a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/lock/HazelcastLockRegistry.java +++ b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/lock/HazelcastLockRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2019 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. @@ -40,7 +40,7 @@ public class HazelcastLockRegistry implements LockRegistry { @Override public Lock obtain(Object lockKey) { Assert.isInstanceOf(String.class, lockKey); - return this.client.getLock((String) lockKey); + return this.client.getCPSubsystem().getLock((String) lockKey); } } diff --git a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/outbound/HazelcastCacheWritingMessageHandler.java b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/outbound/HazelcastCacheWritingMessageHandler.java index adb5276..3262c39 100644 --- a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/outbound/HazelcastCacheWritingMessageHandler.java +++ b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/outbound/HazelcastCacheWritingMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2019 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. @@ -37,6 +37,7 @@ import com.hazelcast.core.MultiMap; * * @author Eren Avsarogullari * @author Artem Bilan + * * @since 1.0.0 */ public class HazelcastCacheWritingMessageHandler extends AbstractMessageHandler { @@ -71,14 +72,14 @@ public class HazelcastCacheWritingMessageHandler extends AbstractMessageHandler } @Override - protected void onInit() throws Exception { + protected void onInit() { super.onInit(); this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory()); } @Override @SuppressWarnings({"unchecked", "rawtypes"}) - protected void handleMessageInternal(final Message message) throws Exception { + protected void handleMessageInternal(final Message message) { Object objectToStore = message; if (this.extractPayload) { objectToStore = message.getPayload(); diff --git a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/store/HazelcastMessageStore.java b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/store/HazelcastMessageStore.java index 7428d85..3022653 100644 --- a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/store/HazelcastMessageStore.java +++ b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/store/HazelcastMessageStore.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2019 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. @@ -57,6 +57,16 @@ public class HazelcastMessageStore extends AbstractKeyValueMessageStore { this.map.put(id, objectToStore); } + @Override + protected void doStoreIfAbsent(Object id, Object objectToStore) { + this.map.putIfAbsent(id, objectToStore); + } + + @Override + protected void doRemoveAll(Collection ids) { + this.map.removeAll((mapEntry) -> ids.contains(mapEntry.getKey())); + } + @Override protected Object doRemove(Object id) { return this.map.remove(id); diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/HazelcastIntegrationDefinitionValidatorTests-context.xml b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/HazelcastIntegrationDefinitionValidatorTests-context.xml index 179174e..b731b11 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/HazelcastIntegrationDefinitionValidatorTests-context.xml +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/HazelcastIntegrationDefinitionValidatorTests-context.xml @@ -8,8 +8,7 @@ - + diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/HazelcastIntegrationDefinitionValidatorTests.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/HazelcastIntegrationDefinitionValidatorTests.java index 00948fe..c1a6a55 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/HazelcastIntegrationDefinitionValidatorTests.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/HazelcastIntegrationDefinitionValidatorTests.java @@ -16,13 +16,14 @@ package org.springframework.integration.hazelcast; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; import java.util.HashSet; import java.util.Set; import javax.annotation.Resource; +import org.junit.AfterClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -32,10 +33,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.hazelcast.core.DistributedObject; import com.hazelcast.core.IList; +import com.hazelcast.instance.HazelcastInstanceFactory; /** * Hazelcast Integration Definition Validator Test Class + * * @author Eren Avsarogullari + * @author Artem Bilan + * * @since 1.0.0 */ @RunWith(SpringJUnit4ClassRunner.class) @@ -46,13 +51,18 @@ public class HazelcastIntegrationDefinitionValidatorTests { @Resource private IList distList; + @AfterClass + public static void shutdown() { + HazelcastInstanceFactory.terminateAll(); + } + @Test public void testValidateEnumType() { final String cacheEventTypes = " ADDED, REMOVED, UPDATED, EVICTED, EVICT_ALL, CLEAR_ALL "; final Set typeSet = HazelcastIntegrationDefinitionValidator .validateEnumType(CacheEventType.class, cacheEventTypes); - assertTrue(typeSet.size() == 6); + assertEquals(6, typeSet.size()); for (String type : typeSet) { Enum.valueOf(CacheEventType.class, type); } diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/HazelcastTestRequestHandlerAdvice.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/HazelcastTestRequestHandlerAdvice.java index 74d2283..c8b1d61 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/HazelcastTestRequestHandlerAdvice.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/HazelcastTestRequestHandlerAdvice.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2019 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,6 +25,8 @@ import org.springframework.messaging.Message; * {@link AbstractRequestHandlerAdvice} advice class for Hazelcast Integration Unit Tests. * * @author Eren Avsarogullari + * @author Artem Bilan + * * @since 1.0.0 */ public class HazelcastTestRequestHandlerAdvice extends AbstractRequestHandlerAdvice { @@ -36,7 +38,7 @@ public class HazelcastTestRequestHandlerAdvice extends AbstractRequestHandlerAdv } @Override - protected Object doInvoke(ExecutionCallback callback, Object target, Message message) throws Exception { + protected Object doInvoke(ExecutionCallback callback, Object target, Message message) { try { return callback.execute(); } diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/common-config.xml b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/common-config.xml new file mode 100644 index 0000000..cd8f7a2 --- /dev/null +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/common-config.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastCQDistributedMapInboundChannelAdapterTests-context.xml b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastCQDistributedMapInboundChannelAdapterTests-context.xml index 33ff86a..0ff55f4 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastCQDistributedMapInboundChannelAdapterTests-context.xml +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastCQDistributedMapInboundChannelAdapterTests-context.xml @@ -10,6 +10,8 @@ http://www.springframework.org/schema/integration/hazelcast https://www.springframework.org/schema/integration/hazelcast/spring-integration-hazelcast.xsd"> + + @@ -32,41 +34,38 @@ + + predicate="name=TestName2"/> + + + predicate="surname=TestSurname2"/> + - + - + - + - + - + - - - - - - diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastCQDistributedMapInboundChannelAdapterTests.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastCQDistributedMapInboundChannelAdapterTests.java index a66f35e..6e003c5 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastCQDistributedMapInboundChannelAdapterTests.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastCQDistributedMapInboundChannelAdapterTests.java @@ -22,6 +22,7 @@ import static org.junit.Assert.assertTrue; import javax.annotation.Resource; +import org.junit.AfterClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -38,6 +39,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.hazelcast.core.EntryEventType; import com.hazelcast.core.IMap; +import com.hazelcast.instance.HazelcastInstanceFactory; /** * Hazelcast Continuous Query Inbound Channel Adapter Unit Test Class @@ -81,6 +83,11 @@ public class HazelcastCQDistributedMapInboundChannelAdapterTests { @Resource private IMap cqDistributedMap5; + @AfterClass + public static void shutdown() { + HazelcastInstanceFactory.terminateAll(); + } + @Test public void testContinuousQueryForOnlyADDEDEntryEvent() { HazelcastInboundChannelAdapterTestUtils diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastClusterMonitorInboundChannelAdapterTests.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastClusterMonitorInboundChannelAdapterTests.java index 197d8cd..8837695 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastClusterMonitorInboundChannelAdapterTests.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastClusterMonitorInboundChannelAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2019 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,6 +21,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import org.junit.AfterClass; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -42,16 +44,18 @@ import com.hazelcast.core.IMap; import com.hazelcast.core.LifecycleEvent; import com.hazelcast.core.LifecycleEvent.LifecycleState; import com.hazelcast.core.MigrationEvent; +import com.hazelcast.instance.HazelcastInstanceFactory; /** * Hazelcast Cluster Monitor Inbound Channel Adapter Unit Test Class * * @author Eren Avsarogullari - * @since 1.0.0 + * @author Artem Bilan */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @DirtiesContext +@Ignore("Hard to reach CP consensus with limited number of members in two clusters") public class HazelcastClusterMonitorInboundChannelAdapterTests { private static final String TEST_GROUP_NAME1 = "Test_Group_Name1"; @@ -83,6 +87,11 @@ public class HazelcastClusterMonitorInboundChannelAdapterTests { @Autowired private HazelcastInstance hazelcastInstance3; + @AfterClass + public static void shutdown() { + HazelcastInstanceFactory.terminateAll(); + } + @Test public void testMembershipEvent() { HazelcastInboundChannelAdapterTestUtils @@ -151,7 +160,6 @@ public class HazelcastClusterMonitorInboundChannelAdapterTests { 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"); diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedListEventDrivenInboundChannelAdapterTests-context.xml b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedListEventDrivenInboundChannelAdapterTests-context.xml index 7f430ef..23e52ac 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedListEventDrivenInboundChannelAdapterTests-context.xml +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedListEventDrivenInboundChannelAdapterTests-context.xml @@ -10,6 +10,8 @@ http://www.springframework.org/schema/integration/hazelcast https://www.springframework.org/schema/integration/hazelcast/spring-integration-hazelcast.xsd"> + + @@ -23,28 +25,22 @@ - + + + - + - + - + - - - - - - diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedListEventDrivenInboundChannelAdapterTests.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedListEventDrivenInboundChannelAdapterTests.java index 24f7691..9571533 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedListEventDrivenInboundChannelAdapterTests.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedListEventDrivenInboundChannelAdapterTests.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertNotNull; import javax.annotation.Resource; +import org.junit.AfterClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -36,6 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.hazelcast.core.EntryEventType; import com.hazelcast.core.IList; +import com.hazelcast.instance.HazelcastInstanceFactory; /** * Hazelcast Distributed List Event Driven Inbound Channel Adapter Test Class @@ -66,6 +68,11 @@ public class HazelcastDistributedListEventDrivenInboundChannelAdapterTests { @Resource private IList edDistributedList3; + @AfterClass + public static void shutdown() { + HazelcastInstanceFactory.terminateAll(); + } + @Test public void testEventDrivenForOnlyADDEDEntryEvent() { edDistributedList1.add(new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1")); diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedMapEventDrivenInboundChannelAdapterTests-context.xml b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedMapEventDrivenInboundChannelAdapterTests-context.xml index b701c9a..1664db3 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedMapEventDrivenInboundChannelAdapterTests-context.xml +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedMapEventDrivenInboundChannelAdapterTests-context.xml @@ -10,6 +10,8 @@ http://www.springframework.org/schema/integration/hazelcast https://www.springframework.org/schema/integration/hazelcast/spring-integration-hazelcast.xsd"> + + @@ -27,33 +29,28 @@ + - + + + - + - + - + - + - - - - - - diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedMapEventDrivenInboundChannelAdapterTests.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedMapEventDrivenInboundChannelAdapterTests.java index b65de69..0011c0d 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedMapEventDrivenInboundChannelAdapterTests.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedMapEventDrivenInboundChannelAdapterTests.java @@ -18,6 +18,7 @@ package org.springframework.integration.hazelcast.inbound; import javax.annotation.Resource; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -35,6 +36,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.hazelcast.core.EntryEventType; import com.hazelcast.core.IMap; +import com.hazelcast.instance.HazelcastInstanceFactory; /** * Hazelcast Distributed Map Event Driven Inbound Channel Adapter Test @@ -72,6 +74,11 @@ public class HazelcastDistributedMapEventDrivenInboundChannelAdapterTests { @Resource private IMap edDistributedMap4; + @AfterClass + public static void shutdown() { + HazelcastInstanceFactory.terminateAll(); + } + @Test public void testEventDrivenForOnlyADDEDEntryEvent() { HazelcastInboundChannelAdapterTestUtils diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedQueueEventDrivenInboundChannelAdapterTests-context.xml b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedQueueEventDrivenInboundChannelAdapterTests-context.xml index dafd070..315f221 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedQueueEventDrivenInboundChannelAdapterTests-context.xml +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedQueueEventDrivenInboundChannelAdapterTests-context.xml @@ -10,6 +10,8 @@ http://www.springframework.org/schema/integration/hazelcast https://www.springframework.org/schema/integration/hazelcast/spring-integration-hazelcast.xsd"> + + @@ -22,30 +24,24 @@ - + + + - + - + - + - - - - - - diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedQueueEventDrivenInboundChannelAdapterTests.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedQueueEventDrivenInboundChannelAdapterTests.java index 2b59688..ed77d6c 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedQueueEventDrivenInboundChannelAdapterTests.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedQueueEventDrivenInboundChannelAdapterTests.java @@ -18,6 +18,7 @@ package org.springframework.integration.hazelcast.inbound; import javax.annotation.Resource; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -34,6 +35,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.hazelcast.core.EntryEventType; import com.hazelcast.core.IQueue; +import com.hazelcast.instance.HazelcastInstanceFactory; /** * Hazelcast Distributed Queue Event Driven Inbound Channel Adapter Test @@ -64,6 +66,11 @@ public class HazelcastDistributedQueueEventDrivenInboundChannelAdapterTests { @Resource private IQueue edDistributedQueue3; + @AfterClass + public static void shutdown() { + HazelcastInstanceFactory.terminateAll(); + } + @Test public void testEventDrivenForOnlyADDEDEntryEvent() { edDistributedQueue1 diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedSQLInboundChannelAdapterTests-context.xml b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedSQLInboundChannelAdapterTests-context.xml index 8e3cfb6..9eeef6d 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedSQLInboundChannelAdapterTests-context.xml +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedSQLInboundChannelAdapterTests-context.xml @@ -10,6 +10,8 @@ http://www.springframework.org/schema/integration/hazelcast https://www.springframework.org/schema/integration/hazelcast/spring-integration-hazelcast.xsd"> + + @@ -37,36 +39,29 @@ + iteration-type="KEY" distributed-sql="age > 10 AND age <= 20"> - - + - + - + - + - - - - - - diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedSQLInboundChannelAdapterTests.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedSQLInboundChannelAdapterTests.java index 1030c61..f18eb86 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedSQLInboundChannelAdapterTests.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedSQLInboundChannelAdapterTests.java @@ -18,6 +18,7 @@ package org.springframework.integration.hazelcast.inbound; import javax.annotation.Resource; +import org.junit.AfterClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -30,6 +31,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.hazelcast.core.IMap; +import com.hazelcast.instance.HazelcastInstanceFactory; /** * Hazelcast Distributed SQL Inbound Channel Adapter Test @@ -66,6 +68,11 @@ public class HazelcastDistributedSQLInboundChannelAdapterTests { @Resource private IMap dsDistributedMap4; + @AfterClass + public static void shutdown() { + HazelcastInstanceFactory.terminateAll(); + } + @Test public void testDistributedSQLForOnlyENTRYIterationType() { HazelcastInboundChannelAdapterTestUtils diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedSetEventDrivenInboundChannelAdapterTests-context.xml b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedSetEventDrivenInboundChannelAdapterTests-context.xml index 6155284..416b1f2 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedSetEventDrivenInboundChannelAdapterTests-context.xml +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedSetEventDrivenInboundChannelAdapterTests-context.xml @@ -10,6 +10,8 @@ http://www.springframework.org/schema/integration/hazelcast https://www.springframework.org/schema/integration/hazelcast/spring-integration-hazelcast.xsd"> + + @@ -25,25 +27,18 @@ + cache-events="ADDED,REMOVED"/> - + - + - + - - - - - - diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedSetEventDrivenInboundChannelAdapterTests.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedSetEventDrivenInboundChannelAdapterTests.java index 19ec142..7f8c0fd 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedSetEventDrivenInboundChannelAdapterTests.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedSetEventDrivenInboundChannelAdapterTests.java @@ -18,6 +18,7 @@ package org.springframework.integration.hazelcast.inbound; import javax.annotation.Resource; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -34,6 +35,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.hazelcast.core.EntryEventType; import com.hazelcast.core.ISet; +import com.hazelcast.instance.HazelcastInstanceFactory; /** * Hazelcast Distributed Set Event Driven Inbound Channel Adapter Test @@ -64,6 +66,11 @@ public class HazelcastDistributedSetEventDrivenInboundChannelAdapterTests { @Resource private ISet edDistributedSet3; + @AfterClass + public static void shutdown() { + HazelcastInstanceFactory.terminateAll(); + } + @Test public void testEventDrivenForOnlyADDEDEntryEvent() { edDistributedSet1 diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedTopicEventDrivenInboundChannelAdapterTests-context.xml b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedTopicEventDrivenInboundChannelAdapterTests-context.xml index 081347a..655d4fc 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedTopicEventDrivenInboundChannelAdapterTests-context.xml +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedTopicEventDrivenInboundChannelAdapterTests-context.xml @@ -10,21 +10,16 @@ http://www.springframework.org/schema/integration/hazelcast https://www.springframework.org/schema/integration/hazelcast/spring-integration-hazelcast.xsd"> + + - + - - - - - - diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedTopicEventDrivenInboundChannelAdapterTests.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedTopicEventDrivenInboundChannelAdapterTests.java index b4e0f48..127f1b0 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedTopicEventDrivenInboundChannelAdapterTests.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastDistributedTopicEventDrivenInboundChannelAdapterTests.java @@ -18,6 +18,7 @@ package org.springframework.integration.hazelcast.inbound; import javax.annotation.Resource; +import org.junit.AfterClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -30,6 +31,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.hazelcast.core.ITopic; +import com.hazelcast.instance.HazelcastInstanceFactory; /** * Hazelcast Distributed Topic Event Driven Inbound Channel Adapter Test @@ -48,6 +50,11 @@ public class HazelcastDistributedTopicEventDrivenInboundChannelAdapterTests { @Resource private ITopic edDistributedTopic1; + @AfterClass + public static void shutdown() { + HazelcastInstanceFactory.terminateAll(); + } + @Test public void testEventDrivenForOnlyADDEDEntryEvent() { HazelcastInboundChannelAdapterTestUtils diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastMultiMapEventDrivenInboundChannelAdapterTests-context.xml b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastMultiMapEventDrivenInboundChannelAdapterTests-context.xml index 9bfcaf4..90fbb6b 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastMultiMapEventDrivenInboundChannelAdapterTests-context.xml +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastMultiMapEventDrivenInboundChannelAdapterTests-context.xml @@ -10,6 +10,8 @@ http://www.springframework.org/schema/integration/hazelcast https://www.springframework.org/schema/integration/hazelcast/spring-integration-hazelcast.xsd"> + + @@ -23,28 +25,20 @@ - + - + - + - + - - - - - - diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastMultiMapEventDrivenInboundChannelAdapterTests.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastMultiMapEventDrivenInboundChannelAdapterTests.java index bb83d7b..d6623d2 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastMultiMapEventDrivenInboundChannelAdapterTests.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastMultiMapEventDrivenInboundChannelAdapterTests.java @@ -18,6 +18,7 @@ package org.springframework.integration.hazelcast.inbound; import javax.annotation.Resource; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -35,6 +36,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.hazelcast.core.EntryEventType; import com.hazelcast.core.MultiMap; +import com.hazelcast.instance.HazelcastInstanceFactory; /** * Hazelcast MultiMap Event Driven Inbound Channel Adapter Test @@ -67,6 +69,11 @@ public class HazelcastMultiMapEventDrivenInboundChannelAdapterTests { @Resource private MultiMap edMultiMap3; + @AfterClass + public static void shutdown() { + HazelcastInstanceFactory.terminateAll(); + } + @Test public void testEventDrivenForOnlyADDEDEntryEvent() { edMultiMap1 diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastReplicatedMapEventDrivenInboundChannelAdapterTests-context.xml b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastReplicatedMapEventDrivenInboundChannelAdapterTests-context.xml index b326d07..4e7163f 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastReplicatedMapEventDrivenInboundChannelAdapterTests-context.xml +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastReplicatedMapEventDrivenInboundChannelAdapterTests-context.xml @@ -10,6 +10,8 @@ http://www.springframework.org/schema/integration/hazelcast https://www.springframework.org/schema/integration/hazelcast/spring-integration-hazelcast.xsd"> + + @@ -34,27 +36,20 @@ - + - + - + - + - - - - - - diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastReplicatedMapEventDrivenInboundChannelAdapterTests.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastReplicatedMapEventDrivenInboundChannelAdapterTests.java index 505f920..44e7e62 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastReplicatedMapEventDrivenInboundChannelAdapterTests.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/HazelcastReplicatedMapEventDrivenInboundChannelAdapterTests.java @@ -18,6 +18,7 @@ package org.springframework.integration.hazelcast.inbound; import javax.annotation.Resource; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -35,6 +36,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.hazelcast.core.EntryEventType; import com.hazelcast.core.ReplicatedMap; +import com.hazelcast.instance.HazelcastInstanceFactory; /** * Hazelcast Replicated Map Event Driven Inbound Channel Adapter Test @@ -72,6 +74,11 @@ public class HazelcastReplicatedMapEventDrivenInboundChannelAdapterTests { @Resource private ReplicatedMap edReplicatedMap4; + @AfterClass + public static void shutdown() { + HazelcastInstanceFactory.terminateAll(); + } + @Test public void testEventDrivenForOnlyADDEDEntryEvent() { edReplicatedMap1 diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/config/HazelcastIntegrationInboundTestConfiguration.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/config/HazelcastIntegrationInboundTestConfiguration.java index 0ae0db1..42765ce 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/config/HazelcastIntegrationInboundTestConfiguration.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/config/HazelcastIntegrationInboundTestConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2019 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,6 +16,8 @@ package org.springframework.integration.hazelcast.inbound.config; +import javax.annotation.PreDestroy; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.integration.annotation.InboundChannelAdapter; @@ -31,6 +33,7 @@ import org.springframework.integration.hazelcast.inbound.HazelcastDistributedSQL import org.springframework.integration.hazelcast.inbound.HazelcastEventDrivenMessageProducer; import org.springframework.messaging.PollableChannel; +import com.hazelcast.config.Config; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.IList; @@ -40,17 +43,23 @@ import com.hazelcast.core.ISet; import com.hazelcast.core.ITopic; import com.hazelcast.core.MultiMap; import com.hazelcast.core.ReplicatedMap; +import com.hazelcast.instance.HazelcastInstanceFactory; /** * Configuration Class for Hazelcast Integration Inbound Test * * @author Eren Avsarogullari - * @since 1.0.0 + * @author Artem Bilan */ @Configuration @EnableIntegration public class HazelcastIntegrationInboundTestConfiguration { + @PreDestroy + public void shutdown() { + HazelcastInstanceFactory.terminateAll(); + } + @Bean public PollableChannel distributedMapChannel() { return new QueueChannel(); @@ -212,8 +221,26 @@ public class HazelcastIntegrationInboundTestConfiguration { } @Bean + public Config hazelcastConfig() { + Config config = new Config(); + config.getCPSubsystemConfig().setCPMemberCount(3) + .setSessionHeartbeatIntervalSeconds(1); + return config; + } + + @Bean(destroyMethod = "") public HazelcastInstance testHazelcastInstance() { - return Hazelcast.newHazelcastInstance(); + return Hazelcast.newHazelcastInstance(hazelcastConfig()); + } + + @Bean(destroyMethod = "") + public HazelcastInstance testHazelcastInstance2() { + return Hazelcast.newHazelcastInstance(hazelcastConfig()); + } + + @Bean(destroyMethod = "") + public HazelcastInstance testHazelcastInstance3() { + return Hazelcast.newHazelcastInstance(hazelcastConfig()); } @Bean(HazelcastLocalInstanceRegistrar.BEAN_NAME) @@ -367,7 +394,7 @@ public class HazelcastIntegrationInboundTestConfiguration { final HazelcastDistributedSQLMessageSource messageSource = new HazelcastDistributedSQLMessageSource(testDSDistributedMap3(), "age > 5"); - messageSource.setIterationType(DistributedSQLIterationType.LOCAL_KEY); + messageSource.setIterationType(DistributedSQLIterationType.KEY); return messageSource; } diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/util/HazelcastInboundChannelAdapterTestUtils.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/util/HazelcastInboundChannelAdapterTestUtils.java index 3930ee8..0fac02b 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/util/HazelcastInboundChannelAdapterTestUtils.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/inbound/util/HazelcastInboundChannelAdapterTestUtils.java @@ -56,7 +56,7 @@ import com.hazelcast.spi.exception.DistributedObjectDestroyedException; @SuppressWarnings("unchecked") public final class HazelcastInboundChannelAdapterTestUtils { - public static final int TIMEOUT = 20_000; + public static final int TIMEOUT = 30_000; public static void verifyEntryEvent(Message msg, String cacheName, EntryEventType event) { @@ -350,7 +350,7 @@ public final class HazelcastInboundChannelAdapterTestUtils { public static void testMembershipEvent(final HazelcastInstance instance, final PollableChannel channel, final String key, final String value) { - Member member = instance.getCluster().getMembers().iterator().next(); + Member member = instance.getCluster().getLocalMember(); member.setStringAttribute(key, value); Message msg = channel.receive(TIMEOUT); diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/leader/LeaderInitiatorTests.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/leader/LeaderInitiatorTests.java index 530f662..44239eb 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/leader/LeaderInitiatorTests.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/leader/LeaderInitiatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2019 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. @@ -14,14 +14,13 @@ * limitations under the License. */ - package org.springframework.integration.hazelcast.leader; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.willAnswer; -import static org.mockito.Matchers.any; import static org.mockito.Mockito.spy; import java.util.ArrayList; @@ -29,6 +28,7 @@ import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import org.junit.AfterClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -45,8 +45,10 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import com.hazelcast.config.Config; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.instance.HazelcastInstanceFactory; /** * Tests for hazelcast leader election. @@ -73,6 +75,11 @@ public class LeaderInitiatorTests { @Autowired private LeaderInitiator initiator; + @AfterClass + public static void shutdown() { + HazelcastInstanceFactory.terminateAll(); + } + @Test public void testLeaderElections() throws Exception { assertThat(this.candidate.onGrantedLatch.await(5, TimeUnit.SECONDS), is(true)); @@ -174,7 +181,6 @@ public class LeaderInitiatorTests { initiator1.destroy(); - CountDownLatch onGranted = new CountDownLatch(1); DefaultCandidate candidate = spy(new DefaultCandidate()); @@ -218,8 +224,26 @@ public class LeaderInitiatorTests { } @Bean + public Config hazelcastConfig() { + Config config = new Config(); + config.getCPSubsystemConfig().setCPMemberCount(3) + .setSessionHeartbeatIntervalSeconds(1); + return config; + } + + @Bean(destroyMethod = "") public HazelcastInstance hazelcastInstance() { - return Hazelcast.newHazelcastInstance(); + return Hazelcast.newHazelcastInstance(hazelcastConfig()); + } + + @Bean(destroyMethod = "") + public HazelcastInstance hazelcastInstance2() { + return Hazelcast.newHazelcastInstance(hazelcastConfig()); + } + + @Bean(destroyMethod = "") + public HazelcastInstance hazelcastInstance3() { + return Hazelcast.newHazelcastInstance(hazelcastConfig()); } @Bean @@ -250,7 +274,7 @@ public class LeaderInitiatorTests { CountDownLatch onEventLatch = new CountDownLatch(1); - ArrayList events = new ArrayList(); + ArrayList events = new ArrayList<>(); @Override public void onApplicationEvent(AbstractLeaderEvent event) { @@ -282,6 +306,11 @@ public class LeaderInitiatorTests { this.revoked.countDown(); } + @Override + public void publishOnFailedToAcquire(Object source, Context context, String role) { + + } + @Override public void publishOnGranted(Object source, Context context, String role) { this.initiator = (LeaderInitiator) source; diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/lock/HazelcastLockRegistryTests.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/lock/HazelcastLockRegistryTests.java index 8ddf37a..d9853a8 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/lock/HazelcastLockRegistryTests.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/lock/HazelcastLockRegistryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2019 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. @@ -35,31 +35,43 @@ import java.util.concurrent.locks.Lock; import org.junit.AfterClass; import org.junit.Test; +import com.hazelcast.config.Config; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.ILock; +import com.hazelcast.cp.lock.FencedLock; +import com.hazelcast.instance.HazelcastInstanceFactory; /** * @author Artem Bilan */ public class HazelcastLockRegistryTests { - private static final HazelcastInstance instance = Hazelcast.newHazelcastInstance(); + private static Config config = new Config(); + + static { + config.getCPSubsystemConfig().setCPMemberCount(3); + } + + private static final HazelcastInstance instance = Hazelcast.newHazelcastInstance(config); + + private static final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config); + + private static final HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(config); @AfterClass - public static void destroy() throws Exception { - instance.shutdown(); + public static void destroy() { + HazelcastInstanceFactory.terminateAll(); } @Test - public void testLock() throws Exception { + public void testLock() { HazelcastLockRegistry registry = new HazelcastLockRegistry(instance); for (int i = 0; i < 10; i++) { Lock lock = registry.obtain("foo"); lock.lock(); try { - assertTrue(((ILock) lock).isLocked()); - assertTrue(((ILock) lock).isLockedByCurrentThread()); + assertTrue(((FencedLock) lock).isLocked()); + assertTrue(((FencedLock) lock).isLockedByCurrentThread()); } finally { lock.unlock(); @@ -74,8 +86,8 @@ public class HazelcastLockRegistryTests { Lock lock = registry.obtain("foo"); lock.lockInterruptibly(); try { - assertTrue(((ILock) lock).isLocked()); - assertTrue(((ILock) lock).isLockedByCurrentThread()); + assertTrue(((FencedLock) lock).isLocked()); + assertTrue(((FencedLock) lock).isLockedByCurrentThread()); } finally { lock.unlock(); @@ -84,7 +96,7 @@ public class HazelcastLockRegistryTests { } @Test - public void testReentrantLock() throws Exception { + public void testReentrantLock() { HazelcastLockRegistry registry = new HazelcastLockRegistry(instance); for (int i = 0; i < 10; i++) { Lock lock1 = registry.obtain("foo"); diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/metadata/HazelcastMetadataStoreTests.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/metadata/HazelcastMetadataStoreTests.java index a346d88..d191a7c 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/metadata/HazelcastMetadataStoreTests.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/metadata/HazelcastMetadataStoreTests.java @@ -52,8 +52,8 @@ public class HazelcastMetadataStoreTests { } @AfterClass - public static void destroy() throws Exception { - instance.shutdown(); + public static void destroy() { + instance.getLifecycleService().terminate(); } @Before diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/outbound/HazelcastOutboundChannelAdapterTests-context.xml b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/outbound/HazelcastOutboundChannelAdapterTests-context.xml index dd0e804..aaf7a85 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/outbound/HazelcastOutboundChannelAdapterTests-context.xml +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/outbound/HazelcastOutboundChannelAdapterTests-context.xml @@ -10,6 +10,8 @@ http://www.springframework.org/schema/integration/hazelcast https://www.springframework.org/schema/integration/hazelcast/spring-integration-hazelcast.xsd"> + + @@ -225,7 +227,7 @@ - + @@ -265,19 +267,14 @@ - + - + + + - - - - - - diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/outbound/HazelcastOutboundChannelAdapterTests.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/outbound/HazelcastOutboundChannelAdapterTests.java index 3686565..5dda7b4 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/outbound/HazelcastOutboundChannelAdapterTests.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/outbound/HazelcastOutboundChannelAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2019 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. @@ -35,6 +35,7 @@ import java.util.concurrent.TimeUnit; import javax.annotation.Resource; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -58,12 +59,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.hazelcast.core.ITopic; import com.hazelcast.core.MultiMap; import com.hazelcast.core.ReplicatedMap; +import com.hazelcast.instance.HazelcastInstanceFactory; /** * Hazelcast Outbound Channel Adapter Test Class. * * @author Eren Avsarogullari * @author Artem Bilan + * * @since 1.0.0 */ @RunWith(SpringJUnit4ClassRunner.class) @@ -247,6 +250,11 @@ public class HazelcastOutboundChannelAdapterTests { @Qualifier("testTopicRequestHandlerAdvice") private HazelcastTestRequestHandlerAdvice testTopicRequestHandlerAdvice; + @AfterClass + public static void shutdown() { + HazelcastInstanceFactory.terminateAll(); + } + @Before public void setUp() { this.distributedMap.clear(); @@ -263,7 +271,7 @@ public class HazelcastOutboundChannelAdapterTests { } @Test - public void testWriteToDistributedMap() throws InterruptedException { + public void testWriteToDistributedMap() { HazelcastOutboundChannelAdapterTestUtils .testWriteToDistributedMap(this.firstMapChannel, this.distributedMap, this.testFirstMapRequestHandlerAdvice); @@ -459,7 +467,7 @@ public class HazelcastOutboundChannelAdapterTests { final Map> map) { int index = 1; assertNotNull(map); - assertEquals(true, map.size() == HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT); + assertEquals(HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT, map.size()); for (Entry> entry : map.entrySet()) { assertNotNull(entry); assertEquals(index, entry.getKey().intValue()); diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/outbound/config/HazelcastIntegrationOutboundTestConfiguration.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/outbound/config/HazelcastIntegrationOutboundTestConfiguration.java index 3aab1a8..38a7a62 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/outbound/config/HazelcastIntegrationOutboundTestConfiguration.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/outbound/config/HazelcastIntegrationOutboundTestConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2019 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. @@ -20,6 +20,8 @@ import java.util.List; import java.util.Queue; import java.util.Set; +import javax.annotation.PreDestroy; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -41,11 +43,14 @@ import com.hazelcast.core.IMap; import com.hazelcast.core.ITopic; import com.hazelcast.core.MultiMap; import com.hazelcast.core.ReplicatedMap; +import com.hazelcast.instance.HazelcastInstanceFactory; /** * Configuration Class for Hazelcast Integration Outbound Test * * @author Eren Avsarogullari + * @author Artem Bilan + * * @since 1.0.0 */ @Configuration @@ -54,6 +59,11 @@ import com.hazelcast.core.ReplicatedMap; @IntegrationComponentScan("org.springframework.integration.hazelcast.outbound") public class HazelcastIntegrationOutboundTestConfiguration { + @PreDestroy + public void terminate() { + HazelcastInstanceFactory.terminateAll(); + } + @Bean public MessageChannel distMapChannel() { return new DirectChannel(); @@ -134,7 +144,7 @@ public class HazelcastIntegrationOutboundTestConfiguration { return testHzInstance().getReplicatedMap("Replicated_Map1"); } - @Bean + @Bean(destroyMethod = "") public HazelcastInstance testHzInstance() { return Hazelcast.newHazelcastInstance(); } diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/outbound/config/HazelcastOutboundChannelAdapterConfigTests.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/outbound/config/HazelcastOutboundChannelAdapterConfigTests.java index cefbbcc..b054799 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/outbound/config/HazelcastOutboundChannelAdapterConfigTests.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/outbound/config/HazelcastOutboundChannelAdapterConfigTests.java @@ -22,6 +22,7 @@ import java.util.Set; import javax.annotation.Resource; +import org.junit.AfterClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -40,6 +41,7 @@ import com.hazelcast.core.IMap; import com.hazelcast.core.ITopic; import com.hazelcast.core.MultiMap; import com.hazelcast.core.ReplicatedMap; +import com.hazelcast.instance.HazelcastInstanceFactory; /** * Hazelcast Outbound Channel Adapter JavaConfig driven Unit Test Class @@ -141,6 +143,11 @@ public class HazelcastOutboundChannelAdapterConfigTests { @Qualifier("replicatedMapRequestHandlerAdvice") private HazelcastTestRequestHandlerAdvice replicatedMapRequestHandlerAdvice; + @AfterClass + public static void shutdown() { + HazelcastInstanceFactory.terminateAll(); + } + @Test public void testWriteToDistributedMap() { HazelcastOutboundChannelAdapterTestUtils diff --git a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/store/HazelcastMessageStoreTests.java b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/store/HazelcastMessageStoreTests.java index 2259d6a..04cd4ac 100644 --- a/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/store/HazelcastMessageStoreTests.java +++ b/spring-integration-hazelcast/src/test/java/org/springframework/integration/hazelcast/store/HazelcastMessageStoreTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2019 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. @@ -55,24 +55,24 @@ public class HazelcastMessageStoreTests { private static IMap map; @BeforeClass - public static void init() throws Exception { + public static void init() { instance = Hazelcast.newHazelcastInstance(); map = instance.getMap("customTestsMessageStore"); store = new HazelcastMessageStore(map); } @AfterClass - public static void destroy() throws Exception { - instance.shutdown(); + public static void destroy() { + instance.getLifecycleService().terminate(); } @Before - public void clean() throws Exception { + public void clean() { map.clear(); } @Test - public void testWithMessageHistory() throws Exception { + public void testWithMessageHistory() { Message message = new GenericMessage<>("Hello"); DirectChannel fooChannel = new DirectChannel(); @@ -94,7 +94,7 @@ public class HazelcastMessageStoreTests { } @Test - public void testAddAndRemoveMessagesFromMessageGroup() throws Exception { + public void testAddAndRemoveMessagesFromMessageGroup() { String groupId = "X"; List> messages = new ArrayList<>(); for (int i = 0; i < 25; i++) { @@ -110,7 +110,7 @@ public class HazelcastMessageStoreTests { } @Test - public void addAndGetMessage() throws Exception { + public void addAndGetMessage() { Message message = MessageBuilder.withPayload("test").build(); store.addMessage(message); @@ -119,14 +119,14 @@ public class HazelcastMessageStoreTests { } @Test - public void customMap() throws Exception { + public void customMap() { assertSame(map, TestUtils.getPropertyValue(store, "map")); HazelcastMessageStore store2 = new HazelcastMessageStore(instance); assertNotSame(map, TestUtils.getPropertyValue(store2, "map")); } @Test - public void messageStoreSize() throws Exception { + public void messageStoreSize() { Message message1 = MessageBuilder.withPayload("test").build(); Message message2 = MessageBuilder.withPayload("test").build(); store.addMessage(message1);