/** * Gets multiple items from the cache matching the pattern. * <p> * @param cacheName * @param pattern * @param requesterId * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no * data in cache matching the pattern. * @throws IOException */ @Override public Map<K, ICacheElement<K, V>> getMatching( String cacheName, String pattern, long requesterId ) throws IOException { if ( !isInitialized() ) { String message = "The Remote Http Client is not initialized. Cannot process request."; log.warn( message ); throw new IOException( message ); } RemoteCacheRequest<K, V> remoteHttpCacheRequest = RemoteCacheRequestFactory.createGetMatchingRequest( cacheName, pattern, requesterId ); RemoteCacheResponse<Map<K, ICacheElement<K, V>>> remoteHttpCacheResponse = getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); if ( log.isDebugEnabled() ) { log.debug( "GetMatching [" + pattern + "] = " + remoteHttpCacheResponse ); } return remoteHttpCacheResponse.getPayload(); }
/** * Gets multiple items from the cache matching the pattern. * <p> * @param cacheName * @param pattern * @param requesterId * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no * data in cache matching the pattern. * @throws IOException */ @Override public Map<K, ICacheElement<K, V>> getMatching( String cacheName, String pattern, long requesterId ) throws IOException { if ( !isInitialized() ) { String message = "The Remote Http Client is not initialized. Cannot process request."; log.warn( message ); throw new IOException( message ); } RemoteCacheRequest<K, V> remoteHttpCacheRequest = RemoteCacheRequestFactory.createGetMatchingRequest( cacheName, pattern, requesterId ); RemoteCacheResponse<Map<K, ICacheElement<K, V>>> remoteHttpCacheResponse = getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); if ( log.isDebugEnabled() ) { log.debug( "GetMatching [" + pattern + "] = " + remoteHttpCacheResponse ); } return remoteHttpCacheResponse.getPayload(); }
/** Verify that the service is called. */ public void testProcessRequest_GetMatching() { String cacheName = "test"; String pattern = "pattern"; long requesterId = 2; RemoteCacheRequest<Serializable, Serializable> request = RemoteCacheRequestFactory.createGetMatchingRequest( cacheName, pattern, requesterId ); // DO WORK RemoteCacheResponse<Object> result = servlet.processRequest( request ); // VERIFY assertNotNull( "Should have a result.", result ); assertEquals( "Wrong pattern.", pattern, remoteHttpCacheService.lastGetMatchingPattern ); }
/** Simple test */ public void testCreateGetMatchingRequest_Normal() { // SETUP String cacheName = "test"; String pattern = "pattern"; long requesterId = 2; // DO WORK RemoteCacheRequest<Serializable, Serializable> result = RemoteCacheRequestFactory.createGetMatchingRequest( cacheName, pattern, requesterId ); // VERIFY assertNotNull( "Should have a result", result ); assertEquals( "Wrong cacheName", cacheName, result.getCacheName() ); assertEquals( "Wrong type", RemoteRequestType.GET_MATCHING, result.getRequestType() ); }
/** Simple test */ public void testCreateGetMatchingRequest_Normal() { // SETUP String cacheName = "test"; String pattern = "pattern"; long requesterId = 2; // DO WORK RemoteCacheRequest<Serializable, Serializable> result = RemoteCacheRequestFactory.createGetMatchingRequest( cacheName, pattern, requesterId ); // VERIFY assertNotNull( "Should have a result", result ); assertEquals( "Wrong cacheName", cacheName, result.getCacheName() ); assertEquals( "Wrong type", RemoteRequestType.GET_MATCHING, result.getRequestType() ); }
/** 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 ); }