예제 #1
0
 private void uglyjoglhack() throws InterruptedException {
   try {
     display();
   } catch (RuntimeException e) {
     if (e.getCause() instanceof InterruptedException) {
       throw ((InterruptedException) e.getCause());
     } else {
       throw (e);
     }
   }
 }
    /*MUST be called under the WriteLock*/
    @NotNull
    private Map<Integer, SerializedStubTree> readOldData(final int key) throws StorageException {
      final Map<Integer, SerializedStubTree> result = new HashMap<Integer, SerializedStubTree>();

      IndexStorage<Integer, SerializedStubTree> indexStorage = myStorage;
      if (indexStorage instanceof MemoryIndexStorage) {
        final MemoryIndexStorage<Integer, SerializedStubTree> memIndexStorage =
            (MemoryIndexStorage<Integer, SerializedStubTree>) indexStorage;
        if (!memIndexStorage.isBufferingEnabled()) {
          // if buffering is not enabled, use backend storage to make sure
          // the returned stub tree contains no data corresponding to unsaved documents.
          // This will ensure that correct set of old keys is used for update
          indexStorage = memIndexStorage.getBackendStorage();
        }
      }
      try {
        final ValueContainer<SerializedStubTree> valueContainer = indexStorage.read(key);
        if (valueContainer.size() != 1) {
          LOG.assertTrue(valueContainer.size() == 0);
          return result;
        }

        result.put(key, valueContainer.getValueIterator().next());
        return result;
      } catch (RuntimeException e) {
        final Throwable cause = e.getCause();
        if (cause instanceof IOException) {
          throw new StorageException(cause);
        }
        throw e;
      }
    }
  @Test
  public void testGetTemporaryFilesThrowsIfCompletingAfterObsoletion() throws Throwable {
    ColumnFamilyStore cfs = MockSchema.newCFS(KEYSPACE);
    File dataFolder = new Directories(cfs.metadata).getDirectoryForNewSSTables();
    SSTableReader sstable = sstable(dataFolder, cfs, 0, 128);

    LogTransaction logs = new LogTransaction(OperationType.COMPACTION);
    assertNotNull(logs);

    LogTransaction.SSTableTidier tidier = logs.obsoleted(sstable);

    sstable.markObsolete(tidier);
    sstable.selfRef().release();

    LogTransaction.waitForDeletions();

    try {
      // This should race with the asynchronous deletion of txn log files
      // it should throw because we are violating the requirement that a transaction must
      // finish before deleting files (i.e. releasing sstables)
      getTemporaryFiles(dataFolder);
      fail("Expected runtime exception");
    } catch (RuntimeException e) {
      // pass as long as the cause is not an assertion
      assertFalse(e.getCause() instanceof AssertionError);
    }

    logs.finish();
  }
 public void revert() throws IOException {
   try {
     new WriteCommandAction(myProject, getCommandName()) {
       @Override
       protected void run(Result objectResult) throws Throwable {
         myGateway.saveAllUnsavedDocuments();
         doRevert();
         myGateway.saveAllUnsavedDocuments();
       }
     }.execute();
   } catch (RuntimeException e) {
     Throwable cause = e.getCause();
     if (cause instanceof IOException) {
       throw (IOException) cause;
     }
     throw e;
   }
 }
  @Override
  public <K> Collection<K> getAllKeys(final StubIndexKey<K, ?> indexKey, @NotNull Project project) {
    FileBasedIndex.getInstance()
        .ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, GlobalSearchScope.allScope(project));

    final MyIndex<K> index = (MyIndex<K>) myIndices.get(indexKey);
    try {
      return index.getAllKeys();
    } catch (StorageException e) {
      forceRebuild(e);
    } catch (RuntimeException e) {
      final Throwable cause = e.getCause();
      if (cause instanceof IOException || cause instanceof StorageException) {
        forceRebuild(e);
      }
      throw e;
    }
    return Collections.emptyList();
  }
  @Test
  public void receiveShouldFailWithUnmappedName() {
    // Given
    Mapping sendMapping =
        new MappingBuilder(OPERATION_FIELD_NAME).mapOperation("mappedCall", "OP").build();
    MappedApi service = service(sendMapping);
    service.mappedCall("a", 0L);

    Mapping receiveMapping = partialMapping();

    // When
    String message = null;
    try {
      MapMessageDecoder.of(MappedApi.class, serviceMock, receiveMapping)
          .onMessage(captureMessage());
      fail("RuntimeException expected");
    } catch (RuntimeException e) {
      message = e.getCause().getMessage();
    }

    // Then
    assertEquals("no mapping for field: s2", message);
  }
  /* **********************************************************************
   * List methods
   ************************************************************************/
  @Override
  @SuppressWarnings("deprecation")
  public E get(final int index) {
    if (invalid_) {
      return null;
    }

    Map<Integer, E> cache = getCache();
    if (!cache.containsKey(index)) {
      try {
        if (searchQuery_ == null || searchQuery_.isEmpty()) {
          ViewNavigator nav = getNavigator();

          // getNth is top-level only, so let's skip to what we need
          int lastFetchedIndex = 0;
          Map<String, Object> requestScope = getRequestScope();
          String key = "lastFetchedIndex-" + toString();
          if (requestScope.containsKey(key)) {
            lastFetchedIndex = (Integer) requestScope.get(key);
          }
          nav.skip(index - lastFetchedIndex);

          requestScope.put(key, index);

          try {
            // Try to get the current one, which may be null due to an as-yet-unsolved
            // "object has been removed or recycled" error. Check for that and switch to
            // our exception handler to retry
            ViewEntry entry = nav.getCurrent();
            if (entry == null) {
              throw new NullPointerException();
            }
            cache.put(index, createFromViewEntry(entry, columnInfo_));
          } catch (NullPointerException npe) {
            // Then we've probably hit an "Object has been removed or recycled" on the nav

            if (reset_ < 10) {
              reset_++;
              clearCache();
              return get(index);
            }

            System.out.println("=============================== NPE in DominoModelList");
            System.out.println(
                "=============================== Current class: " + getClass().getName());
            System.out.println("=============================== Type: " + getClazz().getName());
            System.out.println("=============================== Desired index: " + index);
            System.out.println("=============================== Current cache: " + cache);
            System.out.println("=============================== Current reported size: " + size());
            throw npe;
          } catch (RuntimeException re) {
            if (String.valueOf(re.getCause()).contains("Argument has been removed or recycled")) {
              if (reset_ < 10) {
                reset_++;
                clearCache();
                return get(index);
              }
            }
            // Otherwise, throw it up
            throw re;
          }
        } else {
          ViewEntryCollection vec = getEntries();
          cache.put(index, createFromViewEntry(vec.getNthEntry(index + 1), columnInfo_));
        }
      } catch (Exception e) {
        throw e instanceof RuntimeException ? (RuntimeException) e : new RuntimeException(e);
      }
    }
    return cache.get(index);
  }
예제 #8
0
  private static Properties readOneConfigurationFile(String filename) {
    Properties propsFromFile = null;

    VirtualFile appRoot = VirtualFile.open(applicationPath);

    VirtualFile conf = appRoot.child("conf/" + filename);
    if (confs.contains(conf)) {
      throw new RuntimeException(
          "Detected recursive @include usage. Have seen the file " + filename + " before");
    }

    try {
      propsFromFile = IO.readUtf8Properties(conf.inputstream());
    } catch (RuntimeException e) {
      if (e.getCause() instanceof IOException) {
        Logger.fatal("Cannot read " + filename);
        fatalServerErrorOccurred();
      }
    }
    confs.add(conf);

    // OK, check for instance specifics configuration
    Properties newConfiguration = new OrderSafeProperties();
    Pattern pattern = Pattern.compile("^%([a-zA-Z0-9_\\-]+)\\.(.*)$");
    for (Object key : propsFromFile.keySet()) {
      Matcher matcher = pattern.matcher(key + "");
      if (!matcher.matches()) {
        newConfiguration.put(key, propsFromFile.get(key).toString().trim());
      }
    }
    for (Object key : propsFromFile.keySet()) {
      Matcher matcher = pattern.matcher(key + "");
      if (matcher.matches()) {
        String instance = matcher.group(1);
        if (instance.equals(id)) {
          newConfiguration.put(matcher.group(2), propsFromFile.get(key).toString().trim());
        }
      }
    }
    propsFromFile = newConfiguration;
    // Resolve ${..}
    pattern = Pattern.compile("\\$\\{([^}]+)}");
    for (Object key : propsFromFile.keySet()) {
      String value = propsFromFile.getProperty(key.toString());
      Matcher matcher = pattern.matcher(value);
      StringBuffer newValue = new StringBuffer(100);
      while (matcher.find()) {
        String jp = matcher.group(1);
        String r;
        if (jp.equals("application.path")) {
          r = Play.applicationPath.getAbsolutePath();
        } else if (jp.equals("play.path")) {
          r = Play.frameworkPath.getAbsolutePath();
        } else {
          r = System.getProperty(jp);
          if (r == null) {
            r = System.getenv(jp);
          }
          if (r == null) {
            Logger.warn("Cannot replace %s in configuration (%s=%s)", jp, key, value);
            continue;
          }
        }
        matcher.appendReplacement(newValue, r.replaceAll("\\\\", "\\\\\\\\"));
      }
      matcher.appendTail(newValue);
      propsFromFile.setProperty(key.toString(), newValue.toString());
    }
    // Include
    Map<Object, Object> toInclude = new HashMap<Object, Object>(16);
    for (Object key : propsFromFile.keySet()) {
      if (key.toString().startsWith("@include.")) {
        try {
          String filenameToInclude = propsFromFile.getProperty(key.toString());
          toInclude.putAll(readOneConfigurationFile(filenameToInclude));
        } catch (Exception ex) {
          Logger.warn("Missing include: %s", key);
        }
      }
    }
    propsFromFile.putAll(toInclude);

    return propsFromFile;
  }