Search in sources :

Example 81 with ListeningTestLogger

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

the class IgniteBinaryTest method testBinaryWithNotGenericInterceptor.

/**
 * Tests that {@code org.apache.ignite.cache.CacheInterceptor#onBeforePut(javax.cache.Cache.Entry, java.lang.Object)}
 * throws correct exception in case while cache operations are called from thin client. Only BinaryObject`s are
 * acceptable in this case.
 */
@Test
public void testBinaryWithNotGenericInterceptor() throws Exception {
    IgniteConfiguration ccfg = Config.getServerConfiguration().setCacheConfiguration(new CacheConfiguration("test").setInterceptor(new ThinBinaryValueInterceptor()));
    String castErr = "cannot be cast to";
    String treeErr = "B+Tree is corrupted";
    ListeningTestLogger srvLog = new ListeningTestLogger(log);
    LogListener lsnrCast = LogListener.matches(castErr).andMatches(str -> !str.contains(treeErr)).build();
    srvLog.registerListener(lsnrCast);
    ccfg.setGridLogger(srvLog);
    try (Ignite ign = Ignition.start(ccfg)) {
        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
            ClientCache<Integer, ThinBinaryValue> cache = client.cache("test");
            try {
                cache.put(1, new ThinBinaryValue());
                fail();
            } catch (Exception e) {
                assertFalse(X.getFullStackTrace(e).contains(castErr));
            }
            ClientProcessorMXBean serverMxBean = getMxBean(ign.name(), "Clients", ClientListenerProcessor.class, ClientProcessorMXBean.class);
            serverMxBean.showFullStackOnClientSide(true);
            try {
                cache.put(1, new ThinBinaryValue());
            } catch (Exception e) {
                assertTrue(X.getFullStackTrace(e).contains(castErr));
            }
        }
    }
    assertTrue(lsnrCast.check());
}
Also used : ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryReader(org.apache.ignite.binary.BinaryReader) Arrays(java.util.Arrays) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) CacheInterceptorAdapter(org.apache.ignite.cache.CacheInterceptorAdapter) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) ClientProcessorMXBean(org.apache.ignite.mxbean.ClientProcessorMXBean) Map(java.util.Map) X(org.apache.ignite.internal.util.typedef.X) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Cache(javax.cache.Cache) IgniteBinary(org.apache.ignite.IgniteBinary) BinaryIdMapper(org.apache.ignite.binary.BinaryIdMapper) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) Collection(java.util.Collection) ClientListenerProcessor(org.apache.ignite.internal.processors.odbc.ClientListenerProcessor) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignition(org.apache.ignite.Ignition) BinaryType(org.apache.ignite.binary.BinaryType) Assert.assertNull(org.junit.Assert.assertNull) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) BinaryWriter(org.apache.ignite.binary.BinaryWriter) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) BinaryObjectImpl(org.apache.ignite.internal.binary.BinaryObjectImpl) Collections(java.util.Collections) BinarySerializer(org.apache.ignite.binary.BinarySerializer) Assert.assertEquals(org.junit.Assert.assertEquals) LogListener(org.apache.ignite.testframework.LogListener) ClientProcessorMXBean(org.apache.ignite.mxbean.ClientProcessorMXBean) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 82 with ListeningTestLogger

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

the class IgniteDiagnosticMessagesTest method checkLongRunningTx.

/**
 * @param atomicityMode Cache atomicity mode.
 * @throws Exception If failed.
 */
public void checkLongRunningTx(CacheAtomicityMode atomicityMode) throws Exception {
    final int longOpDumpTimeout = 1000;
    System.setProperty(IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT, String.valueOf(longOpDumpTimeout));
    try {
        final Ignite node0 = startGrid(0);
        CacheConfiguration ccfg = cacheConfiguration(atomicityMode);
        node0.createCache(ccfg);
        UUID id0 = node0.cluster().localNode().id();
        ListeningTestLogger testLog = this.testLog = new ListeningTestLogger(false, log);
        String msg1 = "Cache entries [cacheId=" + CU.cacheId(DEFAULT_CACHE_NAME) + ", cacheName=" + DEFAULT_CACHE_NAME + "]:";
        String msg2 = "General node info [id=" + id0;
        LogListener lsnr = LogListener.matches(msg1).andMatches(msg2).build();
        testLog.registerListener(lsnr);
        final Ignite node1 = startGrid(1);
        awaitPartitionMapExchange();
        final CountDownLatch l1 = new CountDownLatch(1);
        final CountDownLatch l2 = new CountDownLatch(1);
        final AtomicReference<Integer> key = new AtomicReference<>();
        GridCompoundFuture<Void, Void> fut = new GridCompoundFuture<>();
        fut.add(GridTestUtils.runAsync(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                IgniteCache<Object, Object> cache = node0.cache(DEFAULT_CACHE_NAME);
                try (Transaction tx = node0.transactions().txStart()) {
                    key.set(primaryKey(cache));
                    cache.putIfAbsent(key.get(), "dummy val");
                    l1.countDown();
                    l2.await();
                    tx.commit();
                }
                return null;
            }
        }, "tx-1"));
        fut.add(GridTestUtils.runAsync(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                IgniteCache<Object, Object> cache = node1.cache(DEFAULT_CACHE_NAME);
                try (Transaction tx = node1.transactions().txStart()) {
                    l1.await();
                    cache.replace(key.get(), "dummy val2");
                    tx.commit();
                }
                return null;
            }
        }, "tx-2"));
        fut.markInitialized();
        U.sleep(longOpDumpTimeout);
        assertFalse(fut.isDone());
        boolean wait = waitForCondition(lsnr::check, longOpDumpTimeout * 2);
        l2.countDown();
        fut.get();
        assertTrue("Unable to found diagnostic messages.", wait);
    } finally {
        System.clearProperty(IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT);
    }
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) AtomicReference(java.util.concurrent.atomic.AtomicReference) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) CountDownLatch(java.util.concurrent.CountDownLatch) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) Callable(java.util.concurrent.Callable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 83 with ListeningTestLogger

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

the class IgniteDiagnosticMessagesTest method testTimeOutTxLock.

/**
 * Tests that {@link org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLockFuture} timeout object
 * dumps debug info to log.
 *
 * @throws Exception If fails.
 */
@Test
public void testTimeOutTxLock() throws Exception {
    final int longOpDumpTimeout = 500;
    ListeningTestLogger testLog = new ListeningTestLogger(false, log);
    IgniteLogger oldLog = GridTestUtils.getFieldValue(GridDhtLockFuture.class, "log");
    GridTestUtils.setFieldValue(GridDhtLockFuture.class, "log", testLog);
    try {
        IgniteEx grid1 = startGrid(0);
        LogListener lsnr = LogListener.matches(Pattern.compile("Transaction tx=GridNearTxLocal \\[.*\\] timed out, can't acquire lock for")).andMatches(Pattern.compile(".*xid=.*, xidVer=.*, nearXid=.*, nearXidVer=.*, label=lock, " + "nearNodeId=" + grid1.cluster().localNode().id() + ".*")).build();
        testLog.registerListener(lsnr);
        this.testLog = testLog;
        IgniteEx grid2 = startGrid(1);
        grid2.context().cache().context().tm().longOperationsDumpTimeout(longOpDumpTimeout);
        awaitPartitionMapExchange();
        emulateTxLockTimeout(grid1, grid2);
        assertTrue(lsnr.check());
    } finally {
        GridTestUtils.setFieldValue(GridDhtLockFuture.class, "log", oldLog);
    }
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) IgniteEx(org.apache.ignite.internal.IgniteEx) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) IgniteLogger(org.apache.ignite.IgniteLogger) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 84 with ListeningTestLogger

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

the class EvictPartitionInLogTest method beforeTestsStarted.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTestsStarted() throws Exception {
    super.beforeTestsStarted();
    clearStaticLog(GridDhtLocalPartition.class);
    testLog = new ListeningTestLogger(false, log);
}
Also used : ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger)

Example 85 with ListeningTestLogger

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

the class WalDeletionArchiveAbstractTest method testSingleCleanWalArchive.

/**
 * Checks that the deletion of WAL segments occurs with the maximum number of segments.
 *
 * @throws Exception If failed.
 */
@Test
@WithSystemProperty(key = IGNITE_CHECKPOINT_TRIGGER_ARCHIVE_SIZE_PERCENTAGE, value = "1000")
public void testSingleCleanWalArchive() throws Exception {
    IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(0)).setCacheConfiguration(cacheConfiguration()).setDataStorageConfiguration(new DataStorageConfiguration().setCheckpointFrequency(Long.MAX_VALUE).setMaxWalArchiveSize(5 * MB).setWalSegmentSize((int) MB).setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true).setMaxSize(GB).setCheckpointPageBufferSize(GB)));
    ListeningTestLogger listeningLog = new ListeningTestLogger(cfg.getGridLogger());
    cfg.setGridLogger(listeningLog);
    IgniteEx n = startGrid(cfg);
    n.cluster().state(ClusterState.ACTIVE);
    awaitPartitionMapExchange();
    for (int i = 0; walArchiveSize(n) < 20L * cfg.getDataStorageConfiguration().getWalSegmentSize(); ) n.cache(DEFAULT_CACHE_NAME).put(i++, new byte[(int) (512 * KB)]);
    assertEquals(-1, wal(n).lastTruncatedSegment());
    assertEquals(0, gridDatabase(n).lastCheckpointMarkWalPointer().index());
    Collection<String> logStrs = new ConcurrentLinkedQueue<>();
    listeningLog.registerListener(logStr -> {
        if (logStr.contains("Finish clean WAL archive"))
            logStrs.add(logStr);
    });
    forceCheckpoint();
    long maxWalArchiveSize = cfg.getDataStorageConfiguration().getMaxWalArchiveSize();
    assertTrue(waitForCondition(() -> walArchiveSize(n) < maxWalArchiveSize, getTestTimeout()));
    assertEquals(logStrs.toString(), 1, logStrs.size());
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

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