diff --git a/javadoc/pom.xml b/javadoc/pom.xml index 8b565fdaf08..2c62408af29 100644 --- a/javadoc/pom.xml +++ b/javadoc/pom.xml @@ -419,6 +419,12 @@ infinispan-core ${infinispan.version} provided + + + org.wildfly.common + wildfly-common + + @@ -431,7 +437,7 @@ org.infinispan.protostream protostream - 4.2.2.Final + ${infinispan.protostream.version} provided diff --git a/jetty-home/pom.xml b/jetty-home/pom.xml index f4bca94018c..0d370408b61 100644 --- a/jetty-home/pom.xml +++ b/jetty-home/pom.xml @@ -746,6 +746,12 @@ ${project.version} pom true + + + org.wildfly.common + * + + org.eclipse.jetty diff --git a/jetty-infinispan/infinispan-common/pom.xml b/jetty-infinispan/infinispan-common/pom.xml index 5ae82c3b0b7..466498b7c0f 100644 --- a/jetty-infinispan/infinispan-common/pom.xml +++ b/jetty-infinispan/infinispan-common/pom.xml @@ -37,8 +37,13 @@ org.infinispan infinispan-core - ${infinispan.version} true + + + org.wildfly.common + wildfly-common + + org.infinispan.protostream @@ -63,13 +68,11 @@ org.infinispan infinispan-client-hotrod - ${infinispan.version} provided org.infinispan infinispan-remote-query-client - ${infinispan.version} provided diff --git a/jetty-infinispan/infinispan-common/src/main/config/etc/sessions/infinispan/infinispan-common.xml b/jetty-infinispan/infinispan-common/src/main/config/etc/sessions/infinispan/infinispan-common.xml index 95ef9c854f1..0092a534815 100644 --- a/jetty-infinispan/infinispan-common/src/main/config/etc/sessions/infinispan/infinispan-common.xml +++ b/jetty-infinispan/infinispan-common/src/main/config/etc/sessions/infinispan/infinispan-common.xml @@ -10,6 +10,7 @@ + diff --git a/jetty-infinispan/infinispan-common/src/main/config/modules/sessions/infinispan/infinispan-common.mod b/jetty-infinispan/infinispan-common/src/main/config/modules/sessions/infinispan/infinispan-common.mod index 02a77867610..d2a400bdbd8 100644 --- a/jetty-infinispan/infinispan-common/src/main/config/modules/sessions/infinispan/infinispan-common.mod +++ b/jetty-infinispan/infinispan-common/src/main/config/modules/sessions/infinispan/infinispan-common.mod @@ -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. diff --git a/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSerializationContextInitializer.java b/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSerializationContextInitializer.java new file mode 100644 index 00000000000..352ac535775 --- /dev/null +++ b/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSerializationContextInitializer.java @@ -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()); + } +} diff --git a/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionData.java b/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionData.java index 614e518bea0..12c80895b9d 100644 --- a/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionData.java +++ b/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionData.java @@ -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; diff --git a/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStore.java b/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStore.java index fa4ddeeed80..823d029d428 100644 --- a/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStore.java +++ b/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStore.java @@ -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. @@ -270,6 +282,11 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore { return _infinispanIdleTimeoutSec; } + + public void setSerialization(boolean serialization) + { + _serialization = serialization; + } @Override public String toString() diff --git a/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStoreFactory.java b/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStoreFactory.java index f16c257d10e..fd3fa839436 100644 --- a/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStoreFactory.java +++ b/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStoreFactory.java @@ -26,6 +26,7 @@ public class InfinispanSessionDataStoreFactory extends AbstractSessionDataStoreF int _infinispanIdleTimeoutSec; BasicCache _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; + } } diff --git a/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/SessionDataMarshaller.java b/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/SessionDataMarshaller.java index 31036998382..7e0941b01e6 100644 --- a/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/SessionDataMarshaller.java +++ b/jetty-infinispan/infinispan-common/src/main/java/org/eclipse/jetty/session/infinispan/SessionDataMarshaller.java @@ -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, Externalizer +public class SessionDataMarshaller implements MessageMarshaller { /** * 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()); } diff --git a/jetty-infinispan/infinispan-embedded-query/pom.xml b/jetty-infinispan/infinispan-embedded-query/pom.xml index 5bf2776ea1e..05a179acdf1 100644 --- a/jetty-infinispan/infinispan-embedded-query/pom.xml +++ b/jetty-infinispan/infinispan-embedded-query/pom.xml @@ -106,7 +106,6 @@ org.infinispan infinispan-query - ${infinispan.version} org.eclipse.jetty.toolchain diff --git a/jetty-infinispan/infinispan-embedded-query/src/main/java/org/eclipse/jetty/session/infinispan/EmbeddedQueryManager.java b/jetty-infinispan/infinispan-embedded-query/src/main/java/org/eclipse/jetty/session/infinispan/EmbeddedQueryManager.java index a91c1208a75..12319d10c0f 100644 --- a/jetty-infinispan/infinispan-embedded-query/src/main/java/org/eclipse/jetty/session/infinispan/EmbeddedQueryManager.java +++ b/jetty-infinispan/infinispan-embedded-query/src/main/java/org/eclipse/jetty/session/infinispan/EmbeddedQueryManager.java @@ -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 _cache; + private QueryFactory _factory; public EmbeddedQueryManager(Cache cache) { _cache = cache; + _factory = Search.getQueryFactory(_cache); } @Override public Set 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 list = q.list(); + Query 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 list = result.list(); Set 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 list = q.list(); + Query 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 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 list = q.list(); + Query 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 list = result.list(); + return !list.isEmpty(); } } diff --git a/jetty-infinispan/infinispan-embedded-query/src/test/java/org/eclipse/jetty/server/session/infinispan/EmbeddedQueryManagerTest.java b/jetty-infinispan/infinispan-embedded-query/src/test/java/org/eclipse/jetty/server/session/infinispan/EmbeddedQueryManagerTest.java index 6d7c9a9c9dc..ab3adf10e88 100644 --- a/jetty-infinispan/infinispan-embedded-query/src/test/java/org/eclipse/jetty/server/session/infinispan/EmbeddedQueryManagerTest.java +++ b/jetty-infinispan/infinispan-embedded-query/src/test/java/org/eclipse/jetty/server/session/infinispan/EmbeddedQueryManagerTest.java @@ -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); diff --git a/jetty-infinispan/infinispan-embedded/pom.xml b/jetty-infinispan/infinispan-embedded/pom.xml index a1a273138f1..4f0483d2678 100644 --- a/jetty-infinispan/infinispan-embedded/pom.xml +++ b/jetty-infinispan/infinispan-embedded/pom.xml @@ -98,7 +98,12 @@ org.infinispan infinispan-core - ${infinispan.version} + + + org.wildfly.common + wildfly-common + + diff --git a/jetty-infinispan/infinispan-embedded/src/main/config-templates/modules/session-store-infinispan-embedded.mod b/jetty-infinispan/infinispan-embedded/src/main/config-templates/modules/session-store-infinispan-embedded.mod index 8466ac5f200..50aefd3227d 100644 --- a/jetty-infinispan/infinispan-embedded/src/main/config-templates/modules/session-store-infinispan-embedded.mod +++ b/jetty-infinispan/infinispan-embedded/src/main/config-templates/modules/session-store-infinispan-embedded.mod @@ -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 diff --git a/jetty-infinispan/infinispan-remote-query/pom.xml b/jetty-infinispan/infinispan-remote-query/pom.xml index 3a7dd4e379b..cc5b3390d64 100644 --- a/jetty-infinispan/infinispan-remote-query/pom.xml +++ b/jetty-infinispan/infinispan-remote-query/pom.xml @@ -9,7 +9,7 @@ Jetty :: Infinispan Session Manager Remote with Querying ${project.groupId}.infinispan.remote.query - 9.4.8.Final + 11.0.9.Final @@ -116,17 +116,24 @@ org.infinispan infinispan-query - ${infinispan.version} org.infinispan infinispan-client-hotrod - ${infinispan.version} org.infinispan infinispan-remote-query-client - ${infinispan.version} + + + com.google.code.gson + gson + ${gson.version} + + + com.google.code.gson + gson + ${gson.version} org.slf4j diff --git a/jetty-infinispan/infinispan-remote-query/src/main/config-template/etc/sessions/infinispan/infinispan-remote-query.xml b/jetty-infinispan/infinispan-remote-query/src/main/config-template/etc/sessions/infinispan/infinispan-remote-query.xml index e8fb728a9a2..6c2c7565c1a 100644 --- a/jetty-infinispan/infinispan-remote-query/src/main/config-template/etc/sessions/infinispan/infinispan-remote-query.xml +++ b/jetty-infinispan/infinispan-remote-query/src/main/config-template/etc/sessions/infinispan/infinispan-remote-query.xml @@ -45,9 +45,14 @@ - + + + + + + @@ -58,33 +63,6 @@ - - - - - - - - - - - - - - /session.proto - - - - - - - - - - - - - diff --git a/jetty-infinispan/infinispan-remote-query/src/main/config-template/modules/infinispan-remote-query.mod b/jetty-infinispan/infinispan-remote-query/src/main/config-template/modules/infinispan-remote-query.mod index a3bf8912052..fef22344cdb 100644 --- a/jetty-infinispan/infinispan-remote-query/src/main/config-template/modules/infinispan-remote-query.mod +++ b/jetty-infinispan/infinispan-remote-query/src/main/config-template/modules/infinispan-remote-query.mod @@ -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 diff --git a/jetty-infinispan/infinispan-remote-query/src/main/config-template/modules/sessions/infinispan/remote/other_proto_marshallers.xml b/jetty-infinispan/infinispan-remote-query/src/main/config-template/modules/sessions/infinispan/remote/other_proto_marshallers.xml deleted file mode 100644 index 479daf8f657..00000000000 --- a/jetty-infinispan/infinispan-remote-query/src/main/config-template/modules/sessions/infinispan/remote/other_proto_marshallers.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/jetty-infinispan/infinispan-remote-query/src/main/java/org/eclipse/jetty/session/infinispan/RemoteQueryManager.java b/jetty-infinispan/infinispan-remote-query/src/main/java/org/eclipse/jetty/session/infinispan/RemoteQueryManager.java index 96c9abcf51a..316ff4aa39f 100644 --- a/jetty-infinispan/infinispan-remote-query/src/main/java/org/eclipse/jetty/session/infinispan/RemoteQueryManager.java +++ b/jetty-infinispan/infinispan-remote-query/src/main/java/org/eclipse/jetty/session/infinispan/RemoteQueryManager.java @@ -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 _cache; + private QueryFactory _factory; public RemoteQueryManager(RemoteCache cache) { _cache = cache; + _factory = Search.getQueryFactory(_cache); } @Override public Set 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 list = q.list(); + Query 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 list = result.list(); Set 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 list = q.list(); + Query 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 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 list = q.list(); + Query 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 list = result.list(); return !list.isEmpty(); } } diff --git a/jetty-infinispan/infinispan-remote-query/src/test/java/org/eclipse/jetty/server/session/infinispan/RemoteQueryManagerTest.java b/jetty-infinispan/infinispan-remote-query/src/test/java/org/eclipse/jetty/server/session/infinispan/RemoteQueryManagerTest.java index bb8a3127cad..7c9783d96da 100644 --- a/jetty-infinispan/infinispan-remote-query/src/test/java/org/eclipse/jetty/server/session/infinispan/RemoteQueryManagerTest.java +++ b/jetty-infinispan/infinispan-remote-query/src/test/java/org/eclipse/jetty/server/session/infinispan/RemoteQueryManagerTest.java @@ -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() - .host(this.host).port(this.port) - .clientIntelligence(ClientIntelligence.BASIC) - .marshaller(new ProtoStreamMarshaller()); + clientBuilder.withProperties(properties) + .addServer() + .host(this.host).port(this.port) + .clientIntelligence(ClientIntelligence.BASIC) + .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 cache = remoteCacheManager.getCache(DEFAULT_CACHE_NAME); + + //make the remote cache encoded with protostream + String xml = String.format("" + + "" + "" + + "" + + "" + + "" + + "", DEFAULT_CACHE_NAME); + XMLStringConfiguration xmlConfig = new XMLStringConfiguration(xml); + RemoteCache 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 createSessions(RemoteCache cache, SessionContext sessionContext) + private Set createSessions(RemoteCache cache, SessionContext sessionContext) throws Exception { Set 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); diff --git a/jetty-infinispan/infinispan-remote/pom.xml b/jetty-infinispan/infinispan-remote/pom.xml index 4eaa7a39fb9..4517b87bcf2 100644 --- a/jetty-infinispan/infinispan-remote/pom.xml +++ b/jetty-infinispan/infinispan-remote/pom.xml @@ -99,13 +99,11 @@ org.infinispan infinispan-client-hotrod - ${infinispan.version} provided org.infinispan infinispan-remote-query-client - ${infinispan.version} provided diff --git a/jetty-infinispan/infinispan-remote/src/main/config-template/etc/sessions/infinispan/infinispan-remote.xml b/jetty-infinispan/infinispan-remote/src/main/config-template/etc/sessions/infinispan/infinispan-remote.xml index ebce2c69276..f9525cddd30 100644 --- a/jetty-infinispan/infinispan-remote/src/main/config-template/etc/sessions/infinispan/infinispan-remote.xml +++ b/jetty-infinispan/infinispan-remote/src/main/config-template/etc/sessions/infinispan/infinispan-remote.xml @@ -25,7 +25,12 @@ - + + + + + + @@ -38,35 +43,6 @@ - - - - - - - - - - - - - - - /session.proto - - - - - - - - - - - - - - diff --git a/jetty-infinispan/infinispan-remote/src/main/config-template/modules/session-store-infinispan-remote.mod b/jetty-infinispan/infinispan-remote/src/main/config-template/modules/session-store-infinispan-remote.mod index cfa1a035495..00ab7bf01ba 100644 --- a/jetty-infinispan/infinispan-remote/src/main/config-template/modules/session-store-infinispan-remote.mod +++ b/jetty-infinispan/infinispan-remote/src/main/config-template/modules/session-store-infinispan-remote.mod @@ -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 diff --git a/jetty-infinispan/infinispan-remote/src/main/config-template/modules/sessions/infinispan/remote/resources/hotrod-client.properties b/jetty-infinispan/infinispan-remote/src/main/config-template/modules/sessions/infinispan/remote/resources/hotrod-client.properties index bb774cd9c52..44edf0748fe 100644 --- a/jetty-infinispan/infinispan-remote/src/main/config-template/modules/sessions/infinispan/remote/resources/hotrod-client.properties +++ b/jetty-infinispan/infinispan-remote/src/main/config-template/modules/sessions/infinispan/remote/resources/hotrod-client.properties @@ -1 +1,2 @@ #infinispan.client.hotrod.server_list +#infinispan.client.hotrod.context-initializers= diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java index 563de9534cf..2c73ff993c8 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java @@ -144,6 +144,7 @@ public class HttpConfiguration implements Dumpable _responseCookieCompliance = config._responseCookieCompliance; _notifyRemoteAsyncErrors = config._notifyRemoteAsyncErrors; _relativeRedirectAllowed = config._relativeRedirectAllowed; + _uriCompliance = config._uriCompliance; } /** diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionData.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionData.java index bec23bf35db..1c84284f934 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionData.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionData.java @@ -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? @@ -104,7 +105,7 @@ public class SessionData implements Serializable isContextLoader = false; //TCCL can't see the class } } - + if (LOG.isDebugEnabled()) LOG.debug("Attribute {} class={} isServerLoader={}", entry.getKey(), clazz.getName(), (!isContextLoader)); out.writeBoolean(!isContextLoader); @@ -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); } diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClassMatcher.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClassMatcher.java index 3fe7d932b60..b726815968d 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClassMatcher.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClassMatcher.java @@ -496,6 +496,7 @@ public class ClassMatcher extends AbstractSet { } + @SuppressWarnings("CopyConstructorMissesField") public ClassMatcher(ClassMatcher patterns) { if (patterns != null) @@ -676,7 +677,7 @@ public class ClassMatcher extends AbstractSet */ public String[] getPatterns() { - return toArray(new String[_entries.size()]); + return toArray(new String[0]); } /** diff --git a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClassMatcherTest.java b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClassMatcherTest.java index 726234bf452..f618d1baeab 100644 --- a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClassMatcherTest.java +++ b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClassMatcherTest.java @@ -27,6 +27,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -119,6 +120,13 @@ public class ClassMatcherTest assertTrue(_pattern.match("org.example.Anything$Else")); } + @Test + public void testCopy() + { + ClassMatcher copy = new ClassMatcher(_pattern); + assertThat(copy.toString(), is(_pattern.toString())); + } + @Test public void testMatchFundamentalExcludeSpecific() { @@ -145,9 +153,9 @@ public class ClassMatcherTest ClassMatcher pattern = new ClassMatcher(); pattern.include("something"); - assertThat(pattern.match(String.class), Matchers.is(false)); - assertThat(pattern.match(Test.class), Matchers.is(false)); - assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(false)); + assertThat(pattern.match(String.class), is(false)); + assertThat(pattern.match(Test.class), is(false)); + assertThat(pattern.match(ClassMatcherTest.class), is(false)); // Add directory for both JVM classes pattern.include(locString.toASCIIString()); @@ -155,14 +163,14 @@ public class ClassMatcherTest // Add jar for individual class and classes directory pattern.include(locJunit.toString(), locTest.toString()); - assertThat(pattern.match(String.class), Matchers.is(true)); - assertThat(pattern.match(Test.class), Matchers.is(true)); - assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(true)); + assertThat(pattern.match(String.class), is(true)); + assertThat(pattern.match(Test.class), is(true)); + assertThat(pattern.match(ClassMatcherTest.class), is(true)); pattern.add("-java.lang.String"); - assertThat(pattern.match(String.class), Matchers.is(false)); - assertThat(pattern.match(Test.class), Matchers.is(true)); - assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(true)); + assertThat(pattern.match(String.class), is(false)); + assertThat(pattern.match(Test.class), is(true)); + assertThat(pattern.match(ClassMatcherTest.class), is(true)); } @SuppressWarnings("restriction") @@ -183,9 +191,9 @@ public class ClassMatcherTest ClassMatcher pattern = new ClassMatcher(); pattern.include("something"); - assertThat(pattern.match(String.class), Matchers.is(false)); - assertThat(pattern.match(Test.class), Matchers.is(false)); - assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(false)); + assertThat(pattern.match(String.class), is(false)); + assertThat(pattern.match(Test.class), is(false)); + assertThat(pattern.match(ClassMatcherTest.class), is(false)); // Add module for all JVM base classes pattern.include("jrt:/java.base"); @@ -193,14 +201,14 @@ public class ClassMatcherTest // Add jar for individual class and classes directory pattern.include(locJunit.toString(), locTest.toString()); - assertThat(pattern.match(String.class), Matchers.is(true)); - assertThat(pattern.match(Test.class), Matchers.is(true)); - assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(true)); + assertThat(pattern.match(String.class), is(true)); + assertThat(pattern.match(Test.class), is(true)); + assertThat(pattern.match(ClassMatcherTest.class), is(true)); pattern.add("-java.lang.String"); - assertThat(pattern.match(String.class), Matchers.is(false)); - assertThat(pattern.match(Test.class), Matchers.is(true)); - assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(true)); + assertThat(pattern.match(String.class), is(false)); + assertThat(pattern.match(Test.class), is(true)); + assertThat(pattern.match(ClassMatcherTest.class), is(true)); } @SuppressWarnings("restriction") @@ -224,9 +232,9 @@ public class ClassMatcherTest // include everything pattern.include("."); - assertThat(pattern.match(String.class), Matchers.is(true)); - assertThat(pattern.match(Test.class), Matchers.is(true)); - assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(true)); + assertThat(pattern.match(String.class), is(true)); + assertThat(pattern.match(Test.class), is(true)); + assertThat(pattern.match(ClassMatcherTest.class), is(true)); // Add directory for both JVM classes pattern.exclude("jrt:/java.base/"); @@ -234,9 +242,9 @@ public class ClassMatcherTest // Add jar for individual class and classes directory pattern.exclude(locJunit.toString(), locTest.toString()); - assertThat(pattern.match(String.class), Matchers.is(false)); - assertThat(pattern.match(Test.class), Matchers.is(false)); - assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(false)); + assertThat(pattern.match(String.class), is(false)); + assertThat(pattern.match(Test.class), is(false)); + assertThat(pattern.match(ClassMatcherTest.class), is(false)); } @Test @@ -248,33 +256,33 @@ public class ClassMatcherTest IncludeExcludeSet locations = new IncludeExcludeSet<>(ByLocationOrModule.class); //Test no name or location includes or excludes - should match - assertThat(ClassMatcher.combine(names, "a.b.c", locations, NULL_SUPPLIER), Matchers.is(true)); + assertThat(ClassMatcher.combine(names, "a.b.c", locations, NULL_SUPPLIER), is(true)); names.include(matcher.newEntry("a.b.", true)); names.exclude(matcher.newEntry("d.e.", false)); //Test explicit include by name no locations - should match - assertThat(ClassMatcher.combine(names, "a.b.c", locations, NULL_SUPPLIER), Matchers.is(true)); + assertThat(ClassMatcher.combine(names, "a.b.c", locations, NULL_SUPPLIER), is(true)); //Test explicit exclude by name no locations - should not match - assertThat(ClassMatcher.combine(names, "d.e.f", locations, NULL_SUPPLIER), Matchers.is(false)); + assertThat(ClassMatcher.combine(names, "d.e.f", locations, NULL_SUPPLIER), is(false)); //Test include by name with location includes - should match locations.include(matcher.newEntry("file:/foo/bar", true)); - assertThat(ClassMatcher.combine(names, "a.b.c", locations, NULL_SUPPLIER), Matchers.is(true)); + assertThat(ClassMatcher.combine(names, "a.b.c", locations, NULL_SUPPLIER), is(true)); //Test include by name but with location exclusions - should not match locations.clear(); locations.exclude(matcher.newEntry("file:/high/low", false)); - assertThat(ClassMatcher.combine(names, "a.b.c", locations, NULL_SUPPLIER), Matchers.is(false)); + assertThat(ClassMatcher.combine(names, "a.b.c", locations, NULL_SUPPLIER), is(false)); //Test neither included or excluded by name, but with location exclusions - should not match - assertThat(ClassMatcher.combine(names, "g.b.r", locations, NULL_SUPPLIER), Matchers.is(false)); + assertThat(ClassMatcher.combine(names, "g.b.r", locations, NULL_SUPPLIER), is(false)); //Test neither included nor excluded by name, but with location inclusions - should not match locations.clear(); locations.include(matcher.newEntry("file:/foo/bar", true)); - assertThat(ClassMatcher.combine(names, "g.b.r", locations, NULL_SUPPLIER), Matchers.is(false)); + assertThat(ClassMatcher.combine(names, "g.b.r", locations, NULL_SUPPLIER), is(false)); } @Test diff --git a/pom.xml b/pom.xml index def461e2017..5d1218d0f2e 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ 2.0.0 2.0.0 2.0.0 - 9.4.8.Final + 11.0.11.Final 4.3.4.Final 2.8.8 1.40.1 @@ -47,6 +47,11 @@ 9.2 1.33 benchmarks + 0.10.2 + 0.32.9 + 2.2.7 + 3.1.10 + 0.38.11 5.8.0 3.8.2 1.7.2 @@ -1286,6 +1291,39 @@ biz.aQute.bndlib 5.3.0 + + org.infinispan + infinispan-bom + ${infinispan.version} + pom + import + + + + org.jboss.logging + jboss-logging + ${jboss.logging.version} + + + org.jboss.logging + jboss-logging-processor + 2.2.1.Final + + + org.jboss.logging + jboss-logging-annotations + 2.2.1.Final + + + org.jboss.logmanager + jboss-logmanager + 2.1.15.Final + + + org.jboss.threads + jboss-threads + 3.1.0.Final + org.eclipse.jetty.toolchain @@ -1323,11 +1361,6 @@ ${slf4j.version} test - - org.jboss.logging - jboss-logging - ${jboss.logging.version} - org.asciidoctor asciidoctor-maven-plugin @@ -1341,22 +1374,27 @@ com.github.jnr jnr-constants - 0.10.2 + ${jnr-constants.version} com.github.jnr jnr-enxio - 0.32.8 + ${jnr-enxio.version} + + + com.github.jnr + jnr-ffi + ${jnr-ffi.version} com.github.jnr jnr-posix - 3.1.9 + ${jnr-posix.version} com.github.jnr jnr-unixsocket - 0.38.10 + ${jnr-unixsocket.version} diff --git a/tests/test-cdi/pom.xml b/tests/test-cdi/pom.xml index e85852b1760..060aab86fe9 100644 --- a/tests/test-cdi/pom.xml +++ b/tests/test-cdi/pom.xml @@ -42,6 +42,12 @@ weld-servlet-core ${weld.version} test + + + io.undertow + * + + org.jboss.logging diff --git a/tests/test-distribution/pom.xml b/tests/test-distribution/pom.xml index 0e87ac03090..8ae9dbf54e2 100644 --- a/tests/test-distribution/pom.xml +++ b/tests/test-distribution/pom.xml @@ -217,6 +217,7 @@ $(distribution.debug.port} ${home.start.timeout} ${mariadb.version} + ${sessionLogLevel} diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/AbstractSessionDistributionTests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/AbstractSessionDistributionTests.java index 59492c8e12a..dc165ae2157 100644 --- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/AbstractSessionDistributionTests.java +++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/AbstractSessionDistributionTests.java @@ -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; @@ -85,7 +86,10 @@ public abstract class AbstractSessionDistributionTests extends AbstractJettyHome args = new ArrayList<>(Collections.singletonList("jetty.http.port=" + port)); 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; + } diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/FileSessionDistributionTests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/FileSessionDistributionTests.java index 614b89a5e47..8d7d8e86f77 100644 --- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/FileSessionDistributionTests.java +++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/FileSessionDistributionTests.java @@ -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,7 +25,12 @@ 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 { diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/FileSessionWithMemcacheDistributionTests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/FileSessionWithMemcacheDistributionTests.java index 63e4b8616fd..c329a833b26 100644 --- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/FileSessionWithMemcacheDistributionTests.java +++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/FileSessionWithMemcacheDistributionTests.java @@ -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; @@ -50,7 +51,13 @@ public class FileSessionWithMemcacheDistributionTests extends AbstractSessionDis this.port = memcached.getMappedPort(11211); super.prepareJettyHomeTester(); } - + + @Override + public void configureExternalSessionStorage(Path jettyBase) throws Exception + { + // no op + } + @Override public void startExternalSessionStorage() throws Exception { diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/GCloudSessionDistributionTests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/GCloudSessionDistributionTests.java index a7c4b1117a7..736c9cb274d 100644 --- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/GCloudSessionDistributionTests.java +++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/GCloudSessionDistributionTests.java @@ -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; @@ -83,6 +84,12 @@ public class GCloudSessionDistributionTests extends AbstractSessionDistributionT { emulator.stop(); } + + @Override + public void configureExternalSessionStorage(Path jettyBase) throws Exception + { + // no op + } @Override public List getFirstStartExtraArgs() diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/HazelcastSessionDistributionTests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/HazelcastSessionDistributionTests.java index 7e541697e2d..f9ef069f090 100644 --- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/HazelcastSessionDistributionTests.java +++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/HazelcastSessionDistributionTests.java @@ -91,6 +91,12 @@ public class HazelcastSessionDistributionTests extends AbstractSessionDistributi hazelcast.stop(); } + @Override + public void configureExternalSessionStorage(Path jettyBase) throws Exception + { + // no op + } + @Override public List getFirstStartExtraArgs() { diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/InfinispanSessionDistributionTests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/InfinispanSessionDistributionTests.java index 33b46b7f482..12c574e90e7 100644 --- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/InfinispanSessionDistributionTests.java +++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/InfinispanSessionDistributionTests.java @@ -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("" + + "" + "" + + "" + + "" + + "" + + "", "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(); + } + } } diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/JDBCSessionDistributionTests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/JDBCSessionDistributionTests.java index 580a34317c3..876ce1ad5c8 100644 --- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/JDBCSessionDistributionTests.java +++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/JDBCSessionDistributionTests.java @@ -77,6 +77,12 @@ public class JDBCSessionDistributionTests extends AbstractSessionDistributionTes { mariaDBContainer.stop(); } + + @Override + public void configureExternalSessionStorage(Path jettyBase) throws Exception + { + // no op + } @Override public List getFirstStartExtraArgs() diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/MongodbSessionDistributionTests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/MongodbSessionDistributionTests.java index 56a0a6d32df..4d8f2e56b77 100644 --- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/MongodbSessionDistributionTests.java +++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/session/MongodbSessionDistributionTests.java @@ -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 getFirstStartExtraArgs() { diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/FileSessionDataStoreTest.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/FileSessionDataStoreTest.java index 2f2f450f398..2a0e31760ca 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/FileSessionDataStoreTest.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/FileSessionDataStoreTest.java @@ -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; diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStoreTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStoreTest.java index c9421d7047c..8265dea46c3 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStoreTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStoreTest.java @@ -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 diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/HazelcastSessionDataStoreTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/HazelcastSessionDataStoreTest.java index de7bbd838fb..4baad73ff03 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/HazelcastSessionDataStoreTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/HazelcastSessionDataStoreTest.java @@ -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 diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/HazelcastSessionDataStoreTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/HazelcastSessionDataStoreTest.java index 47154c8cc33..6cd17a4ade0 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/HazelcastSessionDataStoreTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/HazelcastSessionDataStoreTest.java @@ -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 diff --git a/tests/test-sessions/test-infinispan-sessions/pom.xml b/tests/test-sessions/test-infinispan-sessions/pom.xml index 8940008a120..55d9cfea528 100644 --- a/tests/test-sessions/test-infinispan-sessions/pom.xml +++ b/tests/test-sessions/test-infinispan-sessions/pom.xml @@ -11,9 +11,9 @@ ${project.groupId}.sessions.infinispan - ${infinispan.version} + 11.0.9.Final - jboss/infinispan-server + infinispan/server @@ -120,6 +120,12 @@ infinispan-core ${infinispan.version} test + + + org.wildfly.common + wildfly-common + + org.infinispan diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ClusteredSerializedSessionScavengingTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ClusteredSerializedSessionScavengingTest.java index d81ac397d41..2879758870b 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ClusteredSerializedSessionScavengingTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ClusteredSerializedSessionScavengingTest.java @@ -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; } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ClusteredSessionScavengingTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ClusteredSessionScavengingTest.java index ffd1834373c..66a5d851a5e 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ClusteredSessionScavengingTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ClusteredSessionScavengingTest.java @@ -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; } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanFileSessionDataStoreTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanFileSessionDataStoreTest.java index 1ec2e399d12..77513b3a4f0 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanFileSessionDataStoreTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanFileSessionDataStoreTest.java @@ -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; + } } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanSessionDataStoreTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanSessionDataStoreTest.java index 1d47703663d..b0e3c4268bd 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanSessionDataStoreTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanSessionDataStoreTest.java @@ -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; @@ -46,7 +47,12 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest public InfinispanTestSupport _testSupport; public WorkDir workDir; - + + public InfinispanSessionDataStoreTest() throws Exception + { + super(); + } + @BeforeEach public void setup() throws Exception { @@ -73,7 +79,16 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest @Override public void persistSession(SessionData data) throws Exception { - _testSupport.createSession(data); + ClassLoader old = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(_contextClassLoader); + try + { + _testSupport.createSession(data); + } + finally + { + Thread.currentThread().setContextClassLoader(old); + } } @Override @@ -85,7 +100,16 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest @Override public boolean checkSessionExists(SessionData data) throws Exception { - return _testSupport.checkSessionExists(data); + ClassLoader old = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(_contextClassLoader); + try + { + return _testSupport.checkSessionExists(data); + } + finally + { + Thread.currentThread().setContextClassLoader(old); + } } /** @@ -98,6 +122,7 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest //create the SessionDataStore 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 q = qf.create("from org.eclipse.jetty.session.infinispan.InfinispanSessionData where expiry < " + now); + QueryResult result = q.execute(); + assertEquals(i, result.list().size()); Thread.sleep(1000); } } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanTestSupport.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanTestSupport.java index e6d3ae4475b..2930f5821b6 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanTestSupport.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanTestSupport.java @@ -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,18 +185,24 @@ 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) { _cache.evict(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()); } - + Object obj = _cache.get(data.getContextPath() + "_" + data.getVhost() + "_" + data.getId()); if (obj == null) return false; 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()); @@ -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 diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SerializedInfinispanSessionDataStoreTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SerializedInfinispanSessionDataStoreTest.java index 8165ddc567a..ea8dbecec0e 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SerializedInfinispanSessionDataStoreTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SerializedInfinispanSessionDataStoreTest.java @@ -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; @@ -69,7 +76,16 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat @Override public void persistSession(SessionData data) throws Exception { - _testSupport.createSession(data); + ClassLoader old = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(_contextClassLoader); + try + { + _testSupport.createSession(data); + } + finally + { + Thread.currentThread().setContextClassLoader(old); + } } @Override @@ -81,7 +97,16 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat @Override public boolean checkSessionExists(SessionData data) throws Exception { - return _testSupport.checkSessionExists(data); + ClassLoader old = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(_contextClassLoader); + try + { + return _testSupport.checkSessionExists(data); + } + finally + { + Thread.currentThread().setContextClassLoader(old); + } } /** @@ -94,6 +119,7 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat //create the SessionDataStore 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 q = qf.create("from org.eclipse.jetty.session.infinispan.InfinispanSessionData where expiry < " + now); + QueryResult result = q.execute(); + assertEquals(i, result.list().size()); Thread.sleep(1000); } } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteInfinispanSessionDataStoreTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteInfinispanSessionDataStoreTest.java index 636a94e53c5..9780b5eb9bf 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteInfinispanSessionDataStoreTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteInfinispanSessionDataStoreTest.java @@ -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 { @@ -75,7 +81,17 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto @Override public void persistSession(SessionData data) throws Exception { - __testSupport.createSession((InfinispanSessionData)data); + ClassLoader old = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(_contextClassLoader); + try + { + __testSupport.createSession((InfinispanSessionData)data); + } + finally + { + Thread.currentThread().setContextClassLoader(old); + } + } @Override @@ -87,7 +103,16 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto @Override public boolean checkSessionExists(SessionData data) throws Exception { - return __testSupport.checkSessionExists((InfinispanSessionData)data); + ClassLoader old = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(_contextClassLoader); + try + { + return __testSupport.checkSessionExists((InfinispanSessionData)data); + } + finally + { + Thread.currentThread().setContextClassLoader(old); + } } @Override @@ -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 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 result = query.execute(); + assertEquals(i, result.list().size()); Thread.sleep(1000); } } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteInfinispanTestSupport.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteInfinispanTestSupport.java index e833d970c31..7638eb552aa 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteInfinispanTestSupport.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteInfinispanTestSupport.java @@ -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,18 +61,18 @@ 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("MGMT_USER", "admin") - .withEnv("MGMT_PASS", "admin") - .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)); + .withEnv("USER", "theuser") + .withEnv("PASS", "foobar") + .withEnv("MGMT_USER", "admin") + .withEnv("MGMT_PASS", "admin") + .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(); System.setProperty("hotrod.host", host); @@ -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("" + + "" + "" + + "" + + "" + + "" + + "", _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,7 +189,8 @@ public class RemoteInfinispanTestSupport return false; InfinispanSessionData saved = (InfinispanSessionData)obj; - saved.deserializeAttributes(); + if (saved.getSerializedAttributes() != null) + saved.deserializeAttributes(); assertEquals(data.getId(), saved.getId()); assertEquals(data.getContextPath(), saved.getContextPath()); diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/resources/jetty-logging.properties b/tests/test-sessions/test-infinispan-sessions/src/test/resources/jetty-logging.properties index a5e96346170..4d20310ac04 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/resources/jetty-logging.properties +++ b/tests/test-sessions/test-infinispan-sessions/src/test/resources/jetty-logging.properties @@ -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 \ No newline at end of file diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/resources/simplelogger.properties b/tests/test-sessions/test-infinispan-sessions/src/test/resources/simplelogger.properties index cc6528beeee..e0718a50a56 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/resources/simplelogger.properties +++ b/tests/test-sessions/test-infinispan-sessions/src/test/resources/simplelogger.properties @@ -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 diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/JDBCSessionDataStoreTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/JDBCSessionDataStoreTest.java index 0a40aff8210..df03904f916 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/JDBCSessionDataStoreTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/JDBCSessionDataStoreTest.java @@ -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 { diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStoreTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStoreTest.java index aa92c3e84bf..fbeeb6a9b35 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStoreTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStoreTest.java @@ -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 { diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionDataStoreTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionDataStoreTest.java index f9556e36e09..d9c9b749475 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionDataStoreTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionDataStoreTest.java @@ -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,8 +94,15 @@ 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()); + } + /** * Test that the store can persist a session. The session uses an attribute * class that is only known to the webapp classloader. This tests that @@ -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()); @@ -197,14 +201,16 @@ 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); - 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