Example usage for org.springframework.cache Cache getClass

List of usage examples for org.springframework.cache Cache getClass

Introduction

In this page you can find the example usage for org.springframework.cache Cache getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.couchbase.client.spring.cache.CouchbaseCacheManagerTests.java

/**
 * Tests the main functionality of the manager: loading the caches.
 *//*w ww  .  j av a  2s .  co  m*/
@Test
public void testCacheInit() {
    HashMap<String, Bucket> instances = new HashMap<String, Bucket>();
    instances.put("test", client);

    CouchbaseCacheManager manager = new CouchbaseCacheManager(instances);
    manager.afterPropertiesSet();

    assertEquals(instances, manager.getClients());

    Cache cache = manager.getCache("test");

    assertNotNull(cache);

    assertEquals(cache.getClass(), CouchbaseCache.class);
    assertEquals(((CouchbaseCache) cache).getName(), "test");
    assertEquals(((CouchbaseCache) cache).getTtl(), 0); // default TTL value
    assertEquals(((CouchbaseCache) cache).getNativeCache(), client);
}

From source file:com.couchbase.client.spring.cache.CouchbaseCacheManagerTests.java

/**
 * Test cache creation with custom TTL values.
 *///from   w ww.  ja  v a  2s  .co  m
@Test
public void testCacheInitWithTtl() {
    HashMap<String, Bucket> instances = new HashMap<String, Bucket>();
    instances.put("cache1", client);
    instances.put("cache2", client);

    HashMap<String, Integer> ttlConfiguration = new HashMap<String, Integer>();
    ttlConfiguration.put("cache1", 100);
    ttlConfiguration.put("cache2", 200);

    CouchbaseCacheManager manager = new CouchbaseCacheManager(instances, ttlConfiguration);
    manager.afterPropertiesSet();

    assertEquals(instances, manager.getClients());

    Cache cache1 = manager.getCache("cache1");
    Cache cache2 = manager.getCache("cache2");

    assertNotNull(cache1);
    assertNotNull(cache2);

    assertEquals(cache1.getClass(), CouchbaseCache.class);
    assertEquals(cache2.getClass(), CouchbaseCache.class);

    assertEquals(cache1.getName(), "cache1");
    assertEquals(cache2.getName(), "cache2");

    assertEquals(((CouchbaseCache) cache1).getTtl(), 100);
    assertEquals(((CouchbaseCache) cache2).getTtl(), 200);

    assertEquals(((CouchbaseCache) cache1).getNativeCache(), client);
    assertEquals(((CouchbaseCache) cache2).getNativeCache(), client);
}