Prepare codebase to adhere to Checkstyle rules

Issue gh-393
This commit is contained in:
Vedran Pavic
2016-03-05 20:27:06 +01:00
committed by Rob Winch
parent 9e3bcafa75
commit 7f3302253b
222 changed files with 4071 additions and 3556 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2014-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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.session.data;
import java.util.HashMap;
@@ -22,8 +23,8 @@ import org.springframework.context.ApplicationListener;
import org.springframework.session.events.AbstractSessionEvent;
public class SessionEventRegistry implements ApplicationListener<AbstractSessionEvent> {
private Map<String,AbstractSessionEvent> events = new HashMap<String,AbstractSessionEvent>();
private Map<String,Object> locks = new HashMap<String,Object>();
private Map<String, AbstractSessionEvent> events = new HashMap<String, AbstractSessionEvent>();
private Map<String, Object> locks = new HashMap<String, Object>();
public void onApplicationEvent(AbstractSessionEvent event) {
String sessionId = event.getSessionId();
@@ -51,20 +52,20 @@ public class SessionEventRegistry implements ApplicationListener<AbstractSession
@SuppressWarnings("unchecked")
private <E extends AbstractSessionEvent> E waitForEvent(String sessionId) throws InterruptedException {
Object lock = getLock(sessionId);
synchronized(lock) {
if(!events.containsKey(sessionId)) {
synchronized (lock) {
if (!this.events.containsKey(sessionId)) {
lock.wait(10000);
}
}
return (E) events.get(sessionId);
return (E) this.events.get(sessionId);
}
private Object getLock(String sessionId) {
synchronized(locks) {
Object lock = locks.get(sessionId);
if(lock == null) {
synchronized (this.locks) {
Object lock = this.locks.get(sessionId);
if (lock == null) {
lock = new Object();
locks.put(sessionId, lock);
this.locks.put(sessionId, lock);
}
return lock;
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,8 +16,6 @@
package org.springframework.session.data.gemfire;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
import java.net.Socket;
@@ -27,13 +25,6 @@ import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.session.ExpiringSession;
import org.springframework.session.data.gemfire.support.GemFireUtils;
import org.springframework.session.events.AbstractSessionEvent;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheClosedException;
import com.gemstone.gemfire.cache.DataPolicy;
@@ -45,12 +36,22 @@ import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.client.ClientCacheFactory;
import com.gemstone.gemfire.cache.query.Index;
import com.gemstone.gemfire.cache.server.CacheServer;
import org.junit.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.session.ExpiringSession;
import org.springframework.session.data.gemfire.support.GemFireUtils;
import org.springframework.session.events.AbstractSessionEvent;
import static org.assertj.core.api.Assertions.assertThat;
/**
* AbstractGemFireIntegrationTests is an abstract base class encapsulating common operations for writing
* Spring Session GemFire integration tests.
*
* @author John Blum
* @since 1.1.0
* @see org.springframework.session.ExpiringSession
* @see org.springframework.session.events.AbstractSessionEvent
* @see com.gemstone.gemfire.cache.Cache
@@ -60,7 +61,6 @@ import com.gemstone.gemfire.cache.server.CacheServer;
* @see com.gemstone.gemfire.cache.Region
* @see com.gemstone.gemfire.cache.client.ClientCache
* @see com.gemstone.gemfire.cache.server.CacheServer
* @since 1.1.0
*/
public abstract class AbstractGemFireIntegrationTests {
@@ -70,7 +70,7 @@ public abstract class AbstractGemFireIntegrationTests {
protected static final int DEFAULT_GEMFIRE_SERVER_PORT = CacheServer.DEFAULT_PORT;
protected static final long DEFAULT_WAIT_DURATION = TimeUnit.SECONDS.toMillis(20);
protected static final long DEFAULT_WAIT_INTERVAL = 500l;
protected static final long DEFAULT_WAIT_INTERVAL = 500L;
protected static final File WORKING_DIRECTORY = new File(System.getProperty("user.dir"));
@@ -355,7 +355,7 @@ public abstract class AbstractGemFireIntegrationTests {
List<String> regionList = new ArrayList<String>(regions.size());
for (Region<?,?> region : regions) {
for (Region<?, ?> region : regions) {
regionList.add(region.getFullPath());
}
@@ -365,7 +365,7 @@ public abstract class AbstractGemFireIntegrationTests {
/* (non-Javadoc) */
@SuppressWarnings("unchecked")
protected <T extends ExpiringSession> T createSession() {
T expiringSession = (T) gemfireSessionRepository.createSession();
T expiringSession = (T) this.gemfireSessionRepository.createSession();
assertThat(expiringSession).isNotNull();
return expiringSession;
}
@@ -380,19 +380,19 @@ public abstract class AbstractGemFireIntegrationTests {
/* (non-Javadoc) */
protected <T extends ExpiringSession> T expire(T session) {
session.setLastAccessedTime(0l);
session.setLastAccessedTime(0L);
return session;
}
/* (non-Javadoc) */
@SuppressWarnings("unchecked")
protected <T extends ExpiringSession> T get(String sessionId) {
return (T) gemfireSessionRepository.getSession(sessionId);
return (T) this.gemfireSessionRepository.getSession(sessionId);
}
/* (non-Javadoc) */
protected <T extends ExpiringSession> T save(T session) {
gemfireSessionRepository.save(session);
this.gemfireSessionRepository.save(session);
return session;
}
@@ -423,14 +423,14 @@ public abstract class AbstractGemFireIntegrationTests {
/* (non-Javadoc) */
public void onApplicationEvent(AbstractSessionEvent event) {
sessionEvent = event;
this.sessionEvent = event;
}
/* (non-Javadoc) */
public <T extends AbstractSessionEvent> T waitForSessionEvent(long duration) {
waitOnCondition(new Condition() {
public boolean evaluate() {
return (sessionEvent != null);
return (SessionEventListener.this.sessionEvent != null);
}
}, duration);

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,8 +16,6 @@
package org.springframework.session.data.gemfire;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
@@ -29,12 +27,19 @@ import java.util.Date;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.client.Pool;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ConfigurableApplicationContext;
@@ -61,18 +66,14 @@ import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.util.FileSystemUtils;
import org.springframework.util.SocketUtils;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.client.Pool;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The ClientServerGemFireOperationsSessionRepositoryIntegrationTests class is a test suite of test cases testing
* the functionality of GemFire-backed Spring Sessions using a GemFire client-server topology.
*
* @author John Blum
* @since 1.1.0
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests
@@ -86,7 +87,6 @@ import com.gemstone.gemfire.cache.client.Pool;
* @see com.gemstone.gemfire.cache.client.ClientCache
* @see com.gemstone.gemfire.cache.client.Pool
* @see com.gemstone.gemfire.cache.server.CacheServer
* @since 1.1.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes =
@@ -164,7 +164,7 @@ public class ClientServerGemFireOperationsSessionRepositoryIntegrationTests exte
@After
public void tearDown() {
sessionEventListener.getSessionEvent();
this.sessionEventListener.getSessionEvent();
}
@Test
@@ -173,7 +173,7 @@ public class ClientServerGemFireOperationsSessionRepositoryIntegrationTests exte
ExpiringSession expectedSession = save(createSession());
AbstractSessionEvent sessionEvent = sessionEventListener.waitForSessionEvent(500);
AbstractSessionEvent sessionEvent = this.sessionEventListener.waitForSessionEvent(500);
assertThat(sessionEvent).isInstanceOf(SessionCreatedEvent.class);
@@ -185,35 +185,35 @@ public class ClientServerGemFireOperationsSessionRepositoryIntegrationTests exte
assertThat(createdSession.getLastAccessedTime()).isEqualTo(createdSession.getCreationTime());
assertThat(createdSession.getMaxInactiveIntervalInSeconds()).isEqualTo(MAX_INACTIVE_INTERVAL_IN_SECONDS);
gemfireSessionRepository.delete(expectedSession.getId());
this.gemfireSessionRepository.delete(expectedSession.getId());
}
@Test
public void getExistingNonExpiredSessionBeforeAndAfterExpiration() {
ExpiringSession expectedSession = save(touch(createSession()));
AbstractSessionEvent sessionEvent = sessionEventListener.waitForSessionEvent(500);
AbstractSessionEvent sessionEvent = this.sessionEventListener.waitForSessionEvent(500);
assertThat(sessionEvent).isInstanceOf(SessionCreatedEvent.class);
assertThat(sessionEvent.<ExpiringSession>getSession()).isEqualTo(expectedSession);
assertThat(sessionEventListener.getSessionEvent()).isNull();
assertThat(this.sessionEventListener.getSessionEvent()).isNull();
ExpiringSession savedSession = gemfireSessionRepository.getSession(expectedSession.getId());
ExpiringSession savedSession = this.gemfireSessionRepository.getSession(expectedSession.getId());
assertThat(savedSession).isEqualTo(expectedSession);
// NOTE for some reason or another, performing a GemFire (Client)Cache Region.get(key)
// causes a Region CREATE event... o.O
// calling sessionEventListener.getSessionEvent() here to clear the event
sessionEventListener.getSessionEvent();
this.sessionEventListener.getSessionEvent();
sessionEvent = sessionEventListener.waitForSessionEvent(TimeUnit.SECONDS.toMillis(
sessionEvent = this.sessionEventListener.waitForSessionEvent(TimeUnit.SECONDS.toMillis(
MAX_INACTIVE_INTERVAL_IN_SECONDS + 1));
assertThat(sessionEvent).isInstanceOf(SessionExpiredEvent.class);
assertThat(sessionEvent.getSessionId()).isEqualTo(expectedSession.getId());
ExpiringSession expiredSession = gemfireSessionRepository.getSession(expectedSession.getId());
ExpiringSession expiredSession = this.gemfireSessionRepository.getSession(expectedSession.getId());
assertThat(expiredSession).isNull();
}
@@ -222,19 +222,19 @@ public class ClientServerGemFireOperationsSessionRepositoryIntegrationTests exte
public void deleteExistingNonExpiredSessionFiresSessionDeletedEventAndReturnsNullOnGet() {
ExpiringSession expectedSession = save(touch(createSession()));
AbstractSessionEvent sessionEvent = sessionEventListener.waitForSessionEvent(500);
AbstractSessionEvent sessionEvent = this.sessionEventListener.waitForSessionEvent(500);
assertThat(sessionEvent).isInstanceOf(SessionCreatedEvent.class);
assertThat(sessionEvent.<ExpiringSession>getSession()).isEqualTo(expectedSession);
gemfireSessionRepository.delete(expectedSession.getId());
this.gemfireSessionRepository.delete(expectedSession.getId());
sessionEvent = sessionEventListener.waitForSessionEvent(500);
sessionEvent = this.sessionEventListener.waitForSessionEvent(500);
assertThat(sessionEvent).isInstanceOf(SessionDeletedEvent.class);
assertThat(sessionEvent.getSessionId()).isEqualTo(expectedSession.getId());
ExpiringSession deletedSession = gemfireSessionRepository.getSession(expectedSession.getId());
ExpiringSession deletedSession = this.gemfireSessionRepository.getSession(expectedSession.getId());
assertThat(deletedSession).isNull();
}
@@ -257,9 +257,10 @@ public class ClientServerGemFireOperationsSessionRepositoryIntegrationTests exte
}
@Bean(name = GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME)
PoolFactoryBean gemfirePool(@Value("${spring.session.data.gemfire.port:"+DEFAULT_GEMFIRE_SERVER_PORT+"}") int port) {
PoolFactoryBean gemfirePool(@Value("${spring.session.data.gemfire.port:" + DEFAULT_GEMFIRE_SERVER_PORT + "}") int port) {
PoolFactoryBean poolFactory = new PoolFactoryBean() {
@Override protected Properties resolveGemfireProperties() {
@Override
protected Properties resolveGemfireProperties() {
return gemfireProperties();
}
};
@@ -350,7 +351,7 @@ public class ClientServerGemFireOperationsSessionRepositoryIntegrationTests exte
@Bean
CacheServerFactoryBean gemfireCacheServer(Cache gemfireCache,
@Value("${spring.session.data.gemfire.port:"+DEFAULT_GEMFIRE_SERVER_PORT+"}") int port) {
@Value("${spring.session.data.gemfire.port:" + DEFAULT_GEMFIRE_SERVER_PORT + "}") int port) {
CacheServerFactoryBean cacheServerFactory = new CacheServerFactoryBean();

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,10 +16,6 @@
package org.springframework.session.data.gemfire;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME;
import static org.springframework.session.data.gemfire.GemFireOperationsSessionRepository.GemFireSession;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -27,9 +23,19 @@ import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.query.Query;
import com.gemstone.gemfire.cache.query.QueryService;
import com.gemstone.gemfire.cache.query.SelectResults;
import com.gemstone.gemfire.pdx.PdxReader;
import com.gemstone.gemfire.pdx.PdxSerializable;
import com.gemstone.gemfire.pdx.PdxWriter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.annotation.Bean;
import org.springframework.data.gemfire.CacheFactoryBean;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -46,21 +52,14 @@ import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.query.Query;
import com.gemstone.gemfire.cache.query.QueryService;
import com.gemstone.gemfire.cache.query.SelectResults;
import com.gemstone.gemfire.pdx.PdxReader;
import com.gemstone.gemfire.pdx.PdxSerializable;
import com.gemstone.gemfire.pdx.PdxWriter;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The GemFireOperationsSessionRepositoryIntegrationTests class is a test suite of test cases testing
* the findByPrincipalName query method on the GemFireOpeationsSessionRepository class.
*
* @author John Blum
* @since 1.1.0
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests
@@ -71,7 +70,6 @@ import com.gemstone.gemfire.pdx.PdxWriter;
* @see org.springframework.test.context.web.WebAppConfiguration
* @see com.gemstone.gemfire.cache.Cache
* @see com.gemstone.gemfire.cache.Region
* @since 1.1.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -91,35 +89,35 @@ public class GemFireOperationsSessionRepositoryIntegrationTests extends Abstract
@Before
public void setup() {
context = SecurityContextHolder.createEmptyContext();
context.setAuthentication(new UsernamePasswordAuthenticationToken("username-"+UUID.randomUUID(), "na", AuthorityUtils.createAuthorityList("ROLE_USER")));
this.context = SecurityContextHolder.createEmptyContext();
this.context.setAuthentication(new UsernamePasswordAuthenticationToken("username-" + UUID.randomUUID(), "na", AuthorityUtils.createAuthorityList("ROLE_USER")));
changedContext = SecurityContextHolder.createEmptyContext();
changedContext.setAuthentication(new UsernamePasswordAuthenticationToken("changedContext-"+UUID.randomUUID(), "na", AuthorityUtils.createAuthorityList("ROLE_USER")));
this.changedContext = SecurityContextHolder.createEmptyContext();
this.changedContext.setAuthentication(new UsernamePasswordAuthenticationToken("changedContext-" + UUID.randomUUID(), "na", AuthorityUtils.createAuthorityList("ROLE_USER")));
assertThat(gemfireCache).isNotNull();
assertThat(gemfireSessionRepository).isNotNull();
assertThat(gemfireSessionRepository.getMaxInactiveIntervalInSeconds()).isEqualTo(
assertThat(this.gemfireCache).isNotNull();
assertThat(this.gemfireSessionRepository).isNotNull();
assertThat(this.gemfireSessionRepository.getMaxInactiveIntervalInSeconds()).isEqualTo(
MAX_INACTIVE_INTERVAL_IN_SECONDS);
Region<Object, ExpiringSession> sessionRegion = gemfireCache.getRegion(SPRING_SESSION_GEMFIRE_REGION_NAME);
Region<Object, ExpiringSession> sessionRegion = this.gemfireCache.getRegion(SPRING_SESSION_GEMFIRE_REGION_NAME);
assertRegion(sessionRegion, SPRING_SESSION_GEMFIRE_REGION_NAME, DataPolicy.PARTITION);
assertEntryIdleTimeout(sessionRegion, ExpirationAction.INVALIDATE, MAX_INACTIVE_INTERVAL_IN_SECONDS);
}
protected Map<String, ExpiringSession> doFindByIndexNameAndIndexValue(String indexName, String indexValue) {
return gemfireSessionRepository.findByIndexNameAndIndexValue(indexName, indexValue);
return this.gemfireSessionRepository.findByIndexNameAndIndexValue(indexName, indexValue);
}
protected Map<String, ExpiringSession> doFindByPrincipalName(String principalName) {
return doFindByIndexNameAndIndexValue(PRINCIPAL_NAME_INDEX_NAME, principalName);
return doFindByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principalName);
}
@SuppressWarnings({ "unchecked" })
protected Map<String, ExpiringSession> doFindByPrincipalName(String regionName, String principalName) {
try {
Region<String, ExpiringSession> region = gemfireCache.getRegion(regionName);
Region<String, ExpiringSession> region = this.gemfireCache.getRegion(regionName);
assertThat(region).isNotNull();
@@ -239,7 +237,7 @@ public class GemFireOperationsSessionRepositoryIntegrationTests extends Abstract
@Test
public void findSessionsBySecurityPrincipalName() {
ExpiringSession toSave = this.gemfireSessionRepository.createSession();
toSave.setAttribute(SPRING_SECURITY_CONTEXT, context);
toSave.setAttribute(SPRING_SECURITY_CONTEXT, this.context);
save(toSave);
@@ -251,10 +249,10 @@ public class GemFireOperationsSessionRepositoryIntegrationTests extends Abstract
@Test
public void findSessionsByChangedSecurityPrincipalName() {
ExpiringSession toSave = this.gemfireSessionRepository.createSession();
toSave.setAttribute(SPRING_SECURITY_CONTEXT, context);
toSave.setAttribute(SPRING_SECURITY_CONTEXT, this.context);
save(toSave);
toSave.setAttribute(SPRING_SECURITY_CONTEXT, changedContext);
toSave.setAttribute(SPRING_SECURITY_CONTEXT, this.changedContext);
save(toSave);
Map<String, ExpiringSession> findByPrincipalName = doFindByPrincipalName(getSecurityName());
@@ -287,11 +285,11 @@ public class GemFireOperationsSessionRepositoryIntegrationTests extends Abstract
@Test
public void saveAndReadSessionWithAttributes() {
ExpiringSession expectedSession = gemfireSessionRepository.createSession();
ExpiringSession expectedSession = this.gemfireSessionRepository.createSession();
assertThat(expectedSession).isInstanceOf(GemFireSession.class);
assertThat(expectedSession).isInstanceOf(AbstractGemFireOperationsSessionRepository.GemFireSession.class);
((GemFireSession) expectedSession).setPrincipalName("jblum");
((AbstractGemFireOperationsSessionRepository.GemFireSession) expectedSession).setPrincipalName("jblum");
List<String> expectedAttributeNames = Arrays.asList(
"booleanAttribute", "numericAttribute", "stringAttribute", "personAttribute");
@@ -303,16 +301,16 @@ public class GemFireOperationsSessionRepositoryIntegrationTests extends Abstract
expectedSession.setAttribute(expectedAttributeNames.get(2), "test");
expectedSession.setAttribute(expectedAttributeNames.get(3), jonDoe);
gemfireSessionRepository.save(touch(expectedSession));
this.gemfireSessionRepository.save(touch(expectedSession));
ExpiringSession savedSession = gemfireSessionRepository.getSession(expectedSession.getId());
ExpiringSession savedSession = this.gemfireSessionRepository.getSession(expectedSession.getId());
assertThat(savedSession).isEqualTo(expectedSession);
assertThat(savedSession).isInstanceOf(GemFireSession.class);
assertThat(((GemFireSession) savedSession).getPrincipalName()).isEqualTo("jblum");
assertThat(savedSession).isInstanceOf(AbstractGemFireOperationsSessionRepository.GemFireSession.class);
assertThat(((AbstractGemFireOperationsSessionRepository.GemFireSession) savedSession).getPrincipalName()).isEqualTo("jblum");
assertThat(savedSession.getAttributeNames().containsAll(expectedAttributeNames)).as(
String.format("Expected (%1$s); but was (%2$s)", expectedAttributeNames,savedSession.getAttributeNames()))
String.format("Expected (%1$s); but was (%2$s)", expectedAttributeNames, savedSession.getAttributeNames()))
.isTrue();
assertThat(Boolean.valueOf(String.valueOf(savedSession.getAttribute(expectedAttributeNames.get(0))))).isTrue();
@@ -323,11 +321,11 @@ public class GemFireOperationsSessionRepositoryIntegrationTests extends Abstract
}
private String getSecurityName() {
return context.getAuthentication().getName();
return this.context.getAuthentication().getName();
}
private String getChangedSecurityName() {
return changedContext.getAuthentication().getName();
return this.changedContext.getAuthentication().getName();
}
@EnableGemFireHttpSession(regionName = SPRING_SESSION_GEMFIRE_REGION_NAME,
@@ -377,11 +375,11 @@ public class GemFireOperationsSessionRepositoryIntegrationTests extends Abstract
}
public String getFirstName() {
return firstName;
return this.firstName;
}
public String getLastName() {
return lastName;
return this.lastName;
}
public String getName() {

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,16 +16,19 @@
package org.springframework.session.data.gemfire.config.annotation.web.http;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionShortcut;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.gemfire.CacheFactoryBean;
@@ -41,16 +44,14 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionShortcut;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The EnableGemFireHttpSessionEventsIntegrationTests class is a test suite of test cases testing the Session Event
* functionality and behavior of the GemFireOperationsSessionRepository and GemFire's configuration.
*
* @author John Blum
* @since 1.1.0
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.springframework.session.ExpiringSession
@@ -64,7 +65,6 @@ import com.gemstone.gemfire.cache.RegionShortcut;
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
* @see org.springframework.test.context.web.WebAppConfiguration
* @see com.gemstone.gemfire.cache.Region
* @since 1.1.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -82,13 +82,13 @@ public class EnableGemFireHttpSessionEventsIntegrationTests extends AbstractGemF
@Before
public void setup() {
assertThat(GemFireUtils.isPeer(gemfireCache)).isTrue();
assertThat(gemfireSessionRepository).isNotNull();
assertThat(gemfireSessionRepository.getMaxInactiveIntervalInSeconds()).isEqualTo(
assertThat(GemFireUtils.isPeer(this.gemfireCache)).isTrue();
assertThat(this.gemfireSessionRepository).isNotNull();
assertThat(this.gemfireSessionRepository.getMaxInactiveIntervalInSeconds()).isEqualTo(
MAX_INACTIVE_INTERVAL_IN_SECONDS);
assertThat(sessionEventListener).isNotNull();
assertThat(this.sessionEventListener).isNotNull();
Region<Object, ExpiringSession> sessionRegion = gemfireCache.getRegion(SPRING_SESSION_GEMFIRE_REGION_NAME);
Region<Object, ExpiringSession> sessionRegion = this.gemfireCache.getRegion(SPRING_SESSION_GEMFIRE_REGION_NAME);
assertRegion(sessionRegion, SPRING_SESSION_GEMFIRE_REGION_NAME, DataPolicy.REPLICATE);
assertEntryIdleTimeout(sessionRegion, ExpirationAction.INVALIDATE, MAX_INACTIVE_INTERVAL_IN_SECONDS);
@@ -96,7 +96,7 @@ public class EnableGemFireHttpSessionEventsIntegrationTests extends AbstractGemF
@After
public void tearDown() {
sessionEventListener.getSessionEvent();
this.sessionEventListener.getSessionEvent();
}
@Test
@@ -105,7 +105,7 @@ public class EnableGemFireHttpSessionEventsIntegrationTests extends AbstractGemF
ExpiringSession expectedSession = save(createSession());
AbstractSessionEvent sessionEvent = sessionEventListener.getSessionEvent();
AbstractSessionEvent sessionEvent = this.sessionEventListener.getSessionEvent();
assertThat(sessionEvent).isInstanceOf(SessionCreatedEvent.class);
@@ -126,7 +126,7 @@ public class EnableGemFireHttpSessionEventsIntegrationTests extends AbstractGemF
assertThat(expectedSession.isExpired()).isFalse();
// NOTE though unlikely, a possible race condition exists between save and get...
ExpiringSession savedSession = gemfireSessionRepository.getSession(expectedSession.getId());
ExpiringSession savedSession = this.gemfireSessionRepository.getSession(expectedSession.getId());
assertThat(savedSession).isEqualTo(expectedSession);
}
@@ -135,7 +135,7 @@ public class EnableGemFireHttpSessionEventsIntegrationTests extends AbstractGemF
public void getExistingExpiredSession() {
ExpiringSession expectedSession = save(expire(createSession()));
AbstractSessionEvent sessionEvent = sessionEventListener.getSessionEvent();
AbstractSessionEvent sessionEvent = this.sessionEventListener.getSessionEvent();
assertThat(sessionEvent).isInstanceOf(SessionCreatedEvent.class);
@@ -143,25 +143,25 @@ public class EnableGemFireHttpSessionEventsIntegrationTests extends AbstractGemF
assertThat(createdSession).isEqualTo(expectedSession);
assertThat(createdSession.isExpired()).isTrue();
assertThat(gemfireSessionRepository.getSession(createdSession.getId())).isNull();
assertThat(this.gemfireSessionRepository.getSession(createdSession.getId())).isNull();
}
@Test
public void getNonExistingSession() {
assertThat(gemfireSessionRepository.getSession(UUID.randomUUID().toString())).isNull();
assertThat(this.gemfireSessionRepository.getSession(UUID.randomUUID().toString())).isNull();
}
@Test
public void deleteExistingNonExpiredSession() {
ExpiringSession expectedSession = save(touch(createSession()));
ExpiringSession savedSession = gemfireSessionRepository.getSession(expectedSession.getId());
ExpiringSession savedSession = this.gemfireSessionRepository.getSession(expectedSession.getId());
assertThat(savedSession).isEqualTo(expectedSession);
assertThat(savedSession.isExpired()).isFalse();
gemfireSessionRepository.delete(savedSession.getId());
this.gemfireSessionRepository.delete(savedSession.getId());
AbstractSessionEvent sessionEvent = sessionEventListener.getSessionEvent();
AbstractSessionEvent sessionEvent = this.sessionEventListener.getSessionEvent();
assertThat(sessionEvent).isInstanceOf(SessionDeletedEvent.class);
assertThat(sessionEvent.getSessionId()).isEqualTo(savedSession.getId());
@@ -169,14 +169,14 @@ public class EnableGemFireHttpSessionEventsIntegrationTests extends AbstractGemF
ExpiringSession deletedSession = sessionEvent.getSession();
assertThat(deletedSession).isEqualTo(savedSession);
assertThat(gemfireSessionRepository.getSession(deletedSession.getId())).isNull();
assertThat(this.gemfireSessionRepository.getSession(deletedSession.getId())).isNull();
}
@Test
public void deleteExistingExpiredSession() {
ExpiringSession expectedSession = save(createSession());
AbstractSessionEvent sessionEvent = sessionEventListener.getSessionEvent();
AbstractSessionEvent sessionEvent = this.sessionEventListener.getSessionEvent();
assertThat(sessionEvent).isInstanceOf(SessionCreatedEvent.class);
@@ -184,8 +184,8 @@ public class EnableGemFireHttpSessionEventsIntegrationTests extends AbstractGemF
assertThat(createdSession).isEqualTo(expectedSession);
sessionEvent = sessionEventListener.waitForSessionEvent(TimeUnit.SECONDS.toMillis(
gemfireSessionRepository.getMaxInactiveIntervalInSeconds() + 1));
sessionEvent = this.sessionEventListener.waitForSessionEvent(TimeUnit.SECONDS.toMillis(
this.gemfireSessionRepository.getMaxInactiveIntervalInSeconds() + 1));
assertThat(sessionEvent).isInstanceOf(SessionExpiredEvent.class);
@@ -194,25 +194,25 @@ public class EnableGemFireHttpSessionEventsIntegrationTests extends AbstractGemF
assertThat(expiredSession).isEqualTo(createdSession);
assertThat(expiredSession.isExpired()).isTrue();
gemfireSessionRepository.delete(expectedSession.getId());
this.gemfireSessionRepository.delete(expectedSession.getId());
sessionEvent = sessionEventListener.getSessionEvent();
sessionEvent = this.sessionEventListener.getSessionEvent();
assertThat(sessionEvent).isInstanceOf(SessionDeletedEvent.class);
assertThat(sessionEvent.getSession()).isNull();
assertThat(sessionEvent.getSessionId()).isEqualTo(expiredSession.getId());
assertThat(gemfireSessionRepository.getSession(sessionEvent.getSessionId())).isNull();
assertThat(this.gemfireSessionRepository.getSession(sessionEvent.getSessionId())).isNull();
}
@Test
public void deleteNonExistingSession() {
String expectedSessionId = UUID.randomUUID().toString();
assertThat(gemfireSessionRepository.getSession(expectedSessionId)).isNull();
assertThat(this.gemfireSessionRepository.getSession(expectedSessionId)).isNull();
gemfireSessionRepository.delete(expectedSessionId);
this.gemfireSessionRepository.delete(expectedSessionId);
AbstractSessionEvent sessionEvent = sessionEventListener.getSessionEvent();
AbstractSessionEvent sessionEvent = this.sessionEventListener.getSessionEvent();
assertThat(sessionEvent).isInstanceOf(SessionDeletedEvent.class);
assertThat(sessionEvent.getSession()).isNull();

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,12 +16,18 @@
package org.springframework.session.data.gemfire.config.annotation.web.http;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Properties;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionShortcut;
import com.gemstone.gemfire.cache.query.Index;
import com.gemstone.gemfire.cache.query.QueryService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.gemfire.CacheFactoryBean;
@@ -33,19 +39,14 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionShortcut;
import com.gemstone.gemfire.cache.query.Index;
import com.gemstone.gemfire.cache.query.QueryService;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The GemFireHttpSessionJavaConfigurationTests class is a test suite of test cases testing the configuration of
* Spring Session backed by GemFire using Java-based configuration meta-data.
*
* @author John Blum
* @since 1.1.0
* @see org.junit.Test
* @see org.springframework.session.ExpiringSession
* @see org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests
@@ -55,7 +56,6 @@ import com.gemstone.gemfire.cache.query.QueryService;
* @see org.springframework.test.context.web.WebAppConfiguration
* @see com.gemstone.gemfire.cache.Cache
* @see com.gemstone.gemfire.cache.Region
* @since 1.1.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -78,7 +78,7 @@ public class GemFireHttpSessionJavaConfigurationTests extends AbstractGemFireInt
@Test
public void gemfireCacheConfigurationIsValid() {
Region<Object, ExpiringSession> example = assertCacheAndRegion(gemfireCache, "JavaExample",
Region<Object, ExpiringSession> example = assertCacheAndRegion(this.gemfireCache, "JavaExample",
DataPolicy.REPLICATE);
assertEntryIdleTimeout(example, ExpirationAction.INVALIDATE, 900);
@@ -86,7 +86,7 @@ public class GemFireHttpSessionJavaConfigurationTests extends AbstractGemFireInt
@Test
public void verifyGemFireExampleCacheRegionPrincipalNameIndexWasCreatedSuccessfully() {
Region<Object, ExpiringSession> example = assertCacheAndRegion(gemfireCache, "JavaExample",
Region<Object, ExpiringSession> example = assertCacheAndRegion(this.gemfireCache, "JavaExample",
DataPolicy.REPLICATE);
QueryService queryService = example.getRegionService().getQueryService();
@@ -100,7 +100,7 @@ public class GemFireHttpSessionJavaConfigurationTests extends AbstractGemFireInt
@Test
public void verifyGemFireExampleCacheRegionSessionAttributesIndexWasNotCreated() {
Region<Object, ExpiringSession> example = assertCacheAndRegion(gemfireCache, "JavaExample",
Region<Object, ExpiringSession> example = assertCacheAndRegion(this.gemfireCache, "JavaExample",
DataPolicy.REPLICATE);
QueryService queryService = example.getRegionService().getQueryService();

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,10 +16,15 @@
package org.springframework.session.data.gemfire.config.annotation.web.http;
import static org.assertj.core.api.Assertions.assertThat;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.query.Index;
import com.gemstone.gemfire.cache.query.QueryService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.session.ExpiringSession;
import org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests;
@@ -29,18 +34,14 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.query.Index;
import com.gemstone.gemfire.cache.query.QueryService;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The GemFireHttpSessionXmlConfigurationTests class is a test suite of test cases testing the configuration of
* Spring Session backed by GemFire using XML configuration meta-data.
*
* @author John Blum
* @since 1.1.0
* @see org.junit.Test
* @see org.springframework.session.ExpiringSession
* @see org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests
@@ -50,7 +51,6 @@ import com.gemstone.gemfire.cache.query.QueryService;
* @see org.springframework.test.context.web.WebAppConfiguration
* @see com.gemstone.gemfire.cache.Cache
* @see com.gemstone.gemfire.cache.Region
* @since 1.1.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -73,14 +73,14 @@ public class GemFireHttpSessionXmlConfigurationTests extends AbstractGemFireInte
@Test
public void gemfireCacheConfigurationIsValid() {
Region<Object, ExpiringSession> example = assertCacheAndRegion(gemfireCache, "XmlExample", DataPolicy.NORMAL);
Region<Object, ExpiringSession> example = assertCacheAndRegion(this.gemfireCache, "XmlExample", DataPolicy.NORMAL);
assertEntryIdleTimeout(example, ExpirationAction.INVALIDATE, 3600);
}
@Test
public void verifyGemFireExampleCacheRegionPrincipalNameIndexWasCreatedSuccessfully() {
Region<Object, ExpiringSession> example = assertCacheAndRegion(gemfireCache, "XmlExample", DataPolicy.NORMAL);
Region<Object, ExpiringSession> example = assertCacheAndRegion(this.gemfireCache, "XmlExample", DataPolicy.NORMAL);
QueryService queryService = example.getRegionService().getQueryService();
@@ -93,7 +93,7 @@ public class GemFireHttpSessionXmlConfigurationTests extends AbstractGemFireInte
@Test
public void verifyGemFireExampleCacheRegionSessionAttributesIndexWasCreatedSuccessfully() {
Region<Object, ExpiringSession> example = assertCacheAndRegion(gemfireCache, "XmlExample", DataPolicy.NORMAL);
Region<Object, ExpiringSession> example = assertCacheAndRegion(this.gemfireCache, "XmlExample", DataPolicy.NORMAL);
QueryService queryService = example.getRegionService().getQueryService();

View File

@@ -1,28 +1,27 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.session.data.redis.config.annotation.web.http;
import static org.assertj.core.api.Assertions.*;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
@@ -40,6 +39,8 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@WebAppConfiguration
@@ -54,35 +55,35 @@ public class EnableRedisHttpSessionExpireSessionDestroyedTests<S extends Expirin
@Before
public void setup() {
registry.setLock(lock);
this.registry.setLock(this.lock);
}
@Test
public void expireFiresSessionExpiredEvent() throws InterruptedException {
S toSave = repository.createSession();
S toSave = this.repository.createSession();
toSave.setAttribute("a", "b");
Authentication toSaveToken = new UsernamePasswordAuthenticationToken("user","password", AuthorityUtils.createAuthorityList("ROLE_USER"));
Authentication toSaveToken = new UsernamePasswordAuthenticationToken("user", "password", AuthorityUtils.createAuthorityList("ROLE_USER"));
SecurityContext toSaveContext = SecurityContextHolder.createEmptyContext();
toSaveContext.setAuthentication(toSaveToken);
toSave.setAttribute("SPRING_SECURITY_CONTEXT", toSaveContext);
repository.save(toSave);
this.repository.save(toSave);
synchronized (lock) {
lock.wait((toSave.getMaxInactiveIntervalInSeconds() * 1000) + 1);
synchronized (this.lock) {
this.lock.wait((toSave.getMaxInactiveIntervalInSeconds() * 1000) + 1);
}
if(!registry.receivedEvent()) {
if (!this.registry.receivedEvent()) {
// Redis makes no guarantees on when an expired event will be fired
// we can ensure it gets fired by trying to get the session
repository.getSession(toSave.getId());
synchronized (lock) {
if(!registry.receivedEvent()) {
this.repository.getSession(toSave.getId());
synchronized (this.lock) {
if (!this.registry.receivedEvent()) {
// wait at most a minute
lock.wait(TimeUnit.MINUTES.toMillis(1));
this.lock.wait(TimeUnit.MINUTES.toMillis(1));
}
}
}
assertThat(registry.receivedEvent()).isTrue();
assertThat(this.registry.receivedEvent()).isTrue();
}
static class SessionExpiredEventRegistry implements ApplicationListener<SessionExpiredEvent> {
@@ -90,14 +91,14 @@ public class EnableRedisHttpSessionExpireSessionDestroyedTests<S extends Expirin
private Object lock;
public void onApplicationEvent(SessionExpiredEvent event) {
synchronized (lock) {
receivedEvent = true;
lock.notifyAll();
synchronized (this.lock) {
this.receivedEvent = true;
this.lock.notifyAll();
}
}
public boolean receivedEvent() {
return receivedEvent;
return this.receivedEvent;
}
public void setLock(Object lock) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2014-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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.session.data.redis.flushimmediately;
import org.springframework.context.annotation.Bean;
@@ -34,4 +35,4 @@ public class RedisHttpSessionConfig {
factory.setUsePool(false);
return factory;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2014-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.
@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.session.data.redis.flushimmediately;
import static org.assertj.core.api.Assertions.assertThat;
package org.springframework.session.data.redis.flushimmediately;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.session.ExpiringSession;
import org.springframework.session.SessionRepository;
@@ -26,8 +26,10 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=RedisHttpSessionConfig.class)
@ContextConfiguration(classes = RedisHttpSessionConfig.class)
@WebAppConfiguration
public class RedisOperationsSessionRepositoryFlushImmediatelyITests<S extends ExpiringSession> {
@@ -36,10 +38,10 @@ public class RedisOperationsSessionRepositoryFlushImmediatelyITests<S extends Ex
@Test
public void savesOnCreate() throws InterruptedException {
S created = sessionRepository.createSession();
S created = this.sessionRepository.createSession();
S getSession = sessionRepository.getSession(created.getId());
S getSession = this.sessionRepository.getSession(created.getId());
assertThat(getSession).isNotNull();
}
}
}

View File

@@ -1,6 +1,20 @@
package org.springframework.session.data.redis.taskexecutor;
/*
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import static org.assertj.core.api.Assertions.assertThat;
package org.springframework.session.data.redis.taskexecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@@ -8,6 +22,7 @@ import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -21,6 +36,8 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Vladimir Tsanev
*/
@@ -37,11 +54,11 @@ public class RedisListenerContainerTaskExecutorITests {
@Test
public void testRedisDelEventsAreDispatchedInSessionTaskExecutor() throws InterruptedException {
BoundSetOperations<Object, Object> ops = redis
BoundSetOperations<Object, Object> ops = this.redis
.boundSetOps("spring:session:RedisListenerContainerTaskExecutorITests:expirations:dummy");
ops.add("value");
ops.remove("value");
assertThat(executor.taskDispatched()).isTrue();
assertThat(this.executor.taskDispatched()).isTrue();
}
@@ -52,29 +69,30 @@ public class RedisListenerContainerTaskExecutorITests {
private Boolean taskDispatched;
public SessionTaskExecutor(Executor executor) {
SessionTaskExecutor(Executor executor) {
this.executor = executor;
}
public void execute(Runnable task) {
synchronized (lock) {
synchronized (this.lock) {
try {
executor.execute(task);
} finally {
taskDispatched = true;
lock.notifyAll();
this.executor.execute(task);
}
finally {
this.taskDispatched = true;
this.lock.notifyAll();
}
}
}
public boolean taskDispatched() throws InterruptedException {
if(taskDispatched != null) {
return taskDispatched;
if (this.taskDispatched != null) {
return this.taskDispatched;
}
synchronized (lock) {
lock.wait(TimeUnit.SECONDS.toMillis(1));
synchronized (this.lock) {
this.lock.wait(TimeUnit.SECONDS.toMillis(1));
}
return taskDispatched == null ? Boolean.FALSE : taskDispatched;
return this.taskDispatched == null ? Boolean.FALSE : this.taskDispatched;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2014-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,16 +16,15 @@
package org.springframework.session.hazelcast;
import static org.assertj.core.api.Assertions.assertThat;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.session.ExpiringSession;
import org.springframework.session.SessionRepository;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Abstract base class for Hazelcast integration tests.
@@ -43,19 +42,19 @@ public abstract class AbstractHazelcastRepositoryITests<S extends ExpiringSessio
@Test
public void createAndDestroySession() {
S sessionToSave = repository.createSession();
S sessionToSave = this.repository.createSession();
String sessionId = sessionToSave.getId();
IMap<String, S> hazelcastMap = hazelcast.getMap("spring:session:sessions");
IMap<String, S> hazelcastMap = this.hazelcast.getMap("spring:session:sessions");
assertThat(hazelcastMap.size()).isEqualTo(0);
repository.save(sessionToSave);
this.repository.save(sessionToSave);
assertThat(hazelcastMap.size()).isEqualTo(1);
assertThat(hazelcastMap.get(sessionId)).isEqualTo(sessionToSave);
repository.delete(sessionId);
this.repository.delete(sessionId);
assertThat(hazelcastMap.size()).isEqualTo(0);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2014-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,6 +16,9 @@
package org.springframework.session.hazelcast;
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.core.HazelcastInstance;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
@@ -29,10 +32,6 @@ 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.
@@ -59,7 +58,7 @@ public class HazelcastClientRepositoryITests<S extends ExpiringSession>
@AfterClass
public static void teardown() {
if(hazelcastInstance != null) {
if (hazelcastInstance != null) {
hazelcastInstance.shutdown();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2014-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.
@@ -27,7 +27,10 @@ import org.springframework.util.SocketUtils;
*
* @author Vedran Pavic
*/
public class HazelcastITestUtils {
public final class HazelcastITestUtils {
private HazelcastITestUtils() {
}
/**
* Creates {@link HazelcastInstance} for use in integration tests.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2014-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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2014-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.
@@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.session.hazelcast.config.annotation.web.http;
import static org.assertj.core.api.Assertions.*;
import com.hazelcast.core.HazelcastInstance;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -41,7 +42,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import com.hazelcast.core.HazelcastInstance;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Ensure that the appropriate SessionEvents are fired at the expected times.
@@ -65,30 +66,30 @@ public class EnableHazelcastHttpSessionEventsTests<S extends ExpiringSession> {
@Before
public void setup() {
registry.clear();
this.registry.clear();
}
@Test
public void saveSessionTest() throws InterruptedException {
String username = "saves-"+System.currentTimeMillis();
String username = "saves-" + System.currentTimeMillis();
S sessionToSave = repository.createSession();
S sessionToSave = this.repository.createSession();
String expectedAttributeName = "a";
String expectedAttributeValue = "b";
sessionToSave.setAttribute(expectedAttributeName, expectedAttributeValue);
Authentication toSaveToken = new UsernamePasswordAuthenticationToken(username,"password", AuthorityUtils.createAuthorityList("ROLE_USER"));
Authentication toSaveToken = new UsernamePasswordAuthenticationToken(username, "password", AuthorityUtils.createAuthorityList("ROLE_USER"));
SecurityContext toSaveContext = SecurityContextHolder.createEmptyContext();
toSaveContext.setAuthentication(toSaveToken);
sessionToSave.setAttribute("SPRING_SECURITY_CONTEXT", toSaveContext);
sessionToSave.setAttribute(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, username);
repository.save(sessionToSave);
this.repository.save(sessionToSave);
assertThat(registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat(registry.getEvent(sessionToSave.getId())).isInstanceOf(SessionCreatedEvent.class);
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat(this.registry.getEvent(sessionToSave.getId())).isInstanceOf(SessionCreatedEvent.class);
Session session = repository.getSession(sessionToSave.getId());
Session session = this.repository.getSession(sessionToSave.getId());
assertThat(session.getId()).isEqualTo(sessionToSave.getId());
assertThat(session.getAttributeNames()).isEqualTo(sessionToSave.getAttributeNames());
@@ -97,62 +98,62 @@ public class EnableHazelcastHttpSessionEventsTests<S extends ExpiringSession> {
@Test
public void expiredSessionTest() throws InterruptedException {
S sessionToSave = repository.createSession();
S sessionToSave = this.repository.createSession();
repository.save(sessionToSave);
this.repository.save(sessionToSave);
assertThat(registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat(registry.getEvent(sessionToSave.getId())).isInstanceOf(SessionCreatedEvent.class);
registry.clear();
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat(this.registry.getEvent(sessionToSave.getId())).isInstanceOf(SessionCreatedEvent.class);
this.registry.clear();
assertThat(sessionToSave.getMaxInactiveIntervalInSeconds()).isEqualTo(MAX_INACTIVE_INTERVAL_IN_SECONDS);
assertThat(registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat(registry.getEvent(sessionToSave.getId())).isInstanceOf(SessionExpiredEvent.class);
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat(this.registry.getEvent(sessionToSave.getId())).isInstanceOf(SessionExpiredEvent.class);
assertThat(repository.getSession(sessionToSave.getId())).isNull();
assertThat(this.repository.getSession(sessionToSave.getId())).isNull();
}
@Test
public void deletedSessionTest() throws InterruptedException {
S sessionToSave = repository.createSession();
S sessionToSave = this.repository.createSession();
repository.save(sessionToSave);
this.repository.save(sessionToSave);
assertThat(registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat(registry.getEvent(sessionToSave.getId())).isInstanceOf(SessionCreatedEvent.class);
registry.clear();
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat(this.registry.getEvent(sessionToSave.getId())).isInstanceOf(SessionCreatedEvent.class);
this.registry.clear();
repository.delete(sessionToSave.getId());
this.repository.delete(sessionToSave.getId());
assertThat(registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat(registry.getEvent(sessionToSave.getId())).isInstanceOf(SessionDeletedEvent.class);
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat(this.registry.getEvent(sessionToSave.getId())).isInstanceOf(SessionDeletedEvent.class);
assertThat(repository.getSession(sessionToSave.getId())).isNull();
assertThat(this.repository.getSession(sessionToSave.getId())).isNull();
}
@Test
public void saveUpdatesTimeToLiveTest() throws InterruptedException {
Object lock = new Object();
S sessionToSave = repository.createSession();
S sessionToSave = this.repository.createSession();
repository.save(sessionToSave);
this.repository.save(sessionToSave);
synchronized (lock) {
lock.wait((sessionToSave.getMaxInactiveIntervalInSeconds() * 1000) - 500);
}
// Get and save the session like SessionRepositoryFilter would.
S sessionToUpdate = repository.getSession(sessionToSave.getId());
S sessionToUpdate = this.repository.getSession(sessionToSave.getId());
sessionToUpdate.setLastAccessedTime(System.currentTimeMillis());
repository.save(sessionToUpdate);
this.repository.save(sessionToUpdate);
synchronized (lock) {
lock.wait((sessionToUpdate.getMaxInactiveIntervalInSeconds() * 1000) - 100);
}
assertThat(repository.getSession(sessionToUpdate.getId())).isNotNull();
assertThat(this.repository.getSession(sessionToUpdate.getId())).isNotNull();
}
@Configuration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2014-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.
@@ -13,12 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.session.hazelcast.config.annotation.web.http;
import static org.assertj.core.api.Assertions.*;
import com.hazelcast.config.ClasspathXmlConfig;
import com.hazelcast.config.Config;
import com.hazelcast.config.NetworkConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -29,16 +34,12 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.util.SocketUtils;
import com.hazelcast.config.ClasspathXmlConfig;
import com.hazelcast.config.Config;
import com.hazelcast.config.NetworkConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test the different configuration options for the
* {@link EnableHazelcastHttpSession} annotation.
*
*
* @author Tommy Ludwig
*/
public class HazelcastHttpSessionConfigurationXmlTests<S extends ExpiringSession> {
@@ -54,11 +55,11 @@ public class HazelcastHttpSessionConfigurationXmlTests<S extends ExpiringSession
@Test
public void saveSessionTest() throws InterruptedException {
S sessionToSave = repository.createSession();
S sessionToSave = this.repository.createSession();
repository.save(sessionToSave);
this.repository.save(sessionToSave);
S session = repository.getSession(sessionToSave.getId());
S session = this.repository.getSession(sessionToSave.getId());
assertThat(session.getId()).isEqualTo(sessionToSave.getId());
assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(1800);
@@ -91,11 +92,11 @@ public class HazelcastHttpSessionConfigurationXmlTests<S extends ExpiringSession
@Test
public void saveSessionTest() throws InterruptedException {
S sessionToSave = repository.createSession();
S sessionToSave = this.repository.createSession();
repository.save(sessionToSave);
this.repository.save(sessionToSave);
S session = repository.getSession(sessionToSave.getId());
S session = this.repository.getSession(sessionToSave.getId());
assertThat(session.getId()).isEqualTo(sessionToSave.getId());
assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(1200);