String cacheName = "sampleCache";
// Tenant wso2.com
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
cc.setTenantDomain("wso2.com");
cc.setTenantId(1);
CacheManager cacheManager =
Caching.getCacheManagerFactory().getCacheManager(cacheManagerName);
Cache<String, Integer> cache1 = cacheManager.getCache(cacheName);
cache1.put(key1, sampleValue);
cache1.put(key2, sampleValue);
cache1 = cacheManager.getCache(cacheName);
assertEquals(sampleValue, cache1.get(key1));
checkCacheSize(cache1, 2);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
// Tenant ibm.com
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
cc.setTenantDomain("ibm.com");
cc.setTenantId(2);
CacheManager cacheManager =
Caching.getCacheManagerFactory().getCacheManager(cacheManagerName);
Cache<String, Integer> cache1 = cacheManager.getCache(cacheName);
cache1.put(key1, sampleValue);