Search in sources :

Example 81 with Cache

use of javax.cache.Cache in project ignite by apache.

the class SqlSystemViewsSelfTest method testIoStatisticsViews.

/**
 * Test IO statistics SQL system views for cache groups.
 *
 * @throws Exception
 */
@Test
public void testIoStatisticsViews() throws Exception {
    Ignite ignite = startGrid(getTestIgniteInstanceName(), getPdsConfiguration("node0"));
    ignite.cluster().active(true);
    execSql("CREATE TABLE TST(id INTEGER PRIMARY KEY, name VARCHAR, age integer)");
    for (int i = 0; i < 500; i++) execSql("INSERT INTO TST(id, name, age) VALUES (" + i + ",'name-" + i + "'," + i + 1 + ")");
    String sql1 = "SELECT CACHE_GROUP_ID, CACHE_GROUP_NAME, PHYSICAL_READS, LOGICAL_READS FROM " + systemSchemaName() + ".LOCAL_CACHE_GROUPS_IO";
    List<List<?>> res1 = execSql(sql1);
    Map<?, ?> map = res1.stream().collect(Collectors.toMap(k -> k.get(1), v -> v.get(3)));
    assertEquals(2, map.size());
    assertTrue(map.containsKey("SQL_PUBLIC_TST"));
    assertTrue((Long) map.get("SQL_PUBLIC_TST") > 0);
    assertTrue(map.containsKey(DEFAULT_CACHE_NAME));
    sql1 = "SELECT CACHE_GROUP_ID, CACHE_GROUP_NAME, PHYSICAL_READS, LOGICAL_READS FROM " + systemSchemaName() + ".LOCAL_CACHE_GROUPS_IO WHERE CACHE_GROUP_NAME='SQL_PUBLIC_TST'";
    assertEquals(1, execSql(sql1).size());
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) Arrays(java.util.Arrays) EvictionFilter(org.apache.ignite.cache.eviction.EvictionFilter) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) ClusterMetricsImpl(org.apache.ignite.internal.managers.discovery.ClusterMetricsImpl) IgniteNodeAttributes(org.apache.ignite.internal.IgniteNodeAttributes) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) ClusterMetrics(org.apache.ignite.cluster.ClusterMetrics) TopologyValidator(org.apache.ignite.configuration.TopologyValidator) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) SqlQuery(org.apache.ignite.cache.query.SqlQuery) X(org.apache.ignite.internal.util.typedef.X) Cache(javax.cache.Cache) QueryEntity(org.apache.ignite.cache.QueryEntity) Path(java.nio.file.Path) Collectors.toSet(java.util.stream.Collectors.toSet) IndexProcessor(org.apache.ignite.internal.cache.query.index.IndexProcessor) IgniteFuture(org.apache.ignite.lang.IgniteFuture) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) Set(java.util.Set) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) List(java.util.List) EvictionPolicy(org.apache.ignite.cache.eviction.EvictionPolicy) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridNodePredicate(org.apache.ignite.internal.util.lang.GridNodePredicate) QueryCursor(org.apache.ignite.cache.query.QueryCursor) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) AffinityKeyMapper(org.apache.ignite.cache.affinity.AffinityKeyMapper) EvictableEntry(org.apache.ignite.cache.eviction.EvictableEntry) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) Callable(java.util.concurrent.Callable) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) METASTORAGE_CACHE_NAME(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage.METASTORAGE_CACHE_NAME) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) CacheException(javax.cache.CacheException) Factory(javax.cache.configuration.Factory) SqlConfiguration(org.apache.ignite.configuration.SqlConfiguration) ClusterMetricsSnapshot(org.apache.ignite.internal.ClusterMetricsSnapshot) G(org.apache.ignite.internal.util.typedef.G) F(org.apache.ignite.internal.util.typedef.F) LongStream(java.util.stream.LongStream) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) AbstractSchemaSelfTest(org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) Field(java.lang.reflect.Field) IgniteQueryErrorCode(org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode) SqlTableView(org.apache.ignite.spi.systemview.view.SqlTableView) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) TimeUnit(java.util.concurrent.TimeUnit) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Assert(org.junit.Assert) Collections(java.util.Collections) QueryIndex(org.apache.ignite.cache.QueryIndex) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) GridCacheProcessor(org.apache.ignite.internal.processors.cache.GridCacheProcessor) CacheMode(org.apache.ignite.cache.CacheMode) Ignite(org.apache.ignite.Ignite) Arrays.asList(java.util.Arrays.asList) List(java.util.List) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) AbstractSchemaSelfTest(org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest) Test(org.junit.Test)

Example 82 with Cache

use of javax.cache.Cache in project ignite by apache.

the class IgniteWalReaderTest method testRebalanceFlag.

/**
 * Tests transaction generation and WAL for putAll cache operation.
 *
 * @throws Exception if failed.
 */
@Test
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_DISABLE_WAL_DURING_REBALANCING, value = "false")
public void testRebalanceFlag() throws Exception {
    backupCnt = 1;
    IgniteEx ignite = startGrid("node0");
    Ignite ignite1 = startGrid(1);
    ignite.cluster().state(ACTIVE);
    IgniteCache<Integer, IndexedObject> cache = ignite.cache(CACHE_NAME);
    int cntEntries = 100;
    List<Integer> keys = findKeys(ignite.localNode(), cache, cntEntries, 0, 0);
    Map<Integer, IndexedObject> map = new TreeMap<>();
    for (Integer key : keys) map.putIfAbsent(key, new IndexedObject(key));
    cache.putAll(map);
    Ignite ignite2 = startGrid(2);
    ignite.cluster().setBaselineTopology(ignite2.cluster().topologyVersion());
    backupCnt = 0;
    awaitPartitionMapExchange(false, true, null);
    String subfolderName1 = genDbSubfolderName(ignite, 0);
    String subfolderName2 = genDbSubfolderName(ignite1, 1);
    String subfolderName3 = genDbSubfolderName(ignite2, 2);
    stopAllGrids();
    String workDir = U.defaultWorkDirectory();
    IgniteWalIteratorFactory factory = new IgniteWalIteratorFactory(log);
    Map<GridCacheOperation, Integer> operationsFound = new EnumMap<>(GridCacheOperation.class);
    IgniteInClosure<DataRecord> drHnd = dataRecord -> {
        for (int i = 0; i < dataRecord.entryCount(); i++) {
            DataEntry entry = dataRecord.get(i);
            GridCacheOperation op = entry.op();
            Integer cnt = operationsFound.get(op);
            operationsFound.put(op, cnt == null ? 1 : (cnt + 1));
        }
    };
    scanIterateAndCount(factory, createIteratorParametersBuilder(workDir, subfolderName1).filesOrDirs(workDir + "/db/wal/" + subfolderName1, workDir + "/db/wal/archive/" + subfolderName1), 1, 1, null, drHnd);
    primary = false;
    scanIterateAndCount(factory, createIteratorParametersBuilder(workDir, subfolderName2).filesOrDirs(workDir + "/db/wal/" + subfolderName2, workDir + "/db/wal/archive/" + subfolderName2), 1, 1, null, drHnd);
    rebalance = true;
    scanIterateAndCount(factory, createIteratorParametersBuilder(workDir, subfolderName3).filesOrDirs(workDir + "/db/wal/" + subfolderName3, workDir + "/db/wal/archive/" + subfolderName3), 1, 0, null, drHnd);
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) BinaryObject(org.apache.ignite.binary.BinaryObject) MVCC_DATA_RECORD(org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.MVCC_DATA_RECORD) ObjectOutput(java.io.ObjectOutput) Transaction(org.apache.ignite.transactions.Transaction) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) DATA_RECORD_V2(org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.DATA_RECORD_V2) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NullLogger(org.apache.ignite.logger.NullLogger) TxRecord(org.apache.ignite.internal.pagemem.wal.record.TxRecord) CREATE(org.apache.ignite.internal.processors.cache.GridCacheOperation.CREATE) Map(java.util.Map) Cache(javax.cache.Cache) DELETE(org.apache.ignite.internal.processors.cache.GridCacheOperation.DELETE) PdsFolderResolver.genNewStyleSubfolderName(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderResolver.genNewStyleSubfolderName) WALMode(org.apache.ignite.configuration.WALMode) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Externalizable(java.io.Externalizable) EnumMap(java.util.EnumMap) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) UUID(java.util.UUID) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) IgniteCache(org.apache.ignite.IgniteCache) Serializable(java.io.Serializable) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) EVT_WAL_SEGMENT_COMPACTED(org.apache.ignite.events.EventType.EVT_WAL_SEGMENT_COMPACTED) MvccFeatureChecker(org.apache.ignite.testframework.MvccFeatureChecker) DFLT_STORE_DIR(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.DFLT_STORE_DIR) ObjectInput(java.io.ObjectInput) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) NotNull(org.jetbrains.annotations.NotNull) MarshalledDataEntry(org.apache.ignite.internal.pagemem.wal.record.MarshalledDataEntry) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) ClusterState(org.apache.ignite.cluster.ClusterState) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) U(org.apache.ignite.internal.util.typedef.internal.U) EVT_WAL_SEGMENT_ARCHIVED(org.apache.ignite.events.EventType.EVT_WAL_SEGMENT_ARCHIVED) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UnwrappedDataEntry(org.apache.ignite.internal.pagemem.wal.record.UnwrappedDataEntry) UnwrapDataEntry(org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry) IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) Assume(org.junit.Assume) IgniteEvents(org.apache.ignite.IgniteEvents) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) Arrays.fill(java.util.Arrays.fill) Iterator(java.util.Iterator) IOException(java.io.IOException) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) File(java.io.File) T2(org.apache.ignite.internal.util.typedef.T2) TimeUnit(java.util.concurrent.TimeUnit) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) AtomicLong(java.util.concurrent.atomic.AtomicLong) TreeMap(java.util.TreeMap) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) RecordUtils(org.apache.ignite.testframework.wal.record.RecordUtils) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) WalSegmentArchivedEvent(org.apache.ignite.events.WalSegmentArchivedEvent) Assert(org.junit.Assert) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) TreeMap(java.util.TreeMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) MarshalledDataEntry(org.apache.ignite.internal.pagemem.wal.record.MarshalledDataEntry) UnwrappedDataEntry(org.apache.ignite.internal.pagemem.wal.record.UnwrappedDataEntry) UnwrapDataEntry(org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) EnumMap(java.util.EnumMap) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 83 with Cache

use of javax.cache.Cache in project ignite by apache.

the class IgniteWalReaderTest method testIteratorWithCurrentKernelContext.

/**
 * Tests WAL iterator which uses shared cache context of currently started Ignite node.
 */
@Test
public void testIteratorWithCurrentKernelContext() throws Exception {
    IgniteEx ignite = startGrid(0);
    ignite.cluster().active(true);
    int cntEntries = 100;
    putDummyRecords(ignite, cntEntries);
    String workDir = U.defaultWorkDirectory();
    IgniteWalIteratorFactory factory = new IgniteWalIteratorFactory(log);
    IteratorParametersBuilder iterParametersBuilder = createIteratorParametersBuilder(workDir, genDbSubfolderName(ignite, 0)).filesOrDirs(workDir).binaryMetadataFileStoreDir(null).marshallerMappingFileStoreDir(null).sharedContext(ignite.context().cache().context());
    AtomicInteger cnt = new AtomicInteger();
    IgniteBiInClosure<Object, Object> objConsumer = (key, val) -> {
        if (val instanceof IndexedObject) {
            assertEquals(key, ((IndexedObject) val).iVal);
            assertEquals(key, cnt.getAndIncrement());
        }
    };
    iterateAndCountDataRecord(factory.iterator(iterParametersBuilder.copy()), objConsumer, null);
    assertEquals(cntEntries, cnt.get());
    // Test without converting non primary types.
    iterParametersBuilder.keepBinary(true);
    cnt.set(0);
    IgniteBiInClosure<Object, Object> binObjConsumer = (key, val) -> {
        if (val instanceof BinaryObject) {
            assertEquals(key, ((BinaryObject) val).field("iVal"));
            assertEquals(key, cnt.getAndIncrement());
        }
    };
    iterateAndCountDataRecord(factory.iterator(iterParametersBuilder.copy()), binObjConsumer, null);
    assertEquals(cntEntries, cnt.get());
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) BinaryObject(org.apache.ignite.binary.BinaryObject) MVCC_DATA_RECORD(org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.MVCC_DATA_RECORD) ObjectOutput(java.io.ObjectOutput) Transaction(org.apache.ignite.transactions.Transaction) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) DATA_RECORD_V2(org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.DATA_RECORD_V2) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NullLogger(org.apache.ignite.logger.NullLogger) TxRecord(org.apache.ignite.internal.pagemem.wal.record.TxRecord) CREATE(org.apache.ignite.internal.processors.cache.GridCacheOperation.CREATE) Map(java.util.Map) Cache(javax.cache.Cache) DELETE(org.apache.ignite.internal.processors.cache.GridCacheOperation.DELETE) PdsFolderResolver.genNewStyleSubfolderName(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderResolver.genNewStyleSubfolderName) WALMode(org.apache.ignite.configuration.WALMode) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Externalizable(java.io.Externalizable) EnumMap(java.util.EnumMap) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) UUID(java.util.UUID) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) IgniteCache(org.apache.ignite.IgniteCache) Serializable(java.io.Serializable) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) EVT_WAL_SEGMENT_COMPACTED(org.apache.ignite.events.EventType.EVT_WAL_SEGMENT_COMPACTED) MvccFeatureChecker(org.apache.ignite.testframework.MvccFeatureChecker) DFLT_STORE_DIR(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.DFLT_STORE_DIR) ObjectInput(java.io.ObjectInput) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) NotNull(org.jetbrains.annotations.NotNull) MarshalledDataEntry(org.apache.ignite.internal.pagemem.wal.record.MarshalledDataEntry) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) ClusterState(org.apache.ignite.cluster.ClusterState) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) U(org.apache.ignite.internal.util.typedef.internal.U) EVT_WAL_SEGMENT_ARCHIVED(org.apache.ignite.events.EventType.EVT_WAL_SEGMENT_ARCHIVED) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UnwrappedDataEntry(org.apache.ignite.internal.pagemem.wal.record.UnwrappedDataEntry) UnwrapDataEntry(org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry) IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) Assume(org.junit.Assume) IgniteEvents(org.apache.ignite.IgniteEvents) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) Arrays.fill(java.util.Arrays.fill) Iterator(java.util.Iterator) IOException(java.io.IOException) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) File(java.io.File) T2(org.apache.ignite.internal.util.typedef.T2) TimeUnit(java.util.concurrent.TimeUnit) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) AtomicLong(java.util.concurrent.atomic.AtomicLong) TreeMap(java.util.TreeMap) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) RecordUtils(org.apache.ignite.testframework.wal.record.RecordUtils) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) WalSegmentArchivedEvent(org.apache.ignite.events.WalSegmentArchivedEvent) Assert(org.junit.Assert) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) BinaryObject(org.apache.ignite.binary.BinaryObject) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) BinaryObject(org.apache.ignite.binary.BinaryObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 84 with Cache

use of javax.cache.Cache in project ignite by apache.

the class GridCommonAbstractTest method assertCountersSame.

/**
 * @param partId Partition.
 * @param withReserveCntr {@code True} to compare reserve counters. Because reserve counters are synced during
 * @param cacheName Cache name.
 * PME invoking with {@code true} makes sense only after PME was finished.
 */
protected void assertCountersSame(int partId, boolean withReserveCntr, String cacheName) throws AssertionFailedError {
    PartitionUpdateCounter cntr0 = null;
    List<T3<String, @Nullable PartitionUpdateCounter, Boolean>> cntrMap = G.allGrids().stream().filter(ignite -> !ignite.configuration().isClientMode()).map(ignite -> new T3<>(ignite.name(), counter(partId, cacheName, ignite.name()), ignite.affinity(cacheName).isPrimary(ignite.cluster().localNode(), partId))).collect(toList());
    for (T3<String, PartitionUpdateCounter, Boolean> cntr : cntrMap) {
        if (cntr.get2() == null)
            continue;
        if (cntr0 != null) {
            assertEquals("Expecting same counters [partId=" + partId + ", cntrs=" + cntrMap + ']', cntr0, cntr.get2());
            if (withReserveCntr)
                assertEquals("Expecting same reservation counters [partId=" + partId + ", cntrs=" + cntrMap + ']', cntr0.reserved(), cntr.get2().reserved());
        }
        cntr0 = cntr.get2();
    }
}
Also used : Arrays(java.util.Arrays) ObjectInstance(javax.management.ObjectInstance) GridCacheUtils.isNearEnabled(org.apache.ignite.internal.processors.cache.GridCacheUtils.isNearEnabled) Map(java.util.Map) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Cache(javax.cache.Cache) AffinityFunctionContext(org.apache.ignite.cache.affinity.AffinityFunctionContext) GridDhtColocatedCache(org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache) ComputeTask(org.apache.ignite.compute.ComputeTask) ComputeTaskFuture(org.apache.ignite.compute.ComputeTaskFuture) GridAffinityFunctionContextImpl(org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteServiceProcessor(org.apache.ignite.internal.processors.service.IgniteServiceProcessor) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) LOCAL(org.apache.ignite.cache.CacheMode.LOCAL) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Event(org.apache.ignite.events.Event) CacheGroupDescriptor(org.apache.ignite.internal.processors.cache.CacheGroupDescriptor) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Set(java.util.Set) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteCache(org.apache.ignite.IgniteCache) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Stream(java.util.stream.Stream) DFLT_STORE_DIR(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.DFLT_STORE_DIR) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteCompute(org.apache.ignite.IgniteCompute) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) Affinity(org.apache.ignite.cache.affinity.Affinity) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) U(org.apache.ignite.internal.util.typedef.internal.U) Callable(java.util.concurrent.Callable) IgniteLogger(org.apache.ignite.IgniteLogger) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) SSLSession(javax.net.ssl.SSLSession) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) IgniteEvents(org.apache.ignite.IgniteEvents) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) CompletionListener(javax.cache.integration.CompletionListener) DFLT_SNAPSHOT_DIRECTORY(org.apache.ignite.configuration.IgniteConfiguration.DFLT_SNAPSHOT_DIRECTORY) AssertionFailedError(junit.framework.AssertionFailedError) Ignite(org.apache.ignite.Ignite) VisorTaskArgument(org.apache.ignite.internal.visor.VisorTaskArgument) T3(org.apache.ignite.internal.util.typedef.T3) GridTestNode(org.apache.ignite.testframework.GridTestNode) GridDhtCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) TreeMap(java.util.TreeMap) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) IgniteCacheProxyImpl(org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl) GridLocalCache(org.apache.ignite.internal.processors.cache.local.GridLocalCache) IgniteMessaging(org.apache.ignite.IgniteMessaging) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) GridCacheExplicitLockSpan(org.apache.ignite.internal.processors.cache.GridCacheExplicitLockSpan) VisorIdleVerifyTaskV2(org.apache.ignite.internal.visor.verify.VisorIdleVerifyTaskV2) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HostnameVerifier(javax.net.ssl.HostnameVerifier) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) Method(java.lang.reflect.Method) LoggerResource(org.apache.ignite.resources.LoggerResource) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) Collectors.toSet(java.util.stream.Collectors.toSet) GridDhtTopologyFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture) IgniteFuture(org.apache.ignite.lang.IgniteFuture) CachePeekMode(org.apache.ignite.cache.CachePeekMode) EventType(org.apache.ignite.events.EventType) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) OWNING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING) UUID(java.util.UUID) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) Collectors(java.util.stream.Collectors) NONE(org.apache.ignite.cache.CacheRebalanceMode.NONE) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2) GridCachePartitionExchangeManager(org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) WALDisableContext(org.apache.ignite.internal.processors.cache.WalStateManager.WALDisableContext) IgniteDhtDemandedPartitionsMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtDemandedPartitionsMap) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter) AtomicReference(java.util.concurrent.atomic.AtomicReference) LT(org.apache.ignite.internal.util.typedef.internal.LT) HashSet(java.util.HashSet) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) MBeanServer(javax.management.MBeanServer) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) CacheException(javax.cache.CacheException) IgniteThrowableFunction(org.apache.ignite.internal.util.lang.IgniteThrowableFunction) MXBeanDescription(org.apache.ignite.mxbean.MXBeanDescription) G(org.apache.ignite.internal.util.typedef.G) F(org.apache.ignite.internal.util.typedef.F) VisorIdleVerifyTaskArg(org.apache.ignite.internal.visor.verify.VisorIdleVerifyTaskArg) Iterator(java.util.Iterator) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) GridCacheFuture(org.apache.ignite.internal.processors.cache.GridCacheFuture) TimeUnit(java.util.concurrent.TimeUnit) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) Collectors.toList(java.util.stream.Collectors.toList) Ignition(org.apache.ignite.Ignition) GridTestUtils.setFieldValue(org.apache.ignite.testframework.GridTestUtils.setFieldValue) PA(org.apache.ignite.internal.util.typedef.PA) BitSet(java.util.BitSet) CacheMetricsImpl(org.apache.ignite.internal.processors.cache.CacheMetricsImpl) Collections(java.util.Collections) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) Nullable(org.jetbrains.annotations.Nullable) T3(org.apache.ignite.internal.util.typedef.T3)

Example 85 with Cache

use of javax.cache.Cache in project ignite by apache.

the class IgniteCacheReplicatedQuerySelfTest method testClientOnlyNode.

/**
 * @throws Exception If failed.
 */
@Test
public void testClientOnlyNode() throws Exception {
    try (Ignite g = startClientGrid("client")) {
        IgniteCache<Integer, Integer> c = jcache(g, Integer.class, Integer.class);
        for (int i = 0; i < 10; i++) c.put(i, i);
        // Client cache should be empty.
        assertEquals(0, c.localSize());
        Collection<Cache.Entry<Integer, Integer>> res = c.query(new SqlQuery<Integer, Integer>(Integer.class, "_key >= 5 order by _key")).getAll();
        assertEquals(5, res.size());
        int i = 5;
        for (Cache.Entry<Integer, Integer> e : res) {
            assertEquals(i, e.getKey().intValue());
            assertEquals(i, e.getValue().intValue());
            i++;
        }
    }
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) Ignite(org.apache.ignite.Ignite) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache) IgniteCacheAbstractQuerySelfTest(org.apache.ignite.internal.processors.cache.IgniteCacheAbstractQuerySelfTest) Test(org.junit.Test)

Aggregations

Cache (javax.cache.Cache)271 IgniteCache (org.apache.ignite.IgniteCache)157 Test (org.junit.Test)130 Ignite (org.apache.ignite.Ignite)101 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)68 List (java.util.List)62 Map (java.util.Map)56 ScanQuery (org.apache.ignite.cache.query.ScanQuery)54 ArrayList (java.util.ArrayList)51 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)45 QueryCursor (org.apache.ignite.cache.query.QueryCursor)43 HashMap (java.util.HashMap)41 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)41 Collection (java.util.Collection)38 HashSet (java.util.HashSet)38 CacheManager (javax.cache.CacheManager)38 CacheException (javax.cache.CacheException)35 IgniteEx (org.apache.ignite.internal.IgniteEx)35 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)32 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)32