Search in sources :

Example 51 with ListeningTestLogger

use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.

the class PageLockTrackerManagerTest method testMemoryCalculation0.

/**
 * @param type Tracker type.
 */
public void testMemoryCalculation0(int type) throws Exception {
    System.out.println(">>> Calculation mempory tracker type:" + type);
    int timeOutWorkerInterval = 10_000;
    System.setProperty("IGNITE_PAGE_LOCK_TRACKER_TYPE", String.valueOf(type));
    System.setProperty("IGNITE_PAGE_LOCK_TRACKER_CHECK_INTERVAL", String.valueOf(timeOutWorkerInterval));
    try {
        PageLockTrackerManager mgr = new PageLockTrackerManager(new ListeningTestLogger());
        mgr.start();
        printOverhead(mgr);
        long heapOverhead0 = mgr.getHeapOverhead();
        long offHeapOverhead0 = mgr.getOffHeapOverhead();
        long totalOverhead0 = mgr.getTotalOverhead();
        Assert.assertTrue(heapOverhead0 > 0);
        Assert.assertTrue(offHeapOverhead0 >= 0);
        Assert.assertEquals(heapOverhead0 + offHeapOverhead0, totalOverhead0);
        PageLockListener pls = mgr.createPageLockTracker("test");
        printOverhead(mgr);
        long heapOverhead1 = mgr.getHeapOverhead();
        long offHeapOverhead1 = mgr.getOffHeapOverhead();
        long totalOverhead1 = mgr.getTotalOverhead();
        Assert.assertTrue(heapOverhead1 > 0);
        Assert.assertTrue(offHeapOverhead1 >= 0);
        Assert.assertTrue(heapOverhead1 > heapOverhead0);
        Assert.assertTrue(offHeapOverhead1 >= offHeapOverhead0);
        Assert.assertEquals(heapOverhead1 + offHeapOverhead1, totalOverhead1);
        int threads = 2_000;
        int cacheId = 1;
        long pageId = 2;
        long page = 3;
        long pageAdder = 4;
        List<Thread> threadsList = new ArrayList<>(threads);
        String threadNamePreffix = "my-thread-";
        CountDownLatch startThreadsLatch = new CountDownLatch(threads);
        CountDownLatch finishThreadsLatch = new CountDownLatch(1);
        for (int i = 0; i < threads; i++) {
            Thread th = new Thread(() -> {
                startThreadsLatch.countDown();
                pls.onBeforeReadLock(cacheId, pageId, page);
                pls.onReadLock(cacheId, pageId, page, pageAdder);
                pls.onReadUnlock(cacheId, pageId, page, pageAdder);
                try {
                    finishThreadsLatch.await();
                } catch (InterruptedException ignored) {
                // No-op.
                }
            });
            th.setName(threadNamePreffix + i);
            threadsList.add(th);
            th.start();
            System.out.println(">>> start thread:" + th.getName());
        }
        startThreadsLatch.await();
        printOverhead(mgr);
        long heapOverhead2 = mgr.getHeapOverhead();
        long offHeapOverhead2 = mgr.getOffHeapOverhead();
        long totalOverhead2 = mgr.getTotalOverhead();
        Assert.assertTrue(heapOverhead2 > heapOverhead1);
        Assert.assertTrue(offHeapOverhead2 >= offHeapOverhead1);
        Assert.assertEquals(heapOverhead2 + offHeapOverhead2, totalOverhead2);
        finishThreadsLatch.countDown();
        threadsList.forEach(th -> {
            try {
                System.out.println(">>> await thread:" + th.getName());
                th.join();
            } catch (InterruptedException ignored) {
            // No-op.
            }
        });
        // Await cleanup worker interval.
        U.sleep(2 * timeOutWorkerInterval);
        printOverhead(mgr);
        long heapOverhead3 = mgr.getHeapOverhead();
        long offHeapOverhead3 = mgr.getOffHeapOverhead();
        long totalOverhead3 = mgr.getTotalOverhead();
        Assert.assertTrue(heapOverhead3 > 0);
        Assert.assertTrue(offHeapOverhead3 >= 0);
        Assert.assertTrue(heapOverhead3 < heapOverhead2);
        Assert.assertTrue(offHeapOverhead3 <= offHeapOverhead2);
        Assert.assertEquals(heapOverhead3 + offHeapOverhead3, totalOverhead3);
        mgr.stop();
    } finally {
        System.clearProperty("IGNITE_PAGE_LOCK_TRACKER_TYPE");
        System.clearProperty("IGNITE_PAGE_LOCK_TRACKER_CHECK_INTERVAL");
    }
}
Also used : ArrayList(java.util.ArrayList) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) PageLockListener(org.apache.ignite.internal.processors.cache.persistence.tree.util.PageLockListener) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 52 with ListeningTestLogger

use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.

the class PageLockTrackerManagerTest method testDisableTracking.

/**
 */
@Test
public void testDisableTracking() {
    System.setProperty("IGNITE_PAGE_LOCK_TRACKER_TYPE", String.valueOf(-1));
    try {
        PageLockTrackerManager mgr = new PageLockTrackerManager(new ListeningTestLogger());
        PageLockListener pll = mgr.createPageLockTracker("test");
        Assert.assertNotNull(pll);
        Assert.assertSame(PageLockTrackerManager.NOOP_LSNR, pll);
    } finally {
        System.clearProperty("IGNITE_PAGE_LOCK_TRACKER_TYPE");
    }
    System.setProperty("IGNITE_PAGE_LOCK_TRACKER_TYPE", String.valueOf(HEAP_LOG));
    try {
        PageLockTrackerManager mgr = new PageLockTrackerManager(new ListeningTestLogger());
        PageLockListener pll = mgr.createPageLockTracker("test");
        Assert.assertNotNull(pll);
        Assert.assertNotSame(PageLockTrackerManager.NOOP_LSNR, pll);
    } finally {
        System.clearProperty("IGNITE_PAGE_LOCK_TRACKER_TYPE");
    }
}
Also used : ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) PageLockListener(org.apache.ignite.internal.processors.cache.persistence.tree.util.PageLockListener) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 53 with ListeningTestLogger

use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.

the class TransactionSensitiveDataTest method beforeTestsStarted.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTestsStarted() throws Exception {
    super.beforeTestsStarted();
    setFieldValue(GridNearTxPrepareFutureAdapter.class, "log", null);
    ((AtomicReference<IgniteLogger>) getFieldValue(GridNearTxPrepareFutureAdapter.class, "logRef")).set(null);
    clearGridToStringClassCache();
    testLog = new ListeningTestLogger(false, log);
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) GridNearTxPrepareFutureAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareFutureAdapter) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger)

Example 54 with ListeningTestLogger

use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.

the class GridNioServerTest method logMessagesCollector.

/**
 */
private ListeningTestLogger logMessagesCollector() {
    ListeningTestLogger log = new ListeningTestLogger();
    log.registerListener(logMessages::add);
    return log;
}
Also used : ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger)

Example 55 with ListeningTestLogger

use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.

the class TcpDiscoveryIpFinderFailureTest method initDynamicIpFinder.

/**
 */
@Before
public void initDynamicIpFinder() {
    dynamicIpFinder = new TestDynamicIpFinder();
    listeningLog = new ListeningTestLogger(log);
}
Also used : ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) Before(org.junit.Before)

Aggregations

ListeningTestLogger (org.apache.ignite.testframework.ListeningTestLogger)101 Test (org.junit.Test)51 LogListener (org.apache.ignite.testframework.LogListener)48 IgniteEx (org.apache.ignite.internal.IgniteEx)36 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)32 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)30 Ignite (org.apache.ignite.Ignite)21 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)21 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)17 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)14 CountDownLatch (java.util.concurrent.CountDownLatch)9 IgniteCache (org.apache.ignite.IgniteCache)9 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)9 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)9 List (java.util.List)8 Pattern (java.util.regex.Pattern)8 ClusterState (org.apache.ignite.cluster.ClusterState)7 GridQueryProcessor (org.apache.ignite.internal.processors.query.GridQueryProcessor)7 Collections (java.util.Collections)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6