/** * Initialize this manager. The memcachedClient parameter is there for testing * purposes. If the memcachedClient is provided it's used, otherwise a "real"/new * memcached client is created based on the configuration (like {@link #setMemcachedNodes(String)} etc.). * * @param storage the storage client to use, for normal operations this should be <code>null</code>. */ void startInternal( final StorageClient storage ) throws LifecycleException { if (storage == null) _storage = null; else _storage = storage; startInternal(); }
/** * Initialize this manager. The storageClient parameter is there for testing * purposes. If the storageClient is provided it's used, otherwise a "real"/new * storage client is created based on the configuration (like {@link #setMemcachedNodes(String)} etc.). * * @param storageClient the storage client to use, for normal operations this should be <code>null</code>. */ protected void startInternal(final StorageClient storageClient ) throws LifecycleException { _msm.setStorageClient(storageClient); _msm.startInternal(); }
/** * {@inheritDoc} */ @Override public void startInternal() throws LifecycleException { super.startInternal(); _msm.startInternal(); setState(LifecycleState.STARTING); }
/** * {@inheritDoc} */ @Override public void startInternal() throws LifecycleException { super.startInternal(); _msm.startInternal(); setState(LifecycleState.STARTING); }
/** * {@inheritDoc} */ @Override public void startInternal() throws LifecycleException { super.startInternal(); _msm.startInternal(); setState(LifecycleState.STARTING); }
@Test public void testConfigurationFormatMemcachedNodesFeature44() throws LifecycleException { _service.setMemcachedNodes( "n1:127.0.0.1:11211" ); _service.startInternal(new MemcachedStorageClient(_memcachedMock)); Assert.assertEquals( _service.getNodeIds(), Arrays.asList( "n1" ) ); _service.setMemcachedNodes( "n1:127.0.0.1:11211 n2:127.0.0.1:11212" ); _service.startInternal(new MemcachedStorageClient(_memcachedMock)); Assert.assertEquals( _service.getNodeIds(), Arrays.asList( "n1", "n2" ) ); _service.setMemcachedNodes( "n1:127.0.0.1:11211,n2:127.0.0.1:11212" ); _service.startInternal(new MemcachedStorageClient(_memcachedMock)); Assert.assertEquals( _service.getNodeIds(), Arrays.asList( "n1", "n2" ) ); }
@Test public void testConfigurationFormatFailoverNodesFeature44() throws LifecycleException { _service.setMemcachedNodes( "n1:127.0.0.1:11211 n2:127.0.0.1:11212" ); _service.setFailoverNodes( "n1" ); _service.startInternal(new MemcachedStorageClient(_memcachedMock)); Assert.assertEquals( _service.getFailoverNodeIds(), Arrays.asList( "n1" ) ); _service.setMemcachedNodes( "n1:127.0.0.1:11211 n2:127.0.0.1:11212 n3:127.0.0.1:11213" ); _service.setFailoverNodes( "n1 n2" ); _service.startInternal(new MemcachedStorageClient(_memcachedMock)); Assert.assertEquals( _service.getFailoverNodeIds(), Arrays.asList( "n1", "n2" ) ); _service.setMemcachedNodes( "n1:127.0.0.1:11211 n2:127.0.0.1:11212 n3:127.0.0.1:11213" ); _service.setFailoverNodes( "n1,n2" ); _service.startInternal(new MemcachedStorageClient(_memcachedMock)); Assert.assertEquals( _service.getFailoverNodeIds(), Arrays.asList( "n1", "n2" ) ); }
/** * Test for issue #105: Make memcached node optional for single-node setup * http://code.google.com/p/memcached-session-manager/issues/detail?id=105 */ @Test public void testBackupSessionFailureWithoutMemcachedNodeIdConfigured105() throws Exception { _service.setMemcachedNodes( "127.0.0.1:11211" ); _service.setSessionBackupAsync(false); _service.startInternal(new MemcachedStorageClient(_memcachedMock)); final MemcachedBackupSession session = createSession( _service ); session.access(); session.endAccess(); session.setAttribute( "foo", "bar" ); @SuppressWarnings( "unchecked" ) final OperationFuture<Boolean> futureMock = mock( OperationFuture.class ); when( futureMock.get( ) ).thenThrow(new ExecutionException(new RuntimeException("Simulated exception."))); when( futureMock.get( anyInt(), any( TimeUnit.class ) ) ).thenThrow(new ExecutionException(new RuntimeException("Simulated exception."))); when( _memcachedMock.set( eq( session.getId() ), anyInt(), any(), any( Transcoder.class ) ) ).thenReturn( futureMock ); final BackupResult backupResult = _service.backupSession( session.getIdInternal(), false, null ).get(); assertEquals(backupResult.getStatus(), BackupResultStatus.FAILURE); verify( _memcachedMock, times( 1 ) ).set( eq( session.getId() ), anyInt(), any(), any( Transcoder.class ) ); }
@Test public void testInvalidNonStickySessionDoesNotCallOnBackupWithoutLoadedSessionIssue137() throws Exception { _service.setStickyInternal( false ); _service.setLockingMode( LockingMode.NONE, null, false ); _service.startInternal(new MemcachedStorageClient(_memcachedMock)); // we must put in our mock again final String sessionId = "nonStickySessionToTimeOut-n1"; // For findSession needed final Request requestMock = mock(Request.class); when(requestMock.getNote(eq(RequestTrackingContextValve.INVOKED))).thenReturn(Boolean.TRUE); _service.getTrackingHostValve().storeRequestThreadLocal(requestMock); final MemcachedBackupSession session = _service.findSession(sessionId); assertNull(session); _service.backupSession( sessionId, false, null ).get(); // check that validity info is not loaded - this would trigger the // WARNING: Found no validity info for session id ... final String validityKey = new SessionIdFormat().createValidityInfoKeyName( sessionId ); verify( _memcachedMock, times( 0 ) ).get( eq( validityKey ) ); }
_service.setLockingMode( LockingMode.NONE, null, false ); _service.setMemcachedNodes( "n1:127.0.0.1:11211 n2:127.0.0.1:11212" ); // for backup support _service.startInternal(new MemcachedStorageClient(_memcachedMock)); // we must put in our mock again
/** * Test for issue #105: Make memcached node optional for single-node setup * http://code.google.com/p/memcached-session-manager/issues/detail?id=105 */ @Test public void testConfigurationFormatMemcachedNodesFeature105() throws LifecycleException { _service.setMemcachedNodes( "127.0.0.1:11211" ); _service.startInternal(new MemcachedStorageClient(_memcachedMock)); assertEquals(_service.getMemcachedNodesManager().getCountNodes(), 1); assertEquals(_service.getMemcachedNodesManager().isEncodeNodeIdInSessionId(), false); assertEquals(_service.getMemcachedNodesManager().isValidForMemcached("123456"), true); _service.shutdown(); _service.setMemcachedNodes( "n1:127.0.0.1:11211" ); _service.startInternal(new MemcachedStorageClient(_memcachedMock)); assertEquals(_service.getMemcachedNodesManager().getCountNodes(), 1); assertEquals(_service.getMemcachedNodesManager().isEncodeNodeIdInSessionId(), true); assertEquals(_service.getMemcachedNodesManager().isValidForMemcached("123456"), false); assertEquals(_service.getMemcachedNodesManager().isValidForMemcached("123456-n1"), true); }
/** * Initialize this manager. The memcachedClient parameter is there for testing * purposes. If the memcachedClient is provided it's used, otherwise a "real"/new * memcached client is created based on the configuration (like {@link #setMemcachedNodes(String)} etc.). * * @param storage the storage client to use, for normal operations this should be <code>null</code>. */ void startInternal( final StorageClient storage ) throws LifecycleException { if (storage == null) _storage = null; else _storage = storage; startInternal(); }
_service.setLockingMode( LockingMode.NONE, null, false ); _service.setMemcachedNodes( "n1:127.0.0.1:11211 n2:127.0.0.1:11212" ); // for backup support _service.startInternal(new MemcachedStorageClient(_memcachedMock)); // we must put in our mock again
/** * {@inheritDoc} */ @Override public void startInternal() throws LifecycleException { super.startInternal(); _msm.startInternal(); setState(LifecycleState.STARTING); }