Search in sources :

Example 41 with IgniteLogger

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);
}
Also used : CheckpointWriteProgressSupplier(org.apache.ignite.internal.processors.cache.persistence.CheckpointWriteProgressSupplier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteLogger(org.apache.ignite.IgniteLogger) Test(org.junit.Test)

Example 42 with IgniteLogger

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);
}
Also used : LoggerResource(org.apache.ignite.resources.LoggerResource) IgniteCountDownLatch(org.apache.ignite.IgniteCountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) Ignite(org.apache.ignite.Ignite) IgniteLogger(org.apache.ignite.IgniteLogger) Nullable(org.jetbrains.annotations.Nullable)

Example 43 with IgniteLogger

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);
}
Also used : LoggerResource(org.apache.ignite.resources.LoggerResource) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) ExpectedException(org.junit.rules.ExpectedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteLock(org.apache.ignite.IgniteLock) Ignite(org.apache.ignite.Ignite) IgniteLogger(org.apache.ignite.IgniteLogger) Nullable(org.jetbrains.annotations.Nullable)

Example 44 with IgniteLogger

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();
        }
    }
}
Also used : JdkMarshaller(org.apache.ignite.marshaller.jdk.JdkMarshaller) Marshaller(org.apache.ignite.marshaller.Marshaller) JdkMarshaller(org.apache.ignite.marshaller.jdk.JdkMarshaller) HadoopExternalCommunication(org.apache.ignite.internal.processors.hadoop.taskexecutor.external.communication.HadoopExternalCommunication) UUID(java.util.UUID) IgniteLogger(org.apache.ignite.IgniteLogger)

Example 45 with IgniteLogger

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;
        }
    });
}
Also used : LoggerResource(org.apache.ignite.resources.LoggerResource) GridLoggerProxy(org.apache.ignite.internal.GridLoggerProxy) Ignite(org.apache.ignite.Ignite) IgniteLogger(org.apache.ignite.IgniteLogger) IOException(java.io.IOException)

Aggregations

IgniteLogger (org.apache.ignite.IgniteLogger)60 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)14 Ignite (org.apache.ignite.Ignite)12 IOException (java.io.IOException)10 LoggerResource (org.apache.ignite.resources.LoggerResource)10 IgniteException (org.apache.ignite.IgniteException)8 Map (java.util.Map)6 UUID (java.util.UUID)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)6 IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)6 HashMap (java.util.HashMap)5 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)5 IgniteBiInClosure (org.apache.ignite.lang.IgniteBiInClosure)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 URL (java.net.URL)3 Callable (java.util.concurrent.Callable)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3