Search in sources :

Example 21 with IgniteLogger

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

Example 22 with IgniteLogger

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);
    }
}
Also used : GridStringLogger(org.apache.ignite.testframework.GridStringLogger) IgniteLogger(org.apache.ignite.IgniteLogger) GridQueryFieldsResult(org.apache.ignite.internal.processors.query.GridQueryFieldsResult)

Example 23 with IgniteLogger

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);
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDhtCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState) IgniteLogger(org.apache.ignite.IgniteLogger) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)

Example 24 with IgniteLogger

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;
        }
    });
}
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)

Example 25 with IgniteLogger

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;
        }
    });
}
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)49 Ignite (org.apache.ignite.Ignite)11 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)11 IOException (java.io.IOException)9 LoggerResource (org.apache.ignite.resources.LoggerResource)9 Map (java.util.Map)6 IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)6 HashMap (java.util.HashMap)5 UUID (java.util.UUID)5 IgniteException (org.apache.ignite.IgniteException)5 ClusterNode (org.apache.ignite.cluster.ClusterNode)5 File (java.io.File)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 Callable (java.util.concurrent.Callable)3 GridLoggerProxy (org.apache.ignite.internal.GridLoggerProxy)3 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 IgniteKernal (org.apache.ignite.internal.IgniteKernal)3 Nullable (org.jetbrains.annotations.Nullable)3 InvalidObjectException (java.io.InvalidObjectException)2 ArrayList (java.util.ArrayList)2