@Test
  public void testRemoteTokenPersistIsEnabled() throws Exception {
    assumeTrue(purgeDeleteTombstone);
    refreshState(false, true, false);
    List<LogSegmentName> segmentsUnderCompaction = getLogSegments(0, 2);
    List<MockReplicaId> localAndPeerReplicas = generateLocalAndPeerReplicas();
    ScheduledExecutorService scheduler = Utils.newScheduler(1, false);
    MockIdFactory keyFactory = new MockIdFactory();
    RemoteTokenTracker tokenTracker =
        new RemoteTokenTracker(localAndPeerReplicas.get(0), scheduler, keyFactory, state.time);
    Properties properties = new Properties();
    int intervalInSeconds = 5;
    properties.setProperty(StoreConfig.storePersistRemoteTokenIntervalInSecondsName,
        Integer.toString(intervalInSeconds));
    StoreConfig storeConfig = new StoreConfig(new VerifiableProperties(properties));

    // Starting the persistor with the storeConfig
    tokenTracker.start(storeConfig.storePersistRemoteTokenIntervalInSeconds);
    Map<String, Pair<Long, FindToken>> emptyTokens = tokenTracker.getPeerReplicaAndToken();

    // Generate one token
    StoreFindToken tombstoneToken = getTombstoneToken(0);
    // update token associated with peer replicas
    tokenTracker.updateTokenFromPeerReplica(tombstoneToken, localAndPeerReplicas.get(1).getDataNodeId().getHostname(),
        localAndPeerReplicas.get(1).getReplicaPath());
    tokenTracker.updateTokenFromPeerReplica(tombstoneToken, localAndPeerReplicas.get(2).getDataNodeId().getHostname(),
        localAndPeerReplicas.get(2).getReplicaPath());
    Map<String, Pair<Long, FindToken>> validTokens = tokenTracker.getPeerReplicaAndToken();
    Thread.sleep(intervalInSeconds * 1000);
    tokenTracker.close();

    // start a new RemoteTokenTracker. It'll pick up the persisted remote tokens.
    tokenTracker = new RemoteTokenTracker(localAndPeerReplicas.get(0), scheduler, keyFactory, state.time);
    Map<String, Pair<Long, FindToken>> tokenAfter = tokenTracker.getPeerReplicaAndToken();

    // check the tokens
    for (Map.Entry<String, Pair<Long, FindToken>> entry : tokenAfter.entrySet()) {
      Pair<Long, FindToken> afterToken = entry.getValue();
      Pair<Long, FindToken> emptyToken = emptyTokens.get(entry.getKey());
      Pair<Long, FindToken> validToken = validTokens.get(entry.getKey());

      assertEquals(FindTokenType.Uninitialized, emptyToken.getSecond().getType());
      assertEquals(tombstoneToken, validToken.getSecond());
      assertEquals(tombstoneToken, afterToken.getSecond());
      assertTrue(emptyToken.getFirst() <= validToken.getFirst());
      assertEquals(validToken.getFirst(), afterToken.getFirst());
    }
  }
Test the remote token persist is enabled by the StoreConfig
@throws Exception
ambry-store/src/test/java/com/github/ambry/store/BlobStoreCompactorTest.java