Search in sources :

Example 36 with EntryView

use of com.hazelcast.core.EntryView in project hazelcast by hazelcast.

the class LazyEvictableEntryViewTest method test_hashCode.

@Test
public void test_hashCode() throws Exception {
    EntryView entryView = createLazyEvictableEntryView();
    assertEquals(entryView.hashCode(), view.hashCode());
}
Also used : EntryView(com.hazelcast.core.EntryView) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) EntryCostEstimatorTest(com.hazelcast.map.EntryCostEstimatorTest) Test(org.junit.Test)

Example 37 with EntryView

use of com.hazelcast.core.EntryView in project hazelcast by hazelcast.

the class EvictionTest method sleepAndAssertTtlExpirationCorrectness.

private void sleepAndAssertTtlExpirationCorrectness(IMap<Integer, String> map, long expected, long startRef, long endRef) {
    sleepAtLeastSeconds(3);
    EntryView view = map.getEntryView(1);
    if (expected == Long.MAX_VALUE) {
        assertEquals(expected, view.getExpirationTime());
    } else {
        long actual = MILLISECONDS.toSeconds(view.getExpirationTime() - startRef);
        long delta = (1 + MILLISECONDS.toSeconds(endRef - startRef));
        assertEquals(expected, actual, delta);
    }
}
Also used : EntryView(com.hazelcast.core.EntryView)

Example 38 with EntryView

use of com.hazelcast.core.EntryView in project hazelcast by hazelcast.

the class EvictionTest method testMaxIdle_readThroughIndex.

private void testMaxIdle_readThroughIndex(IndexType type) {
    String mapName = randomMapName();
    Config config = getConfig();
    config.getMapConfig("default").setPerEntryStatsEnabled(true);
    // "disable" the cleaner task
    config.setProperty(PROP_TASK_PERIOD_SECONDS, Integer.toString(MAX_VALUE));
    HazelcastInstance node = createHazelcastInstance(config);
    IMap<Integer, Employee> map = node.getMap(mapName);
    map.addIndex(type, "city");
    int entryCount = 5;
    Map<Integer, Long> lastAccessTimes = new HashMap<>();
    for (int i = 0; i < entryCount; ++i) {
        String cityName = i % 2 == 0 ? "cityname" : null;
        Employee emp = new Employee(i, "name" + i, cityName, 0, true, i);
        map.put(i, emp, 0L, SECONDS, 60L, SECONDS);
        // we do get to set the last access time
        map.get(i);
        EntryView view = map.getEntryView(i);
        long lastAccessTime = view.getLastAccessTime();
        assertTrue(lastAccessTime > 0);
        lastAccessTimes.put(i, lastAccessTime);
    }
    sleepAtLeastSeconds(1);
    EntryObject entryObject = new PredicateBuilderImpl().getEntryObject();
    Predicate predicateCityNull = entryObject.get("city").isNull();
    Collection<Employee> valuesNullCity = map.values(predicateCityNull);
    Collection<Employee> valuesNotNullCity = map.values(Predicates.equal("city", "cityname"));
    assertEquals(entryCount, valuesNullCity.size() + valuesNotNullCity.size());
    // check that evaluating the predicate didn't update the last access time of the returned records
    for (int i = 0; i < entryCount; ++i) {
        EntryView view = map.getEntryView(i);
        assertNotNull(view);
        long lastAccessTime = view.getLastAccessTime();
        long prevLastAccessTime = lastAccessTimes.get(i);
        assertTrue("lastAccessTime=" + lastAccessTime + ", prevLastAccessTime=" + prevLastAccessTime, lastAccessTime == prevLastAccessTime);
    }
}
Also used : EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) HashMap(java.util.HashMap) MapConfig(com.hazelcast.config.MapConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) Predicate(com.hazelcast.query.Predicate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) PredicateBuilderImpl(com.hazelcast.query.impl.PredicateBuilderImpl) EntryView(com.hazelcast.core.EntryView)

Example 39 with EntryView

use of com.hazelcast.core.EntryView in project hazelcast by hazelcast.

the class EvictionTest method assertTtlExpirationCorrectness.

private void assertTtlExpirationCorrectness(IMap<Integer, String> map, long expected) {
    EntryView view = map.getEntryView(1);
    assertEquals(expected, view.getExpirationTime());
    assertTrue(map.containsKey(1));
}
Also used : EntryView(com.hazelcast.core.EntryView)

Example 40 with EntryView

use of com.hazelcast.core.EntryView in project hazelcast by hazelcast.

the class EntryLoaderSimpleTest method assertExpiredEventually.

private void assertExpiredEventually(IMap map, String prefix, int from, int to) {
    assertTrueEventually(() -> {
        for (int i = from; i < to; i++) {
            EntryView entryView = map.getEntryView(prefix + i);
            assertNull("Current time: " + System.currentTimeMillis(), entryView);
        }
    });
}
Also used : EntryView(com.hazelcast.core.EntryView)

Aggregations

EntryView (com.hazelcast.core.EntryView)40 Test (org.junit.Test)19 QuickTest (com.hazelcast.test.annotation.QuickTest)16 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 Record (com.hazelcast.map.impl.record.Record)8 Data (com.hazelcast.nio.serialization.Data)8 ParallelTest (com.hazelcast.test.annotation.ParallelTest)7 SlowTest (com.hazelcast.test.annotation.SlowTest)6 BasicMapTest (com.hazelcast.map.BasicMapTest)5 EntryViews.createSimpleEntryView (com.hazelcast.map.impl.EntryViews.createSimpleEntryView)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 Config (com.hazelcast.config.Config)2 MapConfig (com.hazelcast.config.MapConfig)2 Data (com.hazelcast.internal.serialization.Data)2 EntryCostEstimatorTest (com.hazelcast.map.EntryCostEstimatorTest)2 MapContainer (com.hazelcast.map.impl.MapContainer)2 MapEventPublisher (com.hazelcast.map.impl.event.MapEventPublisher)2 MapOperation (com.hazelcast.map.impl.operation.MapOperation)2 LazyEvictableEntryView (com.hazelcast.map.impl.recordstore.LazyEvictableEntryView)2 HashMap (java.util.HashMap)2