From dfe3257ab15f44b556e4196fc9887ec0835d61b2 Mon Sep 17 00:00:00 2001 From: Anton Vinogradov Date: Mon, 12 Aug 2024 20:22:38 +0300 Subject: [PATCH] WIP --- .../CacheConflictOperationsAbstractTest.java | 68 ++++++++++--------- ...flictOperationsWithCustomResolverTest.java | 5 +- 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/modules/cdc-ext/src/test/java/org/apache/ignite/cdc/CacheConflictOperationsAbstractTest.java b/modules/cdc-ext/src/test/java/org/apache/ignite/cdc/CacheConflictOperationsAbstractTest.java index cfe82b90..7bed4ed3 100644 --- a/modules/cdc-ext/src/test/java/org/apache/ignite/cdc/CacheConflictOperationsAbstractTest.java +++ b/modules/cdc-ext/src/test/java/org/apache/ignite/cdc/CacheConflictOperationsAbstractTest.java @@ -31,6 +31,7 @@ import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.cache.CacheEntry; import org.apache.ignite.cache.CacheEntryVersion; +import org.apache.ignite.cdc.conflictresolve.CacheVersionConflictResolverImpl; import org.apache.ignite.cdc.conflictresolve.CacheVersionConflictResolverPluginProvider; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; @@ -46,9 +47,11 @@ import org.apache.ignite.internal.processors.cache.version.CacheVersionConflictResolver; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.processors.cache.version.GridCacheVersionEx; -import org.apache.ignite.internal.processors.metric.MetricRegistryImpl; -import org.apache.ignite.internal.processors.metric.impl.LongAdderMetric; +import org.apache.ignite.testframework.ListeningTestLogger; +import org.apache.ignite.testframework.LogListener; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.config.Configurator; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -56,9 +59,6 @@ import static java.util.Collections.singletonMap; import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; -import static org.apache.ignite.cdc.conflictresolve.CacheConflictResolutionManagerImpl.CONFLICT_RESOLVER_METRICS_REGISTRY_NAME; -import static org.apache.ignite.cdc.conflictresolve.CacheVersionConflictResolverImpl.ACCEPTED_EVENTS_CNT; -import static org.apache.ignite.cdc.conflictresolve.CacheVersionConflictResolverImpl.REJECTED_EVENTS_CNT; /** * Cache conflict operations test. @@ -91,12 +91,12 @@ public static Collection parameters() { /** */ private static IgniteInternalCache cachex; - /** */ - private static IgniteEx ign; - /** */ private static IgniteEx client; + /** Listening test logger. */ + private static final ListeningTestLogger listeningLog = new ListeningTestLogger(log); + /** */ private static final AtomicInteger incKey = new AtomicInteger(); @@ -126,13 +126,14 @@ public static Collection parameters() { pluginCfg.setCaches(new HashSet<>(Collections.singleton(DEFAULT_CACHE_NAME))); pluginCfg.setConflictResolveField(conflictResolveField()); - return super.getConfiguration(igniteInstanceName).setPluginProviders(pluginCfg); + return super.getConfiguration(igniteInstanceName) + .setPluginProviders(pluginCfg) + .setGridLogger(listeningLog); } /** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { - ign = startGrid(1); - + startGrid(1); client = startClientGrid(2); } @@ -157,25 +158,41 @@ public static Collection parameters() { cachex = client.cachex(DEFAULT_CACHE_NAME); } - ign.context().metric().registry(CONFLICT_RESOLVER_METRICS_REGISTRY_NAME).reset(); - assert !removeAfterRemove; } - /** */ + /** Test switching debug log level for ConflictResolver during runtime */ @Test - public void testMetrics() throws Exception { + public void testResolveDebug() throws Exception { String key = nextKey(); - checkMetrics(0, 0); + LogListener lsnr = LogListener.matches("isUseNew").build(); + + listeningLog.registerListener(lsnr); + + try { + Configurator.setLevel(CacheVersionConflictResolverImpl.class.getName(), Level.DEBUG); - putFromOther(key, 1, true); + try { + putFromOther(key, 1, true); - checkMetrics(1, 0); + putFromOther(key, 1, false); - putFromOther(key, 1, false); + assertTrue(lsnr.check()); + } + finally { + Configurator.setLevel(CacheVersionConflictResolverImpl.class.getName(), Level.INFO); + } - checkMetrics(1, 1); + lsnr.reset(); + + putFromOther(key, 1, false); + + assertFalse(lsnr.check()); + } + finally { + listeningLog.unregisterListener(lsnr); + } } /** */ @@ -296,17 +313,6 @@ protected String nextKey() { return "Key_" + incKey.incrementAndGet() + "_" + otherClusterId + "_" + cacheMode; } - /** Checks metrics for conflict resolver. */ - protected void checkMetrics(int acceptedCnt, int rejectedCnt) { - MetricRegistryImpl mreg = ign.context().metric().registry(CONFLICT_RESOLVER_METRICS_REGISTRY_NAME); - - assertNotNull(mreg.findMetric(ACCEPTED_EVENTS_CNT)); - assertNotNull(mreg.findMetric(REJECTED_EVENTS_CNT)); - - assertEquals(acceptedCnt, ((LongAdderMetric)mreg.findMetric(ACCEPTED_EVENTS_CNT)).value()); - assertEquals(rejectedCnt, ((LongAdderMetric)mreg.findMetric(REJECTED_EVENTS_CNT)).value()); - } - /** */ protected String conflictResolveField() { return null; diff --git a/modules/cdc-ext/src/test/java/org/apache/ignite/cdc/CacheConflictOperationsWithCustomResolverTest.java b/modules/cdc-ext/src/test/java/org/apache/ignite/cdc/CacheConflictOperationsWithCustomResolverTest.java index c250911c..83a9abe0 100644 --- a/modules/cdc-ext/src/test/java/org/apache/ignite/cdc/CacheConflictOperationsWithCustomResolverTest.java +++ b/modules/cdc-ext/src/test/java/org/apache/ignite/cdc/CacheConflictOperationsWithCustomResolverTest.java @@ -62,8 +62,9 @@ public void testSimpleConflicts() throws IgniteCheckedException { /** {@inheritDoc} */ @Test - @Override public void testMetrics() throws Exception { - // TODO current implementation does not support metrics for custom resolvers. + @Override public void testResolveDebug() throws Exception { + // LWW strategy resolves conflicts in unexpected way at versioned resolve test. + GridTestUtils.assertThrows(log, super::testResolveDebug, AssertionError.class, ""); } /**