add Hazelcast session management #1571
Signed-off-by: olivier lamy <olamy@webtide.com>
This commit is contained in:
parent
caff2b932d
commit
8a300613df
|
@ -232,6 +232,11 @@
|
|||
<artifactId>jetty-infinispan</artifactId>
|
||||
<version>9.4.7-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-hazelcast</artifactId>
|
||||
<version>9.4.6-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-io</artifactId>
|
||||
|
|
|
@ -0,0 +1,165 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<version>9.4.6-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-hazelcast</artifactId>
|
||||
<name>Jetty :: Hazelcast Session Manager</name>
|
||||
|
||||
<properties>
|
||||
<hazelcast.version>3.8.2</hazelcast.version>
|
||||
<bundle-symbolic-name>${project.groupId}.session</bundle-symbolic-name>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.hazelcast</groupId>
|
||||
<artifactId>hazelcast</artifactId>
|
||||
<version>${hazelcast.version}</version>
|
||||
<type>test-jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hazelcast</groupId>
|
||||
<artifactId>hazelcast-client</artifactId>
|
||||
<version>${hazelcast.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hazelcast</groupId>
|
||||
<artifactId>hazelcast</artifactId>
|
||||
<version>${hazelcast.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-webapp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>websocket-servlet</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>websocket-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>manifest</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Export-Package>
|
||||
org.eclipse.jetty.hazelcast.session.*;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}";
|
||||
</Export-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>build-deps-file</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>list</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<appendOutput>false</appendOutput>
|
||||
<outputFile>${project.build.directory}/deps.txt</outputFile>
|
||||
<sort>true</sort>
|
||||
<excludeGroupIds>org.eclipse.jetty</excludeGroupIds>
|
||||
<prependGroupId>true</prependGroupId>
|
||||
<includeScope>runtime</includeScope>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>process-deps</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<replaceregexp file="${project.build.directory}/deps.txt"
|
||||
match="The following files have been resolved:"
|
||||
replace="[files]"
|
||||
/>
|
||||
</tasks>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>process-mod</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<concat destfile="${project.build.directory}/hazelcast-datastore.mod">
|
||||
<fileset file="src/main/config-template/modules/hazelcast-datastore.mod"/>
|
||||
<fileset file="${project.build.directory}/deps.txt"/>
|
||||
</concat>
|
||||
</tasks>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>src/main/assembly/config.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<assembly>
|
||||
<id>config</id>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<formats>
|
||||
<format>jar</format>
|
||||
</formats>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>src/main/config-template</directory>
|
||||
<outputDirectory></outputDirectory>
|
||||
<includes>
|
||||
<include>**</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/session-store-hazelcast.mod</exclude>
|
||||
</excludes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>target</directory>
|
||||
<outputDirectory>modules</outputDirectory>
|
||||
<includes>
|
||||
<include>session-store-hazelcast.mod</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
|
||||
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
|
||||
|
||||
<!-- ===================================================================== -->
|
||||
<!-- Configure a factory HazelcastSessionDataStoreaMap -->
|
||||
<!-- ===================================================================== -->
|
||||
<Call name="addBean">
|
||||
<Arg>
|
||||
<New id="sessionDataStoreFactory" class="org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory">
|
||||
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
||||
</Configure>
|
|
@ -0,0 +1,36 @@
|
|||
[description]
|
||||
Enables Hazelcast session management.
|
||||
|
||||
[tags]
|
||||
session
|
||||
hazelcast
|
||||
|
||||
[provides]
|
||||
session-store
|
||||
|
||||
[depends]
|
||||
annotations
|
||||
webapp
|
||||
sessions
|
||||
|
||||
[lib]
|
||||
lib/hazelcast/*.jar
|
||||
lib/jetty-hazelcast-session-manager-${jetty.version}.jar
|
||||
|
||||
[xml]
|
||||
etc/sessions/hazelcast/session-store.xml
|
||||
|
||||
[license]
|
||||
Hazelcast is an open source project hosted on Github and released under the Apache 2.0 license.
|
||||
http://hazelcast.org/
|
||||
http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
[ini]
|
||||
## Hide the hazelcast libraries from deployed webapps
|
||||
jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/hazelcast/
|
||||
|
||||
[ini-template]
|
||||
|
||||
## Hazelcast Session config
|
||||
#jetty.session.gracePeriod.seconds=3600
|
||||
# FIXME add some configuration
|
|
@ -0,0 +1,211 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session;
|
||||
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import com.hazelcast.core.IMap;
|
||||
import org.eclipse.jetty.server.session.AbstractSessionDataStore;
|
||||
import org.eclipse.jetty.server.session.SessionContext;
|
||||
import org.eclipse.jetty.server.session.SessionData;
|
||||
import org.eclipse.jetty.server.session.SessionDataMap;
|
||||
import org.eclipse.jetty.server.session.SessionDataStore;
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Session data stored in Hazelcast
|
||||
*/
|
||||
@ManagedObject
|
||||
public class HazelcastSessionDataStore
|
||||
extends AbstractSessionDataStore
|
||||
implements SessionDataStore
|
||||
{
|
||||
|
||||
private final static Logger LOG = Log.getLogger( "org.eclipse.jetty.server.session");
|
||||
|
||||
private HazelcastInstance hazelcastInstance;
|
||||
|
||||
private String jettySessionMapName;
|
||||
|
||||
private IMap<String, SessionData> sessionDataMap;
|
||||
|
||||
public HazelcastSessionDataStore()
|
||||
{
|
||||
// no op
|
||||
}
|
||||
|
||||
public HazelcastSessionDataStore( HazelcastInstance hazelcastInstance, String jettySessionMapName )
|
||||
{
|
||||
this.hazelcastInstance = hazelcastInstance;
|
||||
this.jettySessionMapName = jettySessionMapName;
|
||||
this.sessionDataMap = hazelcastInstance.getMap( getJettySessionMapName() );
|
||||
}
|
||||
|
||||
public HazelcastInstance getHazelcastInstance()
|
||||
{
|
||||
return hazelcastInstance;
|
||||
}
|
||||
|
||||
public void setHazelcastInstance( HazelcastInstance hazelcastInstance )
|
||||
{
|
||||
this.hazelcastInstance = hazelcastInstance;
|
||||
}
|
||||
|
||||
public String getJettySessionMapName()
|
||||
{
|
||||
return jettySessionMapName;
|
||||
}
|
||||
|
||||
public void setJettySessionMapName( String jettySessionMapName )
|
||||
{
|
||||
this.jettySessionMapName = jettySessionMapName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SessionData load( String id )
|
||||
throws Exception
|
||||
{
|
||||
return sessionDataMap == null ? null : sessionDataMap.get( id );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete( String id )
|
||||
throws Exception
|
||||
{
|
||||
return sessionDataMap == null ? false : sessionDataMap.remove( id ) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize( SessionContext context )
|
||||
throws Exception
|
||||
{
|
||||
_context = context;
|
||||
if (this.sessionDataMap == null)
|
||||
{
|
||||
this.sessionDataMap = getHazelcastInstance().getMap( getJettySessionMapName() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store( String id, SessionData data )
|
||||
throws Exception
|
||||
{
|
||||
this.sessionDataMap.put( id, data );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doStore( String id, SessionData data, long lastSaveTime )
|
||||
throws Exception
|
||||
{
|
||||
this.sessionDataMap.put( id, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPassivating()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> doGetExpired( Set<String> candidates )
|
||||
{
|
||||
if (candidates == null || candidates.isEmpty())
|
||||
{
|
||||
return Collections.emptySet();
|
||||
}
|
||||
long now = System.currentTimeMillis();
|
||||
return candidates.stream().filter( candidate -> {
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug( "Checking expiry for candidate {}", candidate );
|
||||
}
|
||||
try
|
||||
{
|
||||
SessionData sd = load(candidate);
|
||||
|
||||
//if the session no longer exists
|
||||
if (sd == null)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug( "Session {} does not exist in infinispan", candidate );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_context.getWorkerName().equals(sd.getLastNode()))
|
||||
{
|
||||
//we are its manager, add it to the expired set if it is expired now
|
||||
if ((sd.getExpiry() > 0 ) && sd.getExpiry() <= now)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug( "Session {} managed by {} is expired", candidate, _context.getWorkerName() );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//if we are not the session's manager, only expire it iff:
|
||||
// this is our first expiryCheck and the session expired a long time ago
|
||||
//or
|
||||
//the session expired at least one graceperiod ago
|
||||
if (_lastExpiryCheckTime <=0)
|
||||
{
|
||||
if ((sd.getExpiry() > 0 ) && sd.getExpiry() < (now - (1000L * (3 * _gracePeriodSec))))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((sd.getExpiry() > 0 ) && sd.getExpiry() < (now - (1000L * _gracePeriodSec)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.warn("Error checking if candidate {} is expired so expire it", candidate, e);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} ).collect( Collectors.toSet() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists( String id )
|
||||
throws Exception
|
||||
{
|
||||
return this.sessionDataMap.containsKey( id );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,176 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session;
|
||||
|
||||
import com.hazelcast.client.HazelcastClient;
|
||||
import com.hazelcast.client.config.ClientConfig;
|
||||
import com.hazelcast.client.config.XmlClientConfigBuilder;
|
||||
import com.hazelcast.config.Config;
|
||||
import com.hazelcast.config.MapConfig;
|
||||
import com.hazelcast.config.XmlConfigBuilder;
|
||||
import com.hazelcast.core.Hazelcast;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import org.eclipse.jetty.server.session.AbstractSessionDataStoreFactory;
|
||||
import org.eclipse.jetty.server.session.SessionDataMap;
|
||||
import org.eclipse.jetty.server.session.SessionDataStore;
|
||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||
import org.eclipse.jetty.server.session.SessionHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Factory to construct {@link HazelcastSessionDataStore}
|
||||
*/
|
||||
public class HazelcastSessionDataStoreFactory
|
||||
extends AbstractSessionDataStoreFactory
|
||||
implements SessionDataStoreFactory
|
||||
{
|
||||
|
||||
public static final String DEFAULT_HAZELCAST_INSTANCE_NAME = "JETTY_DISTRIBUTED_SESSION_INSTANCE";
|
||||
|
||||
public static final String DEFAULT_HAZELCAST_MAP_NAME = "jetty-distributed-session-map";
|
||||
|
||||
private boolean onlyClient;
|
||||
|
||||
private String configurationLocation;
|
||||
|
||||
private String jettySessionMapName = DEFAULT_HAZELCAST_MAP_NAME;
|
||||
|
||||
private HazelcastInstance hazelcastInstance;
|
||||
|
||||
private MapConfig mapConfig;
|
||||
|
||||
|
||||
@Override
|
||||
public SessionDataStore getSessionDataStore( SessionHandler handler )
|
||||
throws Exception
|
||||
{
|
||||
HazelcastSessionDataStore hazelcastSessionDataStore = new HazelcastSessionDataStore();
|
||||
|
||||
if ( hazelcastInstance == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( onlyClient )
|
||||
{
|
||||
if ( configurationLocation == null )
|
||||
{
|
||||
hazelcastSessionDataStore.setHazelcastInstance(
|
||||
HazelcastClient.newHazelcastClient( new ClientConfig() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
hazelcastSessionDataStore.setHazelcastInstance( HazelcastClient.newHazelcastClient(
|
||||
new XmlClientConfigBuilder( configurationLocation ).build() ) );
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Config config;
|
||||
if ( configurationLocation == null )
|
||||
{
|
||||
config = new Config();
|
||||
// configure a default Map if null
|
||||
if ( mapConfig == null )
|
||||
{
|
||||
mapConfig = new MapConfig();
|
||||
mapConfig.setName( jettySessionMapName );
|
||||
}
|
||||
else
|
||||
{
|
||||
// otherwise we reuse the name
|
||||
jettySessionMapName = mapConfig.getName();
|
||||
}
|
||||
config.addMapConfig( mapConfig );
|
||||
}
|
||||
else
|
||||
{
|
||||
config = new XmlConfigBuilder( configurationLocation ).build();
|
||||
}
|
||||
config.setInstanceName( DEFAULT_HAZELCAST_INSTANCE_NAME );
|
||||
hazelcastSessionDataStore.setHazelcastInstance( Hazelcast.getOrCreateHazelcastInstance( config ) );
|
||||
}
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new RuntimeException( e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hazelcastSessionDataStore.setHazelcastInstance( hazelcastInstance );
|
||||
}
|
||||
hazelcastSessionDataStore.setJettySessionMapName( jettySessionMapName );
|
||||
// initialize the map
|
||||
hazelcastSessionDataStore.getHazelcastInstance().getMap( jettySessionMapName );
|
||||
|
||||
return hazelcastSessionDataStore;
|
||||
}
|
||||
|
||||
public boolean isOnlyClient()
|
||||
{
|
||||
return onlyClient;
|
||||
}
|
||||
|
||||
public void setOnlyClient( boolean onlyClient )
|
||||
{
|
||||
this.onlyClient = onlyClient;
|
||||
}
|
||||
|
||||
public String getConfigurationLocation()
|
||||
{
|
||||
return configurationLocation;
|
||||
}
|
||||
|
||||
public void setConfigurationLocation( String configurationLocation )
|
||||
{
|
||||
this.configurationLocation = configurationLocation;
|
||||
}
|
||||
|
||||
public String getJettySessionMapName()
|
||||
{
|
||||
return jettySessionMapName;
|
||||
}
|
||||
|
||||
public void setJettySessionMapName( String jettySessionMapName )
|
||||
{
|
||||
this.jettySessionMapName = jettySessionMapName;
|
||||
}
|
||||
|
||||
public HazelcastInstance getHazelcastInstance()
|
||||
{
|
||||
return hazelcastInstance;
|
||||
}
|
||||
|
||||
public void setHazelcastInstance( HazelcastInstance hazelcastInstance )
|
||||
{
|
||||
this.hazelcastInstance = hazelcastInstance;
|
||||
}
|
||||
|
||||
public MapConfig getMapConfig()
|
||||
{
|
||||
return mapConfig;
|
||||
}
|
||||
|
||||
public void setMapConfig( MapConfig mapConfig )
|
||||
{
|
||||
this.mapConfig = mapConfig;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,203 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session;
|
||||
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
import org.eclipse.jetty.server.HttpConnectionFactory;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.server.session.AbstractSessionCache;
|
||||
import org.eclipse.jetty.server.session.CachingSessionDataStore;
|
||||
import org.eclipse.jetty.server.session.DefaultSessionCache;
|
||||
import org.eclipse.jetty.server.session.NullSessionDataStore;
|
||||
import org.eclipse.jetty.server.session.Session;
|
||||
import org.eclipse.jetty.server.session.SessionContext;
|
||||
import org.eclipse.jetty.server.session.SessionData;
|
||||
import org.eclipse.jetty.server.session.SessionDataMap;
|
||||
import org.eclipse.jetty.server.session.SessionHandler;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TestHazelcastSessions
|
||||
{
|
||||
public static class TestServlet
|
||||
extends HttpServlet
|
||||
{
|
||||
|
||||
@Override
|
||||
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
|
||||
throws ServletException, IOException
|
||||
{
|
||||
String arg = req.getParameter( "action" );
|
||||
if ( arg == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
HttpSession s = null;
|
||||
if ( "set".equals( arg ) )
|
||||
{
|
||||
s = req.getSession( true );
|
||||
assertNotNull( s );
|
||||
s.setAttribute( "val", req.getParameter( "value" ) );
|
||||
}
|
||||
else if ( "get".equals( arg ) )
|
||||
{
|
||||
s = req.getSession( false );
|
||||
System.err.println( "GET: s=" + s + ",id=" + (s != null ? s.getId() : "" ) );
|
||||
}
|
||||
else if ( "del".equals( arg ) )
|
||||
{
|
||||
s = req.getSession();
|
||||
assertNotNull( s );
|
||||
s.invalidate();
|
||||
s = null;
|
||||
}
|
||||
|
||||
resp.setContentType( "text/html" );
|
||||
PrintWriter w = resp.getWriter();
|
||||
if ( s == null )
|
||||
{
|
||||
w.write( "No session" );
|
||||
}
|
||||
else
|
||||
{
|
||||
w.write( (String) s.getAttribute( "val" ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private HazelcastSessionDataStore hazelcastSessionDataStore;
|
||||
|
||||
private Server server;
|
||||
|
||||
private ServerConnector serverConnector;
|
||||
|
||||
String contextPath = "/";
|
||||
|
||||
@Before
|
||||
public void initialize()
|
||||
throws Exception
|
||||
{
|
||||
|
||||
server = new Server();
|
||||
serverConnector = new ServerConnector( server, new HttpConnectionFactory() );
|
||||
server.addConnector( serverConnector );
|
||||
|
||||
ServletContextHandler context = new ServletContextHandler( ServletContextHandler.SESSIONS );
|
||||
context.setContextPath( contextPath );
|
||||
context.setResourceBase( System.getProperty( "java.io.tmpdir" ) );
|
||||
server.setHandler( context );
|
||||
|
||||
SessionContext sessionContext = new SessionContext( "foo", null );
|
||||
|
||||
HazelcastSessionDataStoreFactory hazelcastSessionDataStoreFactory = new HazelcastSessionDataStoreFactory();
|
||||
hazelcastSessionDataStore = (HazelcastSessionDataStore) hazelcastSessionDataStoreFactory.getSessionDataStore(
|
||||
context.getSessionHandler() );
|
||||
hazelcastSessionDataStore.initialize( sessionContext );
|
||||
|
||||
DefaultSessionCache defaultSessionCache = new DefaultSessionCache( context.getSessionHandler() );
|
||||
defaultSessionCache.setSessionDataStore( hazelcastSessionDataStore );
|
||||
context.getSessionHandler().setSessionCache( defaultSessionCache );
|
||||
// Add a test servlet
|
||||
context.addServlet( new ServletHolder( new TestServlet() ), contextPath );
|
||||
|
||||
server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
public void shutdown()
|
||||
throws Exception
|
||||
{
|
||||
hazelcastSessionDataStore.getHazelcastInstance().shutdown();
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHazelcast()
|
||||
throws Exception
|
||||
{
|
||||
|
||||
int port = serverConnector.getLocalPort();
|
||||
HttpClient client = new HttpClient();
|
||||
client.start();
|
||||
try
|
||||
{
|
||||
int value = 42;
|
||||
ContentResponse response =
|
||||
client.GET( "http://localhost:" + port + contextPath + "?action=set&value=" + value );
|
||||
assertEquals( HttpServletResponse.SC_OK, response.getStatus() );
|
||||
String sessionCookie = response.getHeaders().get( "Set-Cookie" );
|
||||
assertTrue( sessionCookie != null );
|
||||
// Mangle the cookie, replacing Path with $Path, etc.
|
||||
sessionCookie = sessionCookie.replaceFirst( "(\\W)(P|p)ath=", "$1\\$Path=" );
|
||||
|
||||
String resp = response.getContentAsString();
|
||||
assertEquals( resp.trim(), String.valueOf( value ) );
|
||||
|
||||
// Be sure the session value is still there
|
||||
Request request = client.newRequest( "http://localhost:" + port + contextPath + "?action=get" );
|
||||
request.header( "Cookie", sessionCookie );
|
||||
response = request.send();
|
||||
assertEquals( HttpServletResponse.SC_OK, response.getStatus() );
|
||||
|
||||
resp = response.getContentAsString();
|
||||
assertEquals( String.valueOf( value ), resp.trim() );
|
||||
|
||||
//Delete the session
|
||||
request = client.newRequest( "http://localhost:" + port + contextPath + "?action=del" );
|
||||
request.header( "Cookie", sessionCookie );
|
||||
response = request.send();
|
||||
assertEquals( HttpServletResponse.SC_OK, response.getStatus() );
|
||||
|
||||
//Check that the session is gone
|
||||
request = client.newRequest( "http://localhost:" + port + contextPath + "?action=get" );
|
||||
request.header( "Cookie", sessionCookie );
|
||||
response = request.send();
|
||||
assertEquals( HttpServletResponse.SC_OK, response.getStatus() );
|
||||
resp = response.getContentAsString();
|
||||
assertEquals( "No session", resp.trim() );
|
||||
|
||||
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -562,6 +562,11 @@
|
|||
<artifactId>jetty-infinispan</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-hazelcast</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.gcloud</groupId>
|
||||
<artifactId>jetty-gcloud-session-manager</artifactId>
|
||||
|
|
1
pom.xml
1
pom.xml
|
@ -79,6 +79,7 @@
|
|||
<module>jetty-infinispan</module>
|
||||
<module>jetty-gcloud</module>
|
||||
<module>jetty-memcached</module>
|
||||
<module>jetty-hazelcast</module>
|
||||
<module>jetty-unixsocket</module>
|
||||
<module>tests</module>
|
||||
<module>examples</module>
|
||||
|
|
|
@ -21,5 +21,6 @@
|
|||
<module>test-infinispan-sessions</module>
|
||||
<module>test-gcloud-sessions</module>
|
||||
<module>test-memcached-sessions</module>
|
||||
<module>test-hazelcast-sessions</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-sessions-parent</artifactId>
|
||||
<version>9.4.6-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>test-hazelcast-sessions</artifactId>
|
||||
<name>Jetty Tests :: Sessions :: Hazelcast</name>
|
||||
<url>http://www.eclipse.org/jetty</url>
|
||||
<properties>
|
||||
<bundle-symbolic-name>${project.groupId}.sessions.hazelcast</bundle-symbolic-name>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- DO NOT DEPLOY (or Release) -->
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>unpack</id>
|
||||
<phase>generate-test-resources</phase>
|
||||
<goals>
|
||||
<goal>unpack</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-policy</artifactId>
|
||||
<version>${jetty-test-policy-version}</version>
|
||||
<type>jar</type>
|
||||
<overWrite>true</overWrite>
|
||||
<includes>**/*.keystore,**/*.pem</includes>
|
||||
<outputDirectory>${jetty.test.policy.loc}</outputDirectory>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-webapp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-sessions-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-hazelcast</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-jmx</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,38 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session;
|
||||
|
||||
import org.eclipse.jetty.server.session.AbstractClusteredLastAccessTimeTest;
|
||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||
|
||||
public class ClusteredLastAccessTimeTest
|
||||
extends AbstractClusteredLastAccessTimeTest
|
||||
{
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractTestBase#createSessionDataStoreFactory()
|
||||
*/
|
||||
@Override
|
||||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory();
|
||||
return factory;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session;
|
||||
|
||||
import org.eclipse.jetty.server.session.AbstractClusteredOrphanedSessionTest;
|
||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||
|
||||
/**
|
||||
* ClusteredOrphanedSessionTest
|
||||
*/
|
||||
public class ClusteredOrphanedSessionTest
|
||||
extends AbstractClusteredOrphanedSessionTest
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractTestBase#createSessionDataStoreFactory()
|
||||
*/
|
||||
@Override
|
||||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory();
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session;
|
||||
|
||||
import org.eclipse.jetty.server.session.AbstractClusteredSessionMigrationTest;
|
||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||
|
||||
/**
|
||||
* ClusteredSessionMigrationTest
|
||||
*/
|
||||
public class ClusteredSessionMigrationTest
|
||||
extends AbstractClusteredSessionMigrationTest
|
||||
{
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractTestBase#createSessionDataStoreFactory()
|
||||
*/
|
||||
@Override
|
||||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory();
|
||||
return factory;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session;
|
||||
|
||||
import org.eclipse.jetty.server.session.AbstractClusteredSessionScavengingTest;
|
||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||
|
||||
/**
|
||||
* ClusteredSessionScavengingTest
|
||||
*/
|
||||
public class ClusteredSessionScavengingTest
|
||||
extends AbstractClusteredSessionScavengingTest
|
||||
{
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractTestBase#createSessionDataStoreFactory()
|
||||
*/
|
||||
@Override
|
||||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory();
|
||||
return factory;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session;
|
||||
|
||||
import org.eclipse.jetty.server.session.AbstractModifyMaxInactiveIntervalTest;
|
||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||
|
||||
/**
|
||||
* ModifyMaxInactiveIntervalTest
|
||||
*/
|
||||
public class ModifyMaxInactiveIntervalTest
|
||||
extends AbstractModifyMaxInactiveIntervalTest
|
||||
{
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractTestBase#createSessionDataStoreFactory()
|
||||
*/
|
||||
@Override
|
||||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory();
|
||||
return factory;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session;
|
||||
|
||||
import org.eclipse.jetty.server.session.AbstractNonClusteredSessionScavengingTest;
|
||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* NonClusteredSessionScavengingTest
|
||||
*/
|
||||
public class NonClusteredSessionScavengingTest
|
||||
extends AbstractNonClusteredSessionScavengingTest
|
||||
{
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractNonClusteredSessionScavengingTest#assertSession(java.lang.String, boolean)
|
||||
*/
|
||||
@Override
|
||||
public void assertSession( String id, boolean exists )
|
||||
{
|
||||
assertNotNull( _dataStore );
|
||||
|
||||
try
|
||||
{
|
||||
boolean inmap = _dataStore.exists( id );
|
||||
if ( exists )
|
||||
{
|
||||
assertTrue( inmap );
|
||||
}
|
||||
else
|
||||
{
|
||||
assertFalse( inmap );
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
fail( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractTestBase#createSessionDataStoreFactory()
|
||||
*/
|
||||
@Override
|
||||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory();
|
||||
return factory;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session;
|
||||
|
||||
import org.eclipse.jetty.server.session.AbstractSessionExpiryTest;
|
||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SessionExpiryTest
|
||||
extends AbstractSessionExpiryTest
|
||||
{
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractTestBase#createSessionDataStoreFactory()
|
||||
*/
|
||||
@Override
|
||||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory();
|
||||
return factory;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session;
|
||||
|
||||
import org.eclipse.jetty.server.session.AbstractSessionInvalidateCreateScavengeTest;
|
||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||
|
||||
/**
|
||||
* SessionInvalidateCreateScavengeTest
|
||||
*/
|
||||
public class SessionInvalidateCreateScavengeTest
|
||||
extends AbstractSessionInvalidateCreateScavengeTest
|
||||
{
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractTestBase#createSessionDataStoreFactory()
|
||||
*/
|
||||
@Override
|
||||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory();
|
||||
return factory;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session.client;
|
||||
|
||||
import com.hazelcast.config.Config;
|
||||
import com.hazelcast.config.MapConfig;
|
||||
import com.hazelcast.core.Hazelcast;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory;
|
||||
import org.eclipse.jetty.server.session.AbstractClusteredLastAccessTimeTest;
|
||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
public class ClientLastAccessTimeTest
|
||||
extends AbstractClusteredLastAccessTimeTest
|
||||
{
|
||||
|
||||
private static final String MAP_NAME = "jetty_foo_session";
|
||||
|
||||
private HazelcastInstance hazelcastInstance;
|
||||
|
||||
@Before
|
||||
public void startHazelcast()
|
||||
throws Exception
|
||||
{
|
||||
Config config = new Config().addMapConfig( new MapConfig().setName( MAP_NAME ) ) //
|
||||
.setInstanceName( "beer" );
|
||||
// start Hazelcast instance
|
||||
hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance( config );
|
||||
}
|
||||
|
||||
@After
|
||||
public void stopHazelcast()
|
||||
throws Exception
|
||||
{
|
||||
hazelcastInstance.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractTestBase#createSessionDataStoreFactory()
|
||||
*/
|
||||
@Override
|
||||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory();
|
||||
factory.setOnlyClient( true );
|
||||
factory.setJettySessionMapName( MAP_NAME );
|
||||
return factory;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session.client;
|
||||
|
||||
import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory;
|
||||
import org.eclipse.jetty.server.session.AbstractModifyMaxInactiveIntervalTest;
|
||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||
|
||||
/**
|
||||
* ModifyMaxInactiveIntervalTest
|
||||
*/
|
||||
public class ClientModifyMaxInactiveIntervalTest
|
||||
extends AbstractModifyMaxInactiveIntervalTest
|
||||
{
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractTestBase#createSessionDataStoreFactory()
|
||||
*/
|
||||
@Override
|
||||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory();
|
||||
return factory;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session.client;
|
||||
|
||||
import com.hazelcast.config.Config;
|
||||
import com.hazelcast.config.MapConfig;
|
||||
import com.hazelcast.core.Hazelcast;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory;
|
||||
import org.eclipse.jetty.server.session.AbstractNonClusteredSessionScavengingTest;
|
||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ClientNonClusteredSessionScavengingTest
|
||||
extends AbstractNonClusteredSessionScavengingTest
|
||||
{
|
||||
|
||||
/**
|
||||
* @see AbstractNonClusteredSessionScavengingTest#assertSession(String, boolean)
|
||||
*/
|
||||
@Override
|
||||
public void assertSession( String id, boolean exists )
|
||||
{
|
||||
assertNotNull( _dataStore );
|
||||
|
||||
try
|
||||
{
|
||||
boolean inmap = _dataStore.exists( id );
|
||||
if ( exists )
|
||||
{
|
||||
assertTrue( inmap );
|
||||
}
|
||||
else
|
||||
{
|
||||
assertFalse( inmap );
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
fail( e.getMessage() );
|
||||
}
|
||||
}
|
||||
private static final String MAP_NAME = "jetty_foo_session";
|
||||
|
||||
private HazelcastInstance hazelcastInstance;
|
||||
|
||||
@Before
|
||||
public void startHazelcast()
|
||||
throws Exception
|
||||
{
|
||||
Config config = new Config().addMapConfig( new MapConfig().setName( MAP_NAME ) ) //
|
||||
.setInstanceName( "beer" );
|
||||
// start Hazelcast instance
|
||||
hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance( config );
|
||||
}
|
||||
|
||||
@After
|
||||
public void stopHazelcast()
|
||||
throws Exception
|
||||
{
|
||||
hazelcastInstance.shutdown();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractTestBase#createSessionDataStoreFactory()
|
||||
*/
|
||||
@Override
|
||||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory();
|
||||
factory.setOnlyClient( true );
|
||||
factory.setJettySessionMapName( MAP_NAME );
|
||||
return factory;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session.client;
|
||||
|
||||
import com.hazelcast.config.Config;
|
||||
import com.hazelcast.config.MapConfig;
|
||||
import com.hazelcast.core.Hazelcast;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory;
|
||||
import org.eclipse.jetty.server.session.AbstractClusteredOrphanedSessionTest;
|
||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
public class ClientOrphanedSessionTest
|
||||
extends AbstractClusteredOrphanedSessionTest
|
||||
{
|
||||
|
||||
private static final String MAP_NAME = "jetty_foo_session";
|
||||
|
||||
private HazelcastInstance hazelcastInstance;
|
||||
|
||||
@Before
|
||||
public void startHazelcast()
|
||||
throws Exception
|
||||
{
|
||||
Config config = new Config().addMapConfig( new MapConfig().setName( MAP_NAME ) ) //
|
||||
.setInstanceName( "beer" );
|
||||
// start Hazelcast instance
|
||||
hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance( config );
|
||||
}
|
||||
|
||||
@After
|
||||
public void stopHazelcast()
|
||||
throws Exception
|
||||
{
|
||||
hazelcastInstance.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractTestBase#createSessionDataStoreFactory()
|
||||
*/
|
||||
@Override
|
||||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory();
|
||||
factory.setOnlyClient( true );
|
||||
factory.setJettySessionMapName( MAP_NAME );
|
||||
return factory;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session.client;
|
||||
|
||||
import com.hazelcast.config.Config;
|
||||
import com.hazelcast.config.MapConfig;
|
||||
import com.hazelcast.core.Hazelcast;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory;
|
||||
import org.eclipse.jetty.server.session.AbstractSessionExpiryTest;
|
||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ClientSessionExpiryTest
|
||||
extends AbstractSessionExpiryTest
|
||||
{
|
||||
|
||||
private static final String MAP_NAME = "jetty_foo_session";
|
||||
|
||||
private HazelcastInstance hazelcastInstance;
|
||||
|
||||
@Before
|
||||
public void startHazelcast()
|
||||
throws Exception
|
||||
{
|
||||
Config config = new Config().addMapConfig( new MapConfig().setName( MAP_NAME ) ) //
|
||||
.setInstanceName( "beer" );
|
||||
// start Hazelcast instance
|
||||
hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance( config );
|
||||
}
|
||||
|
||||
@After
|
||||
public void stopHazelcast()
|
||||
throws Exception
|
||||
{
|
||||
hazelcastInstance.shutdown();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractTestBase#createSessionDataStoreFactory()
|
||||
*/
|
||||
@Override
|
||||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory();
|
||||
factory.setOnlyClient( true );
|
||||
factory.setJettySessionMapName( MAP_NAME );
|
||||
return factory;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session.client;
|
||||
|
||||
import com.hazelcast.config.Config;
|
||||
import com.hazelcast.config.MapConfig;
|
||||
import com.hazelcast.core.Hazelcast;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory;
|
||||
import org.eclipse.jetty.server.session.AbstractSessionInvalidateCreateScavengeTest;
|
||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
public class ClientSessionInvalidateCreateScavengeTest
|
||||
extends AbstractSessionInvalidateCreateScavengeTest
|
||||
{
|
||||
private static final String MAP_NAME = "jetty_foo_session";
|
||||
|
||||
private HazelcastInstance hazelcastInstance;
|
||||
|
||||
@Before
|
||||
public void startHazelcast()
|
||||
throws Exception
|
||||
{
|
||||
Config config = new Config().addMapConfig( new MapConfig().setName( MAP_NAME ) ) //
|
||||
.setInstanceName( "beer" );
|
||||
// start Hazelcast instance
|
||||
hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance( config );
|
||||
}
|
||||
|
||||
@After
|
||||
public void stopHazelcast()
|
||||
throws Exception
|
||||
{
|
||||
hazelcastInstance.shutdown();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractTestBase#createSessionDataStoreFactory()
|
||||
*/
|
||||
@Override
|
||||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory();
|
||||
factory.setOnlyClient( true );
|
||||
factory.setJettySessionMapName( MAP_NAME );
|
||||
return factory;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session.client;
|
||||
|
||||
import com.hazelcast.config.Config;
|
||||
import com.hazelcast.config.MapConfig;
|
||||
import com.hazelcast.core.Hazelcast;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory;
|
||||
import org.eclipse.jetty.server.session.AbstractClusteredSessionMigrationTest;
|
||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
/**
|
||||
* ClusteredSessionMigrationTest
|
||||
*/
|
||||
public class ClientSessionMigrationTest
|
||||
extends AbstractClusteredSessionMigrationTest
|
||||
{
|
||||
private static final String MAP_NAME = "jetty_foo_session";
|
||||
|
||||
private HazelcastInstance hazelcastInstance;
|
||||
|
||||
@Before
|
||||
public void startHazelcast()
|
||||
throws Exception
|
||||
{
|
||||
Config config = new Config().addMapConfig( new MapConfig().setName( MAP_NAME ) ) //
|
||||
.setInstanceName( "beer" );
|
||||
// start Hazelcast instance
|
||||
hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance( config );
|
||||
}
|
||||
|
||||
@After
|
||||
public void stopHazelcast()
|
||||
throws Exception
|
||||
{
|
||||
hazelcastInstance.shutdown();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractTestBase#createSessionDataStoreFactory()
|
||||
*/
|
||||
@Override
|
||||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory();
|
||||
factory.setOnlyClient( true );
|
||||
factory.setJettySessionMapName( MAP_NAME );
|
||||
return factory;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.hazelcast.session.client;
|
||||
|
||||
import com.hazelcast.config.Config;
|
||||
import com.hazelcast.config.MapConfig;
|
||||
import com.hazelcast.core.Hazelcast;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory;
|
||||
import org.eclipse.jetty.server.session.AbstractClusteredSessionScavengingTest;
|
||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
public class ClientSessionScavengingTest
|
||||
extends AbstractClusteredSessionScavengingTest
|
||||
{
|
||||
|
||||
private static final String MAP_NAME = "jetty_foo_session";
|
||||
|
||||
private HazelcastInstance hazelcastInstance;
|
||||
|
||||
@Before
|
||||
public void startHazelcast()
|
||||
throws Exception
|
||||
{
|
||||
Config config = new Config().addMapConfig( new MapConfig().setName( MAP_NAME ) ) //
|
||||
.setInstanceName( "beer" );
|
||||
// start Hazelcast instance
|
||||
hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance( config );
|
||||
}
|
||||
|
||||
@After
|
||||
public void stopHazelcast()
|
||||
throws Exception
|
||||
{
|
||||
hazelcastInstance.shutdown();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractTestBase#createSessionDataStoreFactory()
|
||||
*/
|
||||
@Override
|
||||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory();
|
||||
factory.setOnlyClient( true );
|
||||
factory.setJettySessionMapName( MAP_NAME );
|
||||
return factory;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue