@Override
  public void updateDocument(
      String searchEngineId, long companyId, Document document, boolean commitImmediately)
      throws SearchException {

    if (isIndexReadOnly() || (document == null)) {
      return;
    }

    if (_log.isDebugEnabled()) {
      _log.debug("Document " + document.toString());
    }

    SearchEngine searchEngine = _searchEngineHelper.getSearchEngine(searchEngineId);

    IndexWriter indexWriter = searchEngine.getIndexWriter();

    _searchPermissionChecker.addPermissionFields(companyId, document);

    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(companyId);
    searchContext.setSearchEngineId(searchEngineId);

    setCommitImmediately(searchContext, commitImmediately || ProxyModeThreadLocal.isForceSync());

    indexWriter.updateDocument(searchContext, document);
  }
  @Override
  public void runBeforeClass(TestContext testContext) {
    Class<?> testClass = testContext.getClazz();

    Sync sync = AnnotationLocator.locate(testClass, Sync.class);

    classSyncHandler.setSync(sync);
    classSyncHandler.setForceSync(ProxyModeThreadLocal.isForceSync());

    classSyncHandler.enableSync();
  }
  @Override
  public void runBeforeTest(TestContext testContext) {
    Method method = testContext.getMethod();
    Class<?> testClass = testContext.getClazz();

    Sync sync = AnnotationLocator.locate(method, testClass, Sync.class);

    methodSyncHandler.setForceSync(ProxyModeThreadLocal.isForceSync());
    methodSyncHandler.setSync(sync);

    methodSyncHandler.enableSync();
  }