Search in sources :

Example 1 with CacheView

use of org.apache.ignite.spi.systemview.view.CacheView in project ignite by apache.

the class SystemViewSelfTest method testCachesView.

/**
 * Tests work of {@link SystemView} for caches.
 */
@Test
public void testCachesView() throws Exception {
    try (IgniteEx g = startGrid()) {
        Set<String> cacheNames = new HashSet<>(Arrays.asList("cache-1", "cache-2"));
        for (String name : cacheNames) g.createCache(name);
        SystemView<CacheView> caches = g.context().systemView().view(CACHES_VIEW);
        assertEquals(g.context().cache().cacheDescriptors().size(), F.size(caches.iterator()));
        for (CacheView row : caches) cacheNames.remove(row.cacheName());
        assertTrue(cacheNames.toString(), cacheNames.isEmpty());
    }
}
Also used : CacheView(org.apache.ignite.spi.systemview.view.CacheView) IgniteEx(org.apache.ignite.internal.IgniteEx) HashSet(java.util.HashSet) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Example 2 with CacheView

use of org.apache.ignite.spi.systemview.view.CacheView in project ignite by apache.

the class CdcCacheVersionTest method testConflictVersionWritten.

/**
 * Test that conflict version is writtern to WAL.
 */
@Test
public void testConflictVersionWritten() throws Exception {
    walProvider = (ctx) -> new FileWriteAheadLogManager(ctx) {

        @Override
        public WALPointer log(WALRecord rec) throws IgniteCheckedException {
            if (rec.type() != DATA_RECORD_V2)
                return super.log(rec);
            DataRecord dataRec = (DataRecord) rec;
            for (int i = 0; i < dataRec.entryCount(); i++) {
                DataEntry dataEntry = dataRec.writeEntries().get(i);
                assertEquals(CU.cacheId(DEFAULT_CACHE_NAME), dataEntry.cacheId());
                assertEquals(DFLT_CLUSTER_ID, dataEntry.writeVersion().dataCenterId());
                assertNotNull(dataEntry.writeVersion().conflictVersion());
                assertEquals(OTHER_CLUSTER_ID, dataEntry.writeVersion().conflictVersion().dataCenterId());
                walRecCheckedCntr.incrementAndGet();
            }
            return super.log(rec);
        }
    };
    conflictResolutionMgrSupplier = () -> new CacheVersionConflictResolver() {

        @Override
        public <K1, V1> GridCacheVersionConflictContext<K1, V1> resolve(CacheObjectValueContext ctx, GridCacheVersionedEntryEx<K1, V1> oldEntry, GridCacheVersionedEntryEx<K1, V1> newEntry, boolean atomicVerComparator) {
            GridCacheVersionConflictContext<K1, V1> res = new GridCacheVersionConflictContext<>(ctx, oldEntry, newEntry);
            res.useNew();
            assertEquals(OTHER_CLUSTER_ID, newEntry.version().dataCenterId());
            if (!oldEntry.isStartVersion())
                assertEquals(OTHER_CLUSTER_ID, oldEntry.version().dataCenterId());
            conflictCheckedCntr.incrementAndGet();
            return res;
        }

        @Override
        public String toString() {
            return "TestCacheConflictResolutionManager";
        }
    };
    startGrids(gridCnt);
    IgniteEx cli = startClientGrid(gridCnt);
    for (int i = 0; i < gridCnt; i++) {
        grid(i).context().cache().context().versions().dataCenterId(DFLT_CLUSTER_ID);
        assertEquals(DFLT_CLUSTER_ID, grid(i).context().metric().registry(CACHE_METRICS).<IntMetric>findMetric(DATA_VER_CLUSTER_ID).value());
    }
    cli.cluster().state(ACTIVE);
    IgniteCache<Integer, User> cache = cli.getOrCreateCache(new CacheConfiguration<Integer, User>(DEFAULT_CACHE_NAME).setCacheMode(cacheMode).setAtomicityMode(atomicityMode).setBackups(Integer.MAX_VALUE));
    if (atomicityMode == ATOMIC)
        putRemoveCheck(cli, cache, null, null);
    else {
        // Check operations for transaction cache without explicit transaction.
        putRemoveCheck(cli, cache, null, null);
        // Check operations for transaction cache with explicit transaction in all modes.
        for (TransactionConcurrency concurrency : TransactionConcurrency.values()) for (TransactionIsolation isolation : TransactionIsolation.values()) putRemoveCheck(cli, cache, concurrency, isolation);
    }
    for (int i = 0; i < gridCnt; i++) {
        boolean dfltCacheFound = false;
        assertFalse(grid(i).context().clientNode());
        SystemView<CacheView> caches = grid(i).context().systemView().view(CACHES_VIEW);
        for (CacheView v : caches) {
            if (v.cacheName().equals(DEFAULT_CACHE_NAME)) {
                assertEquals(v.conflictResolver(), "TestCacheConflictResolutionManager");
                dfltCacheFound = true;
            } else
                assertNull(v.conflictResolver());
        }
        assertTrue(dfltCacheFound);
    }
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheView(org.apache.ignite.spi.systemview.view.CacheView) CacheObjectValueContext(org.apache.ignite.internal.processors.cache.CacheObjectValueContext) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) IntMetric(org.apache.ignite.spi.metric.IntMetric) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CacheVersionConflictResolver(org.apache.ignite.internal.processors.cache.version.CacheVersionConflictResolver) GridCacheVersionConflictContext(org.apache.ignite.internal.processors.cache.version.GridCacheVersionConflictContext) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) IgniteEx(org.apache.ignite.internal.IgniteEx) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) Test(org.junit.Test)

Aggregations

IgniteEx (org.apache.ignite.internal.IgniteEx)2 CacheView (org.apache.ignite.spi.systemview.view.CacheView)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)1 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)1 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)1 CacheObjectValueContext (org.apache.ignite.internal.processors.cache.CacheObjectValueContext)1 FileWriteAheadLogManager (org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager)1 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)1 CacheVersionConflictResolver (org.apache.ignite.internal.processors.cache.version.CacheVersionConflictResolver)1 GridCacheVersionConflictContext (org.apache.ignite.internal.processors.cache.version.GridCacheVersionConflictContext)1 IntMetric (org.apache.ignite.spi.metric.IntMetric)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 TransactionConcurrency (org.apache.ignite.transactions.TransactionConcurrency)1 TransactionIsolation (org.apache.ignite.transactions.TransactionIsolation)1