3030import java .time .Instant ;
3131import java .util .Arrays ;
3232import java .util .Objects ;
33- import java .util .concurrent .atomic .AtomicReference ;
3433import java .util .function .Predicate ;
3534
3635import org .junit .Before ;
5453import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
5554import org .springframework .data .gemfire .config .annotation .CacheServerApplication ;
5655import org .springframework .data .gemfire .config .annotation .ClientCacheApplication ;
56+ import org .springframework .lang .NonNull ;
5757import org .springframework .session .Session ;
5858import org .springframework .session .data .gemfire .config .annotation .web .http .EnableGemFireHttpSession ;
5959import org .springframework .session .data .gemfire .config .annotation .web .http .GemFireHttpSessionConfiguration ;
9090public class ConcurrentSessionOperationsUsingClientCachingProxyRegionIntegrationTests
9191 extends AbstractConcurrentSessionOperationsIntegrationTests {
9292
93- private static final String GEMFIRE_LOG_LEVEL = "error" ;
94-
9593 @ Before
9694 public void setup () {
9795
@@ -128,10 +126,8 @@ public void regionPutWithNonDirtySessionResultsInInefficientIncorrectBehavior()
128126 // Tests that 2 Threads share the same Session object reference and therefore see's each other's changes.
129127 public static class ConcurrentCachedSessionOperationsTestCase extends AbstractConcurrentSessionOperationsTestCase {
130128
131- private final AtomicReference <String > sessionId = new AtomicReference <>(null );
132-
133129 public ConcurrentCachedSessionOperationsTestCase (
134- ConcurrentSessionOperationsUsingClientCachingProxyRegionIntegrationTests testInstance ) {
130+ @ NonNull ConcurrentSessionOperationsUsingClientCachingProxyRegionIntegrationTests testInstance ) {
135131
136132 super (testInstance );
137133 }
@@ -153,7 +149,7 @@ public void initialize() {
153149
154150 save (session );
155151
156- this . sessionId . set (session .getId ());
152+ setSessionId (session .getId ());
157153 }
158154
159155 public void thread1 () {
@@ -164,10 +160,10 @@ public void thread1() {
164160
165161 Instant beforeLastAccessedTime = Instant .now ();
166162
167- Session session = findById (this . sessionId . get ());
163+ Session session = findById (getSessionId ());
168164
169165 assertThat (session ).isNotNull ();
170- assertThat (session .getId ()).isEqualTo (this . sessionId . get ());
166+ assertThat (session .getId ()).isEqualTo (getSessionId ());
171167 assertThat (session .getLastAccessedTime ()).isAfterOrEqualTo (beforeLastAccessedTime );
172168 assertThat (session .getLastAccessedTime ()).isBeforeOrEqualTo (Instant .now ());
173169 assertThat (session .isExpired ()).isFalse ();
@@ -192,10 +188,10 @@ public void thread2() {
192188
193189 Instant beforeLastAccessedTime = Instant .now ();
194190
195- Session session = findById (this . sessionId . get ());
191+ Session session = findById (getSessionId ());
196192
197193 assertThat (session ).isNotNull ();
198- assertThat (session .getId ()).isEqualTo (this . sessionId . get ());
194+ assertThat (session .getId ()).isEqualTo (getSessionId ());
199195 assertThat (session .getLastAccessedTime ()).isAfterOrEqualTo (beforeLastAccessedTime );
200196 assertThat (session .getLastAccessedTime ()).isBeforeOrEqualTo (Instant .now ());
201197 assertThat (session .isExpired ()).isFalse ();
@@ -217,8 +213,6 @@ public static class RegionPutWithNonDirtySessionTestCase extends AbstractConcurr
217213 private static final String DATA_SERIALIZER_NOT_FOUND_EXCEPTION_MESSAGE =
218214 "No DataSerializer was found capable of de/serializing Sessions" ;
219215
220- private final AtomicReference <String > sessionId = new AtomicReference <>(null );
221-
222216 private final DataSerializer sessionSerializer ;
223217
224218 private final Region <Object , Session > sessions ;
@@ -232,6 +226,14 @@ public RegionPutWithNonDirtySessionTestCase(
232226 this .sessionSerializer = reregisterDataSerializer (resolveDataSerializer ());
233227 }
234228
229+ private DataSerializer reregisterDataSerializer (DataSerializer dataSerializer ) {
230+
231+ InternalDataSerializer .unregister (dataSerializer .getId ());
232+ InternalDataSerializer ._register (dataSerializer , false );
233+
234+ return dataSerializer ;
235+ }
236+
235237 private DataSerializer resolveDataSerializer () {
236238
237239 return Arrays .stream (nullSafeArray (InternalDataSerializer .getSerializers (), DataSerializer .class ))
@@ -258,14 +260,6 @@ private Predicate<? super DataSerializer> sessionSerializerFilter() {
258260 };
259261 }
260262
261- private DataSerializer reregisterDataSerializer (DataSerializer dataSerializer ) {
262-
263- InternalDataSerializer .unregister (dataSerializer .getId ());
264- InternalDataSerializer ._register (dataSerializer , false );
265-
266- return dataSerializer ;
267- }
268-
269263 private Session get (String id ) {
270264 return this .sessions .get (id );
271265 }
@@ -310,7 +304,7 @@ public void thread1() {
310304
311305 getSessionRepository ().commit (loadedSession );
312306
313- this . sessionId . set (session .getId ());
307+ setSessionId (session .getId ());
314308 }
315309
316310 public void thread2 () {
@@ -319,11 +313,12 @@ public void thread2() {
319313
320314 waitForTick (1 );
321315 assertTick (1 );
316+ waitOnAvailableSessionId ();
322317
323- Session session = get (this . sessionId . get ());
318+ Session session = get (getSessionId ());
324319
325320 assertThat (session ).isInstanceOf (GemFireSession .class );
326- assertThat (session .getId ()).isEqualTo (this . sessionId . get ());
321+ assertThat (session .getId ()).isEqualTo (getSessionId ());
327322 assertThat (session .isExpired ()).isFalse ();
328323 assertThat (session .getAttributeNames ()).containsOnly ("attributeOne" , "attributeTwo" );
329324 assertThat (session .<String >getAttribute ("attributeOne" )).isEqualTo ("testOne" );
@@ -336,10 +331,10 @@ public void thread2() {
336331 @ Override
337332 public void finish () {
338333
339- Session session = get (this . sessionId . get ());
334+ Session session = get (getSessionId ());
340335
341336 assertThat (session ).isNotNull ();
342- assertThat (session .getId ()).isEqualTo (this . sessionId . get ());
337+ assertThat (session .getId ()).isEqualTo (getSessionId ());
343338 assertThat (session .isExpired ()).isFalse ();
344339 assertThat (session .getAttributeNames ()).containsOnly ("attributeOne" , "attributeTwo" );
345340 assertThat (session .<String >getAttribute ("attributeOne" )).isEqualTo ("testOne" );
@@ -352,6 +347,7 @@ public void finish() {
352347
353348 verify (this .sessionSerializer , times (2 ))
354349 .toData (isA (GemFireSession .class ), isA (DataOutput .class ));
350+
355351 }
356352 catch (ClassNotFoundException | IOException ignore ) { }
357353 }
@@ -364,7 +360,7 @@ public static void startGemFireServer() throws IOException {
364360
365361 // Tests fail when 'copyOnRead' is set to 'true'!
366362 //@ClientCacheApplication(copyOnRead = true, logLevel = GEMFIRE_LOG_LEVEL, subscriptionEnabled = true)
367- @ ClientCacheApplication (logLevel = GEMFIRE_LOG_LEVEL , subscriptionEnabled = true )
363+ @ ClientCacheApplication (subscriptionEnabled = true )
368364 @ EnableGemFireHttpSession (
369365 clientRegionShortcut = ClientRegionShortcut .CACHING_PROXY ,
370366 poolName = "DEFAULT" ,
@@ -373,10 +369,7 @@ public static void startGemFireServer() throws IOException {
373369 )
374370 static class GemFireClientConfiguration { }
375371
376- @ CacheServerApplication (
377- name = "ConcurrentSessionOperationsUsingClientCachingProxyRegionIntegrationTests" ,
378- logLevel = GEMFIRE_LOG_LEVEL
379- )
372+ @ CacheServerApplication (name = "ConcurrentSessionOperationsUsingClientCachingProxyRegionIntegrationTests" )
380373 @ EnableGemFireHttpSession (
381374 regionName = "Sessions" ,
382375 sessionSerializerBeanName = GemFireHttpSessionConfiguration .SESSION_DATA_SERIALIZER_BEAN_NAME
0 commit comments