use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class CacheContinuousQueryOperationP2PTest method testContinuousQuery.
/**
* @param ccfg Cache configuration.
* @param isClient Client.
* @throws Exception If failed.
*/
protected void testContinuousQuery(CacheConfiguration<Object, Object> ccfg, boolean isClient) throws Exception {
ignite(0).createCache(ccfg);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
QueryCursor<?> cur = null;
final Class<Factory<CacheEntryEventFilter>> evtFilterFactory = (Class<Factory<CacheEntryEventFilter>>) getExternalClassLoader().loadClass("org.apache.ignite.tests.p2p.CacheDeploymentEntryEventFilterFactory");
final CountDownLatch latch = new CountDownLatch(10);
ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
TestLocalListener localLsnr = new TestLocalListener() {
@Override
public void onEvent(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) throws CacheEntryListenerException {
for (CacheEntryEvent<? extends Integer, ? extends Integer> evt : evts) {
latch.countDown();
log.info("Received event: " + evt);
}
}
};
MutableCacheEntryListenerConfiguration<Integer, Integer> lsnrCfg = new MutableCacheEntryListenerConfiguration<>(new FactoryBuilder.SingletonFactory<>(localLsnr), (Factory<? extends CacheEntryEventFilter<? super Integer, ? super Integer>>) (Object) evtFilterFactory.newInstance(), true, true);
qry.setLocalListener(localLsnr);
qry.setRemoteFilterFactory((Factory<? extends CacheEntryEventFilter<Integer, Integer>>) (Object) evtFilterFactory.newInstance());
IgniteCache<Integer, Integer> cache = null;
try {
if (isClient)
cache = grid(NODES - 1).cache(ccfg.getName());
else
cache = grid(rnd.nextInt(NODES - 1)).cache(ccfg.getName());
cur = cache.query(qry);
cache.registerCacheEntryListener(lsnrCfg);
for (int i = 0; i < 10; i++) cache.put(i, i);
assertTrue(latch.await(3, TimeUnit.SECONDS));
} finally {
if (cur != null)
cur.close();
if (cache != null)
cache.deregisterCacheEntryListener(lsnrCfg);
}
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class GridCacheClientNodeBinaryObjectMetadataMultinodeTest method testClientMetadataInitialization.
/**
* @throws Exception If failed.
*/
public void testClientMetadataInitialization() throws Exception {
startGrids(2);
final AtomicBoolean stop = new AtomicBoolean();
final ConcurrentHashSet<String> allTypes = new ConcurrentHashSet<>();
IgniteInternalFuture<?> fut;
try {
// Update binary metadata concurrently with client nodes start.
fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
IgniteBinary binaries = ignite(0).binary();
IgniteCache<Object, Object> cache = ignite(0).cache(DEFAULT_CACHE_NAME).withKeepBinary();
ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int i = 0; i < 1000; i++) {
log.info("Iteration: " + i);
String type = "binary-type-" + i;
allTypes.add(type);
for (int f = 0; f < 10; f++) {
BinaryObjectBuilder builder = binaries.builder(type);
String fieldName = "f" + f;
builder.setField(fieldName, i);
cache.put(rnd.nextInt(0, 100_000), builder.build());
if (f % 100 == 0)
log.info("Put iteration: " + f);
}
if (stop.get())
break;
}
return null;
}
}, 5, "update-thread");
} finally {
stop.set(true);
}
client = true;
startGridsMultiThreaded(2, 5);
fut.get();
assertFalse(allTypes.isEmpty());
log.info("Expected binary types: " + allTypes.size());
assertEquals(7, ignite(0).cluster().nodes().size());
for (int i = 0; i < 7; i++) {
log.info("Check metadata on node: " + i);
boolean client = i > 1;
assertEquals((Object) client, ignite(i).configuration().isClientMode());
IgniteBinary binaries = ignite(i).binary();
Collection<BinaryType> metaCol = binaries.types();
assertEquals(allTypes.size(), metaCol.size());
Set<String> names = new HashSet<>();
for (BinaryType meta : metaCol) {
info("Binary type: " + meta);
assertTrue(names.add(meta.typeName()));
assertNull(meta.affinityKeyFieldName());
assertEquals(10, meta.fieldNames().size());
}
assertEquals(allTypes.size(), names.size());
}
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class IgnitePdsTransactionsHangTest method testTransactionsDontHang.
/**
* Copied from customers benchmark.
*
* @throws Exception If failed.
*/
public void testTransactionsDontHang() throws Exception {
try {
final Ignite g = startGrids(2);
g.active(true);
g.getOrCreateCache(getCacheConfiguration());
ExecutorService threadPool = Executors.newFixedThreadPool(THREADS_CNT);
final CyclicBarrier cyclicBarrier = new CyclicBarrier(THREADS_CNT);
final AtomicBoolean interrupt = new AtomicBoolean(false);
final LongAdder operationCnt = new LongAdder();
final IgniteCache<Long, TestEntity> cache = g.cache(CACHE_NAME);
for (int i = 0; i < THREADS_CNT; i++) {
threadPool.submit(new Runnable() {
@Override
public void run() {
try {
ThreadLocalRandom locRandom = ThreadLocalRandom.current();
cyclicBarrier.await();
while (!interrupt.get()) {
long randomKey = locRandom.nextLong(MAX_KEY_COUNT);
TestEntity entity = TestEntity.newTestEntity(locRandom);
try (Transaction tx = g.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.put(randomKey, entity);
tx.commit();
}
operationCnt.increment();
}
} catch (Throwable e) {
log.error("Unexpected exception:", e);
throw new RuntimeException(e);
}
}
});
}
long stopTime = System.currentTimeMillis() + DURATION * 1000;
long totalOperations = 0;
int periods = 0;
long max = Long.MIN_VALUE, min = Long.MAX_VALUE;
while (System.currentTimeMillis() < stopTime) {
U.sleep(1000);
long sum = operationCnt.sumThenReset();
periods++;
if (periods > WARM_UP_PERIOD) {
totalOperations += sum;
max = Math.max(max, sum);
min = Math.min(min, sum);
log.info("Operation count: " + sum + " min=" + min + " max=" + max + " avg=" + totalOperations / (periods - WARM_UP_PERIOD));
}
}
interrupt.set(true);
threadPool.shutdown();
log.info("Test complete");
threadPool.awaitTermination(getTestTimeout(), TimeUnit.MILLISECONDS);
IgniteTxManager tm = internalCache(cache).context().tm();
assertEquals("There are still active transactions", 0, tm.activeTransactions().size());
} finally {
stopAllGrids();
}
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class TrackingPageIOTest method testMerging.
/**
*/
public void testMerging() {
ByteBuffer buf = ByteBuffer.allocateDirect(PAGE_SIZE);
buf.order(ByteOrder.nativeOrder());
ThreadLocalRandom rand = ThreadLocalRandom.current();
int track = io.countOfPageToTrack(PAGE_SIZE);
long basePageId = io.trackingPageFor(Math.max(rand.nextLong(Integer.MAX_VALUE - track), 0), PAGE_SIZE);
assert basePageId >= 0;
PageIO.setPageId(GridUnsafe.bufferAddress(buf), basePageId);
TreeSet<Long> setIdx = new TreeSet<>();
for (int i = 0; i < 4; i++) generateMarking(buf, track, basePageId, basePageId + rand.nextInt(1, track), setIdx, i, -1);
TreeSet<Long> setIdx2 = new TreeSet<>();
generateMarking(buf, track, basePageId, basePageId + rand.nextInt(1, track), setIdx2, 4, -1);
assertEquals(setIdx2.size(), io.countOfChangedPage(buf, 4, PAGE_SIZE));
assertEquals(setIdx.size(), io.countOfChangedPage(buf, 3, PAGE_SIZE));
for (long i = basePageId; i < basePageId + track; i++) assertEquals("pageId = " + i, setIdx.contains(i), io.wasChanged(buf, i, 3, -1, PAGE_SIZE));
for (long i = basePageId; i < basePageId + track; i++) assertEquals("pageId = " + i, setIdx2.contains(i), io.wasChanged(buf, i, 4, 3, PAGE_SIZE));
for (long i = basePageId; i < basePageId + track; i++) assertFalse(io.wasChanged(buf, i, 5, 4, PAGE_SIZE));
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class IgniteDataStreamerPerformanceTest method doTest.
/**
* @throws Exception If failed.
*/
private void doTest() throws Exception {
System.gc();
System.gc();
System.gc();
try {
useCache = true;
startGridsMultiThreaded(GRID_CNT);
useCache = false;
Ignite ignite = startGrid();
final IgniteDataStreamer<Integer, String> ldr = ignite.dataStreamer(DEFAULT_CACHE_NAME);
ldr.perNodeBufferSize(8192);
ldr.receiver(DataStreamerCacheUpdaters.<Integer, String>batchedSorted());
ldr.autoFlushFrequency(0);
final LongAdder cnt = new LongAdder();
long start = U.currentTimeMillis();
Thread t = new Thread(new Runnable() {
@SuppressWarnings("BusyWait")
@Override
public void run() {
while (true) {
try {
Thread.sleep(10000);
} catch (InterruptedException ignored) {
break;
}
info(">>> Adds/sec: " + cnt.sumThenReset() / 10);
}
}
});
t.setDaemon(true);
t.start();
// Runtime.getRuntime().availableProcessors();
int threadNum = 2;
multithreaded(new Callable<Object>() {
@SuppressWarnings("InfiniteLoopStatement")
@Override
public Object call() throws Exception {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
while (true) {
int i = rnd.nextInt(ENTRY_CNT);
ldr.addData(i, vals[rnd.nextInt(vals.length)]);
cnt.increment();
}
}
}, threadNum, "loader");
info("Closing loader...");
ldr.close(false);
long duration = U.currentTimeMillis() - start;
info("Finished performance test. Duration: " + duration + "ms.");
} finally {
stopAllGrids();
}
}
Aggregations