Prepare project for release

* Upgrade to the latest dependencies
* Migrate assertions in tests to AssertJ
* Optimize tests to use unsafe mode for CP-subsystem
for better test execution performance
This commit is contained in:
Artem Bilan
2020-10-29 14:01:29 -04:00
parent b568662cdb
commit 43ae2d630b
20 changed files with 434 additions and 577 deletions

View File

@@ -28,7 +28,7 @@ compileJava {
ext {
hazelcastVersion = '4.0.3'
slf4jVersion = '1.7.30'
springIntegrationVersion = '5.4.0-SNAPSHOT'
springIntegrationVersion = '5.4.0'
idPrefix = 'hazelcast'

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 the original author or authors.
* Copyright 2015-2020 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,7 +16,7 @@
package org.springframework.integration.hazelcast;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashSet;
import java.util.Set;
@@ -62,7 +62,7 @@ public class HazelcastIntegrationDefinitionValidatorTests {
" ADDED, REMOVED, UPDATED, EVICTED, EVICT_ALL, CLEAR_ALL ";
final Set<String> typeSet = HazelcastIntegrationDefinitionValidator
.validateEnumType(CacheEventType.class, cacheEventTypes);
assertEquals(6, typeSet.size());
assertThat(typeSet.size()).isEqualTo(6);
for (String type : typeSet) {
Enum.valueOf(CacheEventType.class, type);
}

View File

@@ -8,15 +8,11 @@
<bean class="com.hazelcast.config.Config">
<property name="CPSubsystemConfig">
<bean class="com.hazelcast.config.cp.CPSubsystemConfig">
<property name="CPMemberCount" value="3"/>
<property name="CPMemberCount" value="0"/>
</bean>
</property>
</bean>
</constructor-arg>
</bean>
<bean id="instance2" parent="instance"/>
<bean id="instance3" parent="instance"/>
</beans>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2020 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,9 +16,7 @@
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.assertj.core.api.Assertions.assertThat;
import javax.annotation.Resource;
@@ -104,27 +102,21 @@ public class HazelcastCQDistributedMapInboundChannelAdapterTests {
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));
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof EntryEventMessagePayload).isTrue();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE)).isEqualTo(EntryEventType.REMOVED.name());
assertThat(msg.getHeaders().get(HazelcastHeaders.CACHE_NAME)).isEqualTo("cqDistributedMap2");
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());
assertThat(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key).isEqualTo(Integer.valueOf(2));
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId()).isEqualTo(2);
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName()).isEqualTo("TestName2");
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname()).isEqualTo("TestSurname2");
}
@Test
@@ -142,36 +134,27 @@ public class HazelcastCQDistributedMapInboundChannelAdapterTests {
.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));
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof EntryEventMessagePayload).isTrue();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE)).isEqualTo(EntryEventType.UPDATED.name());
assertThat(msg.getHeaders().get(HazelcastHeaders.CACHE_NAME)).isEqualTo("cqDistributedMap4");
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());
assertThat(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key).isEqualTo(Integer.valueOf(1));
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId()).isEqualTo(1);
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName()).isEqualTo("TestName1");
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname()).isEqualTo("TestSurname1");
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId()).isEqualTo(2);
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName()).isEqualTo("TestName2");
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname()).isEqualTo("TestSurname2");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* Copyright 2015-2020 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,9 +16,7 @@
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.assertj.core.api.Assertions.assertThat;
import org.junit.AfterClass;
import org.junit.Ignore;
@@ -107,18 +105,18 @@ public class HazelcastClusterMonitorInboundChannelAdapterTests {
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());
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof LifecycleEvent).isTrue();
assertThat(((LifecycleEvent) msg.getPayload()).getState()).isEqualTo(lifecycleState);
}
private void verifyClientEvent(final Message<?> msg) {
assertNotNull(msg);
assertNotNull(msg.getPayload());
assertTrue(msg.getPayload() instanceof Client);
assertEquals(ConnectionType.JAVA_CLIENT, ((Client) msg.getPayload()).getClientType());
assertNotNull(((Client) msg.getPayload()).getSocketAddress());
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof Client).isTrue();
assertThat(((Client) msg.getPayload()).getClientType()).isEqualTo(ConnectionType.JAVA_CLIENT);
assertThat(((Client) msg.getPayload()).getSocketAddress()).isNotNull();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2020 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,8 +16,7 @@
package org.springframework.integration.hazelcast.inbound;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import javax.annotation.Resource;
@@ -77,13 +76,13 @@ public class HazelcastDistributedListEventDrivenInboundChannelAdapterTests {
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());
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString()).isEqualTo(EntryEventType.ADDED.toString());
assertThat(((HazelcastIntegrationTestUser) msg.getPayload()).getId()).isEqualTo(1);
assertThat(((HazelcastIntegrationTestUser) msg.getPayload()).getName()).isEqualTo("TestName1");
assertThat(((HazelcastIntegrationTestUser) msg.getPayload()).getSurname()).isEqualTo("TestSurname1");
}
@Test
@@ -92,13 +91,13 @@ public class HazelcastDistributedListEventDrivenInboundChannelAdapterTests {
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());
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString()).isEqualTo(EntryEventType.REMOVED.toString());
assertThat(((HazelcastIntegrationTestUser) msg.getPayload()).getId()).isEqualTo(2);
assertThat(((HazelcastIntegrationTestUser) msg.getPayload()).getName()).isEqualTo("TestName2");
assertThat(((HazelcastIntegrationTestUser) msg.getPayload()).getSurname()).isEqualTo("TestSurname2");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2020 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,11 @@
package org.springframework.integration.hazelcast.inbound;
import static org.assertj.core.api.Assertions.assertThat;
import javax.annotation.Resource;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -94,36 +95,27 @@ public class HazelcastDistributedMapEventDrivenInboundChannelAdapterTests {
.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));
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof EntryEventMessagePayload).isTrue();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE)).isEqualTo(EntryEventType.UPDATED.name());
assertThat(msg.getHeaders().get(HazelcastHeaders.CACHE_NAME)).isEqualTo("edDistributedMap2");
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());
assertThat(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key).isEqualTo(Integer.valueOf(2));
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId()).isEqualTo(1);
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName()).isEqualTo("TestName1");
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname()).isEqualTo("TestSurname1");
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId()).isEqualTo(2);
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName()).isEqualTo("TestName2");
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname()).isEqualTo("TestSurname2");
}
@Test
@@ -135,27 +127,21 @@ public class HazelcastDistributedMapEventDrivenInboundChannelAdapterTests {
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));
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof EntryEventMessagePayload).isTrue();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE)).isEqualTo(EntryEventType.REMOVED.name());
assertThat(msg.getHeaders().get(HazelcastHeaders.CACHE_NAME)).isEqualTo("edDistributedMap3");
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());
assertThat(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key).isEqualTo(Integer.valueOf(2));
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId()).isEqualTo(2);
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName()).isEqualTo("TestName2");
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname()).isEqualTo("TestSurname2");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2020 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,11 @@
package org.springframework.integration.hazelcast.inbound;
import static org.assertj.core.api.Assertions.assertThat;
import javax.annotation.Resource;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -77,17 +78,13 @@ public class HazelcastDistributedQueueEventDrivenInboundChannelAdapterTests {
.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()));
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString()).isEqualTo(EntryEventType.ADDED.toString());
assertThat((((HazelcastIntegrationTestUser) msg.getPayload()).getId())).isEqualTo(1);
assertThat((((HazelcastIntegrationTestUser) msg.getPayload()).getName())).isEqualTo("TestName1");
assertThat((((HazelcastIntegrationTestUser) msg.getPayload()).getSurname())).isEqualTo("TestSurname1");
}
@Test
@@ -98,17 +95,13 @@ public class HazelcastDistributedQueueEventDrivenInboundChannelAdapterTests {
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()));
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString()).isEqualTo(EntryEventType.REMOVED.toString());
assertThat((((HazelcastIntegrationTestUser) msg.getPayload()).getId())).isEqualTo(2);
assertThat((((HazelcastIntegrationTestUser) msg.getPayload()).getName())).isEqualTo("TestName2");
assertThat((((HazelcastIntegrationTestUser) msg.getPayload()).getSurname())).isEqualTo("TestSurname2");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2020 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,11 @@
package org.springframework.integration.hazelcast.inbound;
import static org.assertj.core.api.Assertions.assertThat;
import javax.annotation.Resource;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -77,17 +78,13 @@ public class HazelcastDistributedSetEventDrivenInboundChannelAdapterTests {
.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()));
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString()).isEqualTo(EntryEventType.ADDED.toString());
assertThat((((HazelcastIntegrationTestUser) msg.getPayload()).getId())).isEqualTo(1);
assertThat((((HazelcastIntegrationTestUser) msg.getPayload()).getName())).isEqualTo("TestName1");
assertThat((((HazelcastIntegrationTestUser) msg.getPayload()).getSurname())).isEqualTo("TestSurname1");
}
@Test
@@ -98,17 +95,13 @@ public class HazelcastDistributedSetEventDrivenInboundChannelAdapterTests {
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()));
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString()).isEqualTo(EntryEventType.REMOVED.toString());
assertThat((((HazelcastIntegrationTestUser) msg.getPayload()).getId())).isEqualTo(2);
assertThat((((HazelcastIntegrationTestUser) msg.getPayload()).getName())).isEqualTo("TestName2");
assertThat((((HazelcastIntegrationTestUser) msg.getPayload()).getSurname())).isEqualTo("TestSurname2");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2020 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,11 @@
package org.springframework.integration.hazelcast.inbound;
import static org.assertj.core.api.Assertions.assertThat;
import javax.annotation.Resource;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -80,27 +81,21 @@ public class HazelcastMultiMapEventDrivenInboundChannelAdapterTests {
.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));
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof EntryEventMessagePayload).isTrue();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE)).isEqualTo(EntryEventType.ADDED.name());
assertThat(msg.getHeaders().get(HazelcastHeaders.CACHE_NAME)).isEqualTo("edMultiMap1");
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());
assertThat(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key).isEqualTo(Integer.valueOf(1));
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId()).isEqualTo(1);
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName()).isEqualTo("TestName1");
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname()).isEqualTo("TestSurname1");
}
@Test
@@ -112,28 +107,22 @@ public class HazelcastMultiMapEventDrivenInboundChannelAdapterTests {
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));
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof EntryEventMessagePayload).isTrue();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE)).isEqualTo(EntryEventType.REMOVED.name());
assertThat(msg.getHeaders().get(HazelcastHeaders.CACHE_NAME)).isEqualTo("edMultiMap2");
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());
assertThat(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key).isEqualTo(Integer.valueOf(2));
assertThat(((EntryEventMessagePayload<?, ?>) msg.getPayload()).value).isNull();
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId()).isEqualTo(2);
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName()).isEqualTo("TestName2");
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname()).isEqualTo("TestSurname2");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2020 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,11 @@
package org.springframework.integration.hazelcast.inbound;
import static org.assertj.core.api.Assertions.assertThat;
import javax.annotation.Resource;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -85,27 +86,21 @@ public class HazelcastReplicatedMapEventDrivenInboundChannelAdapterTests {
.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));
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof EntryEventMessagePayload).isTrue();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE)).isEqualTo(EntryEventType.ADDED.name());
assertThat(msg.getHeaders().get(HazelcastHeaders.CACHE_NAME)).isEqualTo("edReplicatedMap1");
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());
assertThat(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key).isEqualTo(Integer.valueOf(1));
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId()).isEqualTo(1);
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName()).isEqualTo("TestName1");
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname()).isEqualTo("TestSurname1");
}
@Test
@@ -116,37 +111,28 @@ public class HazelcastReplicatedMapEventDrivenInboundChannelAdapterTests {
.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2"));
Message<?> msg = edReplicatedMapChannel2
.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
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));
assertThat(msg.getPayload() instanceof EntryEventMessagePayload).isTrue();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE)).isEqualTo(EntryEventType.UPDATED.name());
assertThat(msg.getHeaders().get(HazelcastHeaders.CACHE_NAME)).isEqualTo("edReplicatedMap2");
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());
assertThat(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key).isEqualTo(Integer.valueOf(2));
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId()).isEqualTo(1);
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName()).isEqualTo("TestName1");
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname()).isEqualTo("TestSurname1");
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId()).isEqualTo(2);
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName()).isEqualTo("TestName2");
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname()).isEqualTo("TestSurname2");
}
@Test
@@ -158,27 +144,21 @@ public class HazelcastReplicatedMapEventDrivenInboundChannelAdapterTests {
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));
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof EntryEventMessagePayload).isTrue();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE)).isEqualTo(EntryEventType.REMOVED.name());
assertThat(msg.getHeaders().get(HazelcastHeaders.CACHE_NAME)).isEqualTo("edReplicatedMap3");
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());
assertThat(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key).isEqualTo(Integer.valueOf(2));
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getId()).isEqualTo(2);
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getName()).isEqualTo("TestName2");
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).getSurname()).isEqualTo("TestSurname2");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* Copyright 2015-2020 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.
@@ -223,7 +223,7 @@ public class HazelcastIntegrationInboundTestConfiguration {
@Bean
public Config hazelcastConfig() {
Config config = new Config();
config.getCPSubsystemConfig().setCPMemberCount(3)
config.getCPSubsystemConfig().setCPMemberCount(0)
.setSessionHeartbeatIntervalSeconds(1);
return config;
}
@@ -233,16 +233,6 @@ public class HazelcastIntegrationInboundTestConfiguration {
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)
public HazelcastLocalInstanceRegistrar hazelcastLocalInstanceRegistrar() {
return new HazelcastLocalInstanceRegistrar(testHazelcastInstance());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2020 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,19 +16,12 @@
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 static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.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;
@@ -59,27 +52,25 @@ public final class HazelcastInboundChannelAdapterTestUtils {
public static void verifyEntryEvent(Message<?> msg, String cacheName,
EntryEventType event) {
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
if (event == EntryEventType.CLEAR_ALL || event == EntryEventType.EVICT_ALL) {
Assert.assertTrue(msg.getPayload() instanceof Integer);
assertThat(msg.getPayload() instanceof Integer).isTrue();
}
else {
Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload);
assertThat(msg.getPayload() instanceof EntryEventMessagePayload).isTrue();
}
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));
assertThat(msg.getHeaders().get(HazelcastHeaders.CACHE_NAME)).isEqualTo(cacheName);
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE)).isEqualTo(event.name());
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
}
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());
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE).toString()).isEqualTo(event.toString());
}
public static void testEventDrivenForADDEDDistributedMapEntryEvent(
@@ -89,26 +80,21 @@ public final class HazelcastInboundChannelAdapterTestUtils {
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));
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof EntryEventMessagePayload).isTrue();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE)).isEqualTo(EntryEventType.ADDED.name());
assertThat(msg.getHeaders().get(HazelcastHeaders.CACHE_NAME)).isEqualTo(cacheName);
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());
assertThat(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key).isEqualTo(Integer.valueOf(1));
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getId()).isEqualTo(1);
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getName()).isEqualTo("TestName1");
assertThat((((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).getSurname()).isEqualTo("TestSurname1");
}
public static void testEventDrivenForDistributedMapEntryEvents(
@@ -184,17 +170,14 @@ public final class HazelcastInboundChannelAdapterTestUtils {
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());
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.PUBLISHING_TIME)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.CACHE_NAME)).isEqualTo(topic.getName());
assertThat(((HazelcastIntegrationTestUser) msg.getPayload()).getId()).isEqualTo(1);
assertThat(((HazelcastIntegrationTestUser) msg.getPayload()).getName()).isEqualTo("TestName1");
assertThat(((HazelcastIntegrationTestUser) msg.getPayload()).getSurname()).isEqualTo("TestSurname1");
}
public static void testEventDrivenForMultiMapEntryEvents(
@@ -232,21 +215,19 @@ public final class HazelcastInboundChannelAdapterTestUtils {
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));
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof EntryEventMessagePayload).isTrue();
assertThat(msg.getHeaders().get(HazelcastHeaders.MEMBER)).isNotNull();
assertThat(msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE)).isEqualTo(EntryEventType.UPDATED.name());
assertThat(msg.getHeaders().get(HazelcastHeaders.CACHE_NAME)).isEqualTo(cacheName);
assertEquals(Integer.valueOf(1),
((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key);
assertNull(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue);
assertNull(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value);
assertThat(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).key).isEqualTo(Integer.valueOf(1));
assertThat(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).oldValue).isNull();
assertThat(((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg
.getPayload()).value).isNull();
}
public static void testDistributedSQLForENTRYIterationType(
@@ -265,21 +246,17 @@ public final class HazelcastInboundChannelAdapterTestUtils {
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());
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof Collection).isTrue();
assertThat((((Map.Entry<?, ?>) ((Collection<?>) msg.getPayload()).iterator().next())
.getKey())).isEqualTo(4);
assertThat(((HazelcastIntegrationTestUser) ((Map.Entry<?, ?>) ((Collection<?>) msg
.getPayload()).iterator().next()).getValue()).getId()).isEqualTo(4);
assertThat(((HazelcastIntegrationTestUser) ((Map.Entry<?, ?>) ((Collection<?>) msg
.getPayload()).iterator().next()).getValue()).getName()).isEqualTo("TestName4");
assertThat(((HazelcastIntegrationTestUser) ((Map.Entry<?, ?>) ((Collection<?>) msg
.getPayload()).iterator().next()).getValue()).getSurname()).isEqualTo("TestSurname4");
}
public static void testDistributedSQLForKEYIterationType(
@@ -294,10 +271,10 @@ public final class HazelcastInboundChannelAdapterTestUtils {
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());
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof Collection).isTrue();
assertThat(((Collection<?>) msg.getPayload()).iterator().next()).isEqualTo(1);
}
public static void testDistributedSQLForLOCAL_KEYIterationType(
@@ -312,9 +289,9 @@ public final class HazelcastInboundChannelAdapterTestUtils {
Message<?> msg = channel.receive(TIMEOUT);
Assert.assertNotNull(msg);
Assert.assertNotNull(msg.getPayload());
Assert.assertTrue(msg.getPayload() instanceof Collection);
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof Collection).isTrue();
}
public static void testDistributedSQLForVALUEIterationType(
@@ -333,18 +310,15 @@ public final class HazelcastInboundChannelAdapterTestUtils {
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());
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof Collection).isTrue();
assertThat(((HazelcastIntegrationTestUser) (((Collection<?>) msg.getPayload()).iterator()
.next())).getId()).isEqualTo(3);
assertThat(((HazelcastIntegrationTestUser) (((Collection<?>) msg.getPayload()).iterator()
.next())).getName()).isEqualTo("TestName3");
assertThat(((HazelcastIntegrationTestUser) (((Collection<?>) msg.getPayload()).iterator()
.next())).getSurname()).isEqualTo("TestSurname3");
}
public static void testDistributedObjectEventByChannelAndHazelcastInstance(
@@ -366,30 +340,28 @@ public final class HazelcastInboundChannelAdapterTestUtils {
fail("DistributedObjectDestroyedException expected");
}
catch (Exception e) {
assertThat(e, instanceOf(DistributedObjectDestroyedException.class));
assertThat(e).isInstanceOf(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());
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof MembershipEvent).isTrue();
assertThat(((MembershipEvent) msg.getPayload()).getEventType()).isEqualTo(membershipEvent);
assertThat(((MembershipEvent) msg.getPayload()).getMember()).isNotNull();
}
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);
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isNotNull();
assertThat(msg.getPayload() instanceof DistributedObjectEvent).isTrue();
assertThat(((DistributedObjectEvent) msg.getPayload()).getEventType()).isEqualTo(eventType);
assertThat(distributedObjectName).as((((DistributedObjectEvent) msg.getPayload()).getDistributedObject())
.getName()).isNotNull();
}
private HazelcastInboundChannelAdapterTestUtils() {

View File

@@ -16,10 +16,7 @@
package org.springframework.integration.hazelcast.leader;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.willAnswer;
import static org.mockito.Mockito.spy;
@@ -84,9 +81,9 @@ public class LeaderInitiatorTests {
@Test
public void testLeaderElections() throws Exception {
assertTrue(this.candidate.onGrantedLatch.await(5, TimeUnit.SECONDS));
assertTrue(this.listener.onEventLatch.await(5, TimeUnit.SECONDS));
assertEquals(1, this.listener.events.size());
assertThat(this.candidate.onGrantedLatch.await(5, TimeUnit.SECONDS)).isTrue();
assertThat(this.listener.onEventLatch.await(5, TimeUnit.SECONDS)).isTrue();
assertThat(this.listener.events.size()).isEqualTo(1);
this.initiator.destroy();
@@ -103,7 +100,7 @@ public class LeaderInitiatorTests {
initiator.start();
}
assertTrue(granted.await(10, TimeUnit.SECONDS));
assertThat(granted.await(10, TimeUnit.SECONDS)).isTrue();
LeaderInitiator initiator1 = countingPublisher.initiator;
@@ -116,10 +113,10 @@ public class LeaderInitiatorTests {
}
}
assertNotNull(initiator2);
assertThat(initiator2).isNotNull();
assertTrue(initiator1.getContext().isLeader());
assertFalse(initiator2.getContext().isLeader());
assertThat(initiator1.getContext().isLeader()).isTrue();
assertThat(initiator2.getContext().isLeader()).isFalse();
final CountDownLatch granted1 = new CountDownLatch(1);
final CountDownLatch granted2 = new CountDownLatch(1);
@@ -131,7 +128,7 @@ public class LeaderInitiatorTests {
public void publishOnRevoked(Object source, Context context, String role) {
try {
// It's difficult to see round-robin election, so block one initiator until the second is elected.
assertTrue(granted2.await(10, TimeUnit.SECONDS));
assertThat(granted2.await(10, TimeUnit.SECONDS)).isTrue();
}
catch (InterruptedException e) {
// No op
@@ -147,7 +144,7 @@ public class LeaderInitiatorTests {
public void publishOnRevoked(Object source, Context context, String role) {
try {
// It's difficult to see round-robin election, so block one initiator until the second is elected.
assertTrue(granted1.await(10, TimeUnit.SECONDS));
assertThat(granted1.await(10, TimeUnit.SECONDS)).isTrue();
}
catch (InterruptedException e) {
// No op
@@ -159,17 +156,17 @@ public class LeaderInitiatorTests {
initiator1.getContext().yield();
assertTrue(revoked1.await(10, TimeUnit.SECONDS));
assertThat(revoked1.await(10, TimeUnit.SECONDS)).isTrue();
assertTrue(initiator2.getContext().isLeader());
assertFalse(initiator1.getContext().isLeader());
assertThat(initiator2.getContext().isLeader()).isTrue();
assertThat(initiator1.getContext().isLeader()).isFalse();
initiator2.getContext().yield();
assertTrue(revoked2.await(10, TimeUnit.SECONDS));
assertThat(revoked2.await(10, TimeUnit.SECONDS)).isTrue();
assertTrue(initiator1.getContext().isLeader());
assertFalse(initiator2.getContext().isLeader());
assertThat(initiator1.getContext().isLeader()).isTrue();
assertThat(initiator2.getContext().isLeader()).isFalse();
initiator2.destroy();
@@ -178,7 +175,7 @@ public class LeaderInitiatorTests {
initiator1.getContext().yield();
assertTrue(revoked11.await(10, TimeUnit.SECONDS));
assertThat(revoked11.await(10, TimeUnit.SECONDS)).isTrue();
initiator1.destroy();
@@ -209,9 +206,9 @@ public class LeaderInitiatorTests {
initiator.start();
assertTrue(onGranted.await(5, TimeUnit.SECONDS));
assertThat(onGranted.await(5, TimeUnit.SECONDS)).isTrue();
assertTrue(initiator.getContext().isLeader());
assertThat(initiator.getContext().isLeader()).isTrue();
initiator.destroy();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 the original author or authors.
* Copyright 2017-2020 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,7 @@
package org.springframework.integration.hazelcast.lock;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
@@ -46,17 +39,13 @@ import com.hazelcast.instance.impl.HazelcastInstanceFactory;
*/
public class HazelcastLockRegistryTests {
private static Config config = new Config();
private static final Config CONFIG = new Config();
static {
config.getCPSubsystemConfig().setCPMemberCount(3);
CONFIG.getCPSubsystemConfig().setCPMemberCount(0);
}
private static final HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
private static final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);
private static final HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(config);
private static final HazelcastInstance instance = Hazelcast.newHazelcastInstance(CONFIG);
@AfterClass
public static void destroy() {
@@ -70,8 +59,8 @@ public class HazelcastLockRegistryTests {
Lock lock = registry.obtain("foo");
lock.lock();
try {
assertTrue(((FencedLock) lock).isLocked());
assertTrue(((FencedLock) lock).isLockedByCurrentThread());
assertThat(((FencedLock) lock).isLocked()).isTrue();
assertThat(((FencedLock) lock).isLockedByCurrentThread()).isTrue();
}
finally {
lock.unlock();
@@ -86,8 +75,8 @@ public class HazelcastLockRegistryTests {
Lock lock = registry.obtain("foo");
lock.lockInterruptibly();
try {
assertTrue(((FencedLock) lock).isLocked());
assertTrue(((FencedLock) lock).isLockedByCurrentThread());
assertThat(((FencedLock) lock).isLocked()).isTrue();
assertThat(((FencedLock) lock).isLockedByCurrentThread()).isTrue();
}
finally {
lock.unlock();
@@ -103,7 +92,7 @@ public class HazelcastLockRegistryTests {
lock1.lock();
try {
Lock lock2 = registry.obtain("foo");
assertSame(lock1, lock2);
assertThat(lock2).isSameAs(lock1);
lock2.lock();
lock2.unlock();
}
@@ -121,7 +110,7 @@ public class HazelcastLockRegistryTests {
lock1.lockInterruptibly();
try {
Lock lock2 = registry.obtain("foo");
assertSame(lock1, lock2);
assertThat(lock2).isSameAs(lock1);
lock2.lockInterruptibly();
lock2.unlock();
}
@@ -139,7 +128,7 @@ public class HazelcastLockRegistryTests {
lock1.lockInterruptibly();
try {
Lock lock2 = registry.obtain("bar");
assertNotSame(lock1, lock2);
assertThat(lock2).isNotSameAs(lock1);
lock2.lockInterruptibly();
lock2.unlock();
}
@@ -168,12 +157,12 @@ public class HazelcastLockRegistryTests {
}
return null;
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertFalse(locked.get());
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(locked.get()).isFalse();
lock1.unlock();
Object ise = result.get(10, TimeUnit.SECONDS);
assertThat(ise, instanceOf(IllegalMonitorStateException.class));
assertThat(((Exception) ise).getMessage(), containsString("Current thread is not owner of the lock!"));
assertThat(ise).isInstanceOf(IllegalMonitorStateException.class);
assertThat(((Exception) ise).getMessage()).contains("Current thread is not owner of the lock!");
}
@Test
@@ -201,12 +190,12 @@ public class HazelcastLockRegistryTests {
latch3.countDown();
}
});
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertFalse(locked.get());
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(locked.get()).isFalse();
lock1.unlock();
latch2.countDown();
assertTrue(latch3.await(10, TimeUnit.SECONDS));
assertTrue(locked.get());
assertThat(latch3.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(locked.get()).isTrue();
}
@Test
@@ -235,12 +224,12 @@ public class HazelcastLockRegistryTests {
latch3.countDown();
}
});
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertFalse(locked.get());
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(locked.get()).isFalse();
lock1.unlock();
latch2.countDown();
assertTrue(latch3.await(10, TimeUnit.SECONDS));
assertTrue(locked.get());
assertThat(latch3.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(locked.get()).isTrue();
}
@Test
@@ -260,12 +249,12 @@ public class HazelcastLockRegistryTests {
}
return null;
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertFalse(locked.get());
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(locked.get()).isFalse();
lock.unlock();
Object imse = result.get(10, TimeUnit.SECONDS);
assertThat(imse, instanceOf(IllegalMonitorStateException.class));
assertThat(((Exception) imse).getMessage(), containsString("Current thread is not owner of the lock!"));
assertThat(imse).isInstanceOf(IllegalMonitorStateException.class);
assertThat(((Exception) imse).getMessage()).contains("Current thread is not owner of the lock!");
}
@Test
@@ -278,7 +267,7 @@ public class HazelcastLockRegistryTests {
while (!lock.tryLock() && n++ < 100) {
Thread.sleep(100);
}
assertThat(n, lessThan(100));
assertThat(n).isLessThan(100);
lock.unlock();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2020 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,9 +16,8 @@
package org.springframework.integration.hazelcast.metadata;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -70,13 +69,13 @@ public class HazelcastMetadataStoreTests {
@Test
public void testGetNonExistingKeyValue() {
String retrievedValue = this.metadataStore.get("does-not-exist");
assertNull(retrievedValue);
assertThat(retrievedValue).isNull();
}
@Test
public void testPersistKeyValue() {
this.metadataStore.put("HazelcastMetadataStoreTests-Spring", "Integration");
assertEquals("Integration", map.get("HazelcastMetadataStoreTests-Spring"));
assertThat(map.get("HazelcastMetadataStoreTests-Spring")).isEqualTo("Integration");
}
@Test
@@ -84,7 +83,7 @@ public class HazelcastMetadataStoreTests {
this.metadataStore.put("HazelcastMetadataStoreTests-GetValue", "Hello Hazelcast");
String retrievedValue = this.metadataStore
.get("HazelcastMetadataStoreTests-GetValue");
assertEquals("Hello Hazelcast", retrievedValue);
assertThat(retrievedValue).isEqualTo("Hello Hazelcast");
}
@Test
@@ -93,7 +92,7 @@ public class HazelcastMetadataStoreTests {
String retrievedValue = this.metadataStore
.get("HazelcastMetadataStoreTests-PersistEmpty");
assertEquals("", retrievedValue);
assertThat(retrievedValue).isEqualTo("");
}
@Test
@@ -103,7 +102,7 @@ public class HazelcastMetadataStoreTests {
fail("Expected an IllegalArgumentException to be thrown.");
}
catch (IllegalArgumentException e) {
assertEquals("'value' must not be null.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("'value' must not be null.");
}
}
@@ -112,7 +111,7 @@ public class HazelcastMetadataStoreTests {
this.metadataStore.put("", "PersistWithEmptyKey");
String retrievedValue = this.metadataStore.get("");
assertEquals("PersistWithEmptyKey", retrievedValue);
assertThat(retrievedValue).isEqualTo("PersistWithEmptyKey");
}
@Test
@@ -123,7 +122,7 @@ public class HazelcastMetadataStoreTests {
}
catch (IllegalArgumentException e) {
assertEquals("'key' must not be null.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("'key' must not be null.");
}
}
@@ -133,7 +132,7 @@ public class HazelcastMetadataStoreTests {
this.metadataStore.get(null);
}
catch (IllegalArgumentException e) {
assertEquals("'key' must not be null.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("'key' must not be null.");
return;
}
@@ -147,23 +146,23 @@ public class HazelcastMetadataStoreTests {
this.metadataStore.put(testKey, testValue);
assertEquals(testValue, this.metadataStore.remove(testKey));
assertNull(this.metadataStore.remove(testKey));
assertThat(this.metadataStore.remove(testKey)).isEqualTo(testValue);
assertThat(this.metadataStore.remove(testKey)).isNull();
}
@Test
public void testPersistKeyValueIfAbsent() {
this.metadataStore.putIfAbsent("HazelcastMetadataStoreTests-Spring",
"Integration");
assertEquals("Integration", map.get("HazelcastMetadataStoreTests-Spring"));
assertThat(map.get("HazelcastMetadataStoreTests-Spring")).isEqualTo("Integration");
}
@Test
public void testReplaceValue() {
this.metadataStore.put("key", "old");
assertEquals("old", map.get("key"));
assertThat(map.get("key")).isEqualTo("old");
this.metadataStore.replace("key", "old", "new");
assertEquals("new", map.get("key"));
assertThat(map.get("key")).isEqualTo("new");
}
@Test

View File

@@ -227,7 +227,7 @@
<constructor-arg value="distributedMap"/>
</bean>
<bean id="distributedBulkMap" factory-bean="instance2" factory-method="getMap">
<bean id="distributedBulkMap" factory-bean="instance" factory-method="getMap">
<constructor-arg value="distributedBulkMap"/>
</bean>
@@ -267,7 +267,7 @@
<constructor-arg value="bulkReplicatedMap"/>
</bean>
<bean id="topic" factory-bean="instance3" factory-method="getTopic">
<bean id="topic" factory-bean="instance" factory-method="getTopic">
<constructor-arg value="topic"/>
</bean>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* Copyright 2015-2020 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,9 +16,7 @@
package org.springframework.integration.hazelcast.outbound;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.Collections;
@@ -289,8 +287,8 @@ public class HazelcastOutboundChannelAdapterTests {
throws InterruptedException {
sendMessageWithCacheHeaderToChannel(this.secondMapChannel, CACHE_HEADER,
DISTRIBUTED_MAP);
assertTrue(this.testSecondMapRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS));
assertThat(this.testSecondMapRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS)).isTrue();
HazelcastOutboundChannelAdapterTestUtils
.verifyMapForPayload(new TreeMap(this.distributedMap));
}
@@ -300,8 +298,8 @@ public class HazelcastOutboundChannelAdapterTests {
throws InterruptedException {
sendMessageWithCacheHeaderToChannel(this.thirdMapChannel,
HazelcastHeaders.CACHE_NAME, DISTRIBUTED_MAP);
assertTrue(this.testThirdMapRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS));
assertThat(this.testThirdMapRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS)).isTrue();
HazelcastOutboundChannelAdapterTestUtils
.verifyMapForPayload(new TreeMap(this.distributedMap));
}
@@ -311,8 +309,8 @@ public class HazelcastOutboundChannelAdapterTests {
throws InterruptedException {
sendMessageWithCacheHeaderToChannel(this.fourthMapChannel,
HazelcastHeaders.CACHE_NAME, DISTRIBUTED_MAP);
assertTrue(this.testFourthMapRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS));
assertThat(this.testFourthMapRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS)).isTrue();
verifyMapForMessage(new TreeMap(this.distributedMap));
}
@@ -342,8 +340,8 @@ public class HazelcastOutboundChannelAdapterTests {
this.bulkReplicatedMapChannel.send(new GenericMessage<>(userMap));
assertTrue(this.testBulkReplicatedMapRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS));
assertThat(this.testBulkReplicatedMapRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS)).isTrue();
HazelcastOutboundChannelAdapterTestUtils
.verifyMapForPayload(new TreeMap(this.bulkReplicatedMap));
}
@@ -367,8 +365,8 @@ public class HazelcastOutboundChannelAdapterTests {
this.bulkListChannel.send(new GenericMessage<>(userList));
assertTrue(this.testBulkListRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS));
assertThat(this.testBulkListRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS)).isTrue();
HazelcastOutboundChannelAdapterTestUtils
.verifyCollection(this.distributedBulkList,
HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
@@ -392,8 +390,8 @@ public class HazelcastOutboundChannelAdapterTests {
this.bulkSetChannel.send(new GenericMessage<>(userSet));
assertTrue(this.testBulkSetRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS));
assertThat(this.testBulkSetRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS)).isTrue();
final List<HazelcastIntegrationTestUser> list =
new ArrayList(this.distributedBulkSet);
Collections.sort(list);
@@ -419,8 +417,8 @@ public class HazelcastOutboundChannelAdapterTests {
this.bulkQueueChannel.send(new GenericMessage<>(userQueue));
assertTrue(this.testBulkQueueRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS));
assertThat(this.testBulkQueueRequestHandlerAdvice.executeLatch
.await(10, TimeUnit.SECONDS)).isTrue();
HazelcastOutboundChannelAdapterTestUtils
.verifyCollection(this.distributedBulkQueue,
HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
@@ -466,12 +464,12 @@ public class HazelcastOutboundChannelAdapterTests {
private void verifyMapForMessage(
final Map<Integer, Message<HazelcastIntegrationTestUser>> map) {
int index = 1;
assertNotNull(map);
assertEquals(HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT, map.size());
assertThat(map).isNotNull();
assertThat(map.size()).isEqualTo(HazelcastOutboundChannelAdapterTestUtils.DATA_COUNT);
for (Entry<Integer, Message<HazelcastIntegrationTestUser>> entry : map.entrySet()) {
assertNotNull(entry);
assertEquals(index, entry.getKey().intValue());
assertTrue(entry.getValue().getHeaders().size() > 0);
assertThat(entry).isNotNull();
assertThat(entry.getKey().intValue()).isEqualTo(index);
assertThat(entry.getValue().getHeaders().size() > 0).isTrue();
HazelcastOutboundChannelAdapterTestUtils
.verifyHazelcastIntegrationTestUser(entry.getValue().getPayload(), index);
index++;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2020 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,8 @@
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 static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.util.ArrayList;
import java.util.Collection;
@@ -73,7 +71,7 @@ public final class HazelcastOutboundChannelAdapterTestUtils {
HazelcastTestRequestHandlerAdvice requestHandlerAdvice) {
try {
sendMessageToChannel(channel);
assertTrue(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS));
assertThat(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS)).isTrue();
verifyMapForPayload(new TreeMap(distributedMap));
}
catch (InterruptedException e) {
@@ -93,7 +91,7 @@ public final class HazelcastOutboundChannelAdapterTestUtils {
channel.send(new GenericMessage<>(userMap));
assertTrue(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS));
assertThat(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS)).isTrue();
verifyMapForPayload(new TreeMap(distributedMap));
}
catch (InterruptedException e) {
@@ -106,7 +104,7 @@ public final class HazelcastOutboundChannelAdapterTestUtils {
HazelcastTestRequestHandlerAdvice requestHandlerAdvice) {
try {
sendMessageToChannel(channel);
assertTrue(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS));
assertThat(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS)).isTrue();
verifyMultiMapForPayload(multiMap);
}
catch (InterruptedException e) {
@@ -131,7 +129,7 @@ public final class HazelcastOutboundChannelAdapterTestUtils {
HazelcastTestRequestHandlerAdvice requestHandlerAdvice) {
try {
sendMessageToChannel(channel);
assertTrue(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS));
assertThat(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS)).isTrue();
verifyCollection(distributedList, DATA_COUNT);
}
catch (InterruptedException e) {
@@ -144,7 +142,7 @@ public final class HazelcastOutboundChannelAdapterTestUtils {
HazelcastTestRequestHandlerAdvice requestHandlerAdvice) {
try {
sendMessageToChannel(channel);
assertTrue(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS));
assertThat(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS)).isTrue();
final List<HazelcastIntegrationTestUser> list = new ArrayList(distributedSet);
Collections.sort(list);
verifyCollection(list, DATA_COUNT);
@@ -177,7 +175,7 @@ public final class HazelcastOutboundChannelAdapterTestUtils {
}
});
sendMessageToChannel(channel);
assertTrue(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS));
assertThat(requestHandlerAdvice.executeLatch.await(10, TimeUnit.SECONDS)).isTrue();
}
catch (InterruptedException e) {
fail("Test has been failed due to " + e.getMessage());
@@ -193,11 +191,11 @@ public final class HazelcastOutboundChannelAdapterTestUtils {
public static void verifyMapForPayload(
final Map<Integer, HazelcastIntegrationTestUser> map) {
int index = 1;
assertNotNull(map);
assertEquals(true, map.size() == DATA_COUNT);
assertThat(map).isNotNull();
assertThat(map.size() == DATA_COUNT).isEqualTo(true);
for (Map.Entry<Integer, HazelcastIntegrationTestUser> entry : map.entrySet()) {
assertNotNull(entry);
assertEquals(index, entry.getKey().intValue());
assertThat(entry).isNotNull();
assertThat(entry.getKey().intValue()).isEqualTo(index);
verifyHazelcastIntegrationTestUser(entry.getValue(), index);
index++;
}
@@ -206,8 +204,8 @@ public final class HazelcastOutboundChannelAdapterTestUtils {
public static void verifyCollection(
final Collection<HazelcastIntegrationTestUser> coll, final int dataCount) {
int index = 1;
assertNotNull(coll);
assertEquals(true, coll.size() == dataCount);
assertThat(coll).isNotNull();
assertThat(coll.size() == dataCount).isEqualTo(true);
for (HazelcastIntegrationTestUser user : coll) {
verifyHazelcastIntegrationTestUser(user, index);
index++;
@@ -216,11 +214,11 @@ public final class HazelcastOutboundChannelAdapterTestUtils {
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());
assertThat(user).isNotNull();
assertThat(user.getId()).isEqualTo(index);
assertThat(user.getName()).isEqualTo(TEST_NAME);
assertThat(user.getSurname()).isEqualTo(TEST_SURNAME);
assertThat(user.getAge()).isEqualTo(index + DEFAULT_AGE);
}
private static void sendMessageToChannel(final MessageChannel channel) {
@@ -232,12 +230,12 @@ public final class HazelcastOutboundChannelAdapterTestUtils {
private static void verifyMultiMapForPayload(
final MultiMap<Integer, HazelcastIntegrationTestUser> multiMap) {
int index = 1;
assertNotNull(multiMap);
assertEquals(true, multiMap.size() == DATA_COUNT);
assertThat(multiMap).isNotNull();
assertThat(multiMap.size() == DATA_COUNT).isEqualTo(true);
SortedSet<Integer> keys = new TreeSet<>(multiMap.keySet());
for (Integer key : keys) {
assertNotNull(key);
assertEquals(index, key.intValue());
assertThat(key).isNotNull();
assertThat(key.intValue()).isEqualTo(index);
HazelcastIntegrationTestUser user = multiMap.get(key).iterator().next();
verifyHazelcastIntegrationTestUser(user, index);
index++;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 the original author or authors.
* Copyright 2017-2020 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,7 @@
package org.springframework.integration.hazelcast.store;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
@@ -85,11 +82,11 @@ public class HazelcastMessageStoreTests {
store.addMessage(message);
message = store.getMessage(message.getHeaders().getId());
MessageHistory messageHistory = MessageHistory.read(message);
assertNotNull(messageHistory);
assertEquals(2, messageHistory.size());
assertThat(messageHistory).isNotNull();
assertThat(messageHistory.size()).isEqualTo(2);
Properties fooChannelHistory = messageHistory.get(0);
assertEquals("fooChannel", fooChannelHistory.get("name"));
assertEquals("channel", fooChannelHistory.get("type"));
assertThat(fooChannelHistory.get("name")).isEqualTo("fooChannel");
assertThat(fooChannelHistory.get("type")).isEqualTo("channel");
}
@@ -103,10 +100,10 @@ public class HazelcastMessageStoreTests {
messages.add(message);
}
MessageGroup group = store.getMessageGroup(groupId);
assertEquals(25, group.size());
assertThat(group.size()).isEqualTo(25);
store.removeMessagesFromGroup(groupId, messages);
group = store.getMessageGroup(groupId);
assertEquals(0, group.size());
assertThat(group.size()).isEqualTo(0);
}
@Test
@@ -115,14 +112,14 @@ public class HazelcastMessageStoreTests {
Message<?> message = MessageBuilder.withPayload("test").build();
store.addMessage(message);
Message<?> retrieved = store.getMessage(message.getHeaders().getId());
assertEquals(message, retrieved);
assertThat(retrieved).isEqualTo(message);
}
@Test
public void customMap() {
assertSame(map, TestUtils.getPropertyValue(store, "map"));
assertThat(TestUtils.getPropertyValue(store, "map")).isSameAs(map);
HazelcastMessageStore store2 = new HazelcastMessageStore(instance);
assertNotSame(map, TestUtils.getPropertyValue(store2, "map"));
assertThat(TestUtils.getPropertyValue(store2, "map")).isNotSameAs(map);
}
@Test
@@ -132,7 +129,7 @@ public class HazelcastMessageStoreTests {
store.addMessage(message1);
store.addMessage(message2);
long size = store.getMessageCount();
assertEquals(2, size);
assertThat(size).isEqualTo(2);
}
}