You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/09/27 14:49:06 UTC

[GitHub] [ignite] nizhikov commented on a change in pull request #9398: IGNITE-14355 CDC Metrics

nizhikov commented on a change in pull request #9398:
URL: https://github.com/apache/ignite/pull/9398#discussion_r716767461



##########
File path: modules/core/src/test/java/org/apache/ignite/cdc/AbstractCdcTest.java
##########
@@ -96,29 +183,87 @@ public void addAndWaitForConsumption(
     }
 
     /** */
-    public boolean waitForSize(
+    public void waitForSize(
         int expSz,
         String cacheName,
         CdcSelfTest.ChangeEventType evtType,
-        long timeout,
         TestCdcConsumer<?>... cnsmrs
     ) throws IgniteInterruptedCheckedException {
-        return waitForCondition(
-            () -> {
-                int sum = Arrays.stream(cnsmrs).mapToInt(c -> F.size(c.data(evtType, cacheId(cacheName)))).sum();
-                return sum == expSz;
-            },
-            timeout);
+        assertTrue(waitForCondition(sizePredicate(expSz, cacheName, evtType, cnsmrs), getTestTimeout()));
     }
 
     /** */
-    public CdcConfiguration cdcConfig(CdcConsumer cnsmr) {
-        CdcConfiguration cdcCfg = new CdcConfiguration();
+    protected GridAbsPredicate sizePredicate(
+        int expSz,
+        String cacheName,
+        ChangeEventType evtType,
+        TestCdcConsumer<?>... cnsmrs
+    ) {
+        return () -> {
+            int sum = Arrays.stream(cnsmrs).mapToInt(c -> F.size(c.data(evtType, cacheId(cacheName)))).sum();
+            return sum == expSz;
+        };
+    }
 
-        cdcCfg.setConsumer(cnsmr);
-        cdcCfg.setKeepBinary(false);
+    /** */
+    protected long checkMetrics(CdcMain cdc, int expCnt) throws Exception {
+        if (metricExporters() != null) {
+            IgniteConfiguration cfg = getFieldValue(cdc, "igniteCfg");
+
+            DynamicMBean jmxCdcReg = metricRegistry(cdcInstanceName(cfg.getIgniteInstanceName()), null, "cdc");
+
+            Function<String, ?> jmxVal = m -> {
+                try {
+                    return jmxCdcReg.getAttribute(m);
+                }
+                catch (Exception e) {
+                    throw new IgniteException(e);
+                }
+            };
+
+            checkMetrics(expCnt, (Function<String, Long>)jmxVal, (Function<String, String>)jmxVal);
+        }
+
+        MetricRegistry mreg = getFieldValue(cdc, "mreg");
+
+        assertNotNull(mreg);
+
+        return checkMetrics(
+            expCnt,
+            m -> mreg.<LongMetric>findMetric(m).value(),
+            m -> mreg.<ObjectMetric<String>>findMetric(m).value()
+        );
+    }
+
+    /** */
+    private long checkMetrics(long expCnt, Function<String, Long> longMetric, Function<String, String> strMetric) {
+        long committedSegIdx = longMetric.apply(COMMITTED_SEG_IDX);
+        long curSegIdx = longMetric.apply(CUR_SEG_IDX);
+
+        assertTrue(committedSegIdx <= curSegIdx);
 
-        return cdcCfg;
+        assertTrue(longMetric.apply(COMMITTED_SEG_OFFSET) >= 0);
+        assertTrue(longMetric.apply(LAST_SEG_CONSUMPTION_TIME) > 0);
+
+        assertTrue(longMetric.apply(LAST_EVT_TIME) > 0);
+
+        for (String m : new String[] {BINARY_META_DIR, MARSHALLER_DIR, CDC_DIR})
+            assertTrue(new File(strMetric.apply(m)).exists());
+
+        if (expCnt != -1)

Review comment:
       fixed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org