use of org.apache.ignite.IgniteLogger in project ignite by apache.
the class IgniteThrottlingUnitTest method warningInCaseTooMuchThrottling.
/**
*/
@Test
public void warningInCaseTooMuchThrottling() {
AtomicInteger warnings = new AtomicInteger(0);
IgniteLogger log = mock(IgniteLogger.class);
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
System.out.println("log.info() called with arguments: " + Arrays.toString(args));
warnings.incrementAndGet();
return null;
}).when(log).info(anyString());
AtomicInteger written = new AtomicInteger();
CheckpointWriteProgressSupplier cpProgress = mock(CheckpointWriteProgressSupplier.class);
when(cpProgress.writtenPagesCounter()).thenReturn(written);
PagesWriteSpeedBasedThrottle throttle = new PagesWriteSpeedBasedThrottle(pageMemory2g, cpProgress, stateChecker, log) {
@Override
protected void doPark(long throttleParkTimeNs) {
// do nothing
}
};
throttle.onBeginCheckpoint();
// emulating some pages written
written.set(200);
for (int i = 0; i < 100000; i++) {
// emulating high load on marking
throttle.onMarkDirty(false);
if (throttle.throttleWeight() > PagesWriteSpeedBasedThrottle.WARN_THRESHOLD)
break;
}
for (int i = 0; i < 1000; i++) {
// emulating additional page writes to be sure log message is generated
throttle.onMarkDirty(false);
if (warnings.get() > 0)
break;
}
System.out.println(throttle.throttleWeight());
assertTrue(warnings.get() > 0);
}
use of org.apache.ignite.IgniteLogger in project ignite by apache.
the class IgniteCountDownLatchAbstractSelfTest method checkLatch.
/**
* @throws Exception If failed.
*/
private void checkLatch() throws Exception {
// Test API.
checkAutoDelete();
checkAwait();
checkCountDown();
// Test main functionality.
IgniteCountDownLatch latch1 = grid(0).countDownLatch("latch", 2, false, true);
assertEquals(2, latch1.count());
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 latch in multiple threads on each node.
IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
IgniteCountDownLatch latch = ignite.countDownLatch("latch", 2, false, true);
assert latch != null && latch.count() == 2;
log.info("Thread is going to wait on latch: " + Thread.currentThread().getName());
assert latch.await(1, MINUTES);
log.info("Thread is again runnable: " + Thread.currentThread().getName());
return null;
}
}, 5, "test-thread");
fut.get();
return null;
}
});
Thread.sleep(3000);
assert latch1.countDown() == 1;
assert latch1.countDown() == 0;
// Ensure there are no hangs.
fut.get();
// Test operations on removed latch.
latch1.close();
checkRemovedLatch(latch1);
}
use of org.apache.ignite.IgniteLogger in project ignite by apache.
the class IgniteLockAbstractSelfTest method checkReentrantLock.
/**
* @throws Exception If failed.
*/
private void checkReentrantLock(final boolean fair) throws Exception {
// Test API.
checkLock(fair);
checkFailoverSafe(fair);
// Test main functionality.
IgniteLock lock1 = grid(0).reentrantLock("lock", true, fair, true);
assertFalse(lock1.isLocked());
lock1.lock();
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 reentrant lock in multiple threads on each node.
IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
IgniteLock lock = ignite.reentrantLock("lock", true, fair, true);
assert lock != null;
log.info("Thread is going to wait on reentrant lock: " + Thread.currentThread().getName());
assert lock.tryLock(1, MINUTES);
log.info("Thread is again runnable: " + Thread.currentThread().getName());
lock.unlock();
return null;
}
}, 5, "test-thread");
fut.get();
return null;
}
});
Thread.sleep(3000);
assert lock1.isHeldByCurrentThread();
assert lock1.getHoldCount() == 1;
lock1.lock();
assert lock1.isHeldByCurrentThread();
assert lock1.getHoldCount() == 2;
lock1.unlock();
lock1.unlock();
// Ensure there are no hangs.
fut.get();
// Test operations on removed lock.
lock1.close();
checkRemovedReentrantLock(lock1);
}
use of org.apache.ignite.IgniteLogger in project ignite by apache.
the class HadoopExternalCommunicationSelfTest method checkSimpleMessageSending.
/**
* @throws Exception If failed.
*/
private void checkSimpleMessageSending(boolean useShmem) throws Exception {
UUID parentNodeId = UUID.randomUUID();
Marshaller marsh = new JdkMarshaller();
IgniteLogger log = log();
HadoopExternalCommunication[] comms = new HadoopExternalCommunication[4];
try {
String name = "grid";
TestHadoopListener[] lsnrs = new TestHadoopListener[4];
int msgs = 10;
for (int i = 0; i < comms.length; i++) {
comms[i] = new HadoopExternalCommunication(parentNodeId, UUID.randomUUID(), marsh, log, Executors.newFixedThreadPool(1), name + i, U.defaultWorkDirectory());
if (useShmem)
comms[i].setSharedMemoryPort(14000);
lsnrs[i] = new TestHadoopListener(msgs);
comms[i].setListener(lsnrs[i]);
comms[i].start();
}
for (int r = 0; r < msgs; r++) {
for (int from = 0; from < comms.length; from++) {
for (int to = 0; to < comms.length; to++) {
if (from == to)
continue;
comms[from].sendMessage(comms[to].localProcessDescriptor(), new TestMessage(from, to));
}
}
}
U.sleep(1000);
for (TestHadoopListener lsnr : lsnrs) {
lsnr.await(3_000);
assertEquals(String.valueOf(lsnr.messages()), msgs * (comms.length - 1), lsnr.messages().size());
}
} finally {
for (HadoopExternalCommunication comm : comms) {
if (comm != null)
comm.stop();
}
}
}
use of org.apache.ignite.IgniteLogger in project ignite by apache.
the class GridLoggerInjectionSelfTest method testClosureField.
/**
* Test that closure gets right log category injected on all nodes using field injection.
*
* @throws Exception If failed.
*/
public void testClosureField() throws Exception {
Ignite ignite = grid(0);
ignite.compute().call(new IgniteCallable<Object>() {
@LoggerResource(categoryClass = GridLoggerInjectionSelfTest.class)
private IgniteLogger log;
@Override
public Object call() throws Exception {
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.");
return null;
}
});
}
Aggregations