3131import org .apache .ignite .cache .CacheAtomicityMode ;
3232import org .apache .ignite .cache .CacheEntry ;
3333import org .apache .ignite .cache .CacheEntryVersion ;
34+ import org .apache .ignite .cdc .conflictresolve .CacheVersionConflictResolverImpl ;
3435import org .apache .ignite .cdc .conflictresolve .CacheVersionConflictResolverPluginProvider ;
3536import org .apache .ignite .configuration .CacheConfiguration ;
3637import org .apache .ignite .configuration .IgniteConfiguration ;
4647import org .apache .ignite .internal .processors .cache .version .CacheVersionConflictResolver ;
4748import org .apache .ignite .internal .processors .cache .version .GridCacheVersion ;
4849import org .apache .ignite .internal .processors .cache .version .GridCacheVersionEx ;
49- import org .apache .ignite .internal . processors . metric . MetricRegistryImpl ;
50- import org .apache .ignite .internal . processors . metric . impl . LongAdderMetric ;
50+ import org .apache .ignite .testframework . ListeningTestLogger ;
51+ import org .apache .ignite .testframework . LogListener ;
5152import org .apache .ignite .testframework .junits .common .GridCommonAbstractTest ;
53+ import org .apache .logging .log4j .Level ;
54+ import org .apache .logging .log4j .core .config .Configurator ;
5255import org .junit .Test ;
5356import org .junit .runner .RunWith ;
5457import org .junit .runners .Parameterized ;
5558
5659import static java .util .Collections .singletonMap ;
5760import static org .apache .ignite .cache .CacheAtomicityMode .ATOMIC ;
5861import static org .apache .ignite .cache .CacheAtomicityMode .TRANSACTIONAL ;
59- import static org .apache .ignite .cdc .conflictresolve .CacheConflictResolutionManagerImpl .CONFLICT_RESOLVER_METRICS_REGISTRY_NAME ;
60- import static org .apache .ignite .cdc .conflictresolve .CacheVersionConflictResolverImpl .ACCEPTED_EVENTS_CNT ;
61- import static org .apache .ignite .cdc .conflictresolve .CacheVersionConflictResolverImpl .REJECTED_EVENTS_CNT ;
6262
6363/**
6464 * Cache conflict operations test.
@@ -91,12 +91,12 @@ public static Collection<?> parameters() {
9191 /** */
9292 private static IgniteInternalCache <BinaryObject , BinaryObject > cachex ;
9393
94- /** */
95- private static IgniteEx ign ;
96-
9794 /** */
9895 private static IgniteEx client ;
9996
97+ /** Listening test logger. */
98+ private static final ListeningTestLogger listeningLog = new ListeningTestLogger (log );
99+
100100 /** */
101101 private static final AtomicInteger incKey = new AtomicInteger ();
102102
@@ -126,13 +126,14 @@ public static Collection<?> parameters() {
126126 pluginCfg .setCaches (new HashSet <>(Collections .singleton (DEFAULT_CACHE_NAME )));
127127 pluginCfg .setConflictResolveField (conflictResolveField ());
128128
129- return super .getConfiguration (igniteInstanceName ).setPluginProviders (pluginCfg );
129+ return super .getConfiguration (igniteInstanceName )
130+ .setPluginProviders (pluginCfg )
131+ .setGridLogger (listeningLog );
130132 }
131133
132134 /** {@inheritDoc} */
133135 @ Override protected void beforeTestsStarted () throws Exception {
134- ign = startGrid (1 );
135-
136+ startGrid (1 );
136137 client = startClientGrid (2 );
137138 }
138139
@@ -157,25 +158,41 @@ public static Collection<?> parameters() {
157158 cachex = client .cachex (DEFAULT_CACHE_NAME );
158159 }
159160
160- ign .context ().metric ().registry (CONFLICT_RESOLVER_METRICS_REGISTRY_NAME ).reset ();
161-
162161 assert !removeAfterRemove ;
163162 }
164163
165- /** */
164+ /** Test switching debug log level for ConflictResolver during runtime */
166165 @ Test
167- public void testMetrics () throws Exception {
166+ public void testResolveDebug () throws Exception {
168167 String key = nextKey ();
169168
170- checkMetrics (0 , 0 );
169+ LogListener lsnr = LogListener .matches ("isUseNew" ).build ();
170+
171+ listeningLog .registerListener (lsnr );
172+
173+ try {
174+ Configurator .setLevel (CacheVersionConflictResolverImpl .class .getName (), Level .DEBUG );
171175
172- putFromOther (key , 1 , true );
176+ try {
177+ putFromOther (key , 1 , true );
173178
174- checkMetrics ( 1 , 0 );
179+ putFromOther ( key , 1 , false );
175180
176- putFromOther (key , 1 , false );
181+ assertTrue (lsnr .check ());
182+ }
183+ finally {
184+ Configurator .setLevel (CacheVersionConflictResolverImpl .class .getName (), Level .INFO );
185+ }
177186
178- checkMetrics (1 , 1 );
187+ lsnr .reset ();
188+
189+ putFromOther (key , 1 , false );
190+
191+ assertFalse (lsnr .check ());
192+ }
193+ finally {
194+ listeningLog .unregisterListener (lsnr );
195+ }
179196 }
180197
181198 /** */
@@ -296,17 +313,6 @@ protected String nextKey() {
296313 return "Key_" + incKey .incrementAndGet () + "_" + otherClusterId + "_" + cacheMode ;
297314 }
298315
299- /** Checks metrics for conflict resolver. */
300- protected void checkMetrics (int acceptedCnt , int rejectedCnt ) {
301- MetricRegistryImpl mreg = ign .context ().metric ().registry (CONFLICT_RESOLVER_METRICS_REGISTRY_NAME );
302-
303- assertNotNull (mreg .findMetric (ACCEPTED_EVENTS_CNT ));
304- assertNotNull (mreg .findMetric (REJECTED_EVENTS_CNT ));
305-
306- assertEquals (acceptedCnt , ((LongAdderMetric )mreg .findMetric (ACCEPTED_EVENTS_CNT )).value ());
307- assertEquals (rejectedCnt , ((LongAdderMetric )mreg .findMetric (REJECTED_EVENTS_CNT )).value ());
308- }
309-
310316 /** */
311317 protected String conflictResolveField () {
312318 return null ;
0 commit comments