Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* tests cases separated
  • Loading branch information
maksaska committed Jan 16, 2025
1 parent 7080fc3 commit fcf7e89
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -1999,9 +1999,9 @@ protected boolean put0(final K key, final V val, final CacheEntryPredicate filte
return new GridFinishedFuture<Object>();

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());

Expand Down Expand Up @@ -2846,10 +2846,10 @@ protected IgniteInternalFuture<Boolean> 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());

Expand Down Expand Up @@ -2877,9 +2877,9 @@ protected IgniteInternalFuture<Boolean> removeAsync0(final K key, @Nullable fina
return new GridFinishedFuture<Object>();

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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<?, T3<?, GridCacheVersion, Long>> putMap = F.asMap(key, new T3<>(val, confl, CU.EXPIRE_TIME_ETERNAL));
Map<?, GridCacheVersion> 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<Object, Object>)cache).putAllConflict(putMap));
else if (opType.equals(CACHE_REMOVE_ALL_CONFLICT))
checkCacheOperation(opType, cache -> ((TcpClientCache<Object, Object>)cache).removeAllConflict(rmvMap));
}
else {
checkCacheOperation(opType, cache -> {
try {
if (opType.equals(CACHE_PUT_ALL_CONFLICT))
((TcpClientCache<Object, Object>)cache).putAllConflictAsync(putMap).get();
else if (opType.equals(CACHE_REMOVE_ALL_CONFLICT))
((TcpClientCache<Object, Object>)cache).removeAllConflictAsync(rmvMap).get();
}
catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
});
}
}

/** Checks cache operation. */
Expand Down Expand Up @@ -210,36 +275,6 @@ private void checkCacheOperation(OperationType op, Consumer<ClientCache<Object,
assertEquals(1, ops.get());
}

/**
* Cache {@link TcpClientCache#putAllConflict} operation perfomed
* @param map {@link Map} with entries for cache put all.
* @return cache {@link Consumer<ClientCache>}.
*/
private Consumer<ClientCache<Object, Object>> putAllConflict(Map<Integer, Object> map) {
Map<Integer, T3<Object, GridCacheVersion, Long>> 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<Object, Object>)cache).putAllConflict(drMap);
}

/**
* Cache {@link TcpClientCache#putAllConflict} operation perfomed
* @param keys {@link Set} with keys for cache remove all.
* @return cache {@link Consumer<ClientCache>}.
*/
private Consumer<ClientCache<Object, Object>> removeAllConflict(Set<Integer> keys) {
Map<Integer, GridCacheVersion> drMap = new HashMap<>();

GridCacheVersion confl = new GridCacheVersion(1, 0, 1, (byte)2);

keys.forEach(key -> drMap.put(key, confl));

return cache -> ((TcpClientCache<Object, Object>)cache).removeAllConflict(drMap);
}

/** @throws Exception If failed. */
@Test
public void testTransaction() throws Exception {
Expand Down

0 comments on commit fcf7e89

Please sign in to comment.