Search in sources :

Example 1 with PlatformExpiryPolicy

use of org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy in project ignite by apache.

the class IgnitePersistentStoreCacheGroupsTest method _testExpiryPolicy.

/**
 * @throws Exception If failed.
 */
public void _testExpiryPolicy() throws Exception {
    long ttl = 10000;
    CacheConfiguration[] ccfgs1 = new CacheConfiguration[5];
    ccfgs1[0] = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1);
    ccfgs1[1] = cacheConfiguration(GROUP1, "c2", PARTITIONED, TRANSACTIONAL, 1);
    ccfgs1[2] = cacheConfiguration(GROUP2, "c3", PARTITIONED, ATOMIC, 1);
    ccfgs1[3] = cacheConfiguration(GROUP2, "c4", PARTITIONED, TRANSACTIONAL, 1);
    ccfgs1[4] = cacheConfiguration(null, "c5", PARTITIONED, ATOMIC, 1);
    String[] caches = { "c1", "c2", "c3", "c4", "c5" };
    startGrids(3);
    Ignite node = ignite(0);
    node.active(true);
    node.createCaches(Arrays.asList(ccfgs1));
    ExpiryPolicy plc = new PlatformExpiryPolicy(ttl, -2, -2);
    for (String cacheName : caches) {
        IgniteCache<Object, Object> cache = node.cache(cacheName).withExpiryPolicy(plc);
        for (int i = 0; i < entriesCount(); i++) cache.put(i, cacheName + i);
    }
    long deadline = System.currentTimeMillis() + (long) (ttl * 1.2);
    stopAllGrids();
    startGrids(3);
    node = ignite(0);
    node.active(true);
    for (String cacheName : caches) {
        IgniteCache<Object, Object> cache = node.cache(cacheName);
        for (int i = 0; i < entriesCount(); i++) assertEquals(cacheName + i, cache.get(i));
        assertEquals(entriesCount(), cache.size());
    }
    // Wait for expiration.
    Thread.sleep(Math.max(deadline - System.currentTimeMillis(), 0));
    for (String cacheName : caches) {
        IgniteCache<Object, Object> cache = node.cache(cacheName);
        assertEquals(0, cache.size());
    }
}
Also used : PlatformExpiryPolicy(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) Ignite(org.apache.ignite.Ignite) PlatformExpiryPolicy(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 2 with PlatformExpiryPolicy

use of org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy in project ignite by apache.

the class JavaThinCompatibilityTest method testCacheConfiguration.

/**
 */
private void testCacheConfiguration(boolean checkFieldsPrecessionAndScale, boolean checkExpiryPlc) throws Exception {
    X.println(">>>> Testing cache configuration");
    try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(ADDR))) {
        String cacheName = "testCacheConfiguration";
        ClientCacheConfiguration ccfg = new ClientCacheConfiguration();
        ccfg.setName(cacheName);
        ccfg.setBackups(3);
        ccfg.setGroupName("cache");
        ccfg.setCacheMode(CacheMode.PARTITIONED);
        QueryEntity qryEntity = new QueryEntity(int.class.getName(), "Entity").setTableName("ENTITY").setFields(new LinkedHashMap<>(F.asMap("id", Integer.class.getName(), "rate", Double.class.getName())));
        if (checkFieldsPrecessionAndScale) {
            qryEntity.setFieldsPrecision(F.asMap("rate", 5));
            qryEntity.setFieldsScale(F.asMap("rate", 2));
        }
        ccfg.setQueryEntities(qryEntity);
        if (checkExpiryPlc)
            ccfg.setExpiryPolicy(new PlatformExpiryPolicy(10, 20, 30));
        client.createCache(ccfg);
        ClientCacheConfiguration ccfg1 = client.cache(cacheName).getConfiguration();
        assertEquals(ccfg.getName(), ccfg1.getName());
        assertEquals(ccfg.getBackups(), ccfg1.getBackups());
        assertEquals(ccfg.getGroupName(), ccfg1.getGroupName());
        assertEquals(ccfg.getCacheMode(), ccfg1.getCacheMode());
        assertEquals(ccfg.getQueryEntities().length, ccfg1.getQueryEntities().length);
        assertEquals(ccfg.getQueryEntities()[0].getTableName(), ccfg1.getQueryEntities()[0].getTableName());
        assertEquals(ccfg.getQueryEntities()[0].getFields(), ccfg1.getQueryEntities()[0].getFields());
        if (checkFieldsPrecessionAndScale) {
            assertEquals(ccfg.getQueryEntities()[0].getFieldsPrecision(), ccfg1.getQueryEntities()[0].getFieldsPrecision());
            assertEquals(ccfg.getQueryEntities()[0].getFieldsScale(), ccfg1.getQueryEntities()[0].getFieldsScale());
        }
        if (checkExpiryPlc) {
            assertEquals(ccfg.getExpiryPolicy().getExpiryForCreation(), ccfg1.getExpiryPolicy().getExpiryForCreation());
            assertEquals(ccfg.getExpiryPolicy().getExpiryForAccess(), ccfg1.getExpiryPolicy().getExpiryForAccess());
            assertEquals(ccfg.getExpiryPolicy().getExpiryForUpdate(), ccfg1.getExpiryPolicy().getExpiryForUpdate());
        }
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) QueryEntity(org.apache.ignite.cache.QueryEntity) PlatformExpiryPolicy(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration) ClientCacheConfiguration(org.apache.ignite.client.ClientCacheConfiguration)

Example 3 with PlatformExpiryPolicy

use of org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy in project ignite by apache.

the class FunctionalTest method testCacheConfiguration.

/**
 * Tested API:
 * <ul>
 * <li>{@link ClientCache#getName()}</li>
 * <li>{@link ClientCache#getConfiguration()}</li>
 * </ul>
 */
@Test
public void testCacheConfiguration() throws Exception {
    final String dataRegionName = "functional-test-data-region";
    IgniteConfiguration cfg = Config.getServerConfiguration().setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setName(dataRegionName)));
    try (Ignite ignored = Ignition.start(cfg);
        IgniteClient client = Ignition.startClient(getClientConfiguration())) {
        final String CACHE_NAME = "testCacheConfiguration";
        ClientCacheConfiguration cacheCfgTemplate = new ClientCacheConfiguration().setName(CACHE_NAME).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setBackups(3).setCacheMode(CacheMode.PARTITIONED).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setEagerTtl(false).setGroupName("FunctionalTest").setDefaultLockTimeout(12345).setPartitionLossPolicy(PartitionLossPolicy.READ_WRITE_SAFE).setReadFromBackup(true).setRebalanceBatchSize(67890).setRebalanceBatchesPrefetchCount(102938).setRebalanceDelay(54321).setRebalanceMode(CacheRebalanceMode.SYNC).setRebalanceOrder(2).setRebalanceThrottle(564738).setRebalanceTimeout(142536).setKeyConfiguration(new CacheKeyConfiguration("Employee", "orgId")).setQueryEntities(new QueryEntity(int.class.getName(), "Employee").setTableName("EMPLOYEE").setFields(Stream.of(new SimpleEntry<>("id", Integer.class.getName()), new SimpleEntry<>("orgId", Integer.class.getName())).collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue, (a, b) -> a, LinkedHashMap::new))).setKeyFields(Collections.emptySet()).setKeyFieldName("id").setNotNullFields(Collections.singleton("id")).setDefaultFieldValues(Collections.singletonMap("id", 0)).setIndexes(Collections.singletonList(new QueryIndex("id", true, "IDX_EMPLOYEE_ID"))).setAliases(Stream.of("id", "orgId").collect(Collectors.toMap(f -> f, String::toUpperCase)))).setExpiryPolicy(new PlatformExpiryPolicy(10, 20, 30)).setCopyOnRead(!CacheConfiguration.DFLT_COPY_ON_READ).setDataRegionName(dataRegionName).setMaxConcurrentAsyncOperations(4).setMaxQueryIteratorsCount(4).setOnheapCacheEnabled(true).setQueryDetailMetricsSize(1024).setQueryParallelism(4).setSqlEscapeAll(true).setSqlIndexMaxInlineSize(1024).setSqlSchema("functional-test-schema").setStatisticsEnabled(true);
        ClientCacheConfiguration cacheCfg = new ClientCacheConfiguration(cacheCfgTemplate);
        ClientCache<Object, Object> cache = client.createCache(cacheCfg);
        assertEquals(CACHE_NAME, cache.getName());
        assertTrue(Comparers.equal(cacheCfgTemplate, cache.getConfiguration()));
    }
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ModifiedExpiryPolicy(javax.cache.expiry.ModifiedExpiryPolicy) BinaryObject(org.apache.ignite.binary.BinaryObject) Arrays(java.util.Arrays) AbstractBinaryArraysTest(org.apache.ignite.internal.binary.AbstractBinaryArraysTest) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) Date(java.util.Date) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) TestEnum(org.apache.ignite.internal.processors.cache.CacheEnumOperationsAbstractTest.TestEnum) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) AccessedExpiryPolicy(javax.cache.expiry.AccessedExpiryPolicy) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) VAL3(org.apache.ignite.internal.processors.cache.CacheEnumOperationsAbstractTest.TestEnum.VAL3) VAL1(org.apache.ignite.internal.processors.cache.CacheEnumOperationsAbstractTest.TestEnum.VAL1) VAL2(org.apache.ignite.internal.processors.cache.CacheEnumOperationsAbstractTest.TestEnum.VAL2) Map(java.util.Map) QueryEntity(org.apache.ignite.cache.QueryEntity) ClientStatus(org.apache.ignite.internal.processors.platform.client.ClientStatus) GridTestUtils.assertThrowsAnyCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsAnyCause) CyclicBarrier(java.util.concurrent.CyclicBarrier) ImmutableSet(com.google.common.collect.ImmutableSet) CachePeekMode(org.apache.ignite.cache.CachePeekMode) SystemView(org.apache.ignite.spi.systemview.view.SystemView) TransactionView(org.apache.ignite.spi.systemview.view.TransactionView) Set(java.util.Set) OPTIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC) READ_COMMITTED(org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED) ClientListenerProcessor(org.apache.ignite.internal.processors.odbc.ClientListenerProcessor) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Stream(java.util.stream.Stream) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) IntStream(java.util.stream.IntStream) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) ClientServerError(org.apache.ignite.internal.client.thin.ClientServerError) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) PartitionLossPolicy(org.apache.ignite.cache.PartitionLossPolicy) PlatformExpiryPolicy(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy) ClientProcessorMXBean(org.apache.ignite.mxbean.ClientProcessorMXBean) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Timeout(org.junit.rules.Timeout) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) LinkedList(java.util.LinkedList) SimpleEntry(java.util.AbstractMap.SimpleEntry) Duration(javax.cache.expiry.Duration) F(org.apache.ignite.internal.util.typedef.F) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) Iterator(java.util.Iterator) TXS_MON_LIST(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager.TXS_MON_LIST) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) T2(org.apache.ignite.internal.util.typedef.T2) TimeUnit(java.util.concurrent.TimeUnit) Ignition(org.apache.ignite.Ignition) Rule(org.junit.Rule) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Collections(java.util.Collections) QueryIndex(org.apache.ignite.cache.QueryIndex) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) CacheMode(org.apache.ignite.cache.CacheMode) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) SimpleEntry(java.util.AbstractMap.SimpleEntry) QueryEntity(org.apache.ignite.cache.QueryEntity) PlatformExpiryPolicy(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) QueryIndex(org.apache.ignite.cache.QueryIndex) Ignite(org.apache.ignite.Ignite) BinaryObject(org.apache.ignite.binary.BinaryObject) AbstractBinaryArraysTest(org.apache.ignite.internal.binary.AbstractBinaryArraysTest) Test(org.junit.Test)

Example 4 with PlatformExpiryPolicy

use of org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy in project ignite by apache.

the class ClientUtils method cacheConfiguration.

/**
 * Deserialize configuration from stream.
 */
ClientCacheConfiguration cacheConfiguration(BinaryInputStream in, ProtocolContext protocolCtx) throws IOException {
    try (BinaryReaderExImpl reader = createBinaryReader(in)) {
        // Do not need length to read data. The protocol defines fixed configuration layout.
        reader.readInt();
        return // cache name is to be assigned later
        new ClientCacheConfiguration().setName("TBD").setAtomicityMode(CacheAtomicityMode.fromOrdinal(reader.readInt())).setBackups(reader.readInt()).setCacheMode(CacheMode.fromOrdinal(reader.readInt())).setCopyOnRead(reader.readBoolean()).setDataRegionName(reader.readString()).setEagerTtl(reader.readBoolean()).setStatisticsEnabled(reader.readBoolean()).setGroupName(reader.readString()).setDefaultLockTimeout(reader.readLong()).setMaxConcurrentAsyncOperations(reader.readInt()).setMaxQueryIteratorsCount(reader.readInt()).setName(reader.readString()).setOnheapCacheEnabled(reader.readBoolean()).setPartitionLossPolicy(PartitionLossPolicy.fromOrdinal((byte) reader.readInt())).setQueryDetailMetricsSize(reader.readInt()).setQueryParallelism(reader.readInt()).setReadFromBackup(reader.readBoolean()).setRebalanceBatchSize(reader.readInt()).setRebalanceBatchesPrefetchCount(reader.readLong()).setRebalanceDelay(reader.readLong()).setRebalanceMode(CacheRebalanceMode.fromOrdinal(reader.readInt())).setRebalanceOrder(reader.readInt()).setRebalanceThrottle(reader.readLong()).setRebalanceTimeout(reader.readLong()).setSqlEscapeAll(reader.readBoolean()).setSqlIndexMaxInlineSize(reader.readInt()).setSqlSchema(reader.readString()).setWriteSynchronizationMode(CacheWriteSynchronizationMode.fromOrdinal(reader.readInt())).setKeyConfiguration(ClientUtils.collection(in, unused -> new CacheKeyConfiguration(reader.readString(), reader.readString())).toArray(new CacheKeyConfiguration[0])).setQueryEntities(ClientUtils.collection(in, unused -> {
            QueryEntity qryEntity = new QueryEntity(reader.readString(), reader.readString()).setTableName(reader.readString()).setKeyFieldName(reader.readString()).setValueFieldName(reader.readString());
            boolean isPrecisionAndScaleSupported = protocolCtx.isFeatureSupported(QUERY_ENTITY_PRECISION_AND_SCALE);
            Collection<QueryField> qryFields = ClientUtils.collection(in, unused2 -> {
                String name = reader.readString();
                String typeName = reader.readString();
                boolean isKey = reader.readBoolean();
                boolean isNotNull = reader.readBoolean();
                Object dfltVal = reader.readObject();
                int precision = isPrecisionAndScaleSupported ? reader.readInt() : -1;
                int scale = isPrecisionAndScaleSupported ? reader.readInt() : -1;
                return new QueryField(name, typeName, isKey, isNotNull, dfltVal, precision, scale);
            });
            return qryEntity.setFields(qryFields.stream().collect(Collectors.toMap(QueryField::getName, QueryField::getTypeName, (a, b) -> a, LinkedHashMap::new))).setKeyFields(qryFields.stream().filter(QueryField::isKey).map(QueryField::getName).collect(Collectors.toCollection(LinkedHashSet::new))).setNotNullFields(qryFields.stream().filter(QueryField::isNotNull).map(QueryField::getName).collect(Collectors.toSet())).setDefaultFieldValues(qryFields.stream().filter(f -> f.getDefaultValue() != null).collect(Collectors.toMap(QueryField::getName, QueryField::getDefaultValue))).setFieldsPrecision(qryFields.stream().filter(f -> f.getPrecision() != -1).collect(Collectors.toMap(QueryField::getName, QueryField::getPrecision))).setFieldsScale(qryFields.stream().filter(f -> f.getScale() != -1).collect(Collectors.toMap(QueryField::getName, QueryField::getScale))).setAliases(ClientUtils.collection(in, unused3 -> new SimpleEntry<>(reader.readString(), reader.readString())).stream().collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue))).setIndexes(ClientUtils.collection(in, unused4 -> {
                String name = reader.readString();
                QueryIndexType type = QueryIndexType.fromOrdinal(reader.readByte());
                int inlineSize = reader.readInt();
                LinkedHashMap<String, Boolean> fields = ClientUtils.collection(in, unused5 -> new SimpleEntry<>(reader.readString(), reader.readBoolean())).stream().collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue, (a, b) -> a, LinkedHashMap::new));
                return new QueryIndex(fields, type).setName(name).setInlineSize(inlineSize);
            }));
        }).toArray(new QueryEntity[0])).setExpiryPolicy(!protocolCtx.isFeatureSupported(EXPIRY_POLICY) ? null : reader.readBoolean() ? new PlatformExpiryPolicy(reader.readLong(), reader.readLong(), reader.readLong()) : null);
    }
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) BinaryObject(org.apache.ignite.binary.BinaryObject) PlatformExpiryPolicy.convertDuration(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy.convertDuration) Arrays(java.util.Arrays) Array(java.lang.reflect.Array) CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) MutableSingletonList(org.apache.ignite.internal.util.MutableSingletonList) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) BinaryOutputStream(org.apache.ignite.internal.binary.streams.BinaryOutputStream) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) BinaryRawWriter(org.apache.ignite.binary.BinaryRawWriter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BinaryUtils(org.apache.ignite.internal.binary.BinaryUtils) Map(java.util.Map) QueryEntity(org.apache.ignite.cache.QueryEntity) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) ClientCacheConfiguration(org.apache.ignite.client.ClientCacheConfiguration) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) BinaryFieldMetadata(org.apache.ignite.internal.binary.BinaryFieldMetadata) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) BinaryObjectImpl(org.apache.ignite.internal.binary.BinaryObjectImpl) BinarySchema(org.apache.ignite.internal.binary.BinarySchema) BinaryHeapInputStream(org.apache.ignite.internal.binary.streams.BinaryHeapInputStream) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) BinaryWriterExImpl(org.apache.ignite.internal.binary.BinaryWriterExImpl) Function(java.util.function.Function) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) PartitionLossPolicy(org.apache.ignite.cache.PartitionLossPolicy) PlatformExpiryPolicy(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) BiConsumer(java.util.function.BiConsumer) LinkedList(java.util.LinkedList) SimpleEntry(java.util.AbstractMap.SimpleEntry) EXPIRY_POLICY(org.apache.ignite.internal.client.thin.ProtocolVersionFeature.EXPIRY_POLICY) LinkedHashSet(java.util.LinkedHashSet) BinaryThreadLocalContext(org.apache.ignite.internal.binary.BinaryThreadLocalContext) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) QueryIndexType(org.apache.ignite.cache.QueryIndexType) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) IOException(java.io.IOException) BinaryReaderHandles(org.apache.ignite.internal.binary.BinaryReaderHandles) Consumer(java.util.function.Consumer) QUERY_ENTITY_PRECISION_AND_SCALE(org.apache.ignite.internal.client.thin.ProtocolVersionFeature.QUERY_ENTITY_PRECISION_AND_SCALE) QueryIndex(org.apache.ignite.cache.QueryIndex) CacheMode(org.apache.ignite.cache.CacheMode) BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) SimpleEntry(java.util.AbstractMap.SimpleEntry) QueryIndexType(org.apache.ignite.cache.QueryIndexType) QueryEntity(org.apache.ignite.cache.QueryEntity) PlatformExpiryPolicy(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy) ClientCacheConfiguration(org.apache.ignite.client.ClientCacheConfiguration) LinkedHashMap(java.util.LinkedHashMap) Collection(java.util.Collection) QueryIndex(org.apache.ignite.cache.QueryIndex) BinaryObject(org.apache.ignite.binary.BinaryObject)

Example 5 with PlatformExpiryPolicy

use of org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy in project ignite by apache.

the class IgnitePersistentStoreCacheGroupsTest method testExpiryPolicy.

/**
 * @throws Exception If failed.
 */
@Test
public void testExpiryPolicy() throws Exception {
    long ttl = 10 * 60000;
    CacheConfiguration[] ccfgs1 = new CacheConfiguration[5];
    ccfgs1[0] = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1);
    ccfgs1[1] = cacheConfiguration(GROUP1, "c2", PARTITIONED, TRANSACTIONAL, 1);
    ccfgs1[2] = cacheConfiguration(GROUP2, "c3", PARTITIONED, ATOMIC, 1);
    ccfgs1[3] = cacheConfiguration(GROUP2, "c4", PARTITIONED, TRANSACTIONAL, 1);
    ccfgs1[4] = cacheConfiguration(null, "c5", PARTITIONED, ATOMIC, 1);
    String[] caches = { "c1", "c2", "c3", "c4", "c5" };
    startGrids(3);
    Ignite node = ignite(0);
    node.cluster().active(true);
    node.createCaches(Arrays.asList(ccfgs1));
    ExpiryPolicy plc = new PlatformExpiryPolicy(ttl, -2, -2);
    Map<String, Map<Integer, Long>> expTimes = new HashMap<>();
    for (String cacheName : caches) {
        Map<Integer, Long> cacheExpTimes = new HashMap<>();
        expTimes.put(cacheName, cacheExpTimes);
        IgniteCache<Object, Object> cache = node.cache(cacheName).withExpiryPolicy(plc);
        for (int i = 0; i < entriesCount(); i++) {
            Integer key = i;
            cache.put(key, cacheName + i);
            IgniteKernal primaryNode = (IgniteKernal) primaryCache(i, cacheName).unwrap(Ignite.class);
            GridCacheEntryEx entry = primaryNode.internalCache(cacheName).entryEx(key);
            entry.unswap();
            assertTrue(entry.expireTime() > 0);
            cacheExpTimes.put(key, entry.expireTime());
        }
    }
    stopAllGrids();
    startGrids(3);
    node = ignite(0);
    node.cluster().active(true);
    for (String cacheName : caches) {
        IgniteCache<Object, Object> cache = node.cache(cacheName);
        for (int i = 0; i < entriesCount(); i++) {
            Integer key = i;
            assertEquals(cacheName + i, cache.get(i));
            IgniteKernal primaryNode = (IgniteKernal) primaryCache(i, cacheName).unwrap(Ignite.class);
            GridCacheEntryEx entry = primaryNode.internalCache(cacheName).entryEx(key);
            entry.unswap();
            assertEquals(expTimes.get(cacheName).get(key), (Long) entry.expireTime());
        }
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) HashMap(java.util.HashMap) PlatformExpiryPolicy(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) PlatformExpiryPolicy(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) Ignite(org.apache.ignite.Ignite) HashMap(java.util.HashMap) Map(java.util.Map) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

PlatformExpiryPolicy (org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)3 Ignite (org.apache.ignite.Ignite)3 QueryEntity (org.apache.ignite.cache.QueryEntity)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 SimpleEntry (java.util.AbstractMap.SimpleEntry)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)2 CacheKeyConfiguration (org.apache.ignite.cache.CacheKeyConfiguration)2 CacheMode (org.apache.ignite.cache.CacheMode)2 CacheRebalanceMode (org.apache.ignite.cache.CacheRebalanceMode)2 CacheWriteSynchronizationMode (org.apache.ignite.cache.CacheWriteSynchronizationMode)2