/** * Gets multiple items from the cache based on the given set of keys. * <p> * @param cacheName * @param keys * @param requesterId * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no * data in cache for any of these keys * @throws IOException */ @Override public Map<K, ICacheElement<K, V>> getMultiple( String cacheName, Set<K> keys, 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.createGetMultipleRequest( cacheName, keys, requesterId ); RemoteCacheResponse<Map<K, ICacheElement<K, V>>> remoteHttpCacheResponse = getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); if ( log.isDebugEnabled() ) { log.debug( "GetMultiple [" + keys + "] = " + remoteHttpCacheResponse ); } return remoteHttpCacheResponse.getPayload(); }
/** * Gets multiple items from the cache based on the given set of keys. * <p> * @param cacheName * @param keys * @param requesterId * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no * data in cache for any of these keys * @throws IOException */ @Override public Map<K, ICacheElement<K, V>> getMultiple( String cacheName, Set<K> keys, 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.createGetMultipleRequest( cacheName, keys, requesterId ); RemoteCacheResponse<Map<K, ICacheElement<K, V>>> remoteHttpCacheResponse = getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); if ( log.isDebugEnabled() ) { log.debug( "GetMultiple [" + keys + "] = " + remoteHttpCacheResponse ); } return remoteHttpCacheResponse.getPayload(); }
/** Verify that the service is called. */ public void testProcessRequest_GetMultiple() { String cacheName = "test"; Set<Serializable> keys = Collections.emptySet(); long requesterId = 2; RemoteCacheRequest<Serializable, Serializable> request = RemoteCacheRequestFactory.createGetMultipleRequest( cacheName, keys, requesterId ); // DO WORK RemoteCacheResponse<Object> result = servlet.processRequest( request ); // VERIFY assertNotNull( "Should have a result.", result ); assertEquals( "Wrong keys.", keys, remoteHttpCacheService.lastGetMultipleKeys ); }
/** Simple test */ public void testCreateGetMultipleRequest_Normal() { // SETUP String cacheName = "test"; Set<Serializable> keys = Collections.emptySet(); long requesterId = 2; // DO WORK RemoteCacheRequest<Serializable, Serializable> result = RemoteCacheRequestFactory.createGetMultipleRequest( cacheName, keys, requesterId ); // VERIFY assertNotNull( "Should have a result", result ); assertEquals( "Wrong cacheName", cacheName, result.getCacheName() ); assertEquals( "Wrong type", RemoteRequestType.GET_MULTIPLE, result.getRequestType() ); }
/** Simple test */ public void testCreateGetMultipleRequest_Normal() { // SETUP String cacheName = "test"; Set<Serializable> keys = Collections.emptySet(); long requesterId = 2; // DO WORK RemoteCacheRequest<Serializable, Serializable> result = RemoteCacheRequestFactory.createGetMultipleRequest( cacheName, keys, requesterId ); // VERIFY assertNotNull( "Should have a result", result ); assertEquals( "Wrong cacheName", cacheName, result.getCacheName() ); assertEquals( "Wrong type", RemoteRequestType.GET_MULTIPLE, result.getRequestType() ); }
/** 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 ); }