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:
parent
2396594b40
commit
d3bfb61761
|
@ -414,6 +414,12 @@
|
|||
<artifactId>infinispan-core</artifactId>
|
||||
<version>${infinispan.version}</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.wildfly.common</groupId>
|
||||
<artifactId>wildfly-common</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- to make infinispan-common source sane -->
|
||||
<dependency>
|
||||
|
@ -426,7 +432,7 @@
|
|||
<dependency>
|
||||
<groupId>org.infinispan.protostream</groupId>
|
||||
<artifactId>protostream</artifactId>
|
||||
<version>4.2.2.Final</version>
|
||||
<version>${infinispan.protostream.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -750,6 +750,12 @@
|
|||
<version>${project.version}</version>
|
||||
<type>pom</type>
|
||||
<optional>true</optional>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.wildfly.common</groupId>
|
||||
<artifactId>*</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
|
|
|
@ -37,8 +37,13 @@
|
|||
<dependency>
|
||||
<groupId>org.infinispan</groupId>
|
||||
<artifactId>infinispan-core</artifactId>
|
||||
<version>${infinispan.version}</version>
|
||||
<optional>true</optional>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.wildfly.common</groupId>
|
||||
<artifactId>wildfly-common</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.infinispan.protostream</groupId>
|
||||
|
@ -63,13 +68,11 @@
|
|||
<dependency>
|
||||
<groupId>org.infinispan</groupId>
|
||||
<artifactId>infinispan-client-hotrod</artifactId>
|
||||
<version>${infinispan.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.infinispan</groupId>
|
||||
<artifactId>infinispan-remote-query-client</artifactId>
|
||||
<version>${infinispan.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<Set name="infinispanIdleTimeoutSec" property="jetty.session.infinispan.idleTimeout.seconds"/>
|
||||
<Set name="gracePeriodSec" property="jetty.session.gracePeriod.seconds"/>
|
||||
<Set name="savePeriodSec" property="jetty.session.savePeriod.seconds"/>
|
||||
<Set name="serialization" property="jetty.session.infinispan.serialization"/>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
|
|
@ -13,7 +13,7 @@ lib/infinispan-common-${jetty.version}.jar
|
|||
lib/infinispan/*.jar
|
||||
|
||||
[ini]
|
||||
infinispan.version?=9.4.8.Final
|
||||
infinispan.version?=11.0.11.Final
|
||||
|
||||
[license]
|
||||
Infinispan is an open source project hosted on Github and released under the Apache 2.0 license.
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -33,7 +33,6 @@ import org.infinispan.commons.marshall.SerializeWith;
|
|||
* pool and thus these threads have no knowledge of the correct classloader to
|
||||
* use.
|
||||
*/
|
||||
@SerializeWith(SessionDataMarshaller.class)
|
||||
public class InfinispanSessionData extends SessionData
|
||||
{
|
||||
protected byte[] _serializedAttributes;
|
||||
|
|
|
@ -44,6 +44,7 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
|
|||
private int _infinispanIdleTimeoutSec;
|
||||
private QueryManager _queryManager;
|
||||
private boolean _passivating;
|
||||
private boolean _serialization;
|
||||
|
||||
/**
|
||||
* Get the clustered cache instance.
|
||||
|
@ -74,9 +75,8 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
|
|||
|
||||
try
|
||||
{
|
||||
_passivating = false;
|
||||
Class<?> remoteClass = InfinispanSessionDataStore.class.getClassLoader().loadClass("org.infinispan.client.hotrod.RemoteCache");
|
||||
if (remoteClass.isAssignableFrom(_cache.getClass()))
|
||||
if (remoteClass.isAssignableFrom(_cache.getClass()) || _serialization)
|
||||
_passivating = true;
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
|
@ -105,6 +105,9 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
|
|||
LOG.debug("Loading session {} from infinispan", 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 (LOG.isDebugEnabled())
|
||||
|
@ -205,6 +208,15 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
|
|||
@Override
|
||||
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 -
|
||||
//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.
|
||||
|
@ -271,6 +283,11 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
|
|||
return _infinispanIdleTimeoutSec;
|
||||
}
|
||||
|
||||
public void setSerialization(boolean serialization)
|
||||
{
|
||||
_serialization = serialization;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@ public class InfinispanSessionDataStoreFactory extends AbstractSessionDataStoreF
|
|||
int _infinispanIdleTimeoutSec;
|
||||
BasicCache<String, InfinispanSessionData> _cache;
|
||||
protected QueryManager _queryManager;
|
||||
protected boolean _serialization;
|
||||
|
||||
/**
|
||||
* @return the infinispanIdleTimeoutSec
|
||||
|
@ -52,6 +53,7 @@ public class InfinispanSessionDataStoreFactory extends AbstractSessionDataStoreF
|
|||
store.setCache(getCache());
|
||||
store.setSavePeriodSec(getSavePeriodSec());
|
||||
store.setQueryManager(getQueryManager());
|
||||
store.setSerialization(getSerialization());
|
||||
return store;
|
||||
}
|
||||
|
||||
|
@ -84,4 +86,14 @@ public class InfinispanSessionDataStoreFactory extends AbstractSessionDataStoreF
|
|||
{
|
||||
_queryManager = queryManager;
|
||||
}
|
||||
|
||||
public void setSerialization(boolean serialization)
|
||||
{
|
||||
_serialization = serialization;
|
||||
}
|
||||
|
||||
public boolean getSerialization()
|
||||
{
|
||||
return _serialization;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,7 @@
|
|||
package org.eclipse.jetty.session.infinispan;
|
||||
|
||||
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.MessageMarshaller;
|
||||
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
|
||||
* the container class loader or the webapp classloader, as appropriate.
|
||||
*/
|
||||
public class SessionDataMarshaller
|
||||
implements MessageMarshaller<InfinispanSessionData>, Externalizer<InfinispanSessionData>
|
||||
public class SessionDataMarshaller implements MessageMarshaller<InfinispanSessionData>
|
||||
{
|
||||
/**
|
||||
* The version of the serializer.
|
||||
|
@ -67,39 +63,6 @@ public class SessionDataMarshaller
|
|||
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
|
||||
public InfinispanSessionData readFrom(ProtoStreamReader in) throws IOException
|
||||
{
|
||||
|
@ -127,6 +90,9 @@ public class SessionDataMarshaller
|
|||
if (version == 0)
|
||||
{
|
||||
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);
|
||||
return sd;
|
||||
}
|
||||
|
@ -152,7 +118,9 @@ public class SessionDataMarshaller
|
|||
out.writeLong("expiry", sdata.getExpiry());
|
||||
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());
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,6 @@
|
|||
<dependency>
|
||||
<groupId>org.infinispan</groupId>
|
||||
<artifactId>infinispan-query</artifactId>
|
||||
<version>${infinispan.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.infinispan.Cache;
|
|||
import org.infinispan.query.Search;
|
||||
import org.infinispan.query.dsl.Query;
|
||||
import org.infinispan.query.dsl.QueryFactory;
|
||||
import org.infinispan.query.dsl.QueryResult;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -32,39 +33,40 @@ public class EmbeddedQueryManager implements QueryManager
|
|||
private static final Logger LOG = LoggerFactory.getLogger(EmbeddedQueryManager.class);
|
||||
|
||||
private Cache<String, InfinispanSessionData> _cache;
|
||||
private QueryFactory _factory;
|
||||
|
||||
public EmbeddedQueryManager(Cache<String, InfinispanSessionData> cache)
|
||||
{
|
||||
_cache = cache;
|
||||
_factory = Search.getQueryFactory(_cache);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> queryExpiredSessions(SessionContext sessionContext, long time)
|
||||
{
|
||||
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();
|
||||
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);
|
||||
|
||||
List<Object[]> list = q.list();
|
||||
@SuppressWarnings("rawtypes")
|
||||
QueryResult result = expiredQuery.execute();
|
||||
List<Object[]> list = result.list();
|
||||
Set<String> ids = list.stream().map(a -> (String)a[0]).collect(toSet());
|
||||
return ids;
|
||||
}
|
||||
|
||||
public void deleteOrphanSessions(long time)
|
||||
{
|
||||
QueryFactory qf = Search.getQueryFactory(_cache);
|
||||
Query q = qf.from(InfinispanSessionData.class)
|
||||
.select("id", "contextPath", "vhost")
|
||||
.having("expiry").lte(time)
|
||||
.and().having("expiry").gt(0)
|
||||
.build();
|
||||
List<Object[]> list = q.list();
|
||||
Query<InfinispanSessionData> deleteQuery = _factory.create("select id, contextPath, vhost from org.eclipse.jetty.session.infinispan.InfinispanSessionData where " +
|
||||
" expiry <= :expiry and expiry > 0");
|
||||
deleteQuery.setParameter("expiry", time);
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
QueryResult result = deleteQuery.execute();
|
||||
List<Object[]> list = result.list();
|
||||
|
||||
list.stream().forEach(a ->
|
||||
{
|
||||
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)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.hibernate.search.cfg.SearchMapping;
|
|||
import org.infinispan.Cache;
|
||||
import org.infinispan.configuration.cache.Configuration;
|
||||
import org.infinispan.configuration.cache.ConfigurationBuilder;
|
||||
import org.infinispan.configuration.cache.Index;
|
||||
import org.infinispan.configuration.global.GlobalConfigurationBuilder;
|
||||
import org.infinispan.manager.DefaultCacheManager;
|
||||
import org.infinispan.manager.EmbeddedCacheManager;
|
||||
|
@ -51,7 +50,7 @@ public class EmbeddedQueryManagerTest
|
|||
public void test()
|
||||
{
|
||||
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
|
||||
SearchMapping mapping = new SearchMapping();
|
||||
|
@ -66,7 +65,7 @@ public class EmbeddedQueryManagerTest
|
|||
if (dcc != null)
|
||||
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();
|
||||
|
||||
cacheManager.defineConfiguration(name, c);
|
||||
|
|
|
@ -98,7 +98,12 @@
|
|||
<dependency>
|
||||
<groupId>org.infinispan</groupId>
|
||||
<artifactId>infinispan-core</artifactId>
|
||||
<version>${infinispan.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.wildfly.common</groupId>
|
||||
<artifactId>wildfly-common</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -16,9 +16,10 @@ sessions/infinispan/embedded/infinispan-embedded-libs
|
|||
basehome:modules/sessions/infinispan/embedded/infinispan.xml|etc/infinispan.xml
|
||||
|
||||
[ini]
|
||||
infinispan.version?=9.4.8.Final
|
||||
infinispan.version?=11.0.11.Final
|
||||
|
||||
[ini-template]
|
||||
#jetty.session.infinispan.idleTimeout.seconds=0
|
||||
#jetty.session.infinispan.serialization=false
|
||||
#jetty.session.gracePeriod.seconds=3600
|
||||
#jetty.session.savePeriod.seconds=0
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<name>Jetty :: Infinispan Session Manager Remote with Querying</name>
|
||||
<properties>
|
||||
<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>
|
||||
<build>
|
||||
<plugins>
|
||||
|
@ -116,17 +116,24 @@
|
|||
<dependency>
|
||||
<groupId>org.infinispan</groupId>
|
||||
<artifactId>infinispan-query</artifactId>
|
||||
<version>${infinispan.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.infinispan</groupId>
|
||||
<artifactId>infinispan-client-hotrod</artifactId>
|
||||
<version>${infinispan.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.infinispan</groupId>
|
||||
<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>
|
||||
<groupId>org.slf4j</groupId>
|
||||
|
|
|
@ -45,7 +45,12 @@
|
|||
</Call>
|
||||
<Call name="marshaller">
|
||||
<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>
|
||||
</Call>
|
||||
<Call id="config" name="build"/>
|
||||
|
@ -58,33 +63,6 @@
|
|||
<Arg><Ref refid="config"/></Arg>
|
||||
</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. -->
|
||||
<!-- ===================================================================== -->
|
||||
|
|
|
@ -10,13 +10,9 @@ infinispan-remote
|
|||
[depends]
|
||||
sessions/infinispan/remote/infinispan-remote-query-libs
|
||||
|
||||
[files]
|
||||
basehome:modules/sessions/infinispan/remote/other_proto_marshallers.xml|etc/other_proto_marshallers.xml
|
||||
|
||||
[lib]
|
||||
lib/infinispan-remote-query-${jetty.version}.jar
|
||||
|
||||
[xml]
|
||||
etc/sessions/infinispan/infinispan-remote-query.xml
|
||||
etc/other_proto_marshallers.xml
|
||||
etc/sessions/infinispan/infinispan-common.xml
|
||||
|
|
|
@ -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>
|
|
@ -22,6 +22,7 @@ import org.infinispan.client.hotrod.RemoteCache;
|
|||
import org.infinispan.client.hotrod.Search;
|
||||
import org.infinispan.query.dsl.Query;
|
||||
import org.infinispan.query.dsl.QueryFactory;
|
||||
import org.infinispan.query.dsl.QueryResult;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -36,27 +37,27 @@ public class RemoteQueryManager implements QueryManager
|
|||
{
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RemoteQueryManager.class);
|
||||
private RemoteCache<String, InfinispanSessionData> _cache;
|
||||
private QueryFactory _factory;
|
||||
|
||||
public RemoteQueryManager(RemoteCache<String, InfinispanSessionData> cache)
|
||||
{
|
||||
_cache = cache;
|
||||
_factory = Search.getQueryFactory(_cache);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> queryExpiredSessions(SessionContext sessionContext, long time)
|
||||
{
|
||||
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());
|
||||
return ids;
|
||||
}
|
||||
|
@ -64,14 +65,13 @@ public class RemoteQueryManager implements QueryManager
|
|||
@Override
|
||||
public void deleteOrphanSessions(long time)
|
||||
{
|
||||
QueryFactory qf = Search.getQueryFactory(_cache);
|
||||
Query q = qf.from(InfinispanSessionData.class)
|
||||
.select("id", "contextPath", "vhost")
|
||||
.having("expiry").lte(time)
|
||||
.and()
|
||||
.having("expiry").gt(0)
|
||||
.build();
|
||||
List<Object[]> list = q.list();
|
||||
Query<InfinispanSessionData> deleteQuery = _factory.create("select id, contextPath, vhost from org_eclipse_jetty_session_infinispan.InfinispanSessionData where " +
|
||||
" expiry <= :expiry and expiry > 0");
|
||||
deleteQuery.setParameter("expiry", time);
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
QueryResult result = deleteQuery.execute();
|
||||
List<Object[]> list = result.list();
|
||||
list.stream().forEach(a ->
|
||||
{
|
||||
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)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,10 +24,10 @@ import java.util.Set;
|
|||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.session.SessionContext;
|
||||
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.QueryManager;
|
||||
import org.eclipse.jetty.session.infinispan.RemoteQueryManager;
|
||||
import org.eclipse.jetty.session.infinispan.SessionDataMarshaller;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.hibernate.search.cfg.Environment;
|
||||
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.configuration.ClientIntelligence;
|
||||
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
|
||||
import org.infinispan.client.hotrod.marshall.ProtoStreamMarshaller;
|
||||
import org.infinispan.protostream.FileDescriptorSource;
|
||||
import org.infinispan.protostream.SerializationContext;
|
||||
import org.infinispan.commons.configuration.XMLStringConfiguration;
|
||||
import org.infinispan.commons.marshall.ProtoStreamMarshaller;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -69,10 +68,10 @@ public class RemoteQueryManagerTest
|
|||
private int port;
|
||||
|
||||
GenericContainer infinispan =
|
||||
new GenericContainer(System.getProperty("infinispan.docker.image.name", "jboss/infinispan-server") +
|
||||
":" + System.getProperty("infinispan.docker.image.version", "9.4.8.Final"))
|
||||
.withEnv("APP_USER", "theuser")
|
||||
.withEnv("APP_PASS", "foobar")
|
||||
new GenericContainer(System.getProperty("infinispan.docker.image.name", "infinispan/server") +
|
||||
":" + System.getProperty("infinispan.docker.image.version", "11.0.9.Final"))
|
||||
.withEnv("USER", "theuser")
|
||||
.withEnv("PASS", "foobar")
|
||||
.withEnv("MGMT_USER", "admin")
|
||||
.withEnv("MGMT_PASS", "admin")
|
||||
.waitingFor(new LogMessageWaitStrategy()
|
||||
|
@ -101,27 +100,27 @@ public class RemoteQueryManagerTest
|
|||
public void testQuery() throws Exception
|
||||
{
|
||||
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.put(Environment.MODEL_MAPPING, mapping);
|
||||
|
||||
ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
|
||||
clientBuilder.withProperties(properties).addServer()
|
||||
clientBuilder.withProperties(properties)
|
||||
.addServer()
|
||||
.host(this.host).port(this.port)
|
||||
.clientIntelligence(ClientIntelligence.BASIC)
|
||||
.marshaller(new ProtoStreamMarshaller());
|
||||
.marshaller(new ProtoStreamMarshaller())
|
||||
.security()
|
||||
.authentication()
|
||||
.username("theuser").password("foobar");
|
||||
|
||||
clientBuilder.addContextInitializer(new InfinispanSerializationContextInitializer());
|
||||
|
||||
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");
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream())
|
||||
{
|
||||
|
@ -129,10 +128,18 @@ public class RemoteQueryManagerTest
|
|||
throw new IllegalStateException("inputstream is null");
|
||||
IO.copy(is, baos);
|
||||
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
|
||||
ContextHandler fooHandler = new ContextHandler();
|
||||
|
@ -155,7 +162,7 @@ public class RemoteQueryManagerTest
|
|||
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<>();
|
||||
|
||||
|
@ -168,6 +175,7 @@ public class RemoteQueryManagerTest
|
|||
InfinispanSessionData sd = new InfinispanSessionData(id, sessionContext.getCanonicalContextPath(), sessionContext.getVhost(), 0, 0, 0, 0);
|
||||
sd.setLastNode(sessionContext.getWorkerName());
|
||||
sd.setExpiry(expiryTime);
|
||||
sd.serializeAttributes();
|
||||
sessions.add(sd);
|
||||
//add to cache
|
||||
cache.put(id, sd);
|
||||
|
|
|
@ -99,13 +99,11 @@
|
|||
<dependency>
|
||||
<groupId>org.infinispan</groupId>
|
||||
<artifactId>infinispan-client-hotrod</artifactId>
|
||||
<version>${infinispan.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.infinispan</groupId>
|
||||
<artifactId>infinispan-remote-query-client</artifactId>
|
||||
<version>${infinispan.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -25,7 +25,12 @@
|
|||
</Call>
|
||||
<Call name="marshaller">
|
||||
<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>
|
||||
</Call>
|
||||
<Call id="config" name="build"/>
|
||||
|
@ -38,35 +43,6 @@
|
|||
<Arg><Ref refid="config"/></Arg>
|
||||
</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. -->
|
||||
<!-- ===================================================================== -->
|
||||
|
|
|
@ -16,7 +16,7 @@ sessions/infinispan/remote/infinispan-remote-libs
|
|||
basehome:modules/sessions/infinispan/remote/resources/hotrod-client.properties|resources/hotrod-client.properties
|
||||
|
||||
[ini]
|
||||
infinispan.version?=9.4.8.Final
|
||||
infinispan.version?=11.0.11.Final
|
||||
|
||||
|
||||
[license]
|
||||
|
@ -26,6 +26,7 @@ http://www.apache.org/licenses/LICENSE-2.0.html
|
|||
|
||||
[ini-template]
|
||||
#jetty.session.infinispan.remoteCacheName=sessions
|
||||
#jetty.session.infinispan.serialization=true
|
||||
#jetty.session.infinispan.idleTimeout.seconds=0
|
||||
#jetty.session.gracePeriod.seconds=3600
|
||||
#jetty.session.savePeriod.seconds=0
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
#infinispan.client.hotrod.server_list
|
||||
#infinispan.client.hotrod.context-initializers=
|
||||
|
|
|
@ -77,6 +77,7 @@ public class SessionData implements Serializable
|
|||
Class<?> clazz = entry.getValue().getClass();
|
||||
ClassLoader loader = clazz.getClassLoader();
|
||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
boolean isContextLoader;
|
||||
|
||||
if (loader == contextLoader) //is it the context classloader?
|
||||
|
@ -142,7 +143,6 @@ public class SessionData implements Serializable
|
|||
boolean isServerClassLoader = in.readBoolean(); //use server or webapp classloader to load
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Deserialize {} isServerLoader={} serverLoader={} tccl={}", name, isServerClassLoader, serverLoader, contextLoader);
|
||||
|
||||
Object value = ((ClassLoadingObjectInputStream)in).readObject(isServerClassLoader ? serverLoader : contextLoader);
|
||||
data._attributes.put(name, value);
|
||||
}
|
||||
|
|
40
pom.xml
40
pom.xml
|
@ -28,7 +28,7 @@
|
|||
<servlet.api.version>4.0.6</servlet.api.version>
|
||||
<websocket.api.version>1.1.2</websocket.api.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>
|
||||
<gson.version>2.8.8</gson.version>
|
||||
<grpc.version>1.40.1</grpc.version>
|
||||
|
@ -1239,6 +1239,39 @@
|
|||
<artifactId>biz.aQute.bndlib</artifactId>
|
||||
<version>5.3.0</version>
|
||||
</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 -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
|
@ -1276,11 +1309,6 @@
|
|||
<version>${slf4j.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.logging</groupId>
|
||||
<artifactId>jboss-logging</artifactId>
|
||||
<version>${jboss.logging.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.asciidoctor</groupId>
|
||||
<artifactId>asciidoctor-maven-plugin</artifactId>
|
||||
|
|
|
@ -42,6 +42,12 @@
|
|||
<artifactId>weld-servlet-core</artifactId>
|
||||
<version>${weld.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>io.undertow</groupId>
|
||||
<artifactId>*</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
|
|
|
@ -217,6 +217,7 @@
|
|||
<distribution.debug.port>$(distribution.debug.port}</distribution.debug.port>
|
||||
<home.start.timeout>${home.start.timeout}</home.start.timeout>
|
||||
<mariadb.version>${mariadb.version}</mariadb.version>
|
||||
<sessionLogLevel>${sessionLogLevel}</sessionLogLevel>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
|
|
@ -44,6 +44,7 @@ public abstract class AbstractSessionDistributionTests extends AbstractJettyHome
|
|||
{
|
||||
|
||||
private String jettyVersion = System.getProperty("jettyVersion");
|
||||
private String sessionLogLevel = System.getProperty("sessionLogLevel", "INFO");
|
||||
|
||||
protected JettyHomeTester jettyHomeTester;
|
||||
|
||||
|
@ -86,6 +87,9 @@ public abstract class AbstractSessionDistributionTests extends AbstractJettyHome
|
|||
args.addAll(getSecondStartExtraArgs());
|
||||
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))
|
||||
{
|
||||
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"));
|
||||
}
|
||||
|
||||
/*
|
||||
Path logFile = jettyHomeTester.getJettyBase().resolve("resources").resolve("jetty-logging.properties");
|
||||
Files.deleteIfExists(logFile);
|
||||
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))
|
||||
{
|
||||
|
@ -137,4 +139,6 @@ public abstract class AbstractSessionDistributionTests extends AbstractJettyHome
|
|||
|
||||
public abstract void stopExternalSessionStorage() throws Exception;
|
||||
|
||||
public abstract void configureExternalSessionStorage(Path jettyBase) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
package org.eclipse.jetty.tests.distribution.session;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -24,6 +25,11 @@ import org.testcontainers.junit.jupiter.Testcontainers;
|
|||
@Testcontainers(disabledWithoutDocker = false)
|
||||
public class FileSessionDistributionTests extends AbstractSessionDistributionTests
|
||||
{
|
||||
@Override
|
||||
public void configureExternalSessionStorage(Path jettyBase) throws Exception
|
||||
{
|
||||
// no op
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startExternalSessionStorage() throws Exception
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
package org.eclipse.jetty.tests.distribution.session;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -51,6 +52,12 @@ public class FileSessionWithMemcacheDistributionTests extends AbstractSessionDis
|
|||
super.prepareJettyHomeTester();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureExternalSessionStorage(Path jettyBase) throws Exception
|
||||
{
|
||||
// no op
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startExternalSessionStorage() throws Exception
|
||||
{
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.jetty.tests.distribution.session;
|
|||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -84,6 +85,12 @@ public class GCloudSessionDistributionTests extends AbstractSessionDistributionT
|
|||
emulator.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureExternalSessionStorage(Path jettyBase) throws Exception
|
||||
{
|
||||
// no op
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFirstStartExtraArgs()
|
||||
{
|
||||
|
|
|
@ -91,6 +91,12 @@ public class HazelcastSessionDistributionTests extends AbstractSessionDistributi
|
|||
hazelcast.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureExternalSessionStorage(Path jettyBase) throws Exception
|
||||
{
|
||||
// no op
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFirstStartExtraArgs()
|
||||
{
|
||||
|
|
|
@ -13,17 +13,25 @@
|
|||
|
||||
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.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.jetty.session.infinispan.InfinispanSerializationContextInitializer;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.infinispan.client.hotrod.RemoteCacheManager;
|
||||
import org.infinispan.client.hotrod.configuration.Configuration;
|
||||
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.LoggerFactory;
|
||||
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 INFINISPAN_LOG = LoggerFactory.getLogger("org.eclipse.jetty.tests.distribution.session.infinispan");
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private GenericContainer infinispan;
|
||||
|
||||
private String host;
|
||||
private int port;
|
||||
|
||||
@Override
|
||||
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 =
|
||||
new GenericContainer(System.getProperty("infinispan.docker.image.name", "jboss/infinispan-server") +
|
||||
new GenericContainer(System.getProperty("infinispan.docker.image.name", "infinispan/server") +
|
||||
":" + infinispanVersion)
|
||||
//.withEnv("APP_USER", "theuser")
|
||||
//.withEnv("APP_PASS", "foobar")
|
||||
.withEnv("USER", "theuser")
|
||||
.withEnv("PASS", "foobar")
|
||||
.withEnv("MGMT_USER", "admin")
|
||||
.withEnv("MGMT_PASS", "admin")
|
||||
.withCommand("standalone")
|
||||
.waitingFor(new LogMessageWaitStrategy()
|
||||
.withRegEx(".*Infinispan Server.*started in.*\\s"))
|
||||
.withExposedPorts(4712, 4713, 8088, 8089, 8443, 9990, 9993, 11211, 11222, 11223, 11224)
|
||||
.withLogConsumer(new Slf4jLogConsumer(INFINISPAN_LOG));
|
||||
infinispan.start();
|
||||
String host = infinispan.getContainerIpAddress();
|
||||
int port = infinispan.getMappedPort(11222);
|
||||
host = infinispan.getContainerIpAddress();
|
||||
port = infinispan.getMappedPort(11222);
|
||||
|
||||
Path resourcesDirectory = Path.of(jettyHomeTester.getJettyBase().toString(), "resources/");
|
||||
if (Files.exists(resourcesDirectory))
|
||||
{
|
||||
IO.delete(resourcesDirectory.toFile());
|
||||
}
|
||||
|
||||
Files.createDirectories(resourcesDirectory);
|
||||
Properties properties = new Properties();
|
||||
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");
|
||||
Files.deleteIfExists(hotrod);
|
||||
|
@ -82,11 +96,36 @@ public class InfinispanSessionDistributionTests extends AbstractSessionDistribut
|
|||
}
|
||||
|
||||
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.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
|
||||
|
@ -113,4 +152,23 @@ public class InfinispanSessionDistributionTests extends AbstractSessionDistribut
|
|||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,6 +78,12 @@ public class JDBCSessionDistributionTests extends AbstractSessionDistributionTes
|
|||
mariaDBContainer.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureExternalSessionStorage(Path jettyBase) throws Exception
|
||||
{
|
||||
// no op
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFirstStartExtraArgs()
|
||||
{
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
package org.eclipse.jetty.tests.distribution.session;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -56,6 +57,12 @@ public class MongodbSessionDistributionTests extends AbstractSessionDistribution
|
|||
mongoDBContainer.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureExternalSessionStorage(Path jettyBase) throws Exception
|
||||
{
|
||||
// no op
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFirstStartExtraArgs()
|
||||
{
|
||||
|
|
|
@ -24,6 +24,11 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
|||
@ExtendWith(WorkDirExtension.class)
|
||||
public class FileSessionDataStoreTest extends AbstractSessionDataStoreTest
|
||||
{
|
||||
public FileSessionDataStoreTest() throws Exception
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public WorkDir workDir;
|
||||
private FileTestHelper _helper;
|
||||
|
||||
|
|
|
@ -28,6 +28,11 @@ import org.testcontainers.junit.jupiter.Testcontainers;
|
|||
public class GCloudSessionDataStoreTest extends AbstractSessionDataStoreTest
|
||||
{
|
||||
|
||||
public GCloudSessionDataStoreTest() throws Exception
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static GCloudSessionTestSupport __testSupport;
|
||||
|
||||
@BeforeAll
|
||||
|
|
|
@ -32,6 +32,11 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|||
*/
|
||||
public class HazelcastSessionDataStoreTest extends AbstractSessionDataStoreTest
|
||||
{
|
||||
public HazelcastSessionDataStoreTest() throws Exception
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
HazelcastTestHelper _testHelper;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,6 +34,11 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|||
*/
|
||||
public class HazelcastSessionDataStoreTest extends AbstractSessionDataStoreTest
|
||||
{
|
||||
public HazelcastSessionDataStoreTest() throws Exception
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
HazelcastTestHelper _testHelper;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
<properties>
|
||||
<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 -->
|
||||
<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 -->
|
||||
<infinispan.docker.image.name>jboss/infinispan-server</infinispan.docker.image.name>
|
||||
<infinispan.docker.image.name>infinispan/server</infinispan.docker.image.name>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
|
@ -120,6 +120,12 @@
|
|||
<artifactId>infinispan-core</artifactId>
|
||||
<version>${infinispan.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.wildfly.common</groupId>
|
||||
<artifactId>wildfly-common</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.infinispan</groupId>
|
||||
|
|
|
@ -61,6 +61,7 @@ public class ClusteredSerializedSessionScavengingTest extends AbstractClusteredS
|
|||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
InfinispanSessionDataStoreFactory factory = new InfinispanSessionDataStoreFactory();
|
||||
factory.setSerialization(true);
|
||||
factory.setCache(testSupport.getCache());
|
||||
return factory;
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScav
|
|||
public SessionDataStoreFactory createSessionDataStoreFactory()
|
||||
{
|
||||
InfinispanSessionDataStoreFactory factory = new InfinispanSessionDataStoreFactory();
|
||||
factory.setSerialization(true);
|
||||
factory.setCache(testSupport.getCache());
|
||||
return factory;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
|
||||
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.WorkDirExtension;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
@ -26,6 +29,11 @@ public class InfinispanFileSessionDataStoreTest extends InfinispanSessionDataSto
|
|||
{
|
||||
public WorkDir workDir;
|
||||
|
||||
public InfinispanFileSessionDataStoreTest() throws Exception
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception
|
||||
{
|
||||
|
@ -33,4 +41,14 @@ public class InfinispanFileSessionDataStoreTest extends InfinispanSessionDataSto
|
|||
_testSupport.setUseFileStore(true);
|
||||
_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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
|
|||
import org.infinispan.query.Search;
|
||||
import org.infinispan.query.dsl.Query;
|
||||
import org.infinispan.query.dsl.QueryFactory;
|
||||
import org.infinispan.query.dsl.QueryResult;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -47,6 +48,11 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest
|
|||
|
||||
public WorkDir workDir;
|
||||
|
||||
public InfinispanSessionDataStoreTest() throws Exception
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception
|
||||
{
|
||||
|
@ -72,9 +78,18 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest
|
|||
|
||||
@Override
|
||||
public void persistSession(SessionData data) throws Exception
|
||||
{
|
||||
ClassLoader old = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(_contextClassLoader);
|
||||
try
|
||||
{
|
||||
_testSupport.createSession(data);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Thread.currentThread().setContextClassLoader(old);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void persistUnreadableSession(SessionData data) throws Exception
|
||||
|
@ -84,9 +99,18 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest
|
|||
|
||||
@Override
|
||||
public boolean checkSessionExists(SessionData data) throws Exception
|
||||
{
|
||||
ClassLoader old = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(_contextClassLoader);
|
||||
try
|
||||
{
|
||||
return _testSupport.checkSessionExists(data);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Thread.currentThread().setContextClassLoader(old);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This test deliberately sets the infinispan cache to null to
|
||||
|
@ -98,6 +122,7 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -138,14 +163,17 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest
|
|||
{
|
||||
InfinispanSessionData sd1 = new InfinispanSessionData("sd1", "", "", 0, 0, 0, 1000);
|
||||
sd1.setLastNode("fred1");
|
||||
sd1.serializeAttributes();
|
||||
_testSupport.getCache().put("session1", sd1);
|
||||
|
||||
InfinispanSessionData sd2 = new InfinispanSessionData("sd2", "", "", 0, 0, 0, 2000);
|
||||
sd2.setLastNode("fred2");
|
||||
sd2.serializeAttributes();
|
||||
_testSupport.getCache().put("session2", sd2);
|
||||
|
||||
InfinispanSessionData sd3 = new InfinispanSessionData("sd3", "", "", 0, 0, 0, 3000);
|
||||
sd3.setLastNode("fred3");
|
||||
sd3.serializeAttributes();
|
||||
_testSupport.getCache().put("session3", sd3);
|
||||
|
||||
QueryFactory qf = Search.getQueryFactory(_testSupport.getCache());
|
||||
|
@ -153,8 +181,9 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest
|
|||
for (int i = 0; i <= 3; i++)
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
Query q = qf.from(InfinispanSessionData.class).having("expiry").lt(now).build();
|
||||
assertEquals(i, q.list().size());
|
||||
Query<InfinispanSessionData> q = qf.create("from org.eclipse.jetty.session.infinispan.InfinispanSessionData where expiry < " + now);
|
||||
QueryResult<InfinispanSessionData> result = q.execute();
|
||||
assertEquals(i, result.list().size());
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
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.util.IO;
|
||||
import org.hibernate.search.cfg.Environment;
|
||||
|
@ -26,8 +28,9 @@ import org.hibernate.search.cfg.SearchMapping;
|
|||
import org.infinispan.Cache;
|
||||
import org.infinispan.configuration.cache.ConfigurationBuilder;
|
||||
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.eviction.EvictionStrategy;
|
||||
import org.infinispan.manager.DefaultCacheManager;
|
||||
import org.infinispan.manager.EmbeddedCacheManager;
|
||||
|
||||
|
@ -53,7 +56,10 @@ public class InfinispanTestSupport
|
|||
{
|
||||
try
|
||||
{
|
||||
_manager = new DefaultCacheManager(new GlobalConfigurationBuilder().globalJmxStatistics().allowDuplicateDomains(true).build());
|
||||
_manager = new DefaultCacheManager(new GlobalConfigurationBuilder().jmx()
|
||||
.serialization()
|
||||
.addContextInitializer(new InfinispanSerializationContextInitializer())
|
||||
.build());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -100,22 +106,28 @@ public class InfinispanTestSupport
|
|||
Properties properties = new Properties();
|
||||
properties.put(Environment.MODEL_MAPPING, mapping);
|
||||
properties.put("hibernate.search.default.indexBase", indexesDir.toString());
|
||||
properties.put("hibernate.cache.infinispan.entity.eviction.strategy", "NONE");
|
||||
|
||||
if (_useFileStore)
|
||||
{
|
||||
Path tmpDir = Files.createTempDirectory("infinispan");
|
||||
_tmpdir = tmpDir.toFile();
|
||||
|
||||
ConfigurationChildBuilder b = _builder.indexing()
|
||||
.index(Index.ALL)
|
||||
ConfigurationChildBuilder b = _builder
|
||||
.indexing()
|
||||
.addIndexedEntity(SessionData.class)
|
||||
.withProperties(properties)
|
||||
.memory()
|
||||
.whenFull(EvictionStrategy.NONE)
|
||||
.persistence()
|
||||
.addSingleFileStore()
|
||||
.segmented(false)
|
||||
.location(_tmpdir.getAbsolutePath());
|
||||
if (_serializeSessionData)
|
||||
{
|
||||
b = b.storeAsBinary().enable();
|
||||
b = b.memory().storage(StorageType.HEAP)
|
||||
.encoding()
|
||||
.mediaType("application/x-protostream");
|
||||
}
|
||||
|
||||
_manager.defineConfiguration(_name, b.build());
|
||||
|
@ -124,12 +136,13 @@ public class InfinispanTestSupport
|
|||
{
|
||||
ConfigurationChildBuilder b = _builder.indexing()
|
||||
.withProperties(properties)
|
||||
.index(Index.ALL)
|
||||
.addIndexedEntity(SessionData.class);
|
||||
|
||||
if (_serializeSessionData)
|
||||
{
|
||||
b = b.storeAsBinary().enable();
|
||||
b = b.memory().storage(StorageType.HEAP)
|
||||
.encoding()
|
||||
.mediaType("application/x-protostream");
|
||||
}
|
||||
|
||||
_manager.defineConfiguration(_name, b.build());
|
||||
|
@ -140,7 +153,7 @@ public class InfinispanTestSupport
|
|||
public void teardown() throws Exception
|
||||
{
|
||||
_cache.clear();
|
||||
_manager.removeCache(_name);
|
||||
_manager.administration().removeCache(_name);
|
||||
if (_useFileStore)
|
||||
{
|
||||
if (_tmpdir != null)
|
||||
|
@ -154,6 +167,7 @@ public class InfinispanTestSupport
|
|||
public void createSession(SessionData data)
|
||||
throws Exception
|
||||
{
|
||||
((InfinispanSessionData)data).serializeAttributes();
|
||||
_cache.put(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId(), data);
|
||||
}
|
||||
|
||||
|
@ -171,7 +185,6 @@ public class InfinispanTestSupport
|
|||
public boolean checkSessionPersisted(SessionData data)
|
||||
throws Exception
|
||||
{
|
||||
|
||||
//evicts the object from memory. Forces the cache to fetch the data from file
|
||||
if (_useFileStore)
|
||||
{
|
||||
|
@ -184,6 +197,13 @@ public class InfinispanTestSupport
|
|||
|
||||
SessionData saved = (SessionData)obj;
|
||||
|
||||
if (saved instanceof InfinispanSessionData)
|
||||
{
|
||||
InfinispanSessionData isd = (InfinispanSessionData)saved;
|
||||
if (isd.getSerializedAttributes() != null)
|
||||
isd.deserializeAttributes();
|
||||
}
|
||||
|
||||
//turn an Entity into a Session
|
||||
assertEquals(data.getId(), saved.getId());
|
||||
assertEquals(data.getContextPath(), saved.getContextPath());
|
||||
|
@ -197,6 +217,7 @@ public class InfinispanTestSupport
|
|||
assertEquals(data.getExpiry(), saved.getExpiry());
|
||||
assertEquals(data.getMaxInactiveMs(), saved.getMaxInactiveMs());
|
||||
|
||||
|
||||
//same number of attributes
|
||||
assertEquals(data.getAllAttributes().size(), saved.getAllAttributes().size());
|
||||
//same keys
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
|
|||
import org.infinispan.query.Search;
|
||||
import org.infinispan.query.dsl.Query;
|
||||
import org.infinispan.query.dsl.QueryFactory;
|
||||
import org.infinispan.query.dsl.QueryResult;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -42,6 +43,11 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat
|
|||
|
||||
public WorkDir workDir;
|
||||
|
||||
public SerializedInfinispanSessionDataStoreTest() throws Exception
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception
|
||||
{
|
||||
|
@ -61,6 +67,7 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat
|
|||
{
|
||||
InfinispanSessionDataStoreFactory factory = new InfinispanSessionDataStoreFactory();
|
||||
factory.setCache(_testSupport.getCache());
|
||||
factory.setSerialization(true);
|
||||
QueryManager qm = new EmbeddedQueryManager(_testSupport.getCache());
|
||||
factory.setQueryManager(qm);
|
||||
return factory;
|
||||
|
@ -68,9 +75,18 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat
|
|||
|
||||
@Override
|
||||
public void persistSession(SessionData data) throws Exception
|
||||
{
|
||||
ClassLoader old = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(_contextClassLoader);
|
||||
try
|
||||
{
|
||||
_testSupport.createSession(data);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Thread.currentThread().setContextClassLoader(old);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void persistUnreadableSession(SessionData data) throws Exception
|
||||
|
@ -80,9 +96,18 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat
|
|||
|
||||
@Override
|
||||
public boolean checkSessionExists(SessionData data) throws Exception
|
||||
{
|
||||
ClassLoader old = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(_contextClassLoader);
|
||||
try
|
||||
{
|
||||
return _testSupport.checkSessionExists(data);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Thread.currentThread().setContextClassLoader(old);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This test deliberately sets the infinispan cache to null to
|
||||
|
@ -94,6 +119,7 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -134,14 +160,17 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat
|
|||
{
|
||||
InfinispanSessionData sd1 = new InfinispanSessionData("sd1", "", "", 0, 0, 0, 1000);
|
||||
sd1.setLastNode("fred1");
|
||||
sd1.serializeAttributes();
|
||||
_testSupport.getCache().put("session1", sd1);
|
||||
|
||||
InfinispanSessionData sd2 = new InfinispanSessionData("sd2", "", "", 0, 0, 0, 2000);
|
||||
sd2.setLastNode("fred2");
|
||||
sd2.serializeAttributes();
|
||||
_testSupport.getCache().put("session2", sd2);
|
||||
|
||||
InfinispanSessionData sd3 = new InfinispanSessionData("sd3", "", "", 0, 0, 0, 3000);
|
||||
sd3.setLastNode("fred3");
|
||||
sd3.serializeAttributes();
|
||||
_testSupport.getCache().put("session3", sd3);
|
||||
|
||||
QueryFactory qf = Search.getQueryFactory(_testSupport.getCache());
|
||||
|
@ -149,8 +178,9 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat
|
|||
for (int i = 0; i <= 3; i++)
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
Query q = qf.from(InfinispanSessionData.class).having("expiry").lt(now).build();
|
||||
assertEquals(i, q.list().size());
|
||||
Query<InfinispanSessionData> q = qf.create("from org.eclipse.jetty.session.infinispan.InfinispanSessionData where expiry < " + now);
|
||||
QueryResult<InfinispanSessionData> result = q.execute();
|
||||
assertEquals(i, result.list().size());
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.eclipse.jetty.session.infinispan.RemoteQueryManager;
|
|||
import org.infinispan.client.hotrod.Search;
|
||||
import org.infinispan.query.dsl.Query;
|
||||
import org.infinispan.query.dsl.QueryFactory;
|
||||
import org.infinispan.query.dsl.QueryResult;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -50,6 +51,11 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto
|
|||
|
||||
public static RemoteInfinispanTestSupport __testSupport;
|
||||
|
||||
public RemoteInfinispanSessionDataStoreTest() throws Exception
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception
|
||||
{
|
||||
|
@ -74,9 +80,19 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto
|
|||
|
||||
@Override
|
||||
public void persistSession(SessionData data) throws Exception
|
||||
{
|
||||
ClassLoader old = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(_contextClassLoader);
|
||||
try
|
||||
{
|
||||
__testSupport.createSession((InfinispanSessionData)data);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Thread.currentThread().setContextClassLoader(old);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void persistUnreadableSession(SessionData data) throws Exception
|
||||
|
@ -86,9 +102,18 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto
|
|||
|
||||
@Override
|
||||
public boolean checkSessionExists(SessionData data) throws Exception
|
||||
{
|
||||
ClassLoader old = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(_contextClassLoader);
|
||||
try
|
||||
{
|
||||
return __testSupport.checkSessionExists((InfinispanSessionData)data);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Thread.currentThread().setContextClassLoader(old);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkSessionPersisted(SessionData data) throws Exception
|
||||
|
@ -140,23 +165,29 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto
|
|||
{
|
||||
InfinispanSessionData sd1 = new InfinispanSessionData("sd1", "", "", 0, 0, 0, 1000);
|
||||
sd1.setLastNode("fred1");
|
||||
sd1.serializeAttributes();
|
||||
__testSupport.getCache().put("session1", sd1);
|
||||
|
||||
InfinispanSessionData sd2 = new InfinispanSessionData("sd2", "", "", 0, 0, 0, 2000);
|
||||
sd2.setLastNode("fred2");
|
||||
sd2.serializeAttributes();
|
||||
__testSupport.getCache().put("session2", sd2);
|
||||
|
||||
InfinispanSessionData sd3 = new InfinispanSessionData("sd3", "", "", 0, 0, 0, 3000);
|
||||
sd3.setLastNode("fred3");
|
||||
sd3.serializeAttributes();
|
||||
__testSupport.getCache().put("session3", sd3);
|
||||
|
||||
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++)
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
Query q = qf.from(InfinispanSessionData.class).having("expiry").lt(now).build();
|
||||
assertEquals(i, q.list().size());
|
||||
query.setParameter("time", now);
|
||||
QueryResult<InfinispanSessionData> result = query.execute();
|
||||
assertEquals(i, result.list().size());
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@ import java.lang.annotation.ElementType;
|
|||
import java.util.Properties;
|
||||
|
||||
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.SessionDataMarshaller;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.hibernate.search.cfg.Environment;
|
||||
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.Configuration;
|
||||
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
|
||||
import org.infinispan.client.hotrod.marshall.ProtoStreamMarshaller;
|
||||
import org.infinispan.protostream.FileDescriptorSource;
|
||||
import org.infinispan.protostream.SerializationContext;
|
||||
import org.infinispan.commons.configuration.XMLStringConfiguration;
|
||||
import org.infinispan.commons.marshall.ProtoStreamMarshaller;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
|
@ -62,12 +61,12 @@ public class RemoteInfinispanTestSupport
|
|||
{
|
||||
//Testcontainers.exposeHostPorts(11222);
|
||||
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 =
|
||||
new GenericContainer(System.getProperty("infinispan.docker.image.name", "jboss/infinispan-server") +
|
||||
new GenericContainer(System.getProperty("infinispan.docker.image.name", "infinispan/server") +
|
||||
":" + infinispanVersion)
|
||||
.withEnv("APP_USER", "theuser")
|
||||
.withEnv("APP_PASS", "foobar")
|
||||
.withEnv("USER", "theuser")
|
||||
.withEnv("PASS", "foobar")
|
||||
.withEnv("MGMT_USER", "admin")
|
||||
.withEnv("MGMT_PASS", "admin")
|
||||
.waitingFor(new LogMessageWaitStrategy()
|
||||
|
@ -98,23 +97,16 @@ public class RemoteInfinispanTestSupport
|
|||
if (infinispanVersion.startsWith("1"))
|
||||
{
|
||||
configurationBuilder.security().authentication()
|
||||
.realm("default")
|
||||
.serverName("infinispan")
|
||||
.saslMechanism("DIGEST-MD5")
|
||||
.username("theuser").password("foobar");
|
||||
}
|
||||
|
||||
configurationBuilder.addContextInitializer(new InfinispanSerializationContextInitializer());
|
||||
Configuration configuration = configurationBuilder.build();
|
||||
|
||||
_manager = new RemoteCacheManager(configuration);
|
||||
|
||||
FileDescriptorSource fds = new FileDescriptorSource();
|
||||
fds.addProtoFiles("/session.proto");
|
||||
|
||||
SerializationContext serCtx = ProtoStreamMarshaller.getSerializationContext(_manager);
|
||||
serCtx.registerProtoFiles(fds);
|
||||
serCtx.registerMarshaller(new SessionDataMarshaller());
|
||||
|
||||
//upload the session.proto file to the remote cache
|
||||
ByteArrayOutputStream baos;
|
||||
try (InputStream is = RemoteInfinispanSessionDataStoreTest.class.getClassLoader().getResourceAsStream("session.proto"))
|
||||
{
|
||||
|
@ -155,7 +147,15 @@ public class RemoteInfinispanTestSupport
|
|||
|
||||
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
|
||||
|
@ -166,12 +166,13 @@ public class RemoteInfinispanTestSupport
|
|||
public void createSession(InfinispanSessionData data)
|
||||
throws Exception
|
||||
{
|
||||
data.serializeAttributes();
|
||||
_cache.put(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId(), data);
|
||||
}
|
||||
|
||||
public void createUnreadableSession(InfinispanSessionData data)
|
||||
{
|
||||
|
||||
//Unused by test
|
||||
}
|
||||
|
||||
public boolean checkSessionExists(InfinispanSessionData data)
|
||||
|
@ -188,6 +189,7 @@ public class RemoteInfinispanTestSupport
|
|||
return false;
|
||||
|
||||
InfinispanSessionData saved = (InfinispanSessionData)obj;
|
||||
if (saved.getSerializedAttributes() != null)
|
||||
saved.deserializeAttributes();
|
||||
|
||||
assertEquals(data.getId(), saved.getId());
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Jetty Logging using jetty-slf4j-impl
|
||||
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
|
||||
# org.hibernate.LEVEL=WARN
|
||||
# org.infinispan.LEVEL=DEBUG
|
|
@ -1,3 +1,5 @@
|
|||
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.RemoteInfinispanTestSupport=info
|
||||
#org.slf4j.simpleLogger.log.org.eclipse.jetty.server.session=trace
|
||||
#org.slf4j.simpleLogger.log.org.eclipse.jetty.session.infinispan=trace
|
||||
|
|
|
@ -24,6 +24,11 @@ import org.testcontainers.junit.jupiter.Testcontainers;
|
|||
@Testcontainers(disabledWithoutDocker = true)
|
||||
public class JDBCSessionDataStoreTest extends AbstractSessionDataStoreTest
|
||||
{
|
||||
public JDBCSessionDataStoreTest() throws Exception
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
|
|
|
@ -39,6 +39,11 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|||
@Testcontainers(disabledWithoutDocker = true)
|
||||
public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest
|
||||
{
|
||||
public MongoSessionDataStoreTest() throws Exception
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void beforeEach() throws Exception
|
||||
{
|
||||
|
|
|
@ -57,7 +57,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
public static final long RECENT_TIMESTAMP = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(3 * GRACE_PERIOD_SEC);
|
||||
protected static File extraClasses;
|
||||
|
||||
protected URLClassLoader _contextClassLoader = new URLClassLoader(new URL[]{}, Thread.currentThread().getContextClassLoader());
|
||||
protected URLClassLoader _contextClassLoader;
|
||||
|
||||
public abstract SessionDataStoreFactory createSessionDataStoreFactory();
|
||||
|
||||
|
@ -94,6 +94,13 @@ public abstract class AbstractSessionDataStoreTest
|
|||
File factoryClass = new File(extraClasses, "ProxyableFactory.class");
|
||||
IO.copy(is, new FileOutputStream(factoryClass));
|
||||
is.close();
|
||||
|
||||
}
|
||||
|
||||
public AbstractSessionDataStoreTest() throws Exception
|
||||
{
|
||||
URL[] foodirUrls = new URL[]{extraClasses.toURI().toURL()};
|
||||
_contextClassLoader = new URLClassLoader(foodirUrls, Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -104,10 +111,6 @@ public abstract class AbstractSessionDataStoreTest
|
|||
@Test
|
||||
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
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
|
@ -180,6 +183,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -198,13 +202,15 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//put it into the store
|
||||
persistSession(data);
|
||||
|
||||
assertTrue(checkSessionExists(data));
|
||||
|
||||
//now test we can update the session
|
||||
data.setLastAccessed(now - 1);
|
||||
data.setAccessed(now);
|
||||
data.setMaxInactiveMs(TimeUnit.MINUTES.toMillis(2));
|
||||
data.setAttribute("a", "c");
|
||||
store.store("aaa2", data);
|
||||
|
||||
store.store("aaa2", data);
|
||||
assertTrue(checkSessionPersisted(data));
|
||||
}
|
||||
|
||||
|
@ -215,10 +221,6 @@ public abstract class AbstractSessionDataStoreTest
|
|||
@Test
|
||||
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
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
|
@ -303,6 +305,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -336,6 +339,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -370,6 +374,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -391,6 +396,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -428,6 +434,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -455,6 +462,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -491,6 +499,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -521,6 +530,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -542,6 +552,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -577,6 +588,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -611,6 +623,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -634,6 +647,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -670,6 +684,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -695,6 +710,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -795,6 +811,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -821,6 +838,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -847,6 +865,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -864,6 +883,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
SessionDataStore store = factory.getSessionDataStore(context.getSessionHandler());
|
||||
|
@ -892,6 +912,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
((AbstractSessionDataStoreFactory)factory).setSavePeriodSec(20); //only save every 20sec
|
||||
|
@ -932,6 +953,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
((AbstractSessionDataStoreFactory)factory).setSavePeriodSec(20); //only save every 20sec
|
||||
|
@ -961,6 +983,7 @@ public abstract class AbstractSessionDataStoreTest
|
|||
//create the SessionDataStore
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/test");
|
||||
context.setClassLoader(_contextClassLoader);
|
||||
SessionDataStoreFactory factory = createSessionDataStoreFactory();
|
||||
((AbstractSessionDataStoreFactory)factory).setGracePeriodSec(GRACE_PERIOD_SEC);
|
||||
((AbstractSessionDataStoreFactory)factory).setSavePeriodSec(20); //only save every 20sec
|
||||
|
|
Loading…
Reference in New Issue