Search in sources :

Example 1 with CacheEntryView

use of com.hazelcast.cache.CacheEntryView in project hazelcast by hazelcast.

the class GetCacheEntryRequest method writeResponse.

@Override
public void writeResponse(ManagementCenterService mcs, JsonObject root) throws Exception {
    InternalSerializationService serializationService = mcs.getHazelcastInstance().getSerializationService();
    HazelcastInstanceCacheManager cacheManager = mcs.getHazelcastInstance().getCacheManager();
    ICache<Object, Object> cache = cacheManager.getCache(cacheName);
    CacheEntryView cacheEntry = null;
    if ("string".equals(type)) {
        cacheEntry = cache.invoke(key, ENTRY_PROCESSOR, cacheEntry);
    } else if ("long".equals(type)) {
        cacheEntry = cache.invoke(Long.valueOf(key), ENTRY_PROCESSOR, cacheEntry);
    } else if ("integer".equals(type)) {
        cacheEntry = cache.invoke(Integer.valueOf(key), ENTRY_PROCESSOR, cacheEntry);
    }
    JsonObject result = new JsonObject();
    if (cacheEntry != null) {
        Object value = serializationService.toObject(cacheEntry.getValue());
        result.add("cacheBrowse_value", value != null ? value.toString() : "null");
        result.add("cacheBrowse_class", value != null ? value.getClass().getName() : "null");
        result.add("date_cache_creation_time", Long.toString(cacheEntry.getCreationTime()));
        result.add("date_cache_expiration_time", Long.toString(cacheEntry.getExpirationTime()));
        result.add("cacheBrowse_hits", Long.toString(cacheEntry.getAccessHit()));
        result.add("date_cache_access_time", Long.toString(cacheEntry.getLastAccessTime()));
    }
    root.add("result", result);
}
Also used : HazelcastInstanceCacheManager(com.hazelcast.instance.HazelcastInstanceCacheManager) CacheEntryView(com.hazelcast.cache.CacheEntryView) JsonObject(com.eclipsesource.json.JsonObject) JsonObject(com.eclipsesource.json.JsonObject) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService)

Example 2 with CacheEntryView

use of com.hazelcast.cache.CacheEntryView in project hazelcast by hazelcast.

the class AbstractCacheMergePolicyTest method merge_draw_mergingWins.

@Test
public void merge_draw_mergingWins() {
    CacheEntryView existing = entryWithGivenPropertyAndValue(1, EXISTING);
    CacheEntryView merging = entryWithGivenPropertyAndValue(1, MERGING);
    assertEquals(MERGING, policy.merge("cache", merging, existing));
}
Also used : CacheEntryView(com.hazelcast.cache.CacheEntryView) Test(org.junit.Test)

Example 3 with CacheEntryView

use of com.hazelcast.cache.CacheEntryView in project hazelcast by hazelcast.

the class AbstractCacheMergePolicyTest method merge_mergingWins_sinceExistingIsNotExist.

@Test
public void merge_mergingWins_sinceExistingIsNotExist() {
    CacheEntryView existing = null;
    CacheEntryView merging = entryWithGivenPropertyAndValue(1, MERGING);
    assertEquals(MERGING, policy.merge("cache", merging, existing));
}
Also used : CacheEntryView(com.hazelcast.cache.CacheEntryView) Test(org.junit.Test)

Example 4 with CacheEntryView

use of com.hazelcast.cache.CacheEntryView in project hazelcast by hazelcast.

the class AbstractCacheMergePolicyTest method merge_mergingWins.

@Test
public void merge_mergingWins() {
    CacheEntryView existing = entryWithGivenPropertyAndValue(1, EXISTING);
    CacheEntryView merging = entryWithGivenPropertyAndValue(333, MERGING);
    assertEquals(MERGING, policy.merge("cache", merging, existing));
}
Also used : CacheEntryView(com.hazelcast.cache.CacheEntryView) Test(org.junit.Test)

Example 5 with CacheEntryView

use of com.hazelcast.cache.CacheEntryView in project hazelcast by hazelcast.

the class AbstractCacheMergePolicyTest method merge_existingWins.

@Test
public void merge_existingWins() {
    CacheEntryView existing = entryWithGivenPropertyAndValue(333, EXISTING);
    CacheEntryView merging = entryWithGivenPropertyAndValue(1, MERGING);
    assertEquals(EXISTING, policy.merge("cache", merging, existing));
}
Also used : CacheEntryView(com.hazelcast.cache.CacheEntryView) Test(org.junit.Test)

Aggregations

CacheEntryView (com.hazelcast.cache.CacheEntryView)10 Test (org.junit.Test)9 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 JsonObject (com.eclipsesource.json.JsonObject)1 HazelcastInstanceCacheManager (com.hazelcast.instance.HazelcastInstanceCacheManager)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1