public ImmutableSet<WaveletId> lookupWavelets(WaveId waveId) throws WaveletStateException {
   ListenableFuture<ImmutableSet<WaveletId>> future = waves.get(waveId).lookedupWavelets;
   try {
     return FutureUtil.getResultOrPropagateException(future, PersistenceException.class);
   } catch (PersistenceException e) {
     throw new WaveletStateException("Failed to look up wave " + waveId, e);
   } catch (InterruptedException e) {
     Thread.currentThread().interrupt();
     throw new WaveletStateException("Interrupted while looking up wave " + waveId, e);
   }
 }
Example #2
0
  /** @throws Exception */
  @Test(expected = WrapRuntimeException.class)
  public void getQuietlyWhenExceptionOccurred() throws Exception {
    String value = "hoge";
    FakeFuture<String> future =
        new FakeFuture<String>(value) {

          @Override
          public String get() throws InterruptedException, ExecutionException {
            throw new ExecutionException(new Exception("Hoge"));
          }
        };
    FutureUtil.getQuietly(future);
  }
Example #3
0
  /** @throws Exception */
  @Test(expected = Error.class)
  public void getWhenErrorOccurred() throws Exception {
    String value = "hoge";
    FakeFuture<String> future =
        new FakeFuture<String>(value) {

          @Override
          public String get() throws InterruptedException, ExecutionException {
            throw new ExecutionException(new Error("Hoge"));
          }
        };
    FutureUtil.get(future);
  }
 private <T extends WaveletContainer> T getWavelet(
     WaveletId waveletId, ConcurrentMap<WaveletId, T> waveletsMap) throws WaveletStateException {
   ImmutableSet<WaveletId> storedWavelets;
   try {
     storedWavelets =
         FutureUtil.getResultOrPropagateException(lookedupWavelets, PersistenceException.class);
   } catch (PersistenceException e) {
     throw new WaveletStateException(
         "Failed to lookup wavelet " + WaveletName.of(waveId, waveletId), e);
   } catch (InterruptedException e) {
     Thread.currentThread().interrupt();
     throw new WaveletStateException(
         "Interrupted looking up wavelet " + WaveletName.of(waveId, waveletId), e);
   }
   // Since waveletsMap is a computing map, we must call containsKey(waveletId)
   // to tell if waveletId is mapped, we cannot test if get(waveletId) returns null.
   if (!storedWavelets.contains(waveletId) && !waveletsMap.containsKey(waveletId)) {
     return null;
   } else {
     T wavelet = waveletsMap.get(waveletId);
     Preconditions.checkNotNull(wavelet, "computingMap returned null");
     return wavelet;
   }
 }
Example #5
0
 /** @throws Exception */
 @Test
 public void getQuietly() throws Exception {
   String value = "hoge";
   FakeFuture<String> future = new FakeFuture<String>(value);
   assertThat(FutureUtil.getQuietly(future), is(value));
 }