use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class CacheClientsConcurrentStartTest method doTest.
/**
* @throws Exception If failed.
*/
private void doTest() throws Exception {
final AtomicBoolean failed = new AtomicBoolean();
startGrids(SRV_CNT);
for (int i = 0; i < SRV_CNT; i++) {
((TestRecordingCommunicationSpi) ignite(i).configuration().getCommunicationSpi()).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
if (msg instanceof GridDhtPartitionsFullMessage) {
try {
U.sleep(ThreadLocalRandom.current().nextLong(500) + 100);
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
});
}
List<IgniteInternalFuture<?>> futs = new ArrayList<>();
for (int i = 0; i < CLIENTS_CNT; i++) {
final int idx = i;
IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {
@Override
public void run() {
Random rnd = new Random();
try {
Ignite ignite = startGrid(SRV_CNT + idx);
assertTrue(ignite.configuration().isClientMode());
for (int i = 0; i < CACHES / 2; i++) {
String cacheName = "cache-" + rnd.nextInt(CACHES);
IgniteCache<Object, Object> cache = getCache(ignite, cacheName);
cache.put(ignite.cluster().localNode().id(), UUID.randomUUID());
IgniteAtomicSequence seq = ignite.atomicSequence("seq-" + rnd.nextInt(20), 0, true);
seq.getAndIncrement();
}
while (!stopped) {
IgniteCache<Object, Object> cache = getCache(ignite, "cache-" + rnd.nextInt(CACHES));
int val = Math.abs(rnd.nextInt(100));
if (val >= 0 && val < 40)
cache.containsKey(ignite.cluster().localNode().id());
else if (val >= 40 && val < 80)
cache.get(ignite.cluster().localNode().id());
else
cache.put(ignite.cluster().localNode().id(), UUID.randomUUID());
Thread.sleep(10);
}
} catch (Exception e) {
log.error("Unexpected error: " + e, e);
failed.set(true);
}
}
}, 1, "client-thread");
futs.add(fut);
}
Thread.sleep(10_000);
stopped = true;
for (IgniteInternalFuture<?> fut : futs) fut.get();
assertFalse(failed.get());
}
Aggregations