use of org.apache.ignite.IgniteLogger in project ignite by apache.
the class IgniteSemaphoreAbstractSelfTest method checkSemaphore.
/**
* @throws Exception If failed.
*/
private void checkSemaphore() throws Exception {
// Test API.
checkAcquire();
checkRelease();
checkFailoverSafe();
// Test main functionality.
IgniteSemaphore semaphore1 = grid(0).semaphore("semaphore", -2, true, true);
assertEquals(-2, semaphore1.availablePermits());
IgniteFuture<Object> fut = grid(0).compute().callAsync(new IgniteCallable<Object>() {
@IgniteInstanceResource
private Ignite ignite;
@LoggerResource
private IgniteLogger log;
@Nullable
@Override
public Object call() throws Exception {
// Test semaphore in multiple threads on each node.
IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
IgniteSemaphore semaphore = ignite.semaphore("semaphore", -2, true, true);
assert semaphore != null && semaphore.availablePermits() == -2;
log.info("Thread is going to wait on semaphore: " + Thread.currentThread().getName());
assert semaphore.tryAcquire(1, 1, MINUTES);
log.info("Thread is again runnable: " + Thread.currentThread().getName());
semaphore.release();
return null;
}
}, 5, "test-thread");
fut.get();
return null;
}
});
Thread.sleep(3000);
semaphore1.release(2);
assert semaphore1.availablePermits() == 0;
semaphore1.release(1);
// Ensure there are no hangs.
fut.get();
// Test operations on removed semaphore.
semaphore1.close();
checkRemovedSemaphore(semaphore1);
}
use of org.apache.ignite.IgniteLogger in project ignite by apache.
the class GridIndexingSpiAbstractSelfTest method testLongQueries.
/**
* Test long queries write explain warnings into log.
*
* @throws Exception If failed.
*/
public void testLongQueries() throws Exception {
IgniteH2Indexing spi = getIndexing();
ignite0.createCache(cacheACfg());
long longQryExecTime = IgniteConfiguration.DFLT_LONG_QRY_WARN_TIMEOUT;
GridStringLogger log = new GridStringLogger(false, this.log);
IgniteLogger oldLog = GridTestUtils.getFieldValue(spi, "log");
try {
GridTestUtils.setFieldValue(spi, "log", log);
String sql = "select sum(x) FROM SYSTEM_RANGE(?, ?)";
long now = U.currentTimeMillis();
long time = now;
long range = 1000000L;
while (now - time <= longQryExecTime * 3 / 2) {
time = now;
range *= 3;
GridQueryFieldsResult res = spi.queryLocalSqlFields(spi.schema("A"), sql, Arrays.<Object>asList(1, range), null, false, 0, null);
assert res.iterator().hasNext();
now = U.currentTimeMillis();
}
String res = log.toString();
assertTrue(res.contains("/* PUBLIC.RANGE_INDEX */"));
} finally {
GridTestUtils.setFieldValue(spi, "log", oldLog);
}
}
use of org.apache.ignite.IgniteLogger in project ignite by apache.
the class IgniteFailoverAbstractBenchmark method awaitPartitionMapExchange.
/**
* Awaits for partitiona map exchage.
*
* @param ignite Ignite.
* @throws Exception If failed.
*/
@SuppressWarnings("BusyWait")
protected static void awaitPartitionMapExchange(Ignite ignite) throws Exception {
IgniteLogger log = ignite.log();
log.info("Waiting for finishing of a partition exchange on node: " + ignite);
IgniteKernal kernal = (IgniteKernal) ignite;
while (true) {
boolean partitionsExchangeFinished = true;
for (IgniteInternalCache<?, ?> cache : kernal.cachesx(null)) {
log.info("Checking cache: " + cache.name());
GridCacheAdapter<?, ?> c = kernal.internalCache(cache.name());
if (!(c instanceof GridDhtCacheAdapter))
break;
GridDhtCacheAdapter<?, ?> dht = (GridDhtCacheAdapter<?, ?>) c;
GridDhtPartitionFullMap partMap = dht.topology().partitionMap(true);
for (Map.Entry<UUID, GridDhtPartitionMap> e : partMap.entrySet()) {
log.info("Checking node: " + e.getKey());
for (Map.Entry<Integer, GridDhtPartitionState> e1 : e.getValue().entrySet()) {
if (e1.getValue() != GridDhtPartitionState.OWNING) {
log.info("Undesired state [id=" + e1.getKey() + ", state=" + e1.getValue() + ']');
partitionsExchangeFinished = false;
break;
}
}
if (!partitionsExchangeFinished)
break;
}
if (!partitionsExchangeFinished)
break;
}
if (partitionsExchangeFinished)
return;
Thread.sleep(100);
}
}
use of org.apache.ignite.IgniteLogger in project ignite by apache.
the class GridLoggerInjectionSelfTest method testClosureMethod.
/**
* Test that closure gets right log category injected on all nodes using method injection.
*
* @throws Exception If failed.
*/
public void testClosureMethod() throws Exception {
Ignite ignite = grid(0);
ignite.compute().call(new IgniteCallable<Object>() {
@LoggerResource(categoryClass = GridLoggerInjectionSelfTest.class)
private void log(IgniteLogger log) {
if (log instanceof GridLoggerProxy) {
Object category = U.field(log, "ctgr");
assertTrue("Logger created for the wrong category.", category.toString().contains(GridLoggerInjectionSelfTest.class.getName()));
} else
fail("This test should be run with proxy logger.");
}
@Override
public Object call() throws Exception {
return null;
}
});
}
use of org.apache.ignite.IgniteLogger in project ignite by apache.
the class GridLoggerInjectionSelfTest method testStringCategory.
/**
* Test that closure gets right log category injected through {@link org.apache.ignite.resources.LoggerResource#categoryName()}.
*
* @throws Exception If failed.
*/
public void testStringCategory() throws Exception {
Ignite ignite = grid(0);
ignite.compute().call(new IgniteCallable<Object>() {
@LoggerResource(categoryName = "GridLoggerInjectionSelfTest")
private void log(IgniteLogger log) {
if (log instanceof GridLoggerProxy) {
Object category = U.field(log, "ctgr");
assertTrue("Logger created for the wrong category.", "GridLoggerInjectionSelfTest".equals(category.toString()));
} else
fail("This test should be run with proxy logger.");
}
@Override
public Object call() throws Exception {
return null;
}
});
}
Aggregations