Refine search
@Produces <K, V> AdvancedCache<K, V> getDefaultAdvancedCache() { // lazy register stuff infinispanExtension.getEmbeddedExtension().registerCacheConfigurations(eventBridge, cacheManagers, beanManager); return defaultCacheContainer.<K, V>getCache().getAdvancedCache(); } }
private void lookupContainerService() { try { InitialContext initialContext = new InitialContext(); container = (CacheContainer) initialContext.lookup( infinispanServiceName() ); if (container != null) { log.info( "Starting polyglot cache service: " + infinispanServiceName() ); container.start(); } } catch (NamingException e) { log.error( "Cannot get cache container. ", e ); } }
public void testReadChunks() throws Exception { final int BUFFER_SIZE = 64; Cache cache = cacheManager.getCache(); Directory dir = DirectoryBuilder.newDirectoryInstance(cache, cache, cache, INDEXNAME).chunkSize(BUFFER_SIZE).create(); cache.put(key1, file1); cache.put(key2, file2); cache.put(new ChunkCacheKey(INDEXNAME, "Hello.txt", 0, BUFFER_SIZE, -1), helloText.getBytes()); assertTrue(worldText.getBytes().length > BUFFER_SIZE); assertTrue(worldText.getBytes().length < (2 * BUFFER_SIZE)); AssertJUnit.assertEquals(part1 + part2.trim(), worldText);
public void testWriteChunks() throws Exception { final int BUFFER_SIZE = 64; Cache cache = cacheManager.getCache(); Directory dir = DirectoryBuilder.newDirectoryInstance(cache, cache, cache, INDEXNAME).chunkSize(BUFFER_SIZE).create(); IndexOutput io = dir.createOutput("MyNewFile.txt", IOContext.DEFAULT); io.writeByte((byte) 66); io.writeByte((byte) 69); io.close(); assertTrue(Arrays.asList(dir.listAll()).contains("MyNewFile.txt")); assertNotNull(cache.get(new ChunkCacheKey(INDEXNAME, "MyNewFile.txt", 0, BUFFER_SIZE, -1))); // test contents by reading: byte[] buf = new byte[9]; IndexInput ii = dir.openInput("MyNewFile.txt", IOContext.DEFAULT); ii.readBytes(buf, 0, (int) ii.length()); ii.close(); assertEquals(new String(new byte[] { 66, 69 }), new String(buf).trim()); String testText = "This is some rubbish again that will span more than one chunk - one hopes. Who knows, maybe even three or four chunks."; io = dir.createOutput("MyNewFile.txt", IOContext.DEFAULT); ((InfinispanIndexOutput)io).seek(0); io.writeBytes(testText.getBytes(), 0, testText.length()); io.close(); // now compare. byte[] chunk1 = (byte[]) cache.get(new ChunkCacheKey(INDEXNAME, "MyNewFile.txt", 0, BUFFER_SIZE, -1)); byte[] chunk2 = (byte[]) cache.get(new ChunkCacheKey(INDEXNAME, "MyNewFile.txt", 1, BUFFER_SIZE, -1)); assert null != chunk1; assert null != chunk2; assert testText.equals(new String(chunk1) + new String(chunk2).trim()); dir.close(); DirectoryIntegrityCheck.verifyDirectoryStructure(cache, INDEXNAME); }
public void testKeySetAfterExpiryInPut(Method m) throws Exception { Cache<Integer, String> cache = cm.getCache(); Map dataIn = new HashMap(); dataIn.put(1, v(m, 1)); dataIn.put(2, v(m, 2)); final long lifespan = EXPIRATION_TIMEOUT; cache.putAll(dataIn, lifespan, TimeUnit.MILLISECONDS); timeService.advance(lifespan + 100); assertEquals(0, cache.keySet().size()); }
private void doTestEntrySetAfterExpiryInPut(Method m, CacheContainer cc) throws Exception { Cache<Integer, String> cache = cc.getCache(); Map dataIn = new HashMap(); dataIn.put(1, v(m, 1)); dataIn.put(2, v(m, 2)); final long lifespan = EXPIRATION_TIMEOUT; cache.putAll(dataIn, lifespan, TimeUnit.MILLISECONDS); timeService.advance(lifespan + 100); assertEquals(0, cache.entrySet().size()); }
public void testValuesAfterExpiryInPut(Method m) throws Exception { Cache<Integer, String> cache = cm.getCache(); // Values come as a Collection, but comparison of HashMap#Values is done // by reference equality, so wrap the collection around to set to make // testing easier, given that we know that there are dup values. Collection<String> values; Map<Integer, String> dataIn = new HashMap<>(); dataIn.put(1, v(m, 1)); dataIn.put(2, v(m, 2)); final long lifespan = EXPIRATION_TIMEOUT; cache.putAll(dataIn, lifespan, TimeUnit.MILLISECONDS); timeService.advance(lifespan + 100); assertEquals(0, cache.values().size()); }
@Test public void testWriteChunksDefaultChunks() throws Exception { Cache cache = cacheManager.getCache(); Directory dir = DirectoryBuilder.newDirectoryInstance(cache, cache, cache, INDEXNAME).create(); final String testText = "This is some rubbish"; final byte[] testTextAsBytes = testText.getBytes(); IndexOutput io = dir.createOutput("MyNewFile.txt", IOContext.DEFAULT); io.writeByte((byte) 1); io.writeByte((byte) 2); io.writeByte((byte) 3); io.writeBytes(testTextAsBytes, testTextAsBytes.length); io.close(); DirectoryIntegrityCheck.verifyDirectoryStructure(cache, INDEXNAME); FileCacheKey fileCacheKey = new FileCacheKey(INDEXNAME, "MyNewFile.txt", -1); assert null != cache.get(fileCacheKey); FileMetadata metadata = (FileMetadata) cache.get(fileCacheKey); AssertJUnit.assertEquals(testTextAsBytes.length + 3, metadata.getSize()); assert null != cache.get(new ChunkCacheKey(INDEXNAME, "MyNewFile.txt", 0, DirectoryBuilderImpl.DEFAULT_BUFFER_SIZE, -1)); // test contents by reading: IndexInput ii = dir.openInput("MyNewFile.txt", IOContext.DEFAULT); assert ii.readByte() == 1; assert ii.readByte() == 2; assert ii.readByte() == 3; byte[] buf = new byte[testTextAsBytes.length]; ii.readBytes(buf, 0, testTextAsBytes.length); ii.close(); assert testText.equals(new String(buf).trim()); dir.close(); DirectoryIntegrityCheck.verifyDirectoryStructure(cache, INDEXNAME); }
entityCache = container.getCache("entity"); ConfigurationBuilder confBuilder = new ConfigurationBuilder(); confBuilder.clustering().cacheMode(CacheMode.LOCAL); EmbeddedCacheManager cacheManager = new DefaultCacheManager(confBuilder.build()); cacheManager.start();
@Override public void startService() throws Exception { CacheContainer container = this.cacheHandler.getCacheContainer(); this.cache = (this.cacheName != null) ? container.<Serializable, Serializable>getCache(this.cacheName) : container.<Serializable, Serializable>getCache(); if (!this.cache.getStatus().allowInvocations()) { this.cache.start(); } this.cache.addListener(this); }
public MobicentsCache(String name, CacheContainer jBossCacheContainer, ClassLoader classLoader, CacheDataExecutorService cacheDataExecutorService) { this.jBossCacheContainer = jBossCacheContainer; this.cacheDataExecutorService = cacheDataExecutorService; if (this.jBossCacheContainer.getCache().getCacheConfiguration().clustering().cacheMode().isClustered()) { this.cache = new DecoratedCache<Object, Object>(this.jBossCacheContainer.getCache(name).getAdvancedCache(), classLoader); } else { this.cache = this.jBossCacheContainer.getCache(name); } this.name = name; this.managedCache = false; setLocalMode(); }
public void testForJdbcStringBasedCacheStore() throws Exception { CacheContainer cm = null; try { cm = TestCacheManagerFactory.fromXml("configs/string-based.xml"); Cache<String, String> first = cm.getCache("first"); Cache<String, String> second = cm.getCache("second"); StoreConfiguration firstCacheLoaderConfig = first.getCacheConfiguration().persistence().stores().get(0); StoreConfiguration secondCacheLoaderConfig = second.getCacheConfiguration().persistence().stores().get(0); assertEquals(JdbcStringBasedStoreConfiguration.class, firstCacheLoaderConfig.getClass()); assertEquals(JdbcStringBasedStoreConfiguration.class, secondCacheLoaderConfig.getClass()); JdbcStringBasedStore firstCs = (JdbcStringBasedStore) TestingUtil.getFirstLoader(first); JdbcStringBasedStore secondCs = (JdbcStringBasedStore) TestingUtil.getFirstLoader(second); assertTableExistence(firstCs.getConnectionFactory().getConnection(), firstCs.getTableManager().getIdentifierQuoteString(), "second", "first", "ISPN_STRING_TABLE"); assertNoOverlapingState(first, second, firstCs, secondCs); } finally { TestingUtil.killCacheManagers(cm); } }
@BeforeMethod public void setUp() { cfg = new ConfigurationBuilder(); cfg .persistence() .passivation(true) .addStore(DummyInMemoryStoreConfigurationBuilder.class) .storeName(this.getClass().getName()) .purgeOnStartup(false) .memory().storageType(storage); cm = TestCacheManagerFactory.createCacheManager(cfg); cache = cm.getCache(); store = (AdvancedLoadWriteStore) TestingUtil.getCacheLoader(cache); tm = TestingUtil.getTransactionManager(cache); }
public void multipleFlushTest() throws IOException { final String filename = "longFile.writtenInMultipleFlushes"; final int bufferSize = 300; Cache cache = cacheManager.getCache(); cache.clear(); Directory dir = DirectoryBuilder.newDirectoryInstance(cache, cache, cache, INDEXNAME).chunkSize(13).create(); byte[] manyBytes = fillBytes(bufferSize); IndexOutput indexOutput = dir.createOutput(filename, IOContext.DEFAULT); for (int i = 0; i < 10; i++) { indexOutput.writeBytes(manyBytes, bufferSize); } indexOutput.close(); IndexInput input = dir.openInput(filename, IOContext.DEFAULT); final int finalSize = (10 * bufferSize); AssertJUnit.assertEquals(finalSize, input.length()); final byte[] resultingBuffer = new byte[finalSize]; input.readBytes(resultingBuffer, 0, finalSize); int index = 0; for (int i = 0; i < 10; i++) { for (int j = 0; j < bufferSize; j++) AssertJUnit.assertEquals(resultingBuffer[index++], manyBytes[j]); } }
public void testCustomCacheManagerName(Method m) throws Exception { final String otherJmxDomain = getMethodSpecificJmxDomain(m, JMX_DOMAIN); CacheContainer otherContainer = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(otherJmxDomain, "Hibernate2LC", true, false, true); ObjectName otherName = getCacheManagerObjectName(otherJmxDomain, "Hibernate2LC"); try { assertEquals("0", server.getAttribute(otherName, "CreatedCacheCount")); } finally { otherContainer.stop(); } }
@BeforeClass public void setUp() { ConfigurationBuilder c = new ConfigurationBuilder(); c.invocationBatching().enable(); cacheContainer = TestCacheManagerFactory.createCacheManager(c); cache = cacheContainer.getCache(); tm = TestingUtil.getTransactionManager(cache); }
public void testCorrectShutdown() { CacheContainer cc = null; try { ConfigurationBuilder cfg = new ConfigurationBuilder(); cfg .transaction() .transactionMode(TransactionMode.TRANSACTIONAL) .indexing() .index(Index.ALL) .addIndexedEntity(Person.class) .addProperty("default.directory_provider", "local-heap") .addProperty("lucene_version", "LUCENE_CURRENT"); cc = TestCacheManagerFactory.createCacheManager(cfg); Cache<?, ?> cache = cc.getCache(); SearchIntegrator sfi = TestingUtil.extractComponent(cache, SearchIntegrator.class); assert ! sfi.isStopped(); cc.stop(); assert sfi.isStopped(); } finally { // proper cleanup for exceptional execution TestingUtil.killCacheManagers(cc); } }
Cache localNaturalIdCache = localManager.getCache(Citizen.class.getName() + "##NaturalId"); MyListener localListener = new MyListener( "local" ); localNaturalIdCache.addListener(localListener); Cache remoteNaturalIdCache = remoteManager.getCache(Citizen.class.getName() + "##NaturalId"); MyListener remoteListener = new MyListener( "remote" ); remoteNaturalIdCache.addListener(remoteListener); CountDownLatch localUpdate = expectEvict(localNaturalIdCache.getAdvancedCache(), 1); deleteCitizenWithCriteria(remoteFactory); assertTrue(localUpdate.await(2, TimeUnit.SECONDS));
@Override protected void createCacheManagers() throws Throwable { ConfigurationBuilder defaultConfig = new ConfigurationBuilder(); GlobalConfigurationBuilder gcb1 = GlobalConfigurationBuilder.defaultClusteredBuilder(); gcb1.globalJmxStatistics().enable().jmxDomain(JMX_DOMAIN) .mBeanServerLookup(new PerThreadMBeanServerLookup()); CacheContainer cacheManager1 = TestCacheManagerFactory.createClusteredCacheManager(gcb1, defaultConfig, new TransportFlags(), true); cacheManager1.start(); GlobalConfigurationBuilder gcb2 = GlobalConfigurationBuilder.defaultClusteredBuilder(); gcb2.globalJmxStatistics().enable().jmxDomain(JMX_DOMAIN) .mBeanServerLookup(new PerThreadMBeanServerLookup()); CacheContainer cacheManager2 = TestCacheManagerFactory.createClusteredCacheManager(gcb2, defaultConfig, new TransportFlags(), true); cacheManager2.start(); registerCacheManager(cacheManager1, cacheManager2); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.clustering().cacheMode(CacheMode.REPL_SYNC).jmxStatistics().enable(); defineConfigurationOnAllManagers(cachename, cb); defineConfigurationOnAllManagers(cachename2, cb); waitForClusterToForm(cachename); }