use of org.apache.ignite.resources.LoggerResource in project ignite by apache.
the class IgfsSecondaryFileSystemInjectionSelfTest method testInjectPrimaryByField.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "UnusedDeclaration" })
public void testInjectPrimaryByField() throws Exception {
secondary = new TestBaseSecondaryFsMock() {
@FileSystemResource
private IgfsImpl igfs;
@LoggerResource
private IgniteLogger log;
@IgniteInstanceResource
private Ignite ig;
@Override
boolean checkInjection(Ignite ignite, IgniteFileSystem primary) {
return igfs == primary && log instanceof IgniteLogger && ig == ignite;
}
};
Ignite ig = startGrid(0);
IgniteFileSystem igfs = ig.fileSystem(IGFS_NAME);
assert secondary.checkInjection(ig, igfs);
}
use of org.apache.ignite.resources.LoggerResource in project ignite by apache.
the class IgfsSecondaryFileSystemInjectionSelfTest method testInjectPrimaryByMethods.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "UnusedDeclaration" })
public void testInjectPrimaryByMethods() throws Exception {
secondary = new TestBaseSecondaryFsMock() {
/**
* Ignite instance.
*/
private Ignite ig;
/**
* IGFS instance.
*/
private IgniteFileSystem igfs;
/**
* Logger injected flag
*/
private boolean logSet;
/**
* @param igfs Primary IGFS.
*/
@FileSystemResource
void setPrimaryIgfs(IgfsImpl igfs) {
this.igfs = igfs;
}
/**
* @param log Ignite logger.
*/
@LoggerResource
void setIgLogger(IgniteLogger log) {
logSet = log instanceof IgniteLogger;
}
/**
* @param ig Ignite instance.
*/
@IgniteInstanceResource
void setIgniteInst(Ignite ig) {
this.ig = ig;
}
@Override
boolean checkInjection(Ignite ignite, IgniteFileSystem primary) {
return ignite == ig && primary == igfs && logSet;
}
};
Ignite ig = startGrid(0);
IgniteFileSystem igfs = ig.fileSystem(IGFS_NAME);
assert secondary.checkInjection(ig, igfs);
}
use of org.apache.ignite.resources.LoggerResource 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.
*/
@Test
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.resources.LoggerResource 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.
*/
@Test
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;
}
});
}
use of org.apache.ignite.resources.LoggerResource 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.
final 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() + ", node = " + ignite.cluster().localNode() + ", sem = " + semaphore);
assert semaphore.tryAcquire(1, 1, MINUTES);
log.info("Thread is again runnable: " + Thread.currentThread().getName() + ", node = " + ignite.cluster().localNode() + ", sem = " + semaphore);
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);
}
Aggregations