@SuppressFBWarnings(value = "RV_RETURN_VALUE_OF_PUTIFABSENT_IGNORED")
  public int encode(CacheScope scopeInfo) {
    if (!mScopeToId.containsKey(scopeInfo)) {
      synchronized (this) {
        if (!mScopeToId.containsKey(scopeInfo)) {
          // NOTE: If update mScopeToId ahead of updating mIdToScope,
          // we may read a null scope info in decode.
          int id = mNextId;
          Preconditions.checkArgument(id < mMaxNumScopes, "too many scopes in shadow cache");
          mNextId++;
          mScopeToId.putIfAbsent(scopeInfo, id);
          // if we use mScopeToID.put() here,
          // we will get the findBug's error: the hashmap may not be atomic.
        }
      }
    }
    return mScopeToId.get(scopeInfo) & mScopeMask;
  }
@Test
  public void testConcurrentEncodeDecode() throws Exception {
    List<Runnable> runnables = new ArrayList<>();
    for (int k = 0; k < DEFAULT_THREAD_AMOUNT; k++) {
      runnables.add(() -> {
        for (int i = 0; i < NUM_SCOPES * 16; i++) {
          int r = ThreadLocalRandom.current().nextInt(NUM_SCOPES);
          CacheScope scopeInfo = CacheScope.create("schema1.table" + r);
          int id = mScopeEncoder.encode(scopeInfo);
          assertEquals(id, mScopeEncoder.encode(scopeInfo));
          assertTrue(0 <= id && id < NUM_SCOPES);
        }
      });
    }
    ConcurrencyUtils.assertConcurrent(runnables, DEFAULT_TIMEOUT_SECONDS);
  }