ClientServerSessionCache extends AbstractSessionCache { @Override public void initialize() { bootstrapServers(); try { createOrRetrieveRegion(); } catch (Exception ex) { sessionManager.getLogger().fatal("Unable to create or retrieve region", ex); throw new IllegalStateException(ex); } this.operatingRegion = this.sessionRegion; createStatistics(); } ClientServerSessionCache(SessionManager sessionManager, ClientCache cache); @Override void initialize(); @Override String getDefaultRegionAttributesId(); @Override boolean getDefaultEnableLocalCache(); @Override void touchSessions(Set<String> sessionIds); @Override boolean isPeerToPeer(); @Override boolean isClientServer(); @Override Set<String> keySet(); @Override int size(); @Override boolean isBackingCacheAvailable(); @Override GemFireCache getCache();  }
@Test public void initializeSessionCacheSucceeds() { sessionCache.initialize(); verify(emptyExecution).execute(any(BootstrappingFunction.class)); verify(emptyExecution).execute(CreateRegionFunction.ID); verify(cache).createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY_HEAP_LRU); verify(regionFactory, times(0)).setStatisticsEnabled(true); verify(regionFactory, times(0)).setCustomEntryIdleTimeout(any(SessionCustomExpiry.class)); verify(regionFactory, times(0)).addCacheListener(any(SessionExpirationCacheListener.class)); verify(regionFactory).create(sessionRegionName); }
@Test public void bootstrappingFunctionThrowsException() { final FunctionException exception = new FunctionException(); final ResultCollector<Object, List<Object>> exceptionCollector = uncheckedCast(mock(ResultCollector.class)); when(emptyExecution.execute(new BootstrappingFunction())).thenReturn(exceptionCollector); when(exceptionCollector.getResult()).thenThrow(exception); sessionCache.initialize(); verify(logger).warn("Caught unexpected exception:", exception); }
@Test public void createRegionFunctionFailsOnServer() { final ArgumentCaptor<String> stringCaptor = ArgumentCaptor.forClass(String.class); regionStatusResultList.clear(); regionStatusResultList.add(RegionStatus.INVALID); assertThatThrownBy(() -> sessionCache.initialize()).isInstanceOf(IllegalStateException.class) .hasCauseInstanceOf(IllegalStateException.class).hasMessageContaining( "An exception occurred on the server while attempting to create or validate region named " + sessionRegionName + ". See the server log for additional details."); verify(logger).fatal(stringCaptor.capture(), any(Exception.class)); assertThat(stringCaptor.getValue()).isEqualTo("Unable to create or retrieve region"); }
@Test public void nonDefaultMaxTimeoutIntervalSetsExpirationDetails() { when(sessionManager.getMaxInactiveInterval()) .thenReturn(RegionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL + 1); sessionCache.initialize(); verify(regionFactory).setStatisticsEnabled(true); verify(regionFactory).setCustomEntryIdleTimeout(any(SessionCustomExpiry.class)); verify(regionFactory).addCacheListener(any(SessionExpirationCacheListener.class)); }
@Test public void createLocalSessionRegionWithoutEnableLocalCache() { when(sessionManager.getEnableLocalCache()).thenReturn(false); doReturn(regionFactory).when(cache).createClientRegionFactory(ClientRegionShortcut.PROXY); when(regionFactory.create(sessionRegionName)).thenReturn(sessionRegion); sessionCache.initialize(); verify(regionFactory).addCacheListener(any(SessionExpirationCacheListener.class)); verify(sessionRegion).registerInterestForAllKeys(InterestResultPolicy.KEYS); }
@Test public void createOrRetrieveRegionWithNonNullSessionRegionAndNoSessionExpirationCacheListenerCreatesListener() { final CacheListener<String, HttpSession>[] cacheListeners = uncheckedCast(new CacheListener[] {new DebugCacheListener()}); final AttributesMutator<String, HttpSession> attributesMutator = uncheckedCast(mock(AttributesMutator.class)); doReturn(sessionRegion).when(cache).getRegion(sessionRegionName); doReturn(attributes).when(sessionRegion).getAttributes(); doReturn(cacheListeners).when(attributes).getCacheListeners(); doReturn(attributesMutator).when(sessionRegion).getAttributesMutator(); sessionCache.initialize(); verify(attributesMutator).addCacheListener(any(SessionExpirationCacheListener.class)); }
@Test public void createOrRetrieveRegionWithNonNullSessionProxyRegionRegistersInterestForAllKeys() { final CacheListener<String, HttpSession>[] cacheListeners = uncheckedCast(new CacheListener[] {new SessionExpirationCacheListener()}); doReturn(sessionRegion).when(cache).getRegion(sessionRegionName); doReturn(attributes).when(sessionRegion).getAttributes(); doReturn(cacheListeners).when(attributes).getCacheListeners(); when(attributes.getDataPolicy()).thenReturn(DataPolicy.EMPTY); sessionCache.initialize(); verify(sessionRegion).registerInterestForAllKeys(InterestResultPolicy.KEYS); }