/** * @see junit.framework.TestCase#setUp() */ @Override protected void setUp() throws Exception { super.setUp(); servlet = new RemoteHttpCacheServlet(); servlet.init(null); remoteHttpCacheService = new MockRemoteCacheService<Serializable, Serializable>(); servlet.setRemoteCacheService( remoteHttpCacheService ); }
/** * @see junit.framework.TestCase#setUp() */ @Override protected void setUp() throws Exception { super.setUp(); cattr = new RemoteCacheAttributes(); service = new MockRemoteCacheService<String, String>(); listener = new MockRemoteCacheListener<String, String>(); monitor = new RemoteCacheMonitor(); }
/** * Verify that a remove event gets added and then is sent to the service passed to propagate. * <p> * @throws Exception */ public void testRemoveThenWalk() throws Exception { // SETUP MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String, String>(); ZombieCacheServiceNonLocal<String, String> zombie = new ZombieCacheServiceNonLocal<String, String>( 10 ); String cacheName = "testRemoveThenWalk"; String key = "myKey"; // DO WORK zombie.remove( cacheName, key, 123l ); zombie.propagateEvents( service ); // VERIFY assertEquals( "Updated element is not as expected.", key, service.lastRemoveKey ); }
/** * Verify that a removeAll event gets added and then is sent to the service passed to propagate. * <p> * @throws Exception */ public void testRemoveAllThenWalk() throws Exception { // SETUP MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String, String>(); ZombieCacheServiceNonLocal<String, String> zombie = new ZombieCacheServiceNonLocal<String, String>( 10 ); String cacheName = "testRemoveThenWalk"; // DO WORK zombie.removeAll( cacheName, 123l ); zombie.propagateEvents( service ); // VERIFY assertEquals( "Updated element is not as expected.", cacheName, service.lastRemoveAllCacheName); } }
/** Verify that we balk and return an error. */ public void testProcessRequest_null() { // SETUP RemoteCacheServiceAdaptor<String, String> adaptor = new RemoteCacheServiceAdaptor<String, String>(); MockRemoteCacheService<String, String> remoteHttpCacheService = new MockRemoteCacheService<String, String>(); adaptor.setRemoteCacheService( remoteHttpCacheService ); RemoteCacheRequest<String, String> request = null; // DO WORK RemoteCacheResponse<String> result = adaptor.processRequest( request ); // VERIFY assertNotNull( "Should have a result.", result ); assertTrue( "Should have 'The request is null' in the errorMessage", result.getErrorMessage().indexOf( "The request is null" ) != -1 ); assertTrue( "Should have 'The request is null' in the toString", result.toString().indexOf( "The request is null" ) != -1 ); }
/** * Verify that a remove event gets added and then is sent to the service passed to propagate. * <p> * @throws Exception */ public void testRemoveThenWalk() throws Exception { // SETUP MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String, String>(); ZombieCacheServiceNonLocal<String, String> zombie = new ZombieCacheServiceNonLocal<String, String>( 10 ); String cacheName = "testRemoveThenWalk"; String key = "myKey"; // DO WORK zombie.remove( cacheName, key, 123l ); zombie.propagateEvents( service ); // VERIFY assertEquals( "Updated element is not as expected.", key, service.lastRemoveKey ); }
/** * Verify that a removeAll event gets added and then is sent to the service passed to propagate. * <p> * @throws Exception */ public void testRemoveAllThenWalk() throws Exception { // SETUP MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String, String>(); ZombieCacheServiceNonLocal<String, String> zombie = new ZombieCacheServiceNonLocal<String, String>( 10 ); String cacheName = "testRemoveThenWalk"; // DO WORK zombie.removeAll( cacheName, 123l ); zombie.propagateEvents( service ); // VERIFY assertEquals( "Updated element is not as expected.", cacheName, service.lastRemoveAllCacheName); } }
/** Verify that the service is called. */ public void testProcessRequest_GetMultiple() { // SETUP RemoteCacheServiceAdaptor<String, String> adaptor = new RemoteCacheServiceAdaptor<String, String>(); MockRemoteCacheService<String, String> remoteHttpCacheService = new MockRemoteCacheService<String, String>(); adaptor.setRemoteCacheService( remoteHttpCacheService ); String cacheName = "test"; Set<String> keys = Collections.emptySet(); long requesterId = 2; RemoteCacheRequest<String, String> request = RemoteCacheRequestFactory.createGetMultipleRequest( cacheName, keys, requesterId ); // DO WORK RemoteCacheResponse<Object> result = adaptor.processRequest( request ); // VERIFY assertNotNull( "Should have a result.", result ); assertEquals( "Wrong keys.", keys, remoteHttpCacheService.lastGetMultipleKeys ); }
/** * Verify that an update event gets added and then is sent to the service passed to propagate. * <p> * @throws Exception */ public void testUpdateThenWalk() throws Exception { // SETUP MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String, String>(); ZombieCacheServiceNonLocal<String, String> zombie = new ZombieCacheServiceNonLocal<String, String>( 10 ); String cacheName = "testUpdate"; // DO WORK ICacheElement<String, String> element = new CacheElement<String, String>( cacheName, "key", "value" ); zombie.update( element, 123l ); zombie.propagateEvents( service ); // VERIFY assertEquals( "Updated element is not as expected.", element, service.lastUpdate ); }
/** * Verify that nothing is added if the max is set to 0. * <p> * @throws Exception */ public void testUpdateThenWalk_zeroSize() throws Exception { // SETUP MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String, String>(); ZombieCacheServiceNonLocal<String, String> zombie = new ZombieCacheServiceNonLocal<String, String>( 0 ); String cacheName = "testUpdate"; // DO WORK ICacheElement<String, String> element = new CacheElement<String, String>( cacheName, "key", "value" ); zombie.update( element, 123l ); zombie.propagateEvents( service ); // VERIFY assertNull( "Nothing should have been put to the service.", service.lastUpdate ); }
/** * Verify that an update event gets added and then is sent to the service passed to propagate. * <p> * @throws Exception */ public void testUpdateThenWalk() throws Exception { // SETUP MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String, String>(); ZombieCacheServiceNonLocal<String, String> zombie = new ZombieCacheServiceNonLocal<String, String>( 10 ); String cacheName = "testUpdate"; // DO WORK ICacheElement<String, String> element = new CacheElement<String, String>( cacheName, "key", "value" ); zombie.update( element, 123l ); zombie.propagateEvents( service ); // VERIFY assertEquals( "Updated element is not as expected.", element, service.lastUpdate ); }
/** * Verify that nothing is added if the max is set to 0. * <p> * @throws Exception */ public void testUpdateThenWalk_zeroSize() throws Exception { // SETUP MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String, String>(); ZombieCacheServiceNonLocal<String, String> zombie = new ZombieCacheServiceNonLocal<String, String>( 0 ); String cacheName = "testUpdate"; // DO WORK ICacheElement<String, String> element = new CacheElement<String, String>( cacheName, "key", "value" ); zombie.update( element, 123l ); zombie.propagateEvents( service ); // VERIFY assertNull( "Nothing should have been put to the service.", service.lastUpdate ); }
/** Verify that the service is called. */ public void testProcessRequest_Get() { // SETUP RemoteCacheServiceAdaptor<String, String> adaptor = new RemoteCacheServiceAdaptor<String, String>(); MockRemoteCacheService<String, String> remoteHttpCacheService = new MockRemoteCacheService<String, String>(); adaptor.setRemoteCacheService( remoteHttpCacheService ); String cacheName = "test"; String key = "key"; long requesterId = 2; RemoteCacheRequest<String, String> request = RemoteCacheRequestFactory.createGetRequest( cacheName, key, requesterId ); // DO WORK RemoteCacheResponse<Object> result = adaptor.processRequest( request ); // VERIFY assertNotNull( "Should have a result.", result ); assertEquals( "Wrong key.", key, remoteHttpCacheService.lastGetKey ); }
/** Verify that the service is called. */ public void testProcessRequest_Remove() { // SETUP RemoteCacheServiceAdaptor<String, String> adaptor = new RemoteCacheServiceAdaptor<String, String>(); MockRemoteCacheService<String, String> remoteHttpCacheService = new MockRemoteCacheService<String, String>(); adaptor.setRemoteCacheService( remoteHttpCacheService ); String cacheName = "test"; String key = "key"; long requesterId = 2; RemoteCacheRequest<String, String> request = RemoteCacheRequestFactory.createRemoveRequest( cacheName, key, requesterId ); // DO WORK RemoteCacheResponse<String> result = adaptor.processRequest( request ); // VERIFY assertNotNull( "Should have a result.", result ); assertEquals( "Wrong key.", key, remoteHttpCacheService.lastRemoveKey ); }
/** Verify that the service is called. */ public void testProcessRequest_RemoveAll() { // SETUP RemoteCacheServiceAdaptor<String, String> adaptor = new RemoteCacheServiceAdaptor<String, String>(); MockRemoteCacheService<String, String> remoteHttpCacheService = new MockRemoteCacheService<String, String>(); adaptor.setRemoteCacheService( remoteHttpCacheService ); String cacheName = "testRemoveALl"; long requesterId = 2; RemoteCacheRequest<String, String> request = RemoteCacheRequestFactory.createRemoveAllRequest( cacheName, requesterId ); // DO WORK RemoteCacheResponse<String> result = adaptor.processRequest( request ); // VERIFY assertNotNull( "Should have a result.", result ); assertEquals( "Wrong cacheName.", cacheName, remoteHttpCacheService.lastRemoveAllCacheName ); } }
/** Verify that the service is called. */ public void testProcessRequest_GetMatching() { // SETUP RemoteCacheServiceAdaptor<String, String> adaptor = new RemoteCacheServiceAdaptor<String, String>(); MockRemoteCacheService<String, String> remoteHttpCacheService = new MockRemoteCacheService<String, String>(); adaptor.setRemoteCacheService( remoteHttpCacheService ); String cacheName = "test"; String pattern = "pattern"; long requesterId = 2; RemoteCacheRequest<String, String> request = RemoteCacheRequestFactory.createGetMatchingRequest( cacheName, pattern, requesterId ); // DO WORK RemoteCacheResponse<Object> result = adaptor.processRequest( request ); // VERIFY assertNotNull( "Should have a result.", result ); assertEquals( "Wrong pattern.", pattern, remoteHttpCacheService.lastGetMatchingPattern ); }
/** Verify that the service is called. */ public void testProcessRequest_Update() { // SETUP RemoteCacheServiceAdaptor<String, String> adaptor = new RemoteCacheServiceAdaptor<String, String>(); MockRemoteCacheService<String, String> remoteHttpCacheService = new MockRemoteCacheService<String, String>(); adaptor.setRemoteCacheService( remoteHttpCacheService ); String cacheName = "test"; String key = "key"; long requesterId = 2; CacheElement<String, String> element = new CacheElement<String, String>( cacheName, key, null ); RemoteCacheRequest<String, String> request = RemoteCacheRequestFactory.createUpdateRequest( element, requesterId ); // DO WORK RemoteCacheResponse<String> result = adaptor.processRequest( request ); // VERIFY assertNotNull( "Should have a result.", result ); assertEquals( "Wrong object.", element, remoteHttpCacheService.lastUpdate ); }
/** * Verify that there is no problem if there is no listener. * <p> * @throws Exception */ public void testDispose_nullListener() throws Exception { // SETUP IRemoteCacheAttributes cattr = new RemoteCacheAttributes(); MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String, String>(); MockRemoteCacheListener<String, String> listener = null; RemoteCache<String, String> remoteCache = new RemoteCache<String, String>( cattr, service, listener ); MockCacheEventLogger cacheEventLogger = new MockCacheEventLogger(); remoteCache.setCacheEventLogger( cacheEventLogger ); // DO WORK remoteCache.dispose( ); // VERIFY assertEquals( "Start should have been called.", 1, cacheEventLogger.startICacheEventCalls ); assertEquals( "End should have been called.", 1, cacheEventLogger.endICacheEventCalls ); } }
/** * Verify event log calls. * <p> * @throws Exception */ public void testGet_simple() throws Exception { // SETUP IRemoteCacheAttributes cattr = new RemoteCacheAttributes(); MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String, String>(); MockRemoteCacheListener<String, String> listener = new MockRemoteCacheListener<String, String>(); RemoteCache<String, String> remoteCache = new RemoteCache<String, String>( cattr, service, listener ); MockCacheEventLogger cacheEventLogger = new MockCacheEventLogger(); remoteCache.setCacheEventLogger( cacheEventLogger ); // DO WORK remoteCache.get( "key" ); // VERIFY assertEquals( "Start should have been called.", 1, cacheEventLogger.startICacheEventCalls ); assertEquals( "End should have been called.", 1, cacheEventLogger.endICacheEventCalls ); }
/** * Verify event log calls. * <p> * @throws Exception */ public void testDispose_simple() throws Exception { // SETUP IRemoteCacheAttributes cattr = new RemoteCacheAttributes(); MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String, String>(); MockRemoteCacheListener<String, String> listener = new MockRemoteCacheListener<String, String>(); RemoteCache<String, String> remoteCache = new RemoteCache<String, String>( cattr, service, listener ); MockCacheEventLogger cacheEventLogger = new MockCacheEventLogger(); remoteCache.setCacheEventLogger( cacheEventLogger ); // DO WORK remoteCache.dispose( ); // VERIFY assertEquals( "Start should have been called.", 1, cacheEventLogger.startICacheEventCalls ); assertEquals( "End should have been called.", 1, cacheEventLogger.endICacheEventCalls ); }