@Test
public void testRepeatSCN() throws Exception
{

  final Logger log = Logger.getLogger("TestTrailFilePositionSetter.testRepeatSCN");
  File dir = createTempDir();
  long startScn = 100;
  int numTxnsPerFile = 10;
  /**
   * Create trail files with the following SCN range
   *
   * Trail-File       Number of Txns          SCN Range
   *   x300               10                  100-100
   *   x301               10                  100-100
   *   x302               10                  101-101
   *   x303               10                  101-101
   *   x304               10                  102-102
   *   x305               10                  102-102
   *   x306               10                  103-103
   *   x307               10                  103-103
   *   x308               10                  104-104
   *   x309               10                  104-104
   *
   */
  createTrailFiles(dir.getAbsolutePath(),
                   TRAIL_FILENAME_PREFIX,
                   100L,
                   _txnPattern.length * numTxnsPerFile,
                   1L,
                   "\n",
                   0,
                   _txnPattern,
                   2 * numTxnsPerFile * 2, // Transactions in 2 files have the same SCN
                   startScn);
  log.info("Directory is: " + dir);
  TrailFilePositionSetter posSetter = null;
  // GoldenGateTransactionSCNFinder finder = new GoldenGateTransactionSCNFinder();
  GGXMLTrailTransactionFinder finder = new GGXMLTrailTransactionFinder();
  posSetter = new TrailFilePositionSetter(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX);
  // SCN 100 is not found because this is the first SCN in the trail file.
  FilePositionResult res = posSetter.locateFilePosition(100, finder);
  Assert.assertEquals(res.getStatus(),
                      FilePositionResult.Status.ERROR,
                      "Result Status for SCN: " + 100 + ", Result: " + res);
  // SCN 101 is found
  res = posSetter.locateFilePosition(101, finder);
  Assert.assertEquals(res.getStatus(), FilePositionResult.Status.FOUND, "Result Status");
  Assert.assertEquals(res.getTxnPos().getFile(), "x302", "File found");
  Assert.assertEquals(res.getTxnPos().getFileOffset(), 0, "File offset found");
  Assert.assertEquals(res.getTxnPos().getLineNumber(), 1, "File line number found");
  Assert.assertEquals(res.getTxnPos().getMinScn(), 101, "MinScn check");
  Assert.assertEquals(res.getTxnPos().getMaxScn(), 101, "MinScn check");
  Assert.assertEquals(res.getTxnPos().getTxnRank(), 10, "Txn Rank");
  // SCN 102 is found
  res = posSetter.locateFilePosition(102, finder);
  Assert.assertEquals(res.getStatus(), FilePositionResult.Status.FOUND, "Result Status");
  Assert.assertEquals(res.getTxnPos().getFile(), "x304", "File found");
  Assert.assertEquals(res.getTxnPos().getFileOffset(), 0, "File offset found");
  Assert.assertEquals(res.getTxnPos().getLineNumber(), 1, "File line number found");
  Assert.assertEquals(res.getTxnPos().getMinScn(), 102, "MinScn check");
  Assert.assertEquals(res.getTxnPos().getMaxScn(), 102, "MinScn check");
  Assert.assertEquals(res.getTxnPos().getTxnRank(), 10, "Txn Rank");
  // SCN 103 is found
  res = posSetter.locateFilePosition(103, finder);
  Assert.assertEquals(res.getStatus(), FilePositionResult.Status.FOUND, "Result Status");
  Assert.assertEquals(res.getTxnPos().getFile(), "x306", "File found");
  Assert.assertEquals(res.getTxnPos().getFileOffset(), 0, "File offset found");
  Assert.assertEquals(res.getTxnPos().getLineNumber(), 1, "File line number found");
  Assert.assertEquals(res.getTxnPos().getMinScn(), 103, "MinScn check");
  Assert.assertEquals(res.getTxnPos().getMaxScn(), 103, "MinScn check");
  Assert.assertEquals(res.getTxnPos().getTxnRank(), 10, "Txn Rank");
  // SCN 104 is found
  res = posSetter.locateFilePosition(104, finder);
  Assert.assertEquals(res.getStatus(), FilePositionResult.Status.FOUND, "Result Status");
  Assert.assertEquals(res.getTxnPos().getFile(), "x308", "File found");
  Assert.assertEquals(res.getTxnPos().getFileOffset(), 0, "File offset found");
  Assert.assertEquals(res.getTxnPos().getLineNumber(), 1, "File line number found");
  Assert.assertEquals(res.getTxnPos().getMinScn(), 104, "MinScn check");
  Assert.assertEquals(res.getTxnPos().getMaxScn(), 104, "MinScn check");
  Assert.assertEquals(res.getTxnPos().getTxnRank(), 10, "Txn Rank");
}