reddycharan commented on a change in pull request #1902: Metadata checker 
validating EnsemblePlacementpolicy
URL: https://github.com/apache/bookkeeper/pull/1902#discussion_r251637523
 
 

 ##########
 File path: 
bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/AuditorPeriodicCheckTest.java
 ##########
 @@ -454,7 +457,100 @@ void 
validateInitialDelayOfCheckAllLedgers(LedgerUnderreplicationManager urm, lo
         auditor.close();
     }
 
-    class TestAuditor extends Auditor {
+    @Test
+    public void testInitialDelayOfMetadataCheck() throws Exception {
+        for (AuditorElector e : auditorElectors.values()) {
+            e.shutdown();
+        }
+
+        final int numLedgers = 10;
+        List<Long> ids = new LinkedList<Long>();
+        for (int i = 0; i < numLedgers; i++) {
+            LedgerHandle lh = bkc.createLedger(3, 3, DigestType.CRC32, 
"passwd".getBytes());
+            ids.add(lh.getId());
+            for (int j = 0; j < 2; j++) {
+                lh.addEntry("testdata".getBytes());
+            }
+            lh.close();
+        }
+
+        LedgerManagerFactory mFactory = driver.getLedgerManagerFactory();
+        LedgerUnderreplicationManager urm = 
mFactory.newLedgerUnderreplicationManager();
+
+        ServerConfiguration servConf = new ServerConfiguration(bsConfs.get(0));
+        validateInitialDelayOfMetadataCheck(urm, -1, 1000, servConf, bkc);
+        validateInitialDelayOfMetadataCheck(urm, 999, 1000, servConf, bkc);
+        validateInitialDelayOfMetadataCheck(urm, 1001, 1000, servConf, bkc);
+    }
+
+    void validateInitialDelayOfMetadataCheck(LedgerUnderreplicationManager 
urm, long timeSinceLastExecutedInSecs,
+            long auditorPeriodicMetadataCheckInterval, ServerConfiguration 
servConf, BookKeeper bkc)
+            throws UnavailableException, UnknownHostException, 
InterruptedException {
+        TestStatsProvider statsProvider = new TestStatsProvider();
+        TestStatsLogger statsLogger = 
statsProvider.getStatsLogger(AUDITOR_SCOPE);
+        TestOpStatsLogger metadataCheckStatsLogger = (TestOpStatsLogger) 
statsLogger
+                .getOpStatsLogger(ReplicationStats.METADATA_CHECK_TIME);
+        
servConf.setAuditorPeriodicMetadataCheckInterval(auditorPeriodicMetadataCheckInterval);
+        servConf.setAuditorPeriodicCheckInterval(0);
+        servConf.setAuditorPeriodicBookieCheckInterval(0);
+        final TestAuditor auditor = new 
TestAuditor(Bookie.getBookieAddress(servConf).toString(), servConf, bkc, false,
+                statsLogger);
+        CountDownLatch latch = auditor.getLatch();
+        assertEquals("METADATA_CHECK_TIME SuccessCount", 0, 
metadataCheckStatsLogger.getSuccessCount());
+        long curTimeBeforeStart = System.currentTimeMillis();
+        long metadataCheckCTime = -1;
+        long initialDelayInMsecs = -1;
+        long nextExpectedMetadataCheckExecutionTime = -1;
+        long bufferTimeInMsecs = 12000L;
+        if (timeSinceLastExecutedInSecs == -1) {
+            /*
+             * if we are setting metadataCheckCTime to -1, it means that
+             * metadataCheck hasn't run before. So initialDelay for
+             * metadataCheck should be 0.
+             */
+            metadataCheckCTime = -1;
+            initialDelayInMsecs = 0;
+        } else {
+            metadataCheckCTime = curTimeBeforeStart - 
timeSinceLastExecutedInSecs * 1000L;
+            initialDelayInMsecs = timeSinceLastExecutedInSecs > 
auditorPeriodicMetadataCheckInterval ? 0
+                    : (auditorPeriodicMetadataCheckInterval - 
timeSinceLastExecutedInSecs) * 1000L;
+        }
+        /*
+         * next metadataCheck should happen atleast after
+         * nextExpectedMetadataCheckExecutionTime.
+         */
+        nextExpectedMetadataCheckExecutionTime = curTimeBeforeStart + 
initialDelayInMsecs;
+
+        urm.setMetadataCheckCTime(metadataCheckCTime);
+        auditor.start();
+        /*
+         * since auditorPeriodicMetadataCheckInterval are higher values (in the
+         * order of 100s of seconds), its ok bufferTimeInMsecs to be ` 10 secs.
+         */
+        assertTrue("metadataCheck should have executed with initialDelay " + 
initialDelayInMsecs,
+                latch.await(initialDelayInMsecs + bufferTimeInMsecs, 
TimeUnit.MILLISECONDS));
+        for (int i = 0; i < 10; i++) {
 
 Review comment:
   can increase the timeout period.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to