BootstrapSCNProcessor { public boolean shouldBypassSnapshot(long sinceScn, long startScn, List<SourceStatusInfo> srcList) throws SQLException, BootstrapProcessingException { if ((srcList == null) || (srcList.isEmpty())) return false; if ( sinceScn <= 0 ) { LOG.info("Client requesting from SCN (" + sinceScn + "). Bootstrap Snapshot will not be bypassed !!"); return false; } for (SourceStatusInfo pair: srcList) { boolean disableSnapshotBypass = _config.isBypassSnapshotDisabled(pair.getSrcName()); if ( disableSnapshotBypass) return false; boolean canCatchupFromLog = validateIfCanCatchupFromLog(sinceScn, startScn, pair.getSrcId()); if (! canCatchupFromLog) return false; long threshold = _config.getRowsThresholdForSnapshotBypass(pair.getSrcName()); if ( threshold == Long.MAX_VALUE) { continue; } long currRows = getRowDiff(sinceScn, startScn, pair.getSrcId()); if (currRows > threshold) { LOG.info("Threshold check failed for source (" + pair.getSrcName() + ") Threshold:" + threshold + ",Approx Rows:" + currRows ); return false; } } return true; } BootstrapSCNProcessor(BootstrapServerStaticConfig config,
              DbusEventsStatisticsCollector curStatsCollector); protected  BootstrapSCNProcessor(); boolean shouldBypassSnapshot(long sinceScn, long startScn, List<SourceStatusInfo> srcList); long getMinApplierWindowScn(long sinceScn, List<SourceStatusInfo> sourceList); long getSourceTargetScn(int srcId); BootstrapDBMetaDataDAO getBootstrapMetaDataDAO(); List<SourceStatusInfo> getSourceIdAndStatusFromName(List<String> sourceList); SourceStatusInfo getSrcIdStatusFromDB(String source, boolean activeCheck); void shutdown(); static final String MODULE; static final Logger LOG; final static long START_SCN_QUERY_WAIT_TIME; final static long QUERY_WAIT_TIME_SLICE; final static String START_SCN_STMT_SQL_PREFIX; final static String START_SCN_STMT_SQL_SUFFIX; final static String PRODUCER_SCN_STMT_SQL_PREFIX; final static String PRODUCER_SCN_STMT_SQL_SUFFIX; }
@Test public void testShouldBypassSnapshot() throws SQLException, BootstrapProcessingException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException { BootstrapSCNProcessor bsp = new BootstrapSCNProcessor(); Long defaultRowsThresholdForSnapshotBypass = Long.MAX_VALUE; Map<String, Long> rowsThresholdForSnapshotBypass = new HashMap<String, Long>(); Map<String, Boolean> disableSnapshotBypass = new HashMap<String, Boolean>(); boolean predicatePushDown = false; Map<String, Boolean> predicatePushDownBypass = new HashMap<String, Boolean>(); int queryTimeoutInSec = 10; BootstrapReadOnlyConfig db = null; boolean enableMinScnCheck=false; final long longestDbTxnTimeMins = 240L; BootstrapServerStaticConfig bssc = new BootstrapServerStaticConfig(defaultRowsThresholdForSnapshotBypass, rowsThresholdForSnapshotBypass, disableSnapshotBypass, predicatePushDown, predicatePushDownBypass, queryTimeoutInSec, enableMinScnCheck, db, longestDbTxnTimeMins); Field field = bsp.getClass().getDeclaredField("_config"); field.setAccessible(true); field.set(bsp, bssc); int srcId = 101; long sinceScn = 5; long startScn = 10; BootstrapDBMetaDataDAO bmdd = EasyMock.createMock(BootstrapDBMetaDataDAO.class); EasyMock.expect(bmdd.getLogIdToCatchup(srcId, startScn)).andReturn(0).anyTimes(); EasyMock.expect(bmdd.getLogIdToCatchup(srcId, sinceScn)).andReturn(0).anyTimes(); EasyMock.replay(bmdd); Field dbDaoField = bsp.getClass().getDeclaredField("_dbDao"); dbDaoField.setAccessible(true); dbDaoField.set(bsp, bmdd); List<SourceStatusInfo> srcList = new ArrayList<SourceStatusInfo>(); String name = "foo"; SourceStatusInfo ssi = new SourceStatusInfo(name, srcId, 4); srcList.add(ssi); boolean sbs = bsp.shouldBypassSnapshot(sinceScn, startScn, srcList); Assert.assertEquals(true, sbs); rowsThresholdForSnapshotBypass.put(name, Long.MAX_VALUE); BootstrapServerStaticConfig bssc2 = new BootstrapServerStaticConfig(defaultRowsThresholdForSnapshotBypass, rowsThresholdForSnapshotBypass, disableSnapshotBypass, predicatePushDown, predicatePushDownBypass, queryTimeoutInSec, enableMinScnCheck, db, longestDbTxnTimeMins); field.set(bsp, bssc2); sbs = bsp.shouldBypassSnapshot(sinceScn, startScn, srcList); Assert.assertEquals(true, sbs); BootstrapDBMetaDataDAO bmdd2 = EasyMock.createMock(BootstrapDBMetaDataDAO.class); EasyMock.expect(bmdd2.getLogIdToCatchup(srcId, startScn)).andReturn(2).anyTimes(); EasyMock.expect(bmdd2.getLogIdToCatchup(srcId, sinceScn)).andThrow(new BootstrapProcessingException("")); EasyMock.replay(bmdd2); Field dbDaoField2 = bsp.getClass().getDeclaredField("_dbDao"); dbDaoField2.setAccessible(true); dbDaoField2.set(bsp, bmdd2); sbs = bsp.shouldBypassSnapshot(sinceScn, startScn, srcList); Assert.assertEquals(false, sbs); }