From fcf7e89f13e8e4a73edb5c2f33c4a5e1ab7359f9 Mon Sep 17 00:00:00 2001 From: Maksim Davydov Date: Sun, 12 Jan 2025 15:20:11 +0300 Subject: [PATCH] IGNITE-23901 * tests cases separated --- .../processors/cache/GridCacheAdapter.java | 18 ++-- .../performancestatistics/OperationType.java | 2 +- .../PerformanceStatisticsThinClientTest.java | 101 ++++++++++++------ 3 files changed, 78 insertions(+), 43 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java index b3c87a7d0e92b..ee50797be319c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java @@ -1969,9 +1969,9 @@ protected boolean put0(final K key, final V val, final CacheEntryPredicate filte return; final boolean statsEnabled = ctx.statisticsEnabled(); - boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled(); + final boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled(); - long start = statsEnabled || performanceStatsEnabled ? System.nanoTime() : 0L; + final long start = (statsEnabled || performanceStatsEnabled) ? System.nanoTime() : 0L; ctx.dr().onReceiveCacheEntriesReceived(drMap.size()); @@ -1999,9 +1999,9 @@ protected boolean put0(final K key, final V val, final CacheEntryPredicate filte return new GridFinishedFuture(); final boolean statsEnabled = ctx.statisticsEnabled(); - boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled(); + final boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled(); - long start = statsEnabled || performanceStatsEnabled ? System.nanoTime() : 0L; + final long start = (statsEnabled || performanceStatsEnabled) ? System.nanoTime() : 0L; ctx.dr().onReceiveCacheEntriesReceived(drMap.size()); @@ -2846,10 +2846,10 @@ protected IgniteInternalFuture removeAsync0(final K key, @Nullable fina if (F.isEmpty(drMap)) return; - boolean statsEnabled = ctx.statisticsEnabled(); - boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled(); + final boolean statsEnabled = ctx.statisticsEnabled(); + final boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled(); - long start = statsEnabled || performanceStatsEnabled ? System.nanoTime() : 0L; + final long start = (statsEnabled || performanceStatsEnabled) ? System.nanoTime() : 0L; ctx.dr().onReceiveCacheEntriesReceived(drMap.size()); @@ -2877,9 +2877,9 @@ protected IgniteInternalFuture removeAsync0(final K key, @Nullable fina return new GridFinishedFuture(); final boolean statsEnabled = ctx.statisticsEnabled(); - boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled(); + final boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled(); - final long start = statsEnabled || performanceStatsEnabled ? System.nanoTime() : 0L; + final long start = (statsEnabled || performanceStatsEnabled) ? System.nanoTime() : 0L; ctx.dr().onReceiveCacheEntriesReceived(drMap.size()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/OperationType.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/OperationType.java index 2df58146ef7d7..3337f804a6165 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/OperationType.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/OperationType.java @@ -96,7 +96,7 @@ public enum OperationType { /** Cache put all conflict. */ CACHE_PUT_ALL_CONFLICT(22), - /** Cache put all conflict. */ + /** Cache remove all conflict. */ CACHE_REMOVE_ALL_CONFLICT(23); /** Cache operations. */ diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsThinClientTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsThinClientTest.java index c05c6452ca04f..3b672fa6a1510 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsThinClientTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsThinClientTest.java @@ -21,8 +21,8 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.Set; import java.util.UUID; +import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; import org.apache.ignite.Ignition; @@ -176,10 +176,75 @@ public void testCacheOperation() throws Exception { checkCacheOperation(CACHE_REMOVE_ALL, cache -> cache.removeAll(Collections.singleton(3))); checkCacheOperation(CACHE_GET_AND_REMOVE, cache -> cache.getAndRemove(5)); + } + + /** + * Cache {@link TcpClientCache#putAllConflict} operation performed. + * @throws Exception If failed. + */ + @Test + public void testCachePutAllConflict() throws Exception { + checkCacheAllConflictOperations(CACHE_PUT_ALL_CONFLICT, false); + } + + /** + * Cache {@link TcpClientCache#removeAllConflict} operation performed. + * @throws Exception If failed. + */ + @Test + public void testCacheRemoveAllConflict() throws Exception { + checkCacheAllConflictOperations(CACHE_REMOVE_ALL_CONFLICT, false); + } + + /** + * Cache {@link TcpClientCache#putAllConflictAsync} operation performed. + * @throws Exception If failed. + */ + @Test + public void testCachePutAllConflictAsync() throws Exception { + checkCacheAllConflictOperations(CACHE_PUT_ALL_CONFLICT, true); + } + + /** + * Cache {@link TcpClientCache#removeAllConflictAsync} operation performed. + * @throws Exception If failed. + */ + @Test + public void testCacheRemoveAllConflictAsync() throws Exception { + checkCacheAllConflictOperations(CACHE_REMOVE_ALL_CONFLICT, true); + } + + /** + * @param isAsync boolean flag for asynchronous cache operation processing. + */ + private void checkCacheAllConflictOperations(OperationType opType, boolean isAsync) throws Exception { + int key = 6; + int val = 1; + + GridCacheVersion confl = new GridCacheVersion(1, 0, 1, (byte)2); - checkCacheOperation(CACHE_PUT_ALL_CONFLICT, putAllConflict(Collections.singletonMap(6, 1))); + Map> putMap = F.asMap(key, new T3<>(val, confl, CU.EXPIRE_TIME_ETERNAL)); + Map rmvMap = F.asMap(key, confl); - checkCacheOperation(CACHE_REMOVE_ALL_CONFLICT, removeAllConflict(Collections.singleton(6))); + if (!isAsync) { + if (opType.equals(CACHE_PUT_ALL_CONFLICT)) + checkCacheOperation(opType, cache -> ((TcpClientCache)cache).putAllConflict(putMap)); + else if (opType.equals(CACHE_REMOVE_ALL_CONFLICT)) + checkCacheOperation(opType, cache -> ((TcpClientCache)cache).removeAllConflict(rmvMap)); + } + else { + checkCacheOperation(opType, cache -> { + try { + if (opType.equals(CACHE_PUT_ALL_CONFLICT)) + ((TcpClientCache)cache).putAllConflictAsync(putMap).get(); + else if (opType.equals(CACHE_REMOVE_ALL_CONFLICT)) + ((TcpClientCache)cache).removeAllConflictAsync(rmvMap).get(); + } + catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }); + } } /** Checks cache operation. */ @@ -210,36 +275,6 @@ private void checkCacheOperation(OperationType op, Consumer}. - */ - private Consumer> putAllConflict(Map map) { - Map> drMap = new HashMap<>(); - - GridCacheVersion confl = new GridCacheVersion(1, 0, 1, (byte)2); - - map.forEach((key, value) -> drMap.put(key, new T3<>(value, confl, CU.EXPIRE_TIME_ETERNAL))); - - return cache -> ((TcpClientCache)cache).putAllConflict(drMap); - } - - /** - * Cache {@link TcpClientCache#putAllConflict} operation perfomed - * @param keys {@link Set} with keys for cache remove all. - * @return cache {@link Consumer}. - */ - private Consumer> removeAllConflict(Set keys) { - Map drMap = new HashMap<>(); - - GridCacheVersion confl = new GridCacheVersion(1, 0, 1, (byte)2); - - keys.forEach(key -> drMap.put(key, confl)); - - return cache -> ((TcpClientCache)cache).removeAllConflict(drMap); - } - /** @throws Exception If failed. */ @Test public void testTransaction() throws Exception {