From bf7729b936d110ffa8cd8f18d3a31738270c0814 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Tue, 9 Feb 2016 08:21:05 -0600 Subject: [PATCH] Close only used HazelcastInstance * It might be dangerous to shutdownAll() HazelcastInstances from the test-case, especially when we are ran in with the integration test and on the CI environment. Therefore extract the instance variable in the test and close only it from the @AfterClass * Fix typo in the AbstractHazelcastRepositoryITests test method name * Increase lock wait timeout to the 10 seconds in the SessionEventRegistry. Looks like 3 seconds isn't enough for my Windows machine. Fixes gh-358 gh-360 --- .../session/data/SessionEventRegistry.java | 6 +++--- .../AbstractHazelcastRepositoryITests.java | 13 +++++++------ .../HazelcastClientRepositoryITests.java | 19 ++++++++++++------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/spring-session/src/integration-test/java/org/springframework/session/data/SessionEventRegistry.java b/spring-session/src/integration-test/java/org/springframework/session/data/SessionEventRegistry.java index b9c4eb8..7ff74a4 100644 --- a/spring-session/src/integration-test/java/org/springframework/session/data/SessionEventRegistry.java +++ b/spring-session/src/integration-test/java/org/springframework/session/data/SessionEventRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ public class SessionEventRegistry implements ApplicationListener E waitForEvent() throws InterruptedException { synchronized(lock) { if(event == null) { - lock.wait(3000); + lock.wait(10000); } } return (E) event; diff --git a/spring-session/src/integration-test/java/org/springframework/session/hazelcast/AbstractHazelcastRepositoryITests.java b/spring-session/src/integration-test/java/org/springframework/session/hazelcast/AbstractHazelcastRepositoryITests.java index 07dc817..f5a3681 100644 --- a/spring-session/src/integration-test/java/org/springframework/session/hazelcast/AbstractHazelcastRepositoryITests.java +++ b/spring-session/src/integration-test/java/org/springframework/session/hazelcast/AbstractHazelcastRepositoryITests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,19 +16,20 @@ package org.springframework.session.hazelcast; -import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.IMap; +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.session.ExpiringSession; import org.springframework.session.SessionRepository; -import static org.assertj.core.api.Assertions.assertThat; +import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.core.IMap; /** * Abstract base class for Hazelcast integration tests. - * + * * @author Tommy Ludwig * @author Vedran Pavic */ @@ -41,7 +42,7 @@ public abstract class AbstractHazelcastRepositoryITests repository; @Test - public void createAndDestorySession() { + public void createAndDestroySession() { S sessionToSave = repository.createSession(); String sessionId = sessionToSave.getId(); diff --git a/spring-session/src/integration-test/java/org/springframework/session/hazelcast/HazelcastClientRepositoryITests.java b/spring-session/src/integration-test/java/org/springframework/session/hazelcast/HazelcastClientRepositoryITests.java index 58dffc6..1a0824d 100644 --- a/spring-session/src/integration-test/java/org/springframework/session/hazelcast/HazelcastClientRepositoryITests.java +++ b/spring-session/src/integration-test/java/org/springframework/session/hazelcast/HazelcastClientRepositoryITests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,6 @@ package org.springframework.session.hazelcast; -import com.hazelcast.client.HazelcastClient; -import com.hazelcast.client.config.ClientConfig; -import com.hazelcast.core.Hazelcast; -import com.hazelcast.core.HazelcastInstance; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.runner.RunWith; @@ -33,11 +29,17 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.util.SocketUtils; +import com.hazelcast.client.HazelcastClient; +import com.hazelcast.client.config.ClientConfig; +import com.hazelcast.core.HazelcastInstance; + /** * Integration tests that check the underlying data source - in this case * Hazelcast Client. * * @author Vedran Pavic + * @author Artem Bilan + * @since 1.1 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @@ -47,14 +49,17 @@ public class HazelcastClientRepositoryITests private static final int PORT = SocketUtils.findAvailableTcpPort(); + private static HazelcastInstance hazelcastInstance; + + @BeforeClass public static void setup() { - HazelcastITestUtils.embeddedHazelcastServer(PORT); + hazelcastInstance = HazelcastITestUtils.embeddedHazelcastServer(PORT); } @AfterClass public static void teardown() { - Hazelcast.shutdownAll(); + hazelcastInstance.shutdown(); } @Configuration