Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-vinogradov committed Aug 12, 2024
1 parent 2330bb1 commit dfe3257
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,19 +47,18 @@
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;

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.
Expand Down Expand Up @@ -91,12 +91,12 @@ public static Collection<?> parameters() {
/** */
private static IgniteInternalCache<BinaryObject, BinaryObject> 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();

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
}

/** */
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
}

/**
Expand Down

0 comments on commit dfe3257

Please sign in to comment.