Add integration tests covering various Serialization use cases.
Resolves Issue #2.
This commit is contained in:
@@ -16,14 +16,15 @@
|
||||
|
||||
package org.springframework.session.data.gemfire;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -31,7 +32,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.DataSerializer;
|
||||
import org.apache.geode.cache.CacheClosedException;
|
||||
import org.apache.geode.cache.DataPolicy;
|
||||
import org.apache.geode.cache.ExpirationAction;
|
||||
@@ -42,6 +43,7 @@ import org.apache.geode.cache.client.ClientCache;
|
||||
import org.apache.geode.cache.client.ClientCacheFactory;
|
||||
import org.apache.geode.cache.query.Index;
|
||||
import org.apache.geode.cache.server.CacheServer;
|
||||
import org.apache.geode.internal.InternalDataSerializer;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
@@ -55,13 +57,15 @@ import org.springframework.session.events.AbstractSessionEvent;
|
||||
*
|
||||
* @author John Blum
|
||||
* @since 1.1.0
|
||||
* @see org.apache.geode.cache.Cache
|
||||
* @see org.apache.geode.DataSerializer
|
||||
* @see org.apache.geode.cache.DataPolicy
|
||||
* @see org.apache.geode.cache.ExpirationAttributes
|
||||
* @see org.apache.geode.cache.GemFireCache
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.apache.geode.cache.client.ClientCache
|
||||
* @see org.apache.geode.cache.query.Index
|
||||
* @see org.apache.geode.cache.server.CacheServer
|
||||
* @see org.apache.geode.internal.InternalDataSerializer
|
||||
* @see org.springframework.session.Session
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@@ -86,10 +90,10 @@ public abstract class AbstractGemFireIntegrationTests {
|
||||
protected static final String GEMFIRE_LOG_LEVEL =
|
||||
System.getProperty("spring.session.data.gemfire.log-level", "error");
|
||||
|
||||
@Autowired
|
||||
protected Cache gemfireCache;
|
||||
@Autowired(required = false)
|
||||
protected GemFireCache gemfireCache;
|
||||
|
||||
@Autowired
|
||||
@Autowired(required = false)
|
||||
protected GemFireOperationsSessionRepository gemfireSessionRepository;
|
||||
|
||||
@Before
|
||||
@@ -138,12 +142,12 @@ public abstract class AbstractGemFireIntegrationTests {
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected static List<String> extractJvmArguments(String... args) {
|
||||
return Arrays.stream(args).filter(arg -> arg.startsWith("-")).collect(Collectors.toList());
|
||||
return stream(args).filter(arg -> arg.startsWith("-")).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected static List<String> extractProgramArguments(String... args) {
|
||||
return Arrays.stream(args).filter(arg -> !arg.startsWith("-")).collect(Collectors.toList());
|
||||
return stream(args).filter(arg -> !arg.startsWith("-")).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@@ -151,6 +155,12 @@ public abstract class AbstractGemFireIntegrationTests {
|
||||
return new ProcessBuilder().command(createJavaProcessCommandLine(type, args)).directory(directory).start();
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected static void unregisterAllDataSerializers() {
|
||||
stream(nullSafeArray(InternalDataSerializer.getSerializers(), DataSerializer.class))
|
||||
.map(DataSerializer::getId).forEach(InternalDataSerializer::unregister);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected static boolean waitForCacheServerToStart(CacheServer cacheServer) {
|
||||
return waitForCacheServerToStart(cacheServer, DEFAULT_WAIT_DURATION);
|
||||
|
||||
@@ -123,6 +123,7 @@ public class ClientServerHttpSessionAttributesDeltaIntegrationTests extends Abst
|
||||
FileSystemUtils.deleteRecursively(processWorkingDirectory);
|
||||
}
|
||||
|
||||
unregisterAllDataSerializers();
|
||||
assertThat(waitForClientCacheToClose(DEFAULT_WAIT_DURATION)).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.session.data.gemfire.serialization;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
import org.apache.geode.pdx.PdxSerializer;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.gemfire.config.annotation.ClientCacheApplication;
|
||||
import org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer;
|
||||
import org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration;
|
||||
import org.springframework.session.data.gemfire.serialization.pdx.support.ComposablePdxSerializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration tests to assert that any user-configured {@link PdxSerializer} is composed with
|
||||
* Spring Session Data GemFire's Session-based {@link PdxSerializer}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.GemFireCache
|
||||
* @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication
|
||||
* @see org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer
|
||||
* @see org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration
|
||||
* @see org.springframework.session.data.gemfire.serialization.pdx.support.ComposablePdxSerializer
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("unused")
|
||||
public class CompositePdxSerializerConfigurationIntegrationTests extends AbstractGemFireIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private GemFireCache gemfireCache;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("mockPdxSerializer")
|
||||
private PdxSerializer mockPdxSerializer;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(GemFireHttpSessionConfiguration.SESSION_SERIALIZER_BEAN_ALIAS)
|
||||
private SessionSerializer configuredSessionSerializer;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(GemFireHttpSessionConfiguration.SESSION_PDX_SERIALIZER_BEAN_NAME)
|
||||
private SessionSerializer pdxSerializableSessionSerializer;
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
unregisterAllDataSerializers();
|
||||
assertThat(waitForClientCacheToClose(DEFAULT_WAIT_DURATION)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gemfireCachePdxSerializerIsACompositePdxSerializer() {
|
||||
|
||||
PdxSerializer pdxSerializer = this.gemfireCache.getPdxSerializer();
|
||||
|
||||
assertThat(pdxSerializer).isInstanceOf(ComposablePdxSerializer.class);
|
||||
assertThat(((ComposablePdxSerializer) pdxSerializer))
|
||||
.containsExactly((PdxSerializer) this.pdxSerializableSessionSerializer, this.mockPdxSerializer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configuredSessionSerializerIsSetToPdxSerializableSessionSerializer() {
|
||||
assertThat(this.configuredSessionSerializer).isSameAs(this.pdxSerializableSessionSerializer);
|
||||
}
|
||||
|
||||
@ClientCacheApplication(name = "CompositePdxSerializerConfigurationIntegrationTests", logLevel = "warning")
|
||||
@EnableGemFireHttpSession(clientRegionShortcut = ClientRegionShortcut.LOCAL, poolName = "DEFAULT")
|
||||
@SuppressWarnings("all")
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
ClientCacheConfigurer clientCachePdxSerializerConfigurer(@Qualifier("mockPdxSerializer") PdxSerializer pdxSerializer) {
|
||||
return (beanName, clientCacheFactoryBean) -> clientCacheFactoryBean.setPdxSerializer(pdxSerializer);
|
||||
}
|
||||
|
||||
@Bean
|
||||
PdxSerializer mockPdxSerializer() {
|
||||
return mock(PdxSerializer.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.session.data.gemfire.serialization;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.gemfire.config.annotation.ClientCacheApplication;
|
||||
import org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration tests to assert that GemFire/Geode's Data Serialization framework is configured and applied properly.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.DataSerializer
|
||||
* @see org.apache.geode.cache.GemFireCache
|
||||
* @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication
|
||||
* @see org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("unused")
|
||||
public class DataSerializationConfigurationIntegrationTests extends AbstractGemFireIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
@Qualifier(GemFireHttpSessionConfiguration.SESSION_SERIALIZER_BEAN_ALIAS)
|
||||
private SessionSerializer configuredSessionSerializer;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(GemFireHttpSessionConfiguration.SESSION_DATA_SERIALIZER_BEAN_NAME)
|
||||
private SessionSerializer dataSerializableSessionSerialzer;
|
||||
|
||||
@Autowired
|
||||
private GemFireCache gemfireCache;
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
unregisterAllDataSerializers();
|
||||
assertThat(waitForClientCacheToClose(DEFAULT_WAIT_DURATION)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gemfireCachePdxSerializerIsNull() {
|
||||
assertThat(this.gemfireCache.getPdxSerializer()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configuredSessionSerializerIsSetToDataSerializableSessionSerializer() {
|
||||
assertThat(this.configuredSessionSerializer).isSameAs(this.dataSerializableSessionSerialzer);
|
||||
|
||||
}
|
||||
|
||||
@ClientCacheApplication(name = "DataSerializationConfigurationIntegrationTests", logLevel = "warning")
|
||||
@EnableGemFireHttpSession(clientRegionShortcut = ClientRegionShortcut.LOCAL, poolName = "DEFAULT",
|
||||
sessionSerializerBeanName = GemFireHttpSessionConfiguration.SESSION_DATA_SERIALIZER_BEAN_NAME)
|
||||
static class TestConfiguration {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.session.data.gemfire.serialization;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.gemfire.config.annotation.ClientCacheApplication;
|
||||
import org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration tests to assert that GemFire/Geode's PDX Serialization framework is configured and applied properly.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.GemFireCache
|
||||
* @see org.apache.geode.pdx.PdxSerializer
|
||||
* @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication
|
||||
* @see org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("unused")
|
||||
public class PdxSerializationConfigurationIntegrationTests extends AbstractGemFireIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
@Qualifier(GemFireHttpSessionConfiguration.SESSION_SERIALIZER_BEAN_ALIAS)
|
||||
private SessionSerializer configuredSessionSerializer;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(GemFireHttpSessionConfiguration.SESSION_PDX_SERIALIZER_BEAN_NAME)
|
||||
private SessionSerializer pdxSerializableSessionSerialzer;
|
||||
|
||||
@Autowired
|
||||
private GemFireCache gemfireCache;
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
unregisterAllDataSerializers();
|
||||
assertThat(waitForClientCacheToClose(DEFAULT_WAIT_DURATION)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gemfireCachePdxSerializerIsSetToPdxSerializableSessionSerializer() {
|
||||
assertThat(this.gemfireCache.getPdxSerializer()).isSameAs(this.pdxSerializableSessionSerialzer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configuredSessionSerializerIsSetToPdxSerializableSessionSerializer() {
|
||||
assertThat(this.configuredSessionSerializer).isSameAs(this.pdxSerializableSessionSerialzer);
|
||||
|
||||
}
|
||||
|
||||
@ClientCacheApplication(name = "PdxSerializationConfigurationIntegrationTests", logLevel = "warning")
|
||||
@EnableGemFireHttpSession(clientRegionShortcut = ClientRegionShortcut.LOCAL, poolName = "DEFAULT",
|
||||
sessionSerializerBeanName = GemFireHttpSessionConfiguration.SESSION_PDX_SERIALIZER_BEAN_NAME)
|
||||
@SuppressWarnings("all")
|
||||
static class TestConfiguration {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.session.data.gemfire.serialization;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.gemfire.config.annotation.ClientCacheApplication;
|
||||
import org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration;
|
||||
import org.springframework.session.data.gemfire.serialization.data.support.DataSerializerSessionSerializerAdapter;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration tests to assert that any user-provided, custom {@link SessionSerializer} not bound to either
|
||||
* GemFire/Geode's Data Serialization of PDX Serialization framework is wrapped in
|
||||
* the {@link DataSerializerSessionSerializerAdapter} when the {@link DataSerializerSessionSerializerAdapter}
|
||||
* is present as a bean in the Spring context.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.apache.geode.DataSerializer
|
||||
* @see org.apache.geode.cache.GemFireCache
|
||||
* @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication
|
||||
* @see org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration
|
||||
* @see org.springframework.session.data.gemfire.serialization.data.support.DataSerializerSessionSerializerAdapter
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("unused")
|
||||
public class SessionSerializerConfiguredAsDataSerializerIntegrationTests extends AbstractGemFireIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private GemFireCache gemfireCache;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(GemFireHttpSessionConfiguration.SESSION_SERIALIZER_BEAN_ALIAS)
|
||||
private SessionSerializer configuredSessionSerializer;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("customSessionSerializer")
|
||||
private SessionSerializer customSessionSerializer;
|
||||
|
||||
@Autowired(required = false)
|
||||
@Qualifier("dataSerializerSessionSerializer")
|
||||
private SessionSerializer dataSerializerSessionSerializer;
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
unregisterAllDataSerializers();
|
||||
assertThat(waitForClientCacheToClose(DEFAULT_WAIT_DURATION)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gemfireCachePdxSerializerIsNull() {
|
||||
assertThat(this.gemfireCache.getPdxSerializer()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dataSerializerSessionSerializerIsPresent() {
|
||||
assertThat(this.dataSerializerSessionSerializer).isInstanceOf(DataSerializerSessionSerializerAdapter.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configuredSessionSerializerIsSetToCustomSessionSerializer() {
|
||||
assertThat(this.configuredSessionSerializer).isSameAs(this.customSessionSerializer);
|
||||
}
|
||||
|
||||
@ClientCacheApplication(name = "SessionSerializerConfiguredAsPdxSerializerIntegrationTests", logLevel = "warning")
|
||||
@EnableGemFireHttpSession(clientRegionShortcut = ClientRegionShortcut.LOCAL, poolName = "DEFAULT",
|
||||
sessionSerializerBeanName = "customSessionSerializer")
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
DataSerializerSessionSerializerAdapter dataSerializerSessionSerializer() {
|
||||
return new DataSerializerSessionSerializerAdapter();
|
||||
}
|
||||
|
||||
@Bean
|
||||
SessionSerializer customSessionSerializer() {
|
||||
return mock(SessionSerializer.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.session.data.gemfire.serialization;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.gemfire.config.annotation.ClientCacheApplication;
|
||||
import org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration;
|
||||
import org.springframework.session.data.gemfire.serialization.pdx.support.PdxSerializerSessionSerializerAdapter;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration tests to assert that any user-provided, custom {@link SessionSerializer} not bound to either
|
||||
* GemFire/Geode's Data Serialization of PDX Serialization framework is wrapped in
|
||||
* the {@link PdxSerializerSessionSerializerAdapter}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.apache.geode.cache.GemFireCache
|
||||
* @see org.apache.geode.pdx.PdxSerializer
|
||||
* @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication
|
||||
* @see org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration
|
||||
* @see org.springframework.session.data.gemfire.serialization.pdx.support.PdxSerializerSessionSerializerAdapter
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("unused")
|
||||
public class SessionSerializerConfiguredAsPdxSerializerIntegrationTests extends AbstractGemFireIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private GemFireCache gemfireCache;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(GemFireHttpSessionConfiguration.SESSION_SERIALIZER_BEAN_ALIAS)
|
||||
private SessionSerializer configuredSessionSerializer;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("customSessionSerializer")
|
||||
private SessionSerializer customSessionSerializer;
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
unregisterAllDataSerializers();
|
||||
assertThat(waitForClientCacheToClose(DEFAULT_WAIT_DURATION)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gemfireCachePdxSerializerIsPdxSerializerSessionSerializerAdapter() {
|
||||
assertThat(this.gemfireCache.getPdxSerializer()).isInstanceOf(PdxSerializerSessionSerializerAdapter.class);
|
||||
assertThat(((PdxSerializerSessionSerializerAdapter) this.gemfireCache.getPdxSerializer()).getSessionSerializer())
|
||||
.isSameAs(this.customSessionSerializer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configuredSessionSerializerIsSetToCustomSessionSerializer() {
|
||||
assertThat(this.configuredSessionSerializer).isSameAs(this.customSessionSerializer);
|
||||
}
|
||||
|
||||
@ClientCacheApplication(name = "SessionSerializerConfiguredAsPdxSerializerIntegrationTests", logLevel = "warning")
|
||||
@EnableGemFireHttpSession(clientRegionShortcut = ClientRegionShortcut.LOCAL, poolName = "DEFAULT",
|
||||
sessionSerializerBeanName = "customSessionSerializer")
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
SessionSerializer customSessionSerializer() {
|
||||
return mock(SessionSerializer.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import static org.mockito.Mockito.mock;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -32,6 +33,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.gemfire.support.GemfireBeanFactoryLocator;
|
||||
import org.springframework.session.Session;
|
||||
import org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests;
|
||||
import org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository.DeltaCapableGemFireSession;
|
||||
import org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository.DeltaCapableGemFireSessionAttributes;
|
||||
import org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository.GemFireSession;
|
||||
@@ -53,6 +55,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @see org.springframework.context.annotation.Configuration
|
||||
* @see org.springframework.data.gemfire.support.GemfireBeanFactoryLocator
|
||||
* @see org.springframework.session.Session
|
||||
* @see org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests
|
||||
* @see org.springframework.session.data.gemfire.serialization.SessionSerializer
|
||||
* @see org.springframework.session.data.gemfire.serialization.data.support.DataSerializerSessionSerializerAdapter
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
@@ -61,7 +64,8 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
public class DataSerializerSessionSerializerAdapterIntegrationTests {
|
||||
@SuppressWarnings("unused")
|
||||
public class DataSerializerSessionSerializerAdapterIntegrationTests extends AbstractGemFireIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private DataSerializerSessionSerializerAdapter<Session> dataSerializer;
|
||||
@@ -70,6 +74,11 @@ public class DataSerializerSessionSerializerAdapterIntegrationTests {
|
||||
@Qualifier(GemFireHttpSessionConfiguration.SESSION_SERIALIZER_BEAN_ALIAS)
|
||||
private SessionSerializer<Session, DataInput, DataOutput> sessionSerializer;
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
unregisterAllDataSerializers();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructsAndAutowiresDataSerializerSessionSerializerAdapter() {
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ import org.springframework.data.gemfire.IndexFactoryBean;
|
||||
import org.springframework.data.gemfire.IndexType;
|
||||
import org.springframework.data.gemfire.RegionAttributesFactoryBean;
|
||||
import org.springframework.data.gemfire.config.xml.GemfireConstants;
|
||||
import org.springframework.data.gemfire.util.ArrayUtils;
|
||||
import org.springframework.session.Session;
|
||||
import org.springframework.session.SessionRepository;
|
||||
import org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration;
|
||||
@@ -66,6 +67,7 @@ import org.springframework.session.data.gemfire.config.annotation.web.http.suppo
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.support.SessionAttributesIndexFactoryBean;
|
||||
import org.springframework.session.data.gemfire.serialization.SessionSerializer;
|
||||
import org.springframework.session.data.gemfire.serialization.data.provider.DataSerializableSessionSerializer;
|
||||
import org.springframework.session.data.gemfire.serialization.data.support.DataSerializerSessionSerializerAdapter;
|
||||
import org.springframework.session.data.gemfire.serialization.pdx.provider.PdxSerializableSessionSerializer;
|
||||
import org.springframework.session.data.gemfire.serialization.pdx.support.ComposablePdxSerializer;
|
||||
import org.springframework.session.data.gemfire.serialization.pdx.support.PdxSerializerSessionSerializerAdapter;
|
||||
@@ -496,6 +498,11 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
|
||||
return getApplicationContext().getBean(SESSION_SERIALIZER_BEAN_ALIAS, SessionSerializer.class);
|
||||
}
|
||||
|
||||
private boolean isDataSerializerSessionSerializerAdapterPresent() {
|
||||
return !ArrayUtils.isEmpty(getApplicationContext()
|
||||
.getBeanNamesForType(DataSerializerSessionSerializerAdapter.class));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void configureSerialization(CacheFactoryBean cacheFactoryBean, SessionSerializer sessionSerializer) {
|
||||
|
||||
@@ -513,6 +520,7 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
|
||||
}
|
||||
else {
|
||||
Optional.ofNullable(sessionSerializer)
|
||||
.filter(it -> !isDataSerializerSessionSerializerAdapterPresent())
|
||||
.ifPresent(serializer ->
|
||||
cacheFactoryBean.setPdxSerializer(ComposablePdxSerializer.compose(
|
||||
new PdxSerializerSessionSerializerAdapter<>(sessionSerializer),
|
||||
|
||||
@@ -50,8 +50,8 @@ import org.springframework.stereotype.Component;
|
||||
* @see org.springframework.stereotype.Component
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Component
|
||||
@SuppressWarnings("unused")
|
||||
@Component("org.springfamework.session.data.gemfire.serialization.data.support.DataSerializerSessionSerializerAdapter")
|
||||
public class DataSerializerSessionSerializerAdapter<T extends Session> extends WirableDataSerializer<T> {
|
||||
|
||||
static {
|
||||
@@ -76,7 +76,7 @@ public class DataSerializerSessionSerializerAdapter<T extends Session> extends W
|
||||
.orElseThrow(() -> newIllegalArgumentException("SessionSerializer is required"));
|
||||
}
|
||||
|
||||
protected SessionSerializer<T, DataInput, DataOutput> getSessionSerializer() {
|
||||
public SessionSerializer<T, DataInput, DataOutput> getSessionSerializer() {
|
||||
return Optional.ofNullable(this.sessionSerializer)
|
||||
.orElseThrow(() -> newIllegalStateException("SessionSerializer was not properly configured"));
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class PdxSerializerSessionSerializerAdapter<T extends Session>
|
||||
.orElseThrow(() -> newIllegalArgumentException("SessionSerializer is required"));
|
||||
}
|
||||
|
||||
protected SessionSerializer<T, PdxReader, PdxWriter> getSessionSerializer() {
|
||||
public SessionSerializer<T, PdxReader, PdxWriter> getSessionSerializer() {
|
||||
return this.sessionSerializer;
|
||||
}
|
||||
|
||||
|
||||
@@ -271,17 +271,17 @@ public class GemFireHttpSessionConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isUsingDataSerializationIsTrue() {
|
||||
public void isUsingPdxSerializationIsTrue() {
|
||||
|
||||
assertThat(this.gemfireConfiguration.getSessionSerializerBeanName())
|
||||
.isEqualTo(GemFireHttpSessionConfiguration.SESSION_DATA_SERIALIZER_BEAN_NAME);
|
||||
assertThat(this.gemfireConfiguration.isUsingDataSerialization()).isTrue();
|
||||
.isEqualTo(GemFireHttpSessionConfiguration.SESSION_PDX_SERIALIZER_BEAN_NAME);
|
||||
assertThat(this.gemfireConfiguration.isUsingDataSerialization()).isFalse();
|
||||
|
||||
this.gemfireConfiguration.setSessionSerializerBeanName(null);
|
||||
|
||||
assertThat(this.gemfireConfiguration.getSessionSerializerBeanName())
|
||||
.isEqualTo(GemFireHttpSessionConfiguration.SESSION_DATA_SERIALIZER_BEAN_NAME);
|
||||
assertThat(this.gemfireConfiguration.isUsingDataSerialization()).isTrue();
|
||||
.isEqualTo(GemFireHttpSessionConfiguration.SESSION_PDX_SERIALIZER_BEAN_NAME);
|
||||
assertThat(this.gemfireConfiguration.isUsingDataSerialization()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user