Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.replicatedmap.ReplicatedMap;
import org.apache.camel.CamelContext;
import org.apache.camel.Route;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit6.CamelTestSupport;
Expand Down Expand Up @@ -56,9 +57,18 @@ public void afterEach() {
}

@BeforeEach
public void resetState() {
public void resetState() throws Exception {
// Stop routes to deregister the Hazelcast entry listener before clearing
// the map. This prevents async REMOVED events from clear() from bleeding
// into the next test's mock expectations.
for (Route route : context.getRoutes()) {
context.getRouteController().stopRoute(route.getRouteId());
}
map.clear();
MockEndpoint.resetMocks(context);
for (Route route : context.getRoutes()) {
context.getRouteController().startRoute(route.getRouteId());
}
}

@Override
Expand All @@ -83,19 +93,26 @@ public void testAdd() throws InterruptedException {
* mail from talip (hazelcast) on 21.02.2011: MultiMap doesn't support eviction yet. We can and should add this feature.
*/
@Test
public void testEvict() {
public void testEvict() throws InterruptedException {
MockEndpoint out = getMockEndpoint("mock:evicted");
out.expectedMessageCount(1);
map.put("4711", "my-foo", 100, TimeUnit.MILLISECONDS);
Awaitility.await().atMost(30000, TimeUnit.MILLISECONDS).untilAsserted(
() -> MockEndpoint.assertIsSatisfied(context));
MockEndpoint.assertIsSatisfied(context, 30000, TimeUnit.MILLISECONDS);
}

@Test
public void testRemove() throws InterruptedException {
MockEndpoint out = getMockEndpoint("mock:removed");
out.expectedMessageCount(1);

map.put("4711", "my-foo");

// Wait for the ADDED event to be fully processed before removing,
// otherwise the remove may execute before the async ADDED event is delivered.
MockEndpoint added = getMockEndpoint("mock:added");
Awaitility.await().atMost(5, TimeUnit.SECONDS)
.until(() -> added.getReceivedCounter() >= 1);

map.remove("4711");
MockEndpoint.assertIsSatisfied(context, 5000, TimeUnit.MILLISECONDS);
this.checkHeaders(out.getExchanges().get(0).getIn().getHeaders(), HazelcastConstants.REMOVED);
Expand Down