@Test
public void testSCNRegressionStats() throws Exception
{

  short[] sourceIds = new short[] { 505, 506 };
  String[] sourceNames = new String[] { "source1", "source2" };
  PhysicalSourceStaticConfig pssc =
      buildSimplePssc(sourceIds, sourceNames, "gg:///tmp:xxx");
  DbusEventBufferAppendable mb = createBufMult(pssc);
  // start producer
  GoldenGateEventProducer gg = new GoldenGateEventProducer(pssc, null, mb, null, null);
  Object handleXmlCallbackObject = getHandleXmlCallbackInnerInstance(gg);
  Method method = getOnTransactionEndMethod();
  // generates the updates
  List<String> keys = new ArrayList<String>();
  keys.add("key1");
  GGParserStatistics ggParserStats = gg.getParserStats();
  // SCN = 10
  long timestamp = System.currentTimeMillis() * DbusConstants.NUM_NSECS_IN_MSEC;
  List<TransactionState.PerSourceTransactionalUpdate> dbUpdates1 =
      generateUpdates(sourceIds, keys, 10);
  method.invoke(handleXmlCallbackObject, new Object[] { dbUpdates1,
      new TransactionInfo(0, 0, timestamp, 10) });
  timestamp = System.currentTimeMillis() * DbusConstants.NUM_NSECS_IN_MSEC + 1;
  Assert.assertEquals("NumSCNRegressions", 0, ggParserStats.getNumSCNRegressions());
  Assert.assertEquals("NumSCNRegressions", -1, ggParserStats.getLastRegressedScn());
  Assert.assertEquals("MaxScn", 10, ggParserStats.getMaxScn());
  // SCN = 5 Regression
  List<TransactionState.PerSourceTransactionalUpdate> dbUpdates2 =
      generateUpdates(sourceIds, keys, 5); // SCN Regression here
  method.invoke(handleXmlCallbackObject, new Object[] { dbUpdates2,
      new TransactionInfo(0, 0, timestamp + 1, 5) });
  Assert.assertEquals("NumSCNRegressions", 1, ggParserStats.getNumSCNRegressions());
  Assert.assertEquals("NumSCNRegressions", 5, ggParserStats.getLastRegressedScn());
  Assert.assertEquals("MaxScn", 10, ggParserStats.getMaxScn());
  // SCN = 6 No Regression here
  dbUpdates2 = generateUpdates(sourceIds, keys, 6);
  method.invoke(handleXmlCallbackObject, new Object[] { dbUpdates2,
      new TransactionInfo(0, 0, timestamp + 1, 6) });
  Assert.assertEquals("NumSCNRegressions", 1, ggParserStats.getNumSCNRegressions());
  Assert.assertEquals("NumSCNRegressions", 5, ggParserStats.getLastRegressedScn());
  Assert.assertEquals("MaxScn", 10, ggParserStats.getMaxScn());
  // SCN = 3 : SCN regression again
  dbUpdates2 = generateUpdates(sourceIds, keys, 3);
  method.invoke(handleXmlCallbackObject, new Object[] { dbUpdates2,
      new TransactionInfo(0, 0, timestamp + 1, 3) });
  Assert.assertEquals("NumSCNRegressions", 2, ggParserStats.getNumSCNRegressions());
  Assert.assertEquals("NumSCNRegressions", 3, ggParserStats.getLastRegressedScn());
  Assert.assertEquals("MaxScn", 10, ggParserStats.getMaxScn());
  // SCN = 11: No regression here
  dbUpdates2 = generateUpdates(sourceIds, keys, 11);
  method.invoke(handleXmlCallbackObject, new Object[] { dbUpdates2,
      new TransactionInfo(0, 0, timestamp + 1, 11) });
  Assert.assertEquals("NumSCNRegressions", 2, ggParserStats.getNumSCNRegressions());
  Assert.assertEquals("NumSCNRegressions", 3, ggParserStats.getLastRegressedScn());
  Assert.assertEquals("MaxScn", 11, ggParserStats.getMaxScn());
}