Skip to content

Commit ebfdfd8

Browse files
committed
* tests for async all conflict operations * test refactored
1 parent 12cdc48 commit ebfdfd8

File tree

3 files changed

+65
-43
lines changed

3 files changed

+65
-43
lines changed

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -1975,9 +1975,9 @@ protected boolean put0(final K key, final V val, final CacheEntryPredicate filte
19751975
return;
19761976

19771977
final boolean statsEnabled = ctx.statisticsEnabled();
1978-
boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled();
1978+
final boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled();
19791979

1980-
long start = statsEnabled || performanceStatsEnabled ? System.nanoTime() : 0L;
1980+
final long start = (statsEnabled || performanceStatsEnabled) ? System.nanoTime() : 0L;
19811981

19821982
ctx.dr().onReceiveCacheEntriesReceived(drMap.size());
19831983

@@ -2005,9 +2005,9 @@ protected boolean put0(final K key, final V val, final CacheEntryPredicate filte
20052005
return new GridFinishedFuture<Object>();
20062006

20072007
final boolean statsEnabled = ctx.statisticsEnabled();
2008-
boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled();
2008+
final boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled();
20092009

2010-
long start = statsEnabled || performanceStatsEnabled ? System.nanoTime() : 0L;
2010+
final long start = (statsEnabled || performanceStatsEnabled) ? System.nanoTime() : 0L;
20112011

20122012
ctx.dr().onReceiveCacheEntriesReceived(drMap.size());
20132013

@@ -2852,10 +2852,10 @@ protected IgniteInternalFuture<Boolean> removeAsync0(final K key, @Nullable fina
28522852
if (F.isEmpty(drMap))
28532853
return;
28542854

2855-
boolean statsEnabled = ctx.statisticsEnabled();
2856-
boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled();
2855+
final boolean statsEnabled = ctx.statisticsEnabled();
2856+
final boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled();
28572857

2858-
long start = statsEnabled || performanceStatsEnabled ? System.nanoTime() : 0L;
2858+
final long start = (statsEnabled || performanceStatsEnabled) ? System.nanoTime() : 0L;
28592859

28602860
ctx.dr().onReceiveCacheEntriesReceived(drMap.size());
28612861

@@ -2883,9 +2883,9 @@ protected IgniteInternalFuture<Boolean> removeAsync0(final K key, @Nullable fina
28832883
return new GridFinishedFuture<Object>();
28842884

28852885
final boolean statsEnabled = ctx.statisticsEnabled();
2886-
boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled();
2886+
final boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled();
28872887

2888-
final long start = statsEnabled || performanceStatsEnabled ? System.nanoTime() : 0L;
2888+
final long start = (statsEnabled || performanceStatsEnabled) ? System.nanoTime() : 0L;
28892889

28902890
ctx.dr().onReceiveCacheEntriesReceived(drMap.size());
28912891

modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/OperationType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public enum OperationType {
9696
/** Cache put all conflict. */
9797
CACHE_PUT_ALL_CONFLICT(22),
9898

99-
/** Cache put all conflict. */
99+
/** Cache remove all conflict. */
100100
CACHE_REMOVE_ALL_CONFLICT(23);
101101

102102
/** Cache operations. */

modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsThinClientTest.java

+55-33
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import java.util.Collections;
2222
import java.util.HashMap;
2323
import java.util.Map;
24-
import java.util.Set;
2524
import java.util.UUID;
25+
import java.util.concurrent.ExecutionException;
2626
import java.util.concurrent.atomic.AtomicInteger;
2727
import java.util.function.Consumer;
2828
import org.apache.ignite.Ignition;
@@ -176,10 +176,62 @@ public void testCacheOperation() throws Exception {
176176
checkCacheOperation(CACHE_REMOVE_ALL, cache -> cache.removeAll(Collections.singleton(3)));
177177

178178
checkCacheOperation(CACHE_GET_AND_REMOVE, cache -> cache.getAndRemove(5));
179+
}
179180

180-
checkCacheOperation(CACHE_PUT_ALL_CONFLICT, putAllConflict(Collections.singletonMap(6, 1)));
181+
/**
182+
* Cache {@link TcpClientCache#putAllConflict} and {@link TcpClientCache#removeAllConflict} operations performed.
183+
* @throws Exception If failed.
184+
*/
185+
@Test
186+
public void testCacheAllConflictOperations() throws Exception {
187+
checkCacheAllConflictOperations(false);
188+
}
181189

182-
checkCacheOperation(CACHE_REMOVE_ALL_CONFLICT, removeAllConflict(Collections.singleton(6)));
190+
/**
191+
* Cache {@link TcpClientCache#putAllConflictAsync} and {@link TcpClientCache#removeAllConflictAsync} operations performed.
192+
* @throws Exception If failed.
193+
*/
194+
@Test
195+
public void testCacheAllConflictOperationsAsync() throws Exception {
196+
checkCacheAllConflictOperations(true);
197+
}
198+
199+
/**
200+
* @param async boolean flag for asynchronous cache operation processing.
201+
*/
202+
private void checkCacheAllConflictOperations(boolean async) throws Exception {
203+
int key = 6;
204+
int val = 1;
205+
206+
GridCacheVersion confl = new GridCacheVersion(1, 0, 1, (byte)2);
207+
208+
Map<?, T3<?, GridCacheVersion, Long>> putMap = F.asMap(key, new T3<>(val, confl, CU.EXPIRE_TIME_ETERNAL));
209+
Map<?, GridCacheVersion> rmvMap = F.asMap(key, confl);
210+
211+
if (async) {
212+
checkCacheOperation(CACHE_PUT_ALL_CONFLICT, cache -> ((TcpClientCache<Object, Object>)cache).putAllConflict(putMap));
213+
214+
checkCacheOperation(CACHE_REMOVE_ALL_CONFLICT, cache -> ((TcpClientCache<Object, Object>)cache).removeAllConflict(rmvMap));
215+
}
216+
else {
217+
checkCacheOperation(CACHE_PUT_ALL_CONFLICT, cache -> {
218+
try {
219+
((TcpClientCache<Object, Object>)cache).putAllConflictAsync(putMap).get();
220+
}
221+
catch (InterruptedException | ExecutionException e) {
222+
throw new RuntimeException(e);
223+
}
224+
});
225+
226+
checkCacheOperation(CACHE_REMOVE_ALL_CONFLICT, cache -> {
227+
try {
228+
((TcpClientCache<Object, Object>)cache).removeAllConflictAsync(rmvMap).get();
229+
}
230+
catch (InterruptedException | ExecutionException e) {
231+
throw new RuntimeException(e);
232+
}
233+
});
234+
}
183235
}
184236

185237
/** Checks cache operation. */
@@ -210,36 +262,6 @@ private void checkCacheOperation(OperationType op, Consumer<ClientCache<Object,
210262
assertEquals(1, ops.get());
211263
}
212264

213-
/**
214-
* Cache {@link TcpClientCache#putAllConflict} operation perfomed
215-
* @param map {@link Map} with entries for cache put all.
216-
* @return cache {@link Consumer<ClientCache>}.
217-
*/
218-
private Consumer<ClientCache<Object, Object>> putAllConflict(Map<Integer, Object> map) {
219-
Map<Integer, T3<Object, GridCacheVersion, Long>> drMap = new HashMap<>();
220-
221-
GridCacheVersion confl = new GridCacheVersion(1, 0, 1, (byte)2);
222-
223-
map.forEach((key, value) -> drMap.put(key, new T3<>(value, confl, CU.EXPIRE_TIME_ETERNAL)));
224-
225-
return cache -> ((TcpClientCache<Object, Object>)cache).putAllConflict(drMap);
226-
}
227-
228-
/**
229-
* Cache {@link TcpClientCache#putAllConflict} operation perfomed
230-
* @param keys {@link Set} with keys for cache remove all.
231-
* @return cache {@link Consumer<ClientCache>}.
232-
*/
233-
private Consumer<ClientCache<Object, Object>> removeAllConflict(Set<Integer> keys) {
234-
Map<Integer, GridCacheVersion> drMap = new HashMap<>();
235-
236-
GridCacheVersion confl = new GridCacheVersion(1, 0, 1, (byte)2);
237-
238-
keys.forEach(key -> drMap.put(key, confl));
239-
240-
return cache -> ((TcpClientCache<Object, Object>)cache).removeAllConflict(drMap);
241-
}
242-
243265
/** @throws Exception If failed. */
244266
@Test
245267
public void testTransaction() throws Exception {

0 commit comments

Comments
 (0)