@Override public void unlock(long hash) throws TimeoutException { try { clientEntity.invokeAndWaitForComplete(new UnlockMessage(hash), false); locksHeld.remove(hash); } catch (TimeoutException tme) { throw tme; } catch (Exception e) { throw new ServerStoreProxyException(e); } } }
private LockSuccess getlockResponse(long hash) throws TimeoutException { EhcacheEntityResponse response; do { try { response = clientEntity.invokeAndWaitForComplete(new LockMessage(hash), false); } catch (TimeoutException tme) { throw tme; } catch (Exception e) { throw new ServerStoreProxyException(e); } if (response == null) { throw new ServerStoreProxyException("Response for acquiring lock was invalid null message"); } } while (response.getResponseType() == LOCK_FAILURE); return (LockSuccess) response; }
@Test public void testLock() throws Exception { ClusterTierClientEntity clusterTierClientEntity = mock(ClusterTierClientEntity.class); LockManagerImpl lockManager = new LockManagerImpl(clusterTierClientEntity); LockSuccess lockSuccess = getLockSuccessResponse(); when(clusterTierClientEntity.invokeAndWaitForComplete(any(LockMessage.class), anyBoolean())) .thenReturn(lockSuccess); Chain lock = lockManager.lock(2L); assertThat(lock, notNullValue()); assertThat(lock.length(), is(3)); }
@Override public Chain get(long key) throws TimeoutException { EhcacheEntityResponse response; try { response = entity.invokeAndWaitForComplete(new GetMessage(key), false); } catch (TimeoutException e) { throw e; } catch (Exception e) { throw new ServerStoreProxyException(e); } if (response != null && response.getResponseType() == EhcacheResponseType.GET_RESPONSE) { return ((EhcacheEntityResponse.GetResponse)response).getChain(); } else { throw new ServerStoreProxyException("Response for get operation was invalid : " + (response != null ? response.getResponseType() : "null message")); } }
@Test public void testLockWhenFailure() throws Exception { ClusterTierClientEntity clusterTierClientEntity = mock(ClusterTierClientEntity.class); LockManagerImpl lockManager = new LockManagerImpl(clusterTierClientEntity); LockSuccess lockSuccess = getLockSuccessResponse(); when(clusterTierClientEntity.invokeAndWaitForComplete(any(LockMessage.class), anyBoolean())) .thenReturn(lockFailure(), lockFailure(), lockFailure(), lockSuccess); Chain lock = lockManager.lock(2L); assertThat(lock, notNullValue()); assertThat(lock.length(), is(3)); }
@Test public void testLockWhenException() throws Exception { ClusterTierClientEntity clusterTierClientEntity = mock(ClusterTierClientEntity.class); LockManagerImpl lockManager = new LockManagerImpl(clusterTierClientEntity); when(clusterTierClientEntity.invokeAndWaitForComplete(any(LockMessage.class), anyBoolean())) .thenThrow(new UnknownClusterException(""), new TimeoutException("timed out test")); try { lockManager.lock(2L); fail(); } catch (ServerStoreProxyException sspe) { assertThat(sspe.getCause(), instanceOf(UnknownClusterException.class)); } try { lockManager.lock(2L); fail(); } catch (TimeoutException e) { assertThat(e.getMessage(), is("timed out test")); } }
@Override public Chain get(long key) throws TimeoutException { EhcacheEntityResponse response; try { response = entity.invokeAndWaitForComplete(new GetMessage(key), false); } catch (TimeoutException e) { throw e; } catch (Exception e) { throw new ServerStoreProxyException(e); } if (response != null && response.getResponseType() == EhcacheResponseType.GET_RESPONSE) { return ((EhcacheEntityResponse.GetResponse)response).getChain(); } else { throw new ServerStoreProxyException("Response for get operation was invalid : " + (response != null ? response.getResponseType() : "null message")); } }