public void testClose() { withCacheManager(new CacheManagerCallable(TestCacheManagerFactory.createCacheManager()) { @Override public void call() throws Exception { AdvancedCache<Integer, String> advCache = cm.<Integer, String>getCache().getAdvancedCache(); Cache<Integer, String> local = FunctionalJCache.create(advCache); assertFalse(local.isClosed()); local.close(); assertTrue(local.isClosed()); } }); }
public void testSize() throws Exception { TestingUtil.withCacheManager(new CacheCallable(config(false, 1)) { @Override public void call() { cache.put("k1", "v1"); cache.put("k2", "v2"); assertEquals("cache size must be 1", 1, cache.getAdvancedCache().getDataContainer().size()); } }); }
@Test public void testGetCache() { withCacheManager(new CacheManagerCallable(createCacheManager()) { @Override public void call() { cm.getCache(); } }); }
public void testCacheModeConfiguration() throws Exception { withCacheManager(new CacheManagerCallable(createTestCacheManager()) { @Override public void call() { cm.getCache("local").put("key", "value"); } }); }
private void testPutOperation(boolean batching, final boolean inTran) throws Exception { withCacheManager(new CacheManagerCallable(getCacheManager(batching)) { @Override public void call() throws Exception { Cache<Object, Object> c = cm.getCache(); if (inTran) c.getAdvancedCache().getTransactionManager().begin(); c.put("key1", new SEntity(1, "name1", "surname1")); if (inTran) c.getAdvancedCache().getTransactionManager().commit(); assertEquals(searchByName("name1", c).size(), 1, "should be 1, even repeating this"); } }); }
public void testSizeAfterExpiration() throws Exception { TestingUtil.withCacheManager(new CacheCallable(config(false, 1)) { @Override public void call() { cache.put("k1", "v1"); cache.put("k2", "v2"); TestingUtil.sleepThread(200); assertFalse("expiry doesn't work even after expiration", 2 == cache.getAdvancedCache().getDataContainer().size()); } }); }
@Test(expectedExceptions = CacheConfigurationException.class) public void testUnsupportedConfiguration() throws Exception { withCacheManager(new CacheManagerCallable( TestCacheManagerFactory.fromXml("configs/legacy/6.0.xml", true)) { @Override public void call() { fail("Parsing an unsupported file should have failed."); } }); } }
@Test(expectedExceptions = UnsupportedOperationException.class) public void testLockOnNonTransactionalCache() { withCacheManager(new CacheManagerCallable( TestCacheManagerFactory.createCacheManager(false)) { @Override public void call() { cm.getCache().getAdvancedCache().lock("k"); } }); }
@Test public void testDefineNamedCache() { withCacheManager(new CacheManagerCallable(createCacheManager()) { @Override public void call() { cm.defineConfiguration("foo", new ConfigurationBuilder().build()); } }); }
public void testNamedCacheConfiguration() { withCacheManager(new CacheManagerCallable( TestCacheManagerFactory.createCacheManager(false)) { @Override public void call() { cm.defineConfiguration("oneCache", new ConfigurationBuilder().build()); JCacheManager jCacheManager = new JCacheManager(URI.create("oneCacheManager"), cm, null); assertTrue(null != jCacheManager.getCache("oneCache")); } }); }
public void testUnstartedCachemanager() { withCacheManager(new CacheManagerCallable(createCacheManager(false)){ @Override public void call() { assertTrue(cm.getStatus().equals(ComponentStatus.INSTANTIATED)); assertFalse(cm.getStatus().allowInvocations()); Cache<Object, Object> cache = cm.getCache(); cache.put("k","v"); assertTrue(cache.get("k").equals("v")); } }); }
public void testNPE() throws Exception { TestingUtil.withCacheManager(new CacheCallable(config(false, 1)) { @Override public void call() { cache.put("k1", "v1"); cache.remove("k1"); // this causes NPE in AsyncCacheWriter.isLocked(InternalNullEntry.getKey()) cache.put("k2", "v2"); } }); }
public void testLockingInterceptorType() { ConfigurationBuilder builder = new ConfigurationBuilder(); withCacheManager(new CacheManagerCallable( TestCacheManagerFactory.createCacheManager(builder)) { @Override public void call() { AbstractLockingInterceptor lockingInterceptor = TestingUtil.findInterceptor( cm.getCache(), AbstractLockingInterceptor.class); assertTrue(lockingInterceptor instanceof NonTransactionalLockingInterceptor); } }); }
private void assertCacheConfiguration(String config) throws IOException { ConfigurationBuilderHolder holder = parseToHolder(config); withCacheManager(new CacheManagerCallable(TestCacheManagerFactory.createClusteredCacheManager(holder)) { @Override public void call() { Assert.assertEquals(cm.getDefaultCacheConfiguration().module(MyModuleConfiguration.class).attribute(), "test-value"); } }); }
@Test public void testDummyTMGetCache() throws Exception { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.transaction().use1PcForAutoCommitTransactions(true) .transactionManagerLookup(new EmbeddedTransactionManagerLookup()); withCacheManager(new CacheManagerCallable(createCacheManager()) { @Override public void call() { cm.getCache(); } }); }
@Test(expectedExceptions = CacheConfigurationException.class, expectedExceptionsMessageRegExp = ".*ISPN000414.*") public void testIncompleteConfiguration() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.security().authorization().enable().role("reader"); withCacheManager(() -> createCacheManager(builder), CacheContainer::getCache); }
public void testCustomInterceptorsProgramatically() { ConfigurationBuilder cfg = new ConfigurationBuilder(); cfg.customInterceptors().addInterceptor().interceptor(new DummyInterceptor()).position(Position.FIRST); withCacheManager(new CacheManagerCallable(TestCacheManagerFactory.createCacheManager(cfg)) { @Override public void call() { Cache c = cm.getCache(); DummyInterceptor i = TestingUtil.findInterceptor(c, DummyInterceptor.class); assertNotNull(i); } }); }
public void testReliability() { final GlobalConfigurationBuilder builder = defaultGlobalConfigurationBuilder(false); final CounterManagerConfiguration config = builder.addModule(CounterManagerConfigurationBuilder.class) .reliability(Reliability.AVAILABLE).create(); TestingUtil.withCacheManager(() -> buildCacheManager(builder), cacheManager -> { Configuration cacheConfiguration = getCounterCacheConfiguration(cacheManager); assertCounterAndCacheConfiguration(config, cacheConfiguration); }); }
public void testReliability2() { final GlobalConfigurationBuilder builder = defaultGlobalConfigurationBuilder(false); final CounterManagerConfiguration config = builder.addModule(CounterManagerConfigurationBuilder.class) .reliability(Reliability.CONSISTENT).create(); TestingUtil.withCacheManager(() -> buildCacheManager(builder), cacheManager -> { Configuration cacheConfiguration = getCounterCacheConfiguration(cacheManager); assertCounterAndCacheConfiguration(config, cacheConfiguration); }); }
public void testInvocationBatchingAndInducedTm() { final ConfigurationBuilder cb = new ConfigurationBuilder(); cb.invocationBatching().enable(); assert cb.build().transaction().transactionMode().isTransactional(); withCacheManager(new CacheManagerCallable(TestCacheManagerFactory.createCacheManager(cb)){ @Override public void call() { assert cm.getCache().getAdvancedCache().getTransactionManager() != null; } }); }