Jetty 10.0.x 6687 upgrade infinispan (#6766)

* Issue #6687 Update to infinispan 11.0.11

Signed-off-by: Jan Bartel <janb@webtide.com>


* fix upperbound dependency
* use infinispan bom

Signed-off-by: Olivier Lamy <oliver.lamy@gmail.com>

Co-authored-by: Olivier Lamy <oliver.lamy@gmail.com>
This commit is contained in:
Jan Bartel 2021-09-21 11:16:50 +10:00 committed by GitHub
parent 2396594b40
commit d3bfb61761
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 656 additions and 336 deletions

View File

@ -414,6 +414,12 @@
<artifactId>infinispan-core</artifactId> <artifactId>infinispan-core</artifactId>
<version>${infinispan.version}</version> <version>${infinispan.version}</version>
<scope>provided</scope> <scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.wildfly.common</groupId>
<artifactId>wildfly-common</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<!-- to make infinispan-common source sane --> <!-- to make infinispan-common source sane -->
<dependency> <dependency>
@ -426,7 +432,7 @@
<dependency> <dependency>
<groupId>org.infinispan.protostream</groupId> <groupId>org.infinispan.protostream</groupId>
<artifactId>protostream</artifactId> <artifactId>protostream</artifactId>
<version>4.2.2.Final</version> <version>${infinispan.protostream.version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -750,6 +750,12 @@
<version>${project.version}</version> <version>${project.version}</version>
<type>pom</type> <type>pom</type>
<optional>true</optional> <optional>true</optional>
<exclusions>
<exclusion>
<groupId>org.wildfly.common</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>

View File

@ -37,8 +37,13 @@
<dependency> <dependency>
<groupId>org.infinispan</groupId> <groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId> <artifactId>infinispan-core</artifactId>
<version>${infinispan.version}</version>
<optional>true</optional> <optional>true</optional>
<exclusions>
<exclusion>
<groupId>org.wildfly.common</groupId>
<artifactId>wildfly-common</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.infinispan.protostream</groupId> <groupId>org.infinispan.protostream</groupId>
@ -63,13 +68,11 @@
<dependency> <dependency>
<groupId>org.infinispan</groupId> <groupId>org.infinispan</groupId>
<artifactId>infinispan-client-hotrod</artifactId> <artifactId>infinispan-client-hotrod</artifactId>
<version>${infinispan.version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.infinispan</groupId> <groupId>org.infinispan</groupId>
<artifactId>infinispan-remote-query-client</artifactId> <artifactId>infinispan-remote-query-client</artifactId>
<version>${infinispan.version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -10,6 +10,7 @@
<Set name="infinispanIdleTimeoutSec" property="jetty.session.infinispan.idleTimeout.seconds"/> <Set name="infinispanIdleTimeoutSec" property="jetty.session.infinispan.idleTimeout.seconds"/>
<Set name="gracePeriodSec" property="jetty.session.gracePeriod.seconds"/> <Set name="gracePeriodSec" property="jetty.session.gracePeriod.seconds"/>
<Set name="savePeriodSec" property="jetty.session.savePeriod.seconds"/> <Set name="savePeriodSec" property="jetty.session.savePeriod.seconds"/>
<Set name="serialization" property="jetty.session.infinispan.serialization"/>
</New> </New>
</Arg> </Arg>
</Call> </Call>

View File

@ -13,7 +13,7 @@ lib/infinispan-common-${jetty.version}.jar
lib/infinispan/*.jar lib/infinispan/*.jar
[ini] [ini]
infinispan.version?=9.4.8.Final infinispan.version?=11.0.11.Final
[license] [license]
Infinispan is an open source project hosted on Github and released under the Apache 2.0 license. Infinispan is an open source project hosted on Github and released under the Apache 2.0 license.

View File

@ -0,0 +1,51 @@
//
// ========================================================================
// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.session.infinispan;
import java.io.UncheckedIOException;
import org.infinispan.protostream.FileDescriptorSource;
import org.infinispan.protostream.SerializationContext;
import org.infinispan.protostream.SerializationContextInitializer;
/**
* Set up the marshaller for InfinispanSessionData serialization
*
*/
public class InfinispanSerializationContextInitializer implements SerializationContextInitializer
{
@Override
public String getProtoFileName()
{
return "session.proto";
}
@Override
public String getProtoFile() throws UncheckedIOException
{
return FileDescriptorSource.getResourceAsString(getClass(), "/" + getProtoFileName());
}
@Override
public void registerSchema(SerializationContext serCtx)
{
serCtx.registerProtoFiles(FileDescriptorSource.fromString(getProtoFileName(), getProtoFile()));
}
@Override
public void registerMarshallers(SerializationContext serCtx)
{
serCtx.registerMarshaller(new SessionDataMarshaller());
}
}

View File

@ -33,7 +33,6 @@ import org.infinispan.commons.marshall.SerializeWith;
* pool and thus these threads have no knowledge of the correct classloader to * pool and thus these threads have no knowledge of the correct classloader to
* use. * use.
*/ */
@SerializeWith(SessionDataMarshaller.class)
public class InfinispanSessionData extends SessionData public class InfinispanSessionData extends SessionData
{ {
protected byte[] _serializedAttributes; protected byte[] _serializedAttributes;

View File

@ -44,6 +44,7 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
private int _infinispanIdleTimeoutSec; private int _infinispanIdleTimeoutSec;
private QueryManager _queryManager; private QueryManager _queryManager;
private boolean _passivating; private boolean _passivating;
private boolean _serialization;
/** /**
* Get the clustered cache instance. * Get the clustered cache instance.
@ -74,9 +75,8 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
try try
{ {
_passivating = false;
Class<?> remoteClass = InfinispanSessionDataStore.class.getClassLoader().loadClass("org.infinispan.client.hotrod.RemoteCache"); Class<?> remoteClass = InfinispanSessionDataStore.class.getClassLoader().loadClass("org.infinispan.client.hotrod.RemoteCache");
if (remoteClass.isAssignableFrom(_cache.getClass())) if (remoteClass.isAssignableFrom(_cache.getClass()) || _serialization)
_passivating = true; _passivating = true;
} }
catch (ClassNotFoundException e) catch (ClassNotFoundException e)
@ -105,6 +105,9 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
LOG.debug("Loading session {} from infinispan", id); LOG.debug("Loading session {} from infinispan", id);
InfinispanSessionData sd = _cache.get(getCacheKey(id)); InfinispanSessionData sd = _cache.get(getCacheKey(id));
//Deserialize the attributes now that we are back in a thread that
//has the correct classloader set on it
if (isPassivating() && sd != null) if (isPassivating() && sd != null)
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
@ -205,6 +208,15 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
@Override @Override
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
{ {
//prepare for serialization: we need to convert the attributes now while the context
//classloader is set, because infinispan uses a different thread and classloader to
//perform the serialization
if (isPassivating() && data != null)
{
if (LOG.isDebugEnabled())
LOG.debug("Serializing session attributes for {}", id);
((InfinispanSessionData)data).serializeAttributes();
}
//Put an idle timeout on the cache entry if the session is not immortal - //Put an idle timeout on the cache entry if the session is not immortal -
//if no requests arrive at any node before this timeout occurs, or no node //if no requests arrive at any node before this timeout occurs, or no node
//scavenges the session before this timeout occurs, the session will be removed. //scavenges the session before this timeout occurs, the session will be removed.
@ -270,6 +282,11 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
{ {
return _infinispanIdleTimeoutSec; return _infinispanIdleTimeoutSec;
} }
public void setSerialization(boolean serialization)
{
_serialization = serialization;
}
@Override @Override
public String toString() public String toString()

View File

@ -26,6 +26,7 @@ public class InfinispanSessionDataStoreFactory extends AbstractSessionDataStoreF
int _infinispanIdleTimeoutSec; int _infinispanIdleTimeoutSec;
BasicCache<String, InfinispanSessionData> _cache; BasicCache<String, InfinispanSessionData> _cache;
protected QueryManager _queryManager; protected QueryManager _queryManager;
protected boolean _serialization;
/** /**
* @return the infinispanIdleTimeoutSec * @return the infinispanIdleTimeoutSec
@ -52,6 +53,7 @@ public class InfinispanSessionDataStoreFactory extends AbstractSessionDataStoreF
store.setCache(getCache()); store.setCache(getCache());
store.setSavePeriodSec(getSavePeriodSec()); store.setSavePeriodSec(getSavePeriodSec());
store.setQueryManager(getQueryManager()); store.setQueryManager(getQueryManager());
store.setSerialization(getSerialization());
return store; return store;
} }
@ -84,4 +86,14 @@ public class InfinispanSessionDataStoreFactory extends AbstractSessionDataStoreF
{ {
_queryManager = queryManager; _queryManager = queryManager;
} }
public void setSerialization(boolean serialization)
{
_serialization = serialization;
}
public boolean getSerialization()
{
return _serialization;
}
} }

View File

@ -14,10 +14,7 @@
package org.eclipse.jetty.session.infinispan; package org.eclipse.jetty.session.infinispan;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.infinispan.commons.marshall.Externalizer;
import org.infinispan.protostream.FileDescriptorSource; import org.infinispan.protostream.FileDescriptorSource;
import org.infinispan.protostream.MessageMarshaller; import org.infinispan.protostream.MessageMarshaller;
import org.infinispan.protostream.ProtobufUtil; import org.infinispan.protostream.ProtobufUtil;
@ -31,8 +28,7 @@ import org.infinispan.protostream.SerializationContext;
* control to ensure that session attributes can be deserialized using either * control to ensure that session attributes can be deserialized using either
* the container class loader or the webapp classloader, as appropriate. * the container class loader or the webapp classloader, as appropriate.
*/ */
public class SessionDataMarshaller public class SessionDataMarshaller implements MessageMarshaller<InfinispanSessionData>
implements MessageMarshaller<InfinispanSessionData>, Externalizer<InfinispanSessionData>
{ {
/** /**
* The version of the serializer. * The version of the serializer.
@ -67,39 +63,6 @@ public class SessionDataMarshaller
return "org_eclipse_jetty_session_infinispan.InfinispanSessionData"; return "org_eclipse_jetty_session_infinispan.InfinispanSessionData";
} }
@Override
public InfinispanSessionData readObject(ObjectInput input) throws IOException, ClassNotFoundException
{
if (serializationContext == null)
{
initSerializationContext();
}
// invokes readFrom(ProtoStreamReader)
InfinispanSessionData data = ProtobufUtil.readFrom(serializationContext, new BoundDelegatingInputStream(input),
InfinispanSessionData.class);
if (data != null)
{
data.deserializeAttributes();
}
return data;
}
@Override
public void writeObject(ObjectOutput output, InfinispanSessionData object) throws IOException
{
if (serializationContext == null)
{
initSerializationContext();
}
// invokes writeTo(ProtoStreamWriter, InfinispanSessionData)
byte[] data = ProtobufUtil.toByteArray(serializationContext, object);
int length = data.length;
output.writeInt(length);
output.write(data);
}
@Override @Override
public InfinispanSessionData readFrom(ProtoStreamReader in) throws IOException public InfinispanSessionData readFrom(ProtoStreamReader in) throws IOException
{ {
@ -127,6 +90,9 @@ public class SessionDataMarshaller
if (version == 0) if (version == 0)
{ {
byte[] attributeArray = in.readBytes("attributes"); byte[] attributeArray = in.readBytes("attributes");
//only save the serialized bytes here, do NOT deserialize because
//infinispan has called this method with their own thread without
//the appropriate classloader being set
sd.setSerializedAttributes(attributeArray); sd.setSerializedAttributes(attributeArray);
return sd; return sd;
} }
@ -152,7 +118,9 @@ public class SessionDataMarshaller
out.writeLong("expiry", sdata.getExpiry()); out.writeLong("expiry", sdata.getExpiry());
out.writeLong("maxInactiveMs", sdata.getMaxInactiveMs()); out.writeLong("maxInactiveMs", sdata.getMaxInactiveMs());
sdata.serializeAttributes(); //the session data attributes MUST be previously serialized
//because this method is called from an infinispan thread that cannot
//have the appropriate classloader set on it
out.writeBytes("attributes", sdata.getSerializedAttributes()); out.writeBytes("attributes", sdata.getSerializedAttributes());
} }

View File

@ -106,7 +106,6 @@
<dependency> <dependency>
<groupId>org.infinispan</groupId> <groupId>org.infinispan</groupId>
<artifactId>infinispan-query</artifactId> <artifactId>infinispan-query</artifactId>
<version>${infinispan.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty.toolchain</groupId> <groupId>org.eclipse.jetty.toolchain</groupId>

View File

@ -22,6 +22,7 @@ import org.infinispan.Cache;
import org.infinispan.query.Search; import org.infinispan.query.Search;
import org.infinispan.query.dsl.Query; import org.infinispan.query.dsl.Query;
import org.infinispan.query.dsl.QueryFactory; import org.infinispan.query.dsl.QueryFactory;
import org.infinispan.query.dsl.QueryResult;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -32,39 +33,40 @@ public class EmbeddedQueryManager implements QueryManager
private static final Logger LOG = LoggerFactory.getLogger(EmbeddedQueryManager.class); private static final Logger LOG = LoggerFactory.getLogger(EmbeddedQueryManager.class);
private Cache<String, InfinispanSessionData> _cache; private Cache<String, InfinispanSessionData> _cache;
private QueryFactory _factory;
public EmbeddedQueryManager(Cache<String, InfinispanSessionData> cache) public EmbeddedQueryManager(Cache<String, InfinispanSessionData> cache)
{ {
_cache = cache; _cache = cache;
_factory = Search.getQueryFactory(_cache);
} }
@Override @Override
public Set<String> queryExpiredSessions(SessionContext sessionContext, long time) public Set<String> queryExpiredSessions(SessionContext sessionContext, long time)
{ {
Objects.requireNonNull(sessionContext); Objects.requireNonNull(sessionContext);
QueryFactory qf = Search.getQueryFactory(_cache); Query<InfinispanSessionData> expiredQuery = _factory.create("select id from org.eclipse.jetty.session.infinispan.InfinispanSessionData where " +
Query q = qf.from(InfinispanSessionData.class) " contextPath = :contextPath and expiry <= :expiry and expiry > 0");
.select("id") expiredQuery.setParameter("contextPath", sessionContext.getCanonicalContextPath());
.having("contextPath").eq(sessionContext.getCanonicalContextPath()) expiredQuery.setParameter("expiry", time);
.and()
.having("expiry").lte(time) @SuppressWarnings("rawtypes")
.and().having("expiry").gt(0) QueryResult result = expiredQuery.execute();
.build(); List<Object[]> list = result.list();
List<Object[]> list = q.list();
Set<String> ids = list.stream().map(a -> (String)a[0]).collect(toSet()); Set<String> ids = list.stream().map(a -> (String)a[0]).collect(toSet());
return ids; return ids;
} }
public void deleteOrphanSessions(long time) public void deleteOrphanSessions(long time)
{ {
QueryFactory qf = Search.getQueryFactory(_cache); Query<InfinispanSessionData> deleteQuery = _factory.create("select id, contextPath, vhost from org.eclipse.jetty.session.infinispan.InfinispanSessionData where " +
Query q = qf.from(InfinispanSessionData.class) " expiry <= :expiry and expiry > 0");
.select("id", "contextPath", "vhost") deleteQuery.setParameter("expiry", time);
.having("expiry").lte(time)
.and().having("expiry").gt(0) @SuppressWarnings("rawtypes")
.build(); QueryResult result = deleteQuery.execute();
List<Object[]> list = q.list(); List<Object[]> list = result.list();
list.stream().forEach(a -> list.stream().forEach(a ->
{ {
String key = InfinispanKeyBuilder.build((String)a[1], (String)a[2], (String)a[0]); String key = InfinispanKeyBuilder.build((String)a[1], (String)a[2], (String)a[0]);
@ -83,18 +85,16 @@ public class EmbeddedQueryManager implements QueryManager
public boolean exists(SessionContext sessionContext, String id) public boolean exists(SessionContext sessionContext, String id)
{ {
Objects.requireNonNull(sessionContext); Objects.requireNonNull(sessionContext);
QueryFactory qf = Search.getQueryFactory(_cache); Query<InfinispanSessionData> existQuery = _factory.create("select id from org.eclipse.jetty.session.infinispan.InfinispanSessionData where" +
Query q = qf.from(InfinispanSessionData.class) " id = :id and contextPath = :contextPath and expiry > :time or expiry <= 0");
.select("id") existQuery.setParameter("id", id);
.having("id").eq(id) existQuery.setParameter("contextPath", sessionContext.getCanonicalContextPath());
.and() existQuery.setParameter("time", System.currentTimeMillis());
.having("contextPath").eq(sessionContext.getCanonicalContextPath())
.and() @SuppressWarnings("rawtypes")
.having("expiry").gt(System.currentTimeMillis()) QueryResult result = existQuery.execute();
.or() List<Object[]> list = result.list();
.having("expiry").lte(0)
.build();
List<Object[]> list = q.list();
return !list.isEmpty(); return !list.isEmpty();
} }
} }

View File

@ -31,7 +31,6 @@ import org.hibernate.search.cfg.SearchMapping;
import org.infinispan.Cache; import org.infinispan.Cache;
import org.infinispan.configuration.cache.Configuration; import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.cache.ConfigurationBuilder; import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.configuration.cache.Index;
import org.infinispan.configuration.global.GlobalConfigurationBuilder; import org.infinispan.configuration.global.GlobalConfigurationBuilder;
import org.infinispan.manager.DefaultCacheManager; import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.manager.EmbeddedCacheManager;
@ -51,7 +50,7 @@ public class EmbeddedQueryManagerTest
public void test() public void test()
{ {
String name = DEFAULT_CACHE_NAME + System.currentTimeMillis(); String name = DEFAULT_CACHE_NAME + System.currentTimeMillis();
EmbeddedCacheManager cacheManager = new DefaultCacheManager(new GlobalConfigurationBuilder().globalJmxStatistics().allowDuplicateDomains(true).build()); EmbeddedCacheManager cacheManager = new DefaultCacheManager(new GlobalConfigurationBuilder().jmx().build());
//TODO verify that this is being indexed properly, if you change expiry to something that is not a valid field it still passes the tests //TODO verify that this is being indexed properly, if you change expiry to something that is not a valid field it still passes the tests
SearchMapping mapping = new SearchMapping(); SearchMapping mapping = new SearchMapping();
@ -66,7 +65,7 @@ public class EmbeddedQueryManagerTest
if (dcc != null) if (dcc != null)
b = b.read(dcc); b = b.read(dcc);
b.indexing().index(Index.ALL).addIndexedEntity(InfinispanSessionData.class).withProperties(properties); b.indexing().addIndexedEntity(InfinispanSessionData.class).withProperties(properties);
Configuration c = b.build(); Configuration c = b.build();
cacheManager.defineConfiguration(name, c); cacheManager.defineConfiguration(name, c);

View File

@ -98,7 +98,12 @@
<dependency> <dependency>
<groupId>org.infinispan</groupId> <groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId> <artifactId>infinispan-core</artifactId>
<version>${infinispan.version}</version> <exclusions>
<exclusion>
<groupId>org.wildfly.common</groupId>
<artifactId>wildfly-common</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -16,9 +16,10 @@ sessions/infinispan/embedded/infinispan-embedded-libs
basehome:modules/sessions/infinispan/embedded/infinispan.xml|etc/infinispan.xml basehome:modules/sessions/infinispan/embedded/infinispan.xml|etc/infinispan.xml
[ini] [ini]
infinispan.version?=9.4.8.Final infinispan.version?=11.0.11.Final
[ini-template] [ini-template]
#jetty.session.infinispan.idleTimeout.seconds=0 #jetty.session.infinispan.idleTimeout.seconds=0
#jetty.session.infinispan.serialization=false
#jetty.session.gracePeriod.seconds=3600 #jetty.session.gracePeriod.seconds=3600
#jetty.session.savePeriod.seconds=0 #jetty.session.savePeriod.seconds=0

View File

@ -9,7 +9,7 @@
<name>Jetty :: Infinispan Session Manager Remote with Querying</name> <name>Jetty :: Infinispan Session Manager Remote with Querying</name>
<properties> <properties>
<bundle-symbolic-name>${project.groupId}.infinispan.remote.query</bundle-symbolic-name> <bundle-symbolic-name>${project.groupId}.infinispan.remote.query</bundle-symbolic-name>
<infinispan.docker.image.version>9.4.8.Final</infinispan.docker.image.version> <infinispan.docker.image.version>11.0.9.Final</infinispan.docker.image.version>
</properties> </properties>
<build> <build>
<plugins> <plugins>
@ -116,17 +116,24 @@
<dependency> <dependency>
<groupId>org.infinispan</groupId> <groupId>org.infinispan</groupId>
<artifactId>infinispan-query</artifactId> <artifactId>infinispan-query</artifactId>
<version>${infinispan.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.infinispan</groupId> <groupId>org.infinispan</groupId>
<artifactId>infinispan-client-hotrod</artifactId> <artifactId>infinispan-client-hotrod</artifactId>
<version>${infinispan.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.infinispan</groupId> <groupId>org.infinispan</groupId>
<artifactId>infinispan-remote-query-client</artifactId> <artifactId>infinispan-remote-query-client</artifactId>
<version>${infinispan.version}</version> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>

View File

@ -45,9 +45,14 @@
</Call> </Call>
<Call name="marshaller"> <Call name="marshaller">
<Arg> <Arg>
<New class="org.infinispan.client.hotrod.marshall.ProtoStreamMarshaller"/> <New class="org.infinispan.commons.marshall.ProtoStreamMarshaller"/>
</Arg> </Arg>
</Call> </Call>
<Call name="addContextInitializer">
<Arg>
<New class="org.eclipse.jetty.session.infinispan.InfinispanSerializationContextInitializer"/>
</Arg>
</Call>
<Call id="config" name="build"/> <Call id="config" name="build"/>
</New> </New>
@ -58,33 +63,6 @@
<Arg><Ref refid="config"/></Arg> <Arg><Ref refid="config"/></Arg>
</New> </New>
<!-- ===================================================================== -->
<!-- Set up custom session serialization. -->
<!-- ===================================================================== -->
<Call id="serial_context" class="org.infinispan.client.hotrod.marshall.ProtoStreamMarshaller" name="getSerializationContext">
<Arg>
<Ref refid="remoteCacheManager"/>
</Arg>
<Call name="registerProtoFiles">
<Arg>
<New class="org.infinispan.protostream.FileDescriptorSource">
<Call name="addProtoFiles">
<Arg>
<Array type="java.lang.String">
<Item>/session.proto</Item>
</Array>
</Arg>
</Call>
</New>
</Arg>
</Call>
<Call name="registerMarshaller">
<Arg>
<New class="org.eclipse.jetty.session.infinispan.SessionDataMarshaller"/>
</Arg>
</Call>
</Call>
<!-- ===================================================================== --> <!-- ===================================================================== -->
<!-- Get a reference to the remote cache. --> <!-- Get a reference to the remote cache. -->
<!-- ===================================================================== --> <!-- ===================================================================== -->

View File

@ -10,13 +10,9 @@ infinispan-remote
[depends] [depends]
sessions/infinispan/remote/infinispan-remote-query-libs sessions/infinispan/remote/infinispan-remote-query-libs
[files]
basehome:modules/sessions/infinispan/remote/other_proto_marshallers.xml|etc/other_proto_marshallers.xml
[lib] [lib]
lib/infinispan-remote-query-${jetty.version}.jar lib/infinispan-remote-query-${jetty.version}.jar
[xml] [xml]
etc/sessions/infinispan/infinispan-remote-query.xml etc/sessions/infinispan/infinispan-remote-query.xml
etc/other_proto_marshallers.xml
etc/sessions/infinispan/infinispan-common.xml etc/sessions/infinispan/infinispan-common.xml

View File

@ -1,39 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- ============================================================= -->
<!-- If your sessions contain any objects of classes from your -->
<!-- from your application, you need to describe each class in a -->
<!-- .proto file, and supply a marshaller for each to read/write -->
<!-- instances. These classes will need to exist on the server's -->
<!-- classpath because they are referenced BEFORE your webapp is -->
<!-- started. -->
<!-- ============================================================= -->
<Ref refid="serial_context">
<!--
<Call name="registerProtoFiles">
<Arg>
<New class="org.infinispan.protostream.FileDescriptorSource">
<Call name="addProtoFile">
<Arg>my.proto</Arg>
<Arg>
<New class="java.io.File">
<Arg><Property name="jetty.base"/>/etc/my.proto</Arg>
</New>
</Arg>
</Call>
</New>
</Arg>
</Call>
-->
<!--
<Call name="registerMarshaller">
<Arg>
<New class="com.acme.MyMarshaller"/>
</Arg>
</Call>
-->
</Ref>
</Configure>

View File

@ -22,6 +22,7 @@ import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.Search; import org.infinispan.client.hotrod.Search;
import org.infinispan.query.dsl.Query; import org.infinispan.query.dsl.Query;
import org.infinispan.query.dsl.QueryFactory; import org.infinispan.query.dsl.QueryFactory;
import org.infinispan.query.dsl.QueryResult;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -36,27 +37,27 @@ public class RemoteQueryManager implements QueryManager
{ {
private static final Logger LOG = LoggerFactory.getLogger(RemoteQueryManager.class); private static final Logger LOG = LoggerFactory.getLogger(RemoteQueryManager.class);
private RemoteCache<String, InfinispanSessionData> _cache; private RemoteCache<String, InfinispanSessionData> _cache;
private QueryFactory _factory;
public RemoteQueryManager(RemoteCache<String, InfinispanSessionData> cache) public RemoteQueryManager(RemoteCache<String, InfinispanSessionData> cache)
{ {
_cache = cache; _cache = cache;
_factory = Search.getQueryFactory(_cache);
} }
@Override @Override
public Set<String> queryExpiredSessions(SessionContext sessionContext, long time) public Set<String> queryExpiredSessions(SessionContext sessionContext, long time)
{ {
Objects.requireNonNull(sessionContext); Objects.requireNonNull(sessionContext);
QueryFactory qf = Search.getQueryFactory(_cache);
Query q = qf.from(InfinispanSessionData.class)
.select("id")
.having("contextPath").eq(sessionContext.getCanonicalContextPath())
.and()
.having("expiry").lte(time)
.and()
.having("expiry").gt(0)
.build();
List<Object[]> list = q.list(); Query<InfinispanSessionData> expiredQuery = _factory.create("select id from org_eclipse_jetty_session_infinispan.InfinispanSessionData where " +
" contextPath = :contextPath and expiry <= :expiry and expiry > 0");
expiredQuery.setParameter("contextPath", sessionContext.getCanonicalContextPath());
expiredQuery.setParameter("expiry", time);
@SuppressWarnings("rawtypes")
QueryResult result = expiredQuery.execute();
List<Object[]> list = result.list();
Set<String> ids = list.stream().map(a -> (String)a[0]).collect(toSet()); Set<String> ids = list.stream().map(a -> (String)a[0]).collect(toSet());
return ids; return ids;
} }
@ -64,14 +65,13 @@ public class RemoteQueryManager implements QueryManager
@Override @Override
public void deleteOrphanSessions(long time) public void deleteOrphanSessions(long time)
{ {
QueryFactory qf = Search.getQueryFactory(_cache); Query<InfinispanSessionData> deleteQuery = _factory.create("select id, contextPath, vhost from org_eclipse_jetty_session_infinispan.InfinispanSessionData where " +
Query q = qf.from(InfinispanSessionData.class) " expiry <= :expiry and expiry > 0");
.select("id", "contextPath", "vhost") deleteQuery.setParameter("expiry", time);
.having("expiry").lte(time)
.and() @SuppressWarnings("rawtypes")
.having("expiry").gt(0) QueryResult result = deleteQuery.execute();
.build(); List<Object[]> list = result.list();
List<Object[]> list = q.list();
list.stream().forEach(a -> list.stream().forEach(a ->
{ {
String key = InfinispanKeyBuilder.build((String)a[1], (String)a[2], (String)a[0]); String key = InfinispanKeyBuilder.build((String)a[1], (String)a[2], (String)a[0]);
@ -90,19 +90,16 @@ public class RemoteQueryManager implements QueryManager
public boolean exists(SessionContext sessionContext, String id) public boolean exists(SessionContext sessionContext, String id)
{ {
Objects.requireNonNull(sessionContext); Objects.requireNonNull(sessionContext);
QueryFactory qf = Search.getQueryFactory(_cache);
Query q = qf.from(InfinispanSessionData.class)
.select("id")
.having("id").eq(id)
.and()
.having("contextPath").eq(sessionContext.getCanonicalContextPath())
.and()
.having("expiry").gt(System.currentTimeMillis())
.or()
.having("expiry").lte(0)
.build();
List<Object[]> list = q.list(); Query<InfinispanSessionData> existQuery = _factory.create("select id from org_eclipse_jetty_session_infinispan.InfinispanSessionData where" +
" id = :id and contextPath = :contextPath and expiry > :time or expiry <= 0");
existQuery.setParameter("id", id);
existQuery.setParameter("contextPath", sessionContext.getCanonicalContextPath());
existQuery.setParameter("time", System.currentTimeMillis());
@SuppressWarnings("rawtypes")
QueryResult result = existQuery.execute();
List<Object[]> list = result.list();
return !list.isEmpty(); return !list.isEmpty();
} }
} }

View File

@ -24,10 +24,10 @@ import java.util.Set;
import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.session.SessionContext; import org.eclipse.jetty.server.session.SessionContext;
import org.eclipse.jetty.server.session.SessionData; import org.eclipse.jetty.server.session.SessionData;
import org.eclipse.jetty.session.infinispan.InfinispanSerializationContextInitializer;
import org.eclipse.jetty.session.infinispan.InfinispanSessionData; import org.eclipse.jetty.session.infinispan.InfinispanSessionData;
import org.eclipse.jetty.session.infinispan.QueryManager; import org.eclipse.jetty.session.infinispan.QueryManager;
import org.eclipse.jetty.session.infinispan.RemoteQueryManager; import org.eclipse.jetty.session.infinispan.RemoteQueryManager;
import org.eclipse.jetty.session.infinispan.SessionDataMarshaller;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
import org.hibernate.search.cfg.Environment; import org.hibernate.search.cfg.Environment;
import org.hibernate.search.cfg.SearchMapping; import org.hibernate.search.cfg.SearchMapping;
@ -35,9 +35,8 @@ import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager; import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.ClientIntelligence; import org.infinispan.client.hotrod.configuration.ClientIntelligence;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.client.hotrod.marshall.ProtoStreamMarshaller; import org.infinispan.commons.configuration.XMLStringConfiguration;
import org.infinispan.protostream.FileDescriptorSource; import org.infinispan.commons.marshall.ProtoStreamMarshaller;
import org.infinispan.protostream.SerializationContext;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -69,10 +68,10 @@ public class RemoteQueryManagerTest
private int port; private int port;
GenericContainer infinispan = GenericContainer infinispan =
new GenericContainer(System.getProperty("infinispan.docker.image.name", "jboss/infinispan-server") + new GenericContainer(System.getProperty("infinispan.docker.image.name", "infinispan/server") +
":" + System.getProperty("infinispan.docker.image.version", "9.4.8.Final")) ":" + System.getProperty("infinispan.docker.image.version", "11.0.9.Final"))
.withEnv("APP_USER", "theuser") .withEnv("USER", "theuser")
.withEnv("APP_PASS", "foobar") .withEnv("PASS", "foobar")
.withEnv("MGMT_USER", "admin") .withEnv("MGMT_USER", "admin")
.withEnv("MGMT_PASS", "admin") .withEnv("MGMT_PASS", "admin")
.waitingFor(new LogMessageWaitStrategy() .waitingFor(new LogMessageWaitStrategy()
@ -101,27 +100,27 @@ public class RemoteQueryManagerTest
public void testQuery() throws Exception public void testQuery() throws Exception
{ {
SearchMapping mapping = new SearchMapping(); SearchMapping mapping = new SearchMapping();
mapping.entity(SessionData.class).indexed().providedId().property("expiry", ElementType.FIELD).field(); mapping.entity(InfinispanSessionData.class).indexed().providedId()
.property("expiry", ElementType.METHOD).field();
Properties properties = new Properties(); Properties properties = new Properties();
properties.put(Environment.MODEL_MAPPING, mapping); properties.put(Environment.MODEL_MAPPING, mapping);
ConfigurationBuilder clientBuilder = new ConfigurationBuilder(); ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
clientBuilder.withProperties(properties).addServer() clientBuilder.withProperties(properties)
.host(this.host).port(this.port) .addServer()
.clientIntelligence(ClientIntelligence.BASIC) .host(this.host).port(this.port)
.marshaller(new ProtoStreamMarshaller()); .clientIntelligence(ClientIntelligence.BASIC)
.marshaller(new ProtoStreamMarshaller())
.security()
.authentication()
.username("theuser").password("foobar");
clientBuilder.addContextInitializer(new InfinispanSerializationContextInitializer());
RemoteCacheManager remoteCacheManager = new RemoteCacheManager(clientBuilder.build()); RemoteCacheManager remoteCacheManager = new RemoteCacheManager(clientBuilder.build());
remoteCacheManager.administration().getOrCreateCache("remote-session-test", (String)null);
FileDescriptorSource fds = new FileDescriptorSource();
fds.addProtoFiles("/session.proto");
SerializationContext serCtx = ProtoStreamMarshaller.getSerializationContext(remoteCacheManager);
serCtx.registerProtoFiles(fds);
serCtx.registerMarshaller(new SessionDataMarshaller());
//upload the session.proto serialization descriptor to the remote cache
try (InputStream is = RemoteQueryManagerTest.class.getClassLoader().getResourceAsStream("session.proto"); try (InputStream is = RemoteQueryManagerTest.class.getClassLoader().getResourceAsStream("session.proto");
ByteArrayOutputStream baos = new ByteArrayOutputStream()) ByteArrayOutputStream baos = new ByteArrayOutputStream())
{ {
@ -129,10 +128,18 @@ public class RemoteQueryManagerTest
throw new IllegalStateException("inputstream is null"); throw new IllegalStateException("inputstream is null");
IO.copy(is, baos); IO.copy(is, baos);
String content = baos.toString("UTF-8"); String content = baos.toString("UTF-8");
remoteCacheManager.getCache("___protobuf_metadata").put("session.proto", content); remoteCacheManager.administration().getOrCreateCache("___protobuf_metadata", (String)null).put("session.proto", content);
} }
RemoteCache<String, InfinispanSessionData> cache = remoteCacheManager.getCache(DEFAULT_CACHE_NAME); //make the remote cache encoded with protostream
String xml = String.format("<infinispan>" +
"<cache-container>" + "<distributed-cache name=\"%s\" mode=\"SYNC\">" +
"<encoding media-type=\"application/x-protostream\"/>" +
"</distributed-cache>" +
"</cache-container>" +
"</infinispan>", DEFAULT_CACHE_NAME);
XMLStringConfiguration xmlConfig = new XMLStringConfiguration(xml);
RemoteCache<String, InfinispanSessionData> cache = remoteCacheManager.administration().getOrCreateCache(DEFAULT_CACHE_NAME, xmlConfig);
//put some sessions into the cache for "foo" context //put some sessions into the cache for "foo" context
ContextHandler fooHandler = new ContextHandler(); ContextHandler fooHandler = new ContextHandler();
@ -155,7 +162,7 @@ public class RemoteQueryManagerTest
checkResults(cache, barSessionContext, time, barSessions); checkResults(cache, barSessionContext, time, barSessions);
} }
private Set<SessionData> createSessions(RemoteCache<String, InfinispanSessionData> cache, SessionContext sessionContext) private Set<SessionData> createSessions(RemoteCache<String, InfinispanSessionData> cache, SessionContext sessionContext) throws Exception
{ {
Set<SessionData> sessions = new HashSet<>(); Set<SessionData> sessions = new HashSet<>();
@ -168,6 +175,7 @@ public class RemoteQueryManagerTest
InfinispanSessionData sd = new InfinispanSessionData(id, sessionContext.getCanonicalContextPath(), sessionContext.getVhost(), 0, 0, 0, 0); InfinispanSessionData sd = new InfinispanSessionData(id, sessionContext.getCanonicalContextPath(), sessionContext.getVhost(), 0, 0, 0, 0);
sd.setLastNode(sessionContext.getWorkerName()); sd.setLastNode(sessionContext.getWorkerName());
sd.setExpiry(expiryTime); sd.setExpiry(expiryTime);
sd.serializeAttributes();
sessions.add(sd); sessions.add(sd);
//add to cache //add to cache
cache.put(id, sd); cache.put(id, sd);

View File

@ -99,13 +99,11 @@
<dependency> <dependency>
<groupId>org.infinispan</groupId> <groupId>org.infinispan</groupId>
<artifactId>infinispan-client-hotrod</artifactId> <artifactId>infinispan-client-hotrod</artifactId>
<version>${infinispan.version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.infinispan</groupId> <groupId>org.infinispan</groupId>
<artifactId>infinispan-remote-query-client</artifactId> <artifactId>infinispan-remote-query-client</artifactId>
<version>${infinispan.version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -25,7 +25,12 @@
</Call> </Call>
<Call name="marshaller"> <Call name="marshaller">
<Arg> <Arg>
<New class="org.infinispan.client.hotrod.marshall.ProtoStreamMarshaller"/> <New class="org.infinispan.commons.marshall.ProtoStreamMarshaller"/>
</Arg>
</Call>
<Call name="addContextInitializer">
<Arg>
<New class="org.eclipse.jetty.session.infinispan.InfinispanSerializationContextInitializer"/>
</Arg> </Arg>
</Call> </Call>
<Call id="config" name="build"/> <Call id="config" name="build"/>
@ -38,35 +43,6 @@
<Arg><Ref refid="config"/></Arg> <Arg><Ref refid="config"/></Arg>
</New> </New>
<!-- ===================================================================== -->
<!-- Set up custom session serialization. -->
<!-- ===================================================================== -->
<Call id="serial_context" class="org.infinispan.client.hotrod.marshall.ProtoStreamMarshaller" name="getSerializationContext">
<Arg>
<Ref refid="hotrodMgr"/>
</Arg>
<Call name="registerProtoFiles">
<Arg>
<New class="org.infinispan.protostream.FileDescriptorSource">
<Call name="addProtoFiles">
<Arg>
<Array type="java.lang.String">
<Item>/session.proto</Item>
</Array>
</Arg>
</Call>
</New>
</Arg>
</Call>
<Call name="registerMarshaller">
<Arg>
<New class="org.eclipse.jetty.session.infinispan.SessionDataMarshaller"/>
</Arg>
</Call>
</Call>
<!-- ===================================================================== --> <!-- ===================================================================== -->
<!-- Get a reference to the remote cache. --> <!-- Get a reference to the remote cache. -->
<!-- ===================================================================== --> <!-- ===================================================================== -->

View File

@ -16,7 +16,7 @@ sessions/infinispan/remote/infinispan-remote-libs
basehome:modules/sessions/infinispan/remote/resources/hotrod-client.properties|resources/hotrod-client.properties basehome:modules/sessions/infinispan/remote/resources/hotrod-client.properties|resources/hotrod-client.properties
[ini] [ini]
infinispan.version?=9.4.8.Final infinispan.version?=11.0.11.Final
[license] [license]
@ -26,6 +26,7 @@ http://www.apache.org/licenses/LICENSE-2.0.html
[ini-template] [ini-template]
#jetty.session.infinispan.remoteCacheName=sessions #jetty.session.infinispan.remoteCacheName=sessions
#jetty.session.infinispan.serialization=true
#jetty.session.infinispan.idleTimeout.seconds=0 #jetty.session.infinispan.idleTimeout.seconds=0
#jetty.session.gracePeriod.seconds=3600 #jetty.session.gracePeriod.seconds=3600
#jetty.session.savePeriod.seconds=0 #jetty.session.savePeriod.seconds=0

View File

@ -1 +1,2 @@
#infinispan.client.hotrod.server_list #infinispan.client.hotrod.server_list
#infinispan.client.hotrod.context-initializers=

View File

@ -77,6 +77,7 @@ public class SessionData implements Serializable
Class<?> clazz = entry.getValue().getClass(); Class<?> clazz = entry.getValue().getClass();
ClassLoader loader = clazz.getClassLoader(); ClassLoader loader = clazz.getClassLoader();
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
boolean isContextLoader; boolean isContextLoader;
if (loader == contextLoader) //is it the context classloader? if (loader == contextLoader) //is it the context classloader?
@ -104,7 +105,7 @@ public class SessionData implements Serializable
isContextLoader = false; //TCCL can't see the class isContextLoader = false; //TCCL can't see the class
} }
} }
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("Attribute {} class={} isServerLoader={}", entry.getKey(), clazz.getName(), (!isContextLoader)); LOG.debug("Attribute {} class={} isServerLoader={}", entry.getKey(), clazz.getName(), (!isContextLoader));
out.writeBoolean(!isContextLoader); out.writeBoolean(!isContextLoader);
@ -142,7 +143,6 @@ public class SessionData implements Serializable
boolean isServerClassLoader = in.readBoolean(); //use server or webapp classloader to load boolean isServerClassLoader = in.readBoolean(); //use server or webapp classloader to load
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("Deserialize {} isServerLoader={} serverLoader={} tccl={}", name, isServerClassLoader, serverLoader, contextLoader); LOG.debug("Deserialize {} isServerLoader={} serverLoader={} tccl={}", name, isServerClassLoader, serverLoader, contextLoader);
Object value = ((ClassLoadingObjectInputStream)in).readObject(isServerClassLoader ? serverLoader : contextLoader); Object value = ((ClassLoadingObjectInputStream)in).readObject(isServerClassLoader ? serverLoader : contextLoader);
data._attributes.put(name, value); data._attributes.put(name, value);
} }

40
pom.xml
View File

@ -28,7 +28,7 @@
<servlet.api.version>4.0.6</servlet.api.version> <servlet.api.version>4.0.6</servlet.api.version>
<websocket.api.version>1.1.2</websocket.api.version> <websocket.api.version>1.1.2</websocket.api.version>
<jsp.version>9.0.52</jsp.version> <jsp.version>9.0.52</jsp.version>
<infinispan.version>9.4.8.Final</infinispan.version> <infinispan.version>11.0.11.Final</infinispan.version>
<infinispan.protostream.version>4.3.4.Final</infinispan.protostream.version> <infinispan.protostream.version>4.3.4.Final</infinispan.protostream.version>
<gson.version>2.8.8</gson.version> <gson.version>2.8.8</gson.version>
<grpc.version>1.40.1</grpc.version> <grpc.version>1.40.1</grpc.version>
@ -1239,6 +1239,39 @@
<artifactId>biz.aQute.bndlib</artifactId> <artifactId>biz.aQute.bndlib</artifactId>
<version>5.3.0</version> <version>5.3.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-bom</artifactId>
<version>${infinispan.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- jboss deps.. -->
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>${jboss.logging.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
<version>2.2.1.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-annotations</artifactId>
<version>2.2.1.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager</artifactId>
<version>2.1.15.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.threads</groupId>
<artifactId>jboss-threads</artifactId>
<version>3.1.0.Final</version>
</dependency>
<!-- Old Deps --> <!-- Old Deps -->
<dependency> <dependency>
<groupId>org.eclipse.jetty.toolchain</groupId> <groupId>org.eclipse.jetty.toolchain</groupId>
@ -1276,11 +1309,6 @@
<version>${slf4j.version}</version> <version>${slf4j.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>${jboss.logging.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.asciidoctor</groupId> <groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId> <artifactId>asciidoctor-maven-plugin</artifactId>

View File

@ -42,6 +42,12 @@
<artifactId>weld-servlet-core</artifactId> <artifactId>weld-servlet-core</artifactId>
<version>${weld.version}</version> <version>${weld.version}</version>
<scope>test</scope> <scope>test</scope>
<exclusions>
<exclusion>
<groupId>io.undertow</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>

View File

@ -217,6 +217,7 @@
<distribution.debug.port>$(distribution.debug.port}</distribution.debug.port> <distribution.debug.port>$(distribution.debug.port}</distribution.debug.port>
<home.start.timeout>${home.start.timeout}</home.start.timeout> <home.start.timeout>${home.start.timeout}</home.start.timeout>
<mariadb.version>${mariadb.version}</mariadb.version> <mariadb.version>${mariadb.version}</mariadb.version>
<sessionLogLevel>${sessionLogLevel}</sessionLogLevel>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -44,6 +44,7 @@ public abstract class AbstractSessionDistributionTests extends AbstractJettyHome
{ {
private String jettyVersion = System.getProperty("jettyVersion"); private String jettyVersion = System.getProperty("jettyVersion");
private String sessionLogLevel = System.getProperty("sessionLogLevel", "INFO");
protected JettyHomeTester jettyHomeTester; protected JettyHomeTester jettyHomeTester;
@ -85,7 +86,10 @@ public abstract class AbstractSessionDistributionTests extends AbstractJettyHome
args = new ArrayList<>(Collections.singletonList("jetty.http.port=" + port)); args = new ArrayList<>(Collections.singletonList("jetty.http.port=" + port));
args.addAll(getSecondStartExtraArgs()); args.addAll(getSecondStartExtraArgs());
argsStart = args.toArray(new String[0]); argsStart = args.toArray(new String[0]);
//allow the external storage mechanisms to do some config before starting test
configureExternalSessionStorage(jettyHomeTester.getJettyBase());
try (JettyHomeTester.Run run2 = jettyHomeTester.start(argsStart)) try (JettyHomeTester.Run run2 = jettyHomeTester.start(argsStart))
{ {
assertTrue(run2.awaitConsoleLogsFor("Started Server@", START_TIMEOUT, TimeUnit.SECONDS)); assertTrue(run2.awaitConsoleLogsFor("Started Server@", START_TIMEOUT, TimeUnit.SECONDS));
@ -100,14 +104,12 @@ public abstract class AbstractSessionDistributionTests extends AbstractJettyHome
assertThat(response.getContentAsString(), containsString("SESSION READ CHOCOLATE THE BEST:FRENCH")); assertThat(response.getContentAsString(), containsString("SESSION READ CHOCOLATE THE BEST:FRENCH"));
} }
/*
Path logFile = jettyHomeTester.getJettyBase().resolve("resources").resolve("jetty-logging.properties"); Path logFile = jettyHomeTester.getJettyBase().resolve("resources").resolve("jetty-logging.properties");
Files.deleteIfExists(logFile); Files.deleteIfExists(logFile);
try (BufferedWriter writer = Files.newBufferedWriter(logFile, StandardCharsets.UTF_8, StandardOpenOption.CREATE)) try (BufferedWriter writer = Files.newBufferedWriter(logFile, StandardCharsets.UTF_8, StandardOpenOption.CREATE))
{ {
writer.write("org.eclipse.jetty.server.session.LEVEL=DEBUG"); writer.write("org.eclipse.jetty.server.session.LEVEL=" + sessionLogLevel);
} }
*/
try (JettyHomeTester.Run run2 = jettyHomeTester.start(argsStart)) try (JettyHomeTester.Run run2 = jettyHomeTester.start(argsStart))
{ {
@ -137,4 +139,6 @@ public abstract class AbstractSessionDistributionTests extends AbstractJettyHome
public abstract void stopExternalSessionStorage() throws Exception; public abstract void stopExternalSessionStorage() throws Exception;
public abstract void configureExternalSessionStorage(Path jettyBase) throws Exception;
} }

View File

@ -13,6 +13,7 @@
package org.eclipse.jetty.tests.distribution.session; package org.eclipse.jetty.tests.distribution.session;
import java.nio.file.Path;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -24,7 +25,12 @@ import org.testcontainers.junit.jupiter.Testcontainers;
@Testcontainers(disabledWithoutDocker = false) @Testcontainers(disabledWithoutDocker = false)
public class FileSessionDistributionTests extends AbstractSessionDistributionTests public class FileSessionDistributionTests extends AbstractSessionDistributionTests
{ {
@Override
public void configureExternalSessionStorage(Path jettyBase) throws Exception
{
// no op
}
@Override @Override
public void startExternalSessionStorage() throws Exception public void startExternalSessionStorage() throws Exception
{ {

View File

@ -13,6 +13,7 @@
package org.eclipse.jetty.tests.distribution.session; package org.eclipse.jetty.tests.distribution.session;
import java.nio.file.Path;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -50,7 +51,13 @@ public class FileSessionWithMemcacheDistributionTests extends AbstractSessionDis
this.port = memcached.getMappedPort(11211); this.port = memcached.getMappedPort(11211);
super.prepareJettyHomeTester(); super.prepareJettyHomeTester();
} }
@Override
public void configureExternalSessionStorage(Path jettyBase) throws Exception
{
// no op
}
@Override @Override
public void startExternalSessionStorage() throws Exception public void startExternalSessionStorage() throws Exception
{ {

View File

@ -15,6 +15,7 @@ package org.eclipse.jetty.tests.distribution.session;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URL; import java.net.URL;
import java.nio.file.Path;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -83,6 +84,12 @@ public class GCloudSessionDistributionTests extends AbstractSessionDistributionT
{ {
emulator.stop(); emulator.stop();
} }
@Override
public void configureExternalSessionStorage(Path jettyBase) throws Exception
{
// no op
}
@Override @Override
public List<String> getFirstStartExtraArgs() public List<String> getFirstStartExtraArgs()

View File

@ -91,6 +91,12 @@ public class HazelcastSessionDistributionTests extends AbstractSessionDistributi
hazelcast.stop(); hazelcast.stop();
} }
@Override
public void configureExternalSessionStorage(Path jettyBase) throws Exception
{
// no op
}
@Override @Override
public List<String> getFirstStartExtraArgs() public List<String> getFirstStartExtraArgs()
{ {

View File

@ -13,17 +13,25 @@
package org.eclipse.jetty.tests.distribution.session; package org.eclipse.jetty.tests.distribution.session;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.Writer; import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import org.eclipse.jetty.session.infinispan.InfinispanSerializationContextInitializer;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
import org.infinispan.client.hotrod.RemoteCacheManager; import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.Configuration; import org.infinispan.client.hotrod.configuration.Configuration;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.commons.configuration.XMLStringConfiguration;
import org.infinispan.commons.marshall.ProtoStreamMarshaller;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.GenericContainer;
@ -39,39 +47,45 @@ public class InfinispanSessionDistributionTests extends AbstractSessionDistribut
private static final Logger LOGGER = LoggerFactory.getLogger(InfinispanSessionDistributionTests.class); private static final Logger LOGGER = LoggerFactory.getLogger(InfinispanSessionDistributionTests.class);
private static final Logger INFINISPAN_LOG = LoggerFactory.getLogger("org.eclipse.jetty.tests.distribution.session.infinispan"); private static final Logger INFINISPAN_LOG = LoggerFactory.getLogger("org.eclipse.jetty.tests.distribution.session.infinispan");
@SuppressWarnings("rawtypes")
private GenericContainer infinispan; private GenericContainer infinispan;
private String host; private String host;
private int port;
@Override @Override
public void startExternalSessionStorage() throws Exception public void startExternalSessionStorage() throws Exception
{ {
String infinispanVersion = System.getProperty("infinispan.docker.image.version", "9.4.8.Final"); String infinispanVersion = System.getProperty("infinispan.docker.image.version", "11.0.9.Final");
infinispan = infinispan =
new GenericContainer(System.getProperty("infinispan.docker.image.name", "jboss/infinispan-server") + new GenericContainer(System.getProperty("infinispan.docker.image.name", "infinispan/server") +
":" + infinispanVersion) ":" + infinispanVersion)
//.withEnv("APP_USER", "theuser") .withEnv("USER", "theuser")
//.withEnv("APP_PASS", "foobar") .withEnv("PASS", "foobar")
.withEnv("MGMT_USER", "admin") .withEnv("MGMT_USER", "admin")
.withEnv("MGMT_PASS", "admin") .withEnv("MGMT_PASS", "admin")
.withCommand("standalone")
.waitingFor(new LogMessageWaitStrategy() .waitingFor(new LogMessageWaitStrategy()
.withRegEx(".*Infinispan Server.*started in.*\\s")) .withRegEx(".*Infinispan Server.*started in.*\\s"))
.withExposedPorts(4712, 4713, 8088, 8089, 8443, 9990, 9993, 11211, 11222, 11223, 11224) .withExposedPorts(4712, 4713, 8088, 8089, 8443, 9990, 9993, 11211, 11222, 11223, 11224)
.withLogConsumer(new Slf4jLogConsumer(INFINISPAN_LOG)); .withLogConsumer(new Slf4jLogConsumer(INFINISPAN_LOG));
infinispan.start(); infinispan.start();
String host = infinispan.getContainerIpAddress(); host = infinispan.getContainerIpAddress();
int port = infinispan.getMappedPort(11222); port = infinispan.getMappedPort(11222);
Path resourcesDirectory = Path.of(jettyHomeTester.getJettyBase().toString(), "resources/"); Path resourcesDirectory = Path.of(jettyHomeTester.getJettyBase().toString(), "resources/");
if (Files.exists(resourcesDirectory)) if (Files.exists(resourcesDirectory))
{ {
IO.delete(resourcesDirectory.toFile()); IO.delete(resourcesDirectory.toFile());
} }
Files.createDirectories(resourcesDirectory); Files.createDirectories(resourcesDirectory);
Properties properties = new Properties(); Properties properties = new Properties();
properties.put("infinispan.client.hotrod.server_list", host + ":" + port); properties.put("infinispan.client.hotrod.server_list", host + ":" + port);
//properties.put("jetty.session.infinispan.clientIntelligence", "BASIC"); properties.put("infinispan.client.hotrod.use_auth", "true");
properties.put("infinispan.client.hotrod.sasl_mechanism", "DIGEST-MD5");
properties.put("infinispan.client.hotrod.auth_username", "theuser");
properties.put("infinispan.client.hotrod.auth_password", "foobar");
Path hotrod = Path.of(resourcesDirectory.toString(), "hotrod-client.properties"); Path hotrod = Path.of(resourcesDirectory.toString(), "hotrod-client.properties");
Files.deleteIfExists(hotrod); Files.deleteIfExists(hotrod);
@ -82,11 +96,36 @@ public class InfinispanSessionDistributionTests extends AbstractSessionDistribut
} }
Configuration configuration = new ConfigurationBuilder().withProperties(properties) Configuration configuration = new ConfigurationBuilder().withProperties(properties)
.addServer().host(host).port(port).build(); .addServer().host(host).port(port)
.marshaller(new ProtoStreamMarshaller())
.addContextInitializer(new InfinispanSerializationContextInitializer())
.security().authentication().saslMechanism("DIGEST-MD5")
.username("theuser").password("foobar")
.build();
RemoteCacheManager remoteCacheManager = new RemoteCacheManager(configuration); RemoteCacheManager remoteCacheManager = new RemoteCacheManager(configuration);
remoteCacheManager.administration().getOrCreateCache("sessions", (String)null); ByteArrayOutputStream baos;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream("session.proto"))
{
if (is == null)
throw new IllegalStateException("inputstream is null");
baos = new ByteArrayOutputStream();
IO.copy(is, baos);
}
String content = baos.toString("UTF-8");
remoteCacheManager.administration().getOrCreateCache("___protobuf_metadata", (String)null).put("session.proto", content);
String xml = String.format("<infinispan>" +
"<cache-container>" + "<distributed-cache name=\"%s\" mode=\"SYNC\">" +
"<encoding media-type=\"application/x-protostream\"/>" +
"</distributed-cache>" +
"</cache-container>" +
"</infinispan>", "sessions");
XMLStringConfiguration xmlConfig = new XMLStringConfiguration(xml);
remoteCacheManager.administration().getOrCreateCache("sessions", xmlConfig);
} }
@Override @Override
@ -113,4 +152,23 @@ public class InfinispanSessionDistributionTests extends AbstractSessionDistribut
return Arrays.asList(); return Arrays.asList();
} }
@Override
public void configureExternalSessionStorage(Path jettyBase) throws Exception
{
Path hotRodProperties = jettyBase.resolve("resources").resolve("hotrod-client.properties");
Files.deleteIfExists(hotRodProperties);
try (BufferedWriter writer = Files.newBufferedWriter(hotRodProperties, StandardCharsets.UTF_8, StandardOpenOption.CREATE))
{
writer.write("infinispan.client.hotrod.use_auth=true");
writer.newLine();
writer.write("infinispan.client.hotrod.server_list=" + host + ":" + port);
writer.newLine();
writer.write("infinispan.client.hotrod.sasl_mechanism=DIGEST-MD5");
writer.newLine();
writer.write("infinispan.client.hotrod.auth_username=theuser");
writer.newLine();
writer.write("infinispan.client.hotrod.auth_password=foobar");
writer.newLine();
}
}
} }

View File

@ -77,6 +77,12 @@ public class JDBCSessionDistributionTests extends AbstractSessionDistributionTes
{ {
mariaDBContainer.stop(); mariaDBContainer.stop();
} }
@Override
public void configureExternalSessionStorage(Path jettyBase) throws Exception
{
// no op
}
@Override @Override
public List<String> getFirstStartExtraArgs() public List<String> getFirstStartExtraArgs()

View File

@ -13,6 +13,7 @@
package org.eclipse.jetty.tests.distribution.session; package org.eclipse.jetty.tests.distribution.session;
import java.nio.file.Path;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -56,6 +57,12 @@ public class MongodbSessionDistributionTests extends AbstractSessionDistribution
mongoDBContainer.stop(); mongoDBContainer.stop();
} }
@Override
public void configureExternalSessionStorage(Path jettyBase) throws Exception
{
// no op
}
@Override @Override
public List<String> getFirstStartExtraArgs() public List<String> getFirstStartExtraArgs()
{ {

View File

@ -24,6 +24,11 @@ import org.junit.jupiter.api.extension.ExtendWith;
@ExtendWith(WorkDirExtension.class) @ExtendWith(WorkDirExtension.class)
public class FileSessionDataStoreTest extends AbstractSessionDataStoreTest public class FileSessionDataStoreTest extends AbstractSessionDataStoreTest
{ {
public FileSessionDataStoreTest() throws Exception
{
super();
}
public WorkDir workDir; public WorkDir workDir;
private FileTestHelper _helper; private FileTestHelper _helper;

View File

@ -28,6 +28,11 @@ import org.testcontainers.junit.jupiter.Testcontainers;
public class GCloudSessionDataStoreTest extends AbstractSessionDataStoreTest public class GCloudSessionDataStoreTest extends AbstractSessionDataStoreTest
{ {
public GCloudSessionDataStoreTest() throws Exception
{
super();
}
public static GCloudSessionTestSupport __testSupport; public static GCloudSessionTestSupport __testSupport;
@BeforeAll @BeforeAll

View File

@ -32,6 +32,11 @@ import static org.junit.jupiter.api.Assertions.fail;
*/ */
public class HazelcastSessionDataStoreTest extends AbstractSessionDataStoreTest public class HazelcastSessionDataStoreTest extends AbstractSessionDataStoreTest
{ {
public HazelcastSessionDataStoreTest() throws Exception
{
super();
}
HazelcastTestHelper _testHelper; HazelcastTestHelper _testHelper;
@Override @Override

View File

@ -34,6 +34,11 @@ import static org.junit.jupiter.api.Assertions.fail;
*/ */
public class HazelcastSessionDataStoreTest extends AbstractSessionDataStoreTest public class HazelcastSessionDataStoreTest extends AbstractSessionDataStoreTest
{ {
public HazelcastSessionDataStoreTest() throws Exception
{
super();
}
HazelcastTestHelper _testHelper; HazelcastTestHelper _testHelper;
@Override @Override

View File

@ -11,9 +11,9 @@
<properties> <properties>
<bundle-symbolic-name>${project.groupId}.sessions.infinispan</bundle-symbolic-name> <bundle-symbolic-name>${project.groupId}.sessions.infinispan</bundle-symbolic-name>
<!-- if changing this version please update default in RemoteInfinispanTestSupport you will get thanks from Eclipse IDE users --> <!-- if changing this version please update default in RemoteInfinispanTestSupport you will get thanks from Eclipse IDE users -->
<infinispan.docker.image.version>${infinispan.version}</infinispan.docker.image.version> <infinispan.docker.image.version>11.0.9.Final</infinispan.docker.image.version>
<!-- from 10.xx it has changed to jboss/infinispan --> <!-- from 10.xx it has changed to jboss/infinispan -->
<infinispan.docker.image.name>jboss/infinispan-server</infinispan.docker.image.name> <infinispan.docker.image.name>infinispan/server</infinispan.docker.image.name>
</properties> </properties>
<build> <build>
<plugins> <plugins>
@ -120,6 +120,12 @@
<artifactId>infinispan-core</artifactId> <artifactId>infinispan-core</artifactId>
<version>${infinispan.version}</version> <version>${infinispan.version}</version>
<scope>test</scope> <scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.wildfly.common</groupId>
<artifactId>wildfly-common</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.infinispan</groupId> <groupId>org.infinispan</groupId>

View File

@ -61,6 +61,7 @@ public class ClusteredSerializedSessionScavengingTest extends AbstractClusteredS
public SessionDataStoreFactory createSessionDataStoreFactory() public SessionDataStoreFactory createSessionDataStoreFactory()
{ {
InfinispanSessionDataStoreFactory factory = new InfinispanSessionDataStoreFactory(); InfinispanSessionDataStoreFactory factory = new InfinispanSessionDataStoreFactory();
factory.setSerialization(true);
factory.setCache(testSupport.getCache()); factory.setCache(testSupport.getCache());
return factory; return factory;
} }

View File

@ -62,6 +62,7 @@ public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScav
public SessionDataStoreFactory createSessionDataStoreFactory() public SessionDataStoreFactory createSessionDataStoreFactory()
{ {
InfinispanSessionDataStoreFactory factory = new InfinispanSessionDataStoreFactory(); InfinispanSessionDataStoreFactory factory = new InfinispanSessionDataStoreFactory();
factory.setSerialization(true);
factory.setCache(testSupport.getCache()); factory.setCache(testSupport.getCache());
return factory; return factory;
} }

View File

@ -13,6 +13,9 @@
package org.eclipse.jetty.server.session; package org.eclipse.jetty.server.session;
import org.eclipse.jetty.session.infinispan.EmbeddedQueryManager;
import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory;
import org.eclipse.jetty.session.infinispan.QueryManager;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -26,6 +29,11 @@ public class InfinispanFileSessionDataStoreTest extends InfinispanSessionDataSto
{ {
public WorkDir workDir; public WorkDir workDir;
public InfinispanFileSessionDataStoreTest() throws Exception
{
super();
}
@BeforeEach @BeforeEach
public void setup() throws Exception public void setup() throws Exception
{ {
@ -33,4 +41,14 @@ public class InfinispanFileSessionDataStoreTest extends InfinispanSessionDataSto
_testSupport.setUseFileStore(true); _testSupport.setUseFileStore(true);
_testSupport.setup(workDir.getEmptyPathDir()); _testSupport.setup(workDir.getEmptyPathDir());
} }
public SessionDataStoreFactory createSessionDataStoreFactory()
{
InfinispanSessionDataStoreFactory factory = new InfinispanSessionDataStoreFactory();
factory.setSerialization(true);
factory.setCache(_testSupport.getCache());
QueryManager qm = new EmbeddedQueryManager(_testSupport.getCache());
factory.setQueryManager(qm);
return factory;
}
} }

View File

@ -24,6 +24,7 @@ import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.infinispan.query.Search; import org.infinispan.query.Search;
import org.infinispan.query.dsl.Query; import org.infinispan.query.dsl.Query;
import org.infinispan.query.dsl.QueryFactory; import org.infinispan.query.dsl.QueryFactory;
import org.infinispan.query.dsl.QueryResult;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -46,7 +47,12 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest
public InfinispanTestSupport _testSupport; public InfinispanTestSupport _testSupport;
public WorkDir workDir; public WorkDir workDir;
public InfinispanSessionDataStoreTest() throws Exception
{
super();
}
@BeforeEach @BeforeEach
public void setup() throws Exception public void setup() throws Exception
{ {
@ -73,7 +79,16 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest
@Override @Override
public void persistSession(SessionData data) throws Exception public void persistSession(SessionData data) throws Exception
{ {
_testSupport.createSession(data); ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(_contextClassLoader);
try
{
_testSupport.createSession(data);
}
finally
{
Thread.currentThread().setContextClassLoader(old);
}
} }
@Override @Override
@ -85,7 +100,16 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest
@Override @Override
public boolean checkSessionExists(SessionData data) throws Exception public boolean checkSessionExists(SessionData data) throws Exception
{ {
return _testSupport.checkSessionExists(data); ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(_contextClassLoader);
try
{
return _testSupport.checkSessionExists(data);
}
finally
{
Thread.currentThread().setContextClassLoader(old);
}
} }
/** /**
@ -98,6 +122,7 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -138,14 +163,17 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest
{ {
InfinispanSessionData sd1 = new InfinispanSessionData("sd1", "", "", 0, 0, 0, 1000); InfinispanSessionData sd1 = new InfinispanSessionData("sd1", "", "", 0, 0, 0, 1000);
sd1.setLastNode("fred1"); sd1.setLastNode("fred1");
sd1.serializeAttributes();
_testSupport.getCache().put("session1", sd1); _testSupport.getCache().put("session1", sd1);
InfinispanSessionData sd2 = new InfinispanSessionData("sd2", "", "", 0, 0, 0, 2000); InfinispanSessionData sd2 = new InfinispanSessionData("sd2", "", "", 0, 0, 0, 2000);
sd2.setLastNode("fred2"); sd2.setLastNode("fred2");
sd2.serializeAttributes();
_testSupport.getCache().put("session2", sd2); _testSupport.getCache().put("session2", sd2);
InfinispanSessionData sd3 = new InfinispanSessionData("sd3", "", "", 0, 0, 0, 3000); InfinispanSessionData sd3 = new InfinispanSessionData("sd3", "", "", 0, 0, 0, 3000);
sd3.setLastNode("fred3"); sd3.setLastNode("fred3");
sd3.serializeAttributes();
_testSupport.getCache().put("session3", sd3); _testSupport.getCache().put("session3", sd3);
QueryFactory qf = Search.getQueryFactory(_testSupport.getCache()); QueryFactory qf = Search.getQueryFactory(_testSupport.getCache());
@ -153,8 +181,9 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest
for (int i = 0; i <= 3; i++) for (int i = 0; i <= 3; i++)
{ {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
Query q = qf.from(InfinispanSessionData.class).having("expiry").lt(now).build(); Query<InfinispanSessionData> q = qf.create("from org.eclipse.jetty.session.infinispan.InfinispanSessionData where expiry < " + now);
assertEquals(i, q.list().size()); QueryResult<InfinispanSessionData> result = q.execute();
assertEquals(i, result.list().size());
Thread.sleep(1000); Thread.sleep(1000);
} }
} }

View File

@ -19,6 +19,8 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Properties; import java.util.Properties;
import org.eclipse.jetty.session.infinispan.InfinispanSerializationContextInitializer;
import org.eclipse.jetty.session.infinispan.InfinispanSessionData;
import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
import org.hibernate.search.cfg.Environment; import org.hibernate.search.cfg.Environment;
@ -26,8 +28,9 @@ import org.hibernate.search.cfg.SearchMapping;
import org.infinispan.Cache; import org.infinispan.Cache;
import org.infinispan.configuration.cache.ConfigurationBuilder; import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.configuration.cache.ConfigurationChildBuilder; import org.infinispan.configuration.cache.ConfigurationChildBuilder;
import org.infinispan.configuration.cache.Index; import org.infinispan.configuration.cache.StorageType;
import org.infinispan.configuration.global.GlobalConfigurationBuilder; import org.infinispan.configuration.global.GlobalConfigurationBuilder;
import org.infinispan.eviction.EvictionStrategy;
import org.infinispan.manager.DefaultCacheManager; import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.manager.EmbeddedCacheManager;
@ -53,7 +56,10 @@ public class InfinispanTestSupport
{ {
try try
{ {
_manager = new DefaultCacheManager(new GlobalConfigurationBuilder().globalJmxStatistics().allowDuplicateDomains(true).build()); _manager = new DefaultCacheManager(new GlobalConfigurationBuilder().jmx()
.serialization()
.addContextInitializer(new InfinispanSerializationContextInitializer())
.build());
} }
catch (Exception e) catch (Exception e)
{ {
@ -100,22 +106,28 @@ public class InfinispanTestSupport
Properties properties = new Properties(); Properties properties = new Properties();
properties.put(Environment.MODEL_MAPPING, mapping); properties.put(Environment.MODEL_MAPPING, mapping);
properties.put("hibernate.search.default.indexBase", indexesDir.toString()); properties.put("hibernate.search.default.indexBase", indexesDir.toString());
properties.put("hibernate.cache.infinispan.entity.eviction.strategy", "NONE");
if (_useFileStore) if (_useFileStore)
{ {
Path tmpDir = Files.createTempDirectory("infinispan"); Path tmpDir = Files.createTempDirectory("infinispan");
_tmpdir = tmpDir.toFile(); _tmpdir = tmpDir.toFile();
ConfigurationChildBuilder b = _builder.indexing() ConfigurationChildBuilder b = _builder
.index(Index.ALL) .indexing()
.addIndexedEntity(SessionData.class) .addIndexedEntity(SessionData.class)
.withProperties(properties) .withProperties(properties)
.memory()
.whenFull(EvictionStrategy.NONE)
.persistence() .persistence()
.addSingleFileStore() .addSingleFileStore()
.segmented(false)
.location(_tmpdir.getAbsolutePath()); .location(_tmpdir.getAbsolutePath());
if (_serializeSessionData) if (_serializeSessionData)
{ {
b = b.storeAsBinary().enable(); b = b.memory().storage(StorageType.HEAP)
.encoding()
.mediaType("application/x-protostream");
} }
_manager.defineConfiguration(_name, b.build()); _manager.defineConfiguration(_name, b.build());
@ -124,12 +136,13 @@ public class InfinispanTestSupport
{ {
ConfigurationChildBuilder b = _builder.indexing() ConfigurationChildBuilder b = _builder.indexing()
.withProperties(properties) .withProperties(properties)
.index(Index.ALL)
.addIndexedEntity(SessionData.class); .addIndexedEntity(SessionData.class);
if (_serializeSessionData) if (_serializeSessionData)
{ {
b = b.storeAsBinary().enable(); b = b.memory().storage(StorageType.HEAP)
.encoding()
.mediaType("application/x-protostream");
} }
_manager.defineConfiguration(_name, b.build()); _manager.defineConfiguration(_name, b.build());
@ -140,7 +153,7 @@ public class InfinispanTestSupport
public void teardown() throws Exception public void teardown() throws Exception
{ {
_cache.clear(); _cache.clear();
_manager.removeCache(_name); _manager.administration().removeCache(_name);
if (_useFileStore) if (_useFileStore)
{ {
if (_tmpdir != null) if (_tmpdir != null)
@ -154,6 +167,7 @@ public class InfinispanTestSupport
public void createSession(SessionData data) public void createSession(SessionData data)
throws Exception throws Exception
{ {
((InfinispanSessionData)data).serializeAttributes();
_cache.put(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId(), data); _cache.put(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId(), data);
} }
@ -171,18 +185,24 @@ public class InfinispanTestSupport
public boolean checkSessionPersisted(SessionData data) public boolean checkSessionPersisted(SessionData data)
throws Exception throws Exception
{ {
//evicts the object from memory. Forces the cache to fetch the data from file //evicts the object from memory. Forces the cache to fetch the data from file
if (_useFileStore) if (_useFileStore)
{ {
_cache.evict(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()); _cache.evict(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId());
} }
Object obj = _cache.get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()); Object obj = _cache.get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId());
if (obj == null) if (obj == null)
return false; return false;
SessionData saved = (SessionData)obj; SessionData saved = (SessionData)obj;
if (saved instanceof InfinispanSessionData)
{
InfinispanSessionData isd = (InfinispanSessionData)saved;
if (isd.getSerializedAttributes() != null)
isd.deserializeAttributes();
}
//turn an Entity into a Session //turn an Entity into a Session
assertEquals(data.getId(), saved.getId()); assertEquals(data.getId(), saved.getId());
@ -197,6 +217,7 @@ public class InfinispanTestSupport
assertEquals(data.getExpiry(), saved.getExpiry()); assertEquals(data.getExpiry(), saved.getExpiry());
assertEquals(data.getMaxInactiveMs(), saved.getMaxInactiveMs()); assertEquals(data.getMaxInactiveMs(), saved.getMaxInactiveMs());
//same number of attributes //same number of attributes
assertEquals(data.getAllAttributes().size(), saved.getAllAttributes().size()); assertEquals(data.getAllAttributes().size(), saved.getAllAttributes().size());
//same keys //same keys

View File

@ -24,6 +24,7 @@ import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.infinispan.query.Search; import org.infinispan.query.Search;
import org.infinispan.query.dsl.Query; import org.infinispan.query.dsl.Query;
import org.infinispan.query.dsl.QueryFactory; import org.infinispan.query.dsl.QueryFactory;
import org.infinispan.query.dsl.QueryResult;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -42,6 +43,11 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat
public WorkDir workDir; public WorkDir workDir;
public SerializedInfinispanSessionDataStoreTest() throws Exception
{
super();
}
@BeforeEach @BeforeEach
public void setup() throws Exception public void setup() throws Exception
{ {
@ -61,6 +67,7 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat
{ {
InfinispanSessionDataStoreFactory factory = new InfinispanSessionDataStoreFactory(); InfinispanSessionDataStoreFactory factory = new InfinispanSessionDataStoreFactory();
factory.setCache(_testSupport.getCache()); factory.setCache(_testSupport.getCache());
factory.setSerialization(true);
QueryManager qm = new EmbeddedQueryManager(_testSupport.getCache()); QueryManager qm = new EmbeddedQueryManager(_testSupport.getCache());
factory.setQueryManager(qm); factory.setQueryManager(qm);
return factory; return factory;
@ -69,7 +76,16 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat
@Override @Override
public void persistSession(SessionData data) throws Exception public void persistSession(SessionData data) throws Exception
{ {
_testSupport.createSession(data); ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(_contextClassLoader);
try
{
_testSupport.createSession(data);
}
finally
{
Thread.currentThread().setContextClassLoader(old);
}
} }
@Override @Override
@ -81,7 +97,16 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat
@Override @Override
public boolean checkSessionExists(SessionData data) throws Exception public boolean checkSessionExists(SessionData data) throws Exception
{ {
return _testSupport.checkSessionExists(data); ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(_contextClassLoader);
try
{
return _testSupport.checkSessionExists(data);
}
finally
{
Thread.currentThread().setContextClassLoader(old);
}
} }
/** /**
@ -94,6 +119,7 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -134,14 +160,17 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat
{ {
InfinispanSessionData sd1 = new InfinispanSessionData("sd1", "", "", 0, 0, 0, 1000); InfinispanSessionData sd1 = new InfinispanSessionData("sd1", "", "", 0, 0, 0, 1000);
sd1.setLastNode("fred1"); sd1.setLastNode("fred1");
sd1.serializeAttributes();
_testSupport.getCache().put("session1", sd1); _testSupport.getCache().put("session1", sd1);
InfinispanSessionData sd2 = new InfinispanSessionData("sd2", "", "", 0, 0, 0, 2000); InfinispanSessionData sd2 = new InfinispanSessionData("sd2", "", "", 0, 0, 0, 2000);
sd2.setLastNode("fred2"); sd2.setLastNode("fred2");
sd2.serializeAttributes();
_testSupport.getCache().put("session2", sd2); _testSupport.getCache().put("session2", sd2);
InfinispanSessionData sd3 = new InfinispanSessionData("sd3", "", "", 0, 0, 0, 3000); InfinispanSessionData sd3 = new InfinispanSessionData("sd3", "", "", 0, 0, 0, 3000);
sd3.setLastNode("fred3"); sd3.setLastNode("fred3");
sd3.serializeAttributes();
_testSupport.getCache().put("session3", sd3); _testSupport.getCache().put("session3", sd3);
QueryFactory qf = Search.getQueryFactory(_testSupport.getCache()); QueryFactory qf = Search.getQueryFactory(_testSupport.getCache());
@ -149,8 +178,9 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat
for (int i = 0; i <= 3; i++) for (int i = 0; i <= 3; i++)
{ {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
Query q = qf.from(InfinispanSessionData.class).having("expiry").lt(now).build(); Query<InfinispanSessionData> q = qf.create("from org.eclipse.jetty.session.infinispan.InfinispanSessionData where expiry < " + now);
assertEquals(i, q.list().size()); QueryResult<InfinispanSessionData> result = q.execute();
assertEquals(i, result.list().size());
Thread.sleep(1000); Thread.sleep(1000);
} }
} }

View File

@ -29,6 +29,7 @@ import org.eclipse.jetty.session.infinispan.RemoteQueryManager;
import org.infinispan.client.hotrod.Search; import org.infinispan.client.hotrod.Search;
import org.infinispan.query.dsl.Query; import org.infinispan.query.dsl.Query;
import org.infinispan.query.dsl.QueryFactory; import org.infinispan.query.dsl.QueryFactory;
import org.infinispan.query.dsl.QueryResult;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -50,6 +51,11 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto
public static RemoteInfinispanTestSupport __testSupport; public static RemoteInfinispanTestSupport __testSupport;
public RemoteInfinispanSessionDataStoreTest() throws Exception
{
super();
}
@BeforeEach @BeforeEach
public void setup() throws Exception public void setup() throws Exception
{ {
@ -75,7 +81,17 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto
@Override @Override
public void persistSession(SessionData data) throws Exception public void persistSession(SessionData data) throws Exception
{ {
__testSupport.createSession((InfinispanSessionData)data); ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(_contextClassLoader);
try
{
__testSupport.createSession((InfinispanSessionData)data);
}
finally
{
Thread.currentThread().setContextClassLoader(old);
}
} }
@Override @Override
@ -87,7 +103,16 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto
@Override @Override
public boolean checkSessionExists(SessionData data) throws Exception public boolean checkSessionExists(SessionData data) throws Exception
{ {
return __testSupport.checkSessionExists((InfinispanSessionData)data); ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(_contextClassLoader);
try
{
return __testSupport.checkSessionExists((InfinispanSessionData)data);
}
finally
{
Thread.currentThread().setContextClassLoader(old);
}
} }
@Override @Override
@ -140,23 +165,29 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto
{ {
InfinispanSessionData sd1 = new InfinispanSessionData("sd1", "", "", 0, 0, 0, 1000); InfinispanSessionData sd1 = new InfinispanSessionData("sd1", "", "", 0, 0, 0, 1000);
sd1.setLastNode("fred1"); sd1.setLastNode("fred1");
sd1.serializeAttributes();
__testSupport.getCache().put("session1", sd1); __testSupport.getCache().put("session1", sd1);
InfinispanSessionData sd2 = new InfinispanSessionData("sd2", "", "", 0, 0, 0, 2000); InfinispanSessionData sd2 = new InfinispanSessionData("sd2", "", "", 0, 0, 0, 2000);
sd2.setLastNode("fred2"); sd2.setLastNode("fred2");
sd2.serializeAttributes();
__testSupport.getCache().put("session2", sd2); __testSupport.getCache().put("session2", sd2);
InfinispanSessionData sd3 = new InfinispanSessionData("sd3", "", "", 0, 0, 0, 3000); InfinispanSessionData sd3 = new InfinispanSessionData("sd3", "", "", 0, 0, 0, 3000);
sd3.setLastNode("fred3"); sd3.setLastNode("fred3");
sd3.serializeAttributes();
__testSupport.getCache().put("session3", sd3); __testSupport.getCache().put("session3", sd3);
QueryFactory qf = Search.getQueryFactory(__testSupport.getCache()); QueryFactory qf = Search.getQueryFactory(__testSupport.getCache());
Query<InfinispanSessionData> query = qf.create("from org_eclipse_jetty_session_infinispan.InfinispanSessionData where " +
" expiry < :time");
for (int i = 0; i <= 3; i++) for (int i = 0; i <= 3; i++)
{ {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
Query q = qf.from(InfinispanSessionData.class).having("expiry").lt(now).build(); query.setParameter("time", now);
assertEquals(i, q.list().size()); QueryResult<InfinispanSessionData> result = query.execute();
assertEquals(i, result.list().size());
Thread.sleep(1000); Thread.sleep(1000);
} }
} }

View File

@ -19,8 +19,8 @@ import java.lang.annotation.ElementType;
import java.util.Properties; import java.util.Properties;
import org.eclipse.jetty.server.session.SessionData; import org.eclipse.jetty.server.session.SessionData;
import org.eclipse.jetty.session.infinispan.InfinispanSerializationContextInitializer;
import org.eclipse.jetty.session.infinispan.InfinispanSessionData; import org.eclipse.jetty.session.infinispan.InfinispanSessionData;
import org.eclipse.jetty.session.infinispan.SessionDataMarshaller;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
import org.hibernate.search.cfg.Environment; import org.hibernate.search.cfg.Environment;
import org.hibernate.search.cfg.SearchMapping; import org.hibernate.search.cfg.SearchMapping;
@ -29,9 +29,8 @@ import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.ClientIntelligence; import org.infinispan.client.hotrod.configuration.ClientIntelligence;
import org.infinispan.client.hotrod.configuration.Configuration; import org.infinispan.client.hotrod.configuration.Configuration;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.client.hotrod.marshall.ProtoStreamMarshaller; import org.infinispan.commons.configuration.XMLStringConfiguration;
import org.infinispan.protostream.FileDescriptorSource; import org.infinispan.commons.marshall.ProtoStreamMarshaller;
import org.infinispan.protostream.SerializationContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.GenericContainer;
@ -62,18 +61,18 @@ public class RemoteInfinispanTestSupport
{ {
//Testcontainers.exposeHostPorts(11222); //Testcontainers.exposeHostPorts(11222);
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
String infinispanVersion = System.getProperty("infinispan.docker.image.version", "9.4.8.Final"); String infinispanVersion = System.getProperty("infinispan.docker.image.version", "11.0.9.Final");
infinispan = infinispan =
new GenericContainer(System.getProperty("infinispan.docker.image.name", "jboss/infinispan-server") + new GenericContainer(System.getProperty("infinispan.docker.image.name", "infinispan/server") +
":" + infinispanVersion) ":" + infinispanVersion)
.withEnv("APP_USER", "theuser") .withEnv("USER", "theuser")
.withEnv("APP_PASS", "foobar") .withEnv("PASS", "foobar")
.withEnv("MGMT_USER", "admin") .withEnv("MGMT_USER", "admin")
.withEnv("MGMT_PASS", "admin") .withEnv("MGMT_PASS", "admin")
.waitingFor(new LogMessageWaitStrategy() .waitingFor(new LogMessageWaitStrategy()
.withRegEx(".*Infinispan Server.*started in.*\\s")) .withRegEx(".*Infinispan Server.*started in.*\\s"))
.withExposedPorts(4712, 4713, 8088, 8089, 8443, 9990, 9993, 11211, 11222, 11223, 11224) .withExposedPorts(4712, 4713, 8088, 8089, 8443, 9990, 9993, 11211, 11222, 11223, 11224)
.withLogConsumer(new Slf4jLogConsumer(INFINISPAN_LOG)); .withLogConsumer(new Slf4jLogConsumer(INFINISPAN_LOG));
infinispan.start(); infinispan.start();
String host = infinispan.getContainerIpAddress(); String host = infinispan.getContainerIpAddress();
System.setProperty("hotrod.host", host); System.setProperty("hotrod.host", host);
@ -98,23 +97,16 @@ public class RemoteInfinispanTestSupport
if (infinispanVersion.startsWith("1")) if (infinispanVersion.startsWith("1"))
{ {
configurationBuilder.security().authentication() configurationBuilder.security().authentication()
.realm("default")
.serverName("infinispan")
.saslMechanism("DIGEST-MD5") .saslMechanism("DIGEST-MD5")
.username("theuser").password("foobar"); .username("theuser").password("foobar");
} }
configurationBuilder.addContextInitializer(new InfinispanSerializationContextInitializer());
Configuration configuration = configurationBuilder.build(); Configuration configuration = configurationBuilder.build();
_manager = new RemoteCacheManager(configuration); _manager = new RemoteCacheManager(configuration);
FileDescriptorSource fds = new FileDescriptorSource(); //upload the session.proto file to the remote cache
fds.addProtoFiles("/session.proto");
SerializationContext serCtx = ProtoStreamMarshaller.getSerializationContext(_manager);
serCtx.registerProtoFiles(fds);
serCtx.registerMarshaller(new SessionDataMarshaller());
ByteArrayOutputStream baos; ByteArrayOutputStream baos;
try (InputStream is = RemoteInfinispanSessionDataStoreTest.class.getClassLoader().getResourceAsStream("session.proto")) try (InputStream is = RemoteInfinispanSessionDataStoreTest.class.getClassLoader().getResourceAsStream("session.proto"))
{ {
@ -155,7 +147,15 @@ public class RemoteInfinispanTestSupport
public void setup() throws Exception public void setup() throws Exception
{ {
_cache = _manager.administration().getOrCreateCache(_name, (String)null); String xml = String.format("<infinispan>" +
"<cache-container>" + "<distributed-cache name=\"%s\" mode=\"SYNC\">" +
"<encoding media-type=\"application/x-protostream\"/>" +
"</distributed-cache>" +
"</cache-container>" +
"</infinispan>", _name);
XMLStringConfiguration xmlConfig = new XMLStringConfiguration(xml);
_cache = _manager.administration().getOrCreateCache(_name, xmlConfig);
} }
public void teardown() throws Exception public void teardown() throws Exception
@ -166,12 +166,13 @@ public class RemoteInfinispanTestSupport
public void createSession(InfinispanSessionData data) public void createSession(InfinispanSessionData data)
throws Exception throws Exception
{ {
data.serializeAttributes();
_cache.put(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId(), data); _cache.put(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId(), data);
} }
public void createUnreadableSession(InfinispanSessionData data) public void createUnreadableSession(InfinispanSessionData data)
{ {
//Unused by test
} }
public boolean checkSessionExists(InfinispanSessionData data) public boolean checkSessionExists(InfinispanSessionData data)
@ -188,7 +189,8 @@ public class RemoteInfinispanTestSupport
return false; return false;
InfinispanSessionData saved = (InfinispanSessionData)obj; InfinispanSessionData saved = (InfinispanSessionData)obj;
saved.deserializeAttributes(); if (saved.getSerializedAttributes() != null)
saved.deserializeAttributes();
assertEquals(data.getId(), saved.getId()); assertEquals(data.getId(), saved.getId());
assertEquals(data.getContextPath(), saved.getContextPath()); assertEquals(data.getContextPath(), saved.getContextPath());

View File

@ -1,6 +1,6 @@
# Jetty Logging using jetty-slf4j-impl # Jetty Logging using jetty-slf4j-impl
org.eclipse.jetty.logging.appender.NAME_CONDENSE=false org.eclipse.jetty.logging.appender.NAME_CONDENSE=false
org.eclipse.jetty.LEVEL=WARN org.eclipse.jetty.LEVEL=INFO
org.eclipse.jetty.server.session.LEVEL=INFO
org.eclipse.jetty.server.infinispan.session.LEVEL=INFO
log.LEVEL=INFO log.LEVEL=INFO
# org.hibernate.LEVEL=WARN
# org.infinispan.LEVEL=DEBUG

View File

@ -1,3 +1,5 @@
org.slf4j.simpleLogger.defaultLogLevel=info org.slf4j.simpleLogger.defaultLogLevel=info
org.slf4j.simpleLogger.log.org.eclipse.jetty.server.session.remote.infinispanLogs=info org.slf4j.simpleLogger.log.org.eclipse.jetty.server.session.remote.infinispanLogs=info
org.slf4j.simpleLogger.log.org.eclipse.jetty.server.session.remote.RemoteInfinispanTestSupport=info org.slf4j.simpleLogger.log.org.eclipse.jetty.server.session.remote.RemoteInfinispanTestSupport=info
#org.slf4j.simpleLogger.log.org.eclipse.jetty.server.session=trace
#org.slf4j.simpleLogger.log.org.eclipse.jetty.session.infinispan=trace

View File

@ -24,6 +24,11 @@ import org.testcontainers.junit.jupiter.Testcontainers;
@Testcontainers(disabledWithoutDocker = true) @Testcontainers(disabledWithoutDocker = true)
public class JDBCSessionDataStoreTest extends AbstractSessionDataStoreTest public class JDBCSessionDataStoreTest extends AbstractSessionDataStoreTest
{ {
public JDBCSessionDataStoreTest() throws Exception
{
super();
}
@BeforeEach @BeforeEach
public void setUp() throws Exception public void setUp() throws Exception
{ {

View File

@ -39,6 +39,11 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
@Testcontainers(disabledWithoutDocker = true) @Testcontainers(disabledWithoutDocker = true)
public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest
{ {
public MongoSessionDataStoreTest() throws Exception
{
super();
}
@BeforeEach @BeforeEach
public void beforeEach() throws Exception public void beforeEach() throws Exception
{ {

View File

@ -57,7 +57,7 @@ public abstract class AbstractSessionDataStoreTest
public static final long RECENT_TIMESTAMP = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(3 * GRACE_PERIOD_SEC); public static final long RECENT_TIMESTAMP = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(3 * GRACE_PERIOD_SEC);
protected static File extraClasses; protected static File extraClasses;
protected URLClassLoader _contextClassLoader = new URLClassLoader(new URL[]{}, Thread.currentThread().getContextClassLoader()); protected URLClassLoader _contextClassLoader;
public abstract SessionDataStoreFactory createSessionDataStoreFactory(); public abstract SessionDataStoreFactory createSessionDataStoreFactory();
@ -94,8 +94,15 @@ public abstract class AbstractSessionDataStoreTest
File factoryClass = new File(extraClasses, "ProxyableFactory.class"); File factoryClass = new File(extraClasses, "ProxyableFactory.class");
IO.copy(is, new FileOutputStream(factoryClass)); IO.copy(is, new FileOutputStream(factoryClass));
is.close(); is.close();
}
}
public AbstractSessionDataStoreTest() throws Exception
{
URL[] foodirUrls = new URL[]{extraClasses.toURI().toURL()};
_contextClassLoader = new URLClassLoader(foodirUrls, Thread.currentThread().getContextClassLoader());
}
/** /**
* Test that the store can persist a session. The session uses an attribute * Test that the store can persist a session. The session uses an attribute
* class that is only known to the webapp classloader. This tests that * class that is only known to the webapp classloader. This tests that
@ -104,10 +111,6 @@ public abstract class AbstractSessionDataStoreTest
@Test @Test
public void testStoreSession() throws Exception public void testStoreSession() throws Exception
{ {
//Use a class that would only be known to the webapp classloader
URL[] foodirUrls = new URL[]{extraClasses.toURI().toURL()};
_contextClassLoader = new URLClassLoader(foodirUrls, Thread.currentThread().getContextClassLoader());
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
@ -180,6 +183,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -197,14 +201,16 @@ public abstract class AbstractSessionDataStoreTest
//put it into the store //put it into the store
persistSession(data); persistSession(data);
assertTrue(checkSessionExists(data));
//now test we can update the session //now test we can update the session
data.setLastAccessed(now - 1); data.setLastAccessed(now - 1);
data.setAccessed(now); data.setAccessed(now);
data.setMaxInactiveMs(TimeUnit.MINUTES.toMillis(2)); data.setMaxInactiveMs(TimeUnit.MINUTES.toMillis(2));
data.setAttribute("a", "c"); data.setAttribute("a", "c");
store.store("aaa2", data); store.store("aaa2", data);
assertTrue(checkSessionPersisted(data)); assertTrue(checkSessionPersisted(data));
} }
@ -215,10 +221,6 @@ public abstract class AbstractSessionDataStoreTest
@Test @Test
public void testStoreObjectAttributes() throws Exception public void testStoreObjectAttributes() throws Exception
{ {
//Use classes that would only be known to the webapp classloader
URL[] proxyabledirUrls = new URL[]{extraClasses.toURI().toURL()};
_contextClassLoader = new URLClassLoader(proxyabledirUrls, Thread.currentThread().getContextClassLoader());
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
@ -303,6 +305,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -336,6 +339,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -370,6 +374,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -391,6 +396,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -428,6 +434,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -455,6 +462,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -491,6 +499,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -521,6 +530,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -542,6 +552,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -577,6 +588,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -611,6 +623,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -634,6 +647,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -670,6 +684,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -695,6 +710,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -795,6 +811,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -821,6 +838,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -847,6 +865,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -864,6 +883,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler()); SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
@ -892,6 +912,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
((AbstractSessionDataStoreFactory)factory).setSavePeriodSec(20); //only save every 20sec ((AbstractSessionDataStoreFactory)factory).setSavePeriodSec(20); //only save every 20sec
@ -932,6 +953,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
((AbstractSessionDataStoreFactory)factory).setSavePeriodSec(20); //only save every 20sec ((AbstractSessionDataStoreFactory)factory).setSavePeriodSec(20); //only save every 20sec
@ -961,6 +983,7 @@ public abstract class AbstractSessionDataStoreTest
//create the SessionDataStore //create the SessionDataStore
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/test"); context.setContextPath("/test");
context.setClassLoader(_contextClassLoader);
SessionDataStoreFactory factory = createSessionDataStoreFactory(); SessionDataStoreFactory factory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC); ((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
((AbstractSessionDataStoreFactory)factory).setSavePeriodSec(20); //only save every 20sec ((AbstractSessionDataStoreFactory)factory).setSavePeriodSec(20); //only save every 20sec