/** * When a <code>client-cache</code> element is first encountered, we create a * {@link ClientCacheCreation}and fill it in appropriately */ private void startClientCache(Attributes atts) { if (this.cache != null) { throw new CacheXmlException("Only a single cache or client-cache element is allowed"); } this.cache = new ClientCacheCreation(true); String copyOnRead = atts.getValue(COPY_ON_READ); if (copyOnRead != null) { this.cache.setCopyOnRead(Boolean.valueOf(copyOnRead).booleanValue()); } stack.push(this.cache); } /**
public Pool getDefaultPool() { return (Pool) getPools().get(getDefaultPoolName()); }
public void testNoTXWriterOnClient() { //test writer is not created ClientCacheCreation cc = new ClientCacheCreation(); CacheTransactionManagerCreation txMgrCreation = new CacheTransactionManagerCreation(); txMgrCreation.setWriter(new TestTransactionWriter()); cc.addCacheTransactionManagerCreation(txMgrCreation); try { testXml(cc); fail("expected exception not thrown"); } catch (IllegalStateException e) { } }
GatewayException, RegionExistsException { cache.setDeclarativeCacheConfig(this.getCacheConfig()); if (!cache.isClient()) { throw new IllegalStateException("You must use ClientCacheFactory when the cache.xml uses client-cache."); Map m = getPools(); if (!m.isEmpty()) { boolean setDefault = m.size() == 1; if (hasResourceManager()) { getResourceManager().configure(cache.getResourceManager()); DiskStoreAttributesCreation pdxRegDSC = initializePdxDiskStore(cache); for (Iterator iter = listDiskStores().iterator(); iter.hasNext();) { DiskStoreAttributesCreation creation = (DiskStoreAttributesCreation) iter.next(); if (creation != pdxRegDSC) { createDiskStore(creation, cache); for (Iterator iter = listDiskStores().iterator(); iter.hasNext();) { DiskStoreAttributesCreation creation = (DiskStoreAttributesCreation) iter.next(); if (hasDynamicRegionFactory()) { DynamicRegionFactory.get().open(getDynamicRegionFactoryConfig()); if (hasCopyOnRead()) { cache.setCopyOnRead(getCopyOnRead());
public void testCACHING_PROXY() throws CacheException { ClientCacheCreation cache = new ClientCacheCreation(); RegionCreation root = (RegionCreation) cache.createRegion("cproxy", "CACHING_PROXY"); testXml(cache); GemFireCacheImpl c = (GemFireCacheImpl) getCache(); assertEquals(true, c.isClient()); Region r = c.getRegion("cproxy"); assertNotNull(r); RegionAttributes ra = r.getAttributes(); assertEquals(DataPolicy.NORMAL, ra.getDataPolicy()); assertEquals(Scope.LOCAL, ra.getScope()); assertEquals("DEFAULT", ra.getPoolName()); } public void testCACHING_PROXY_HEAP_LRU() throws CacheException {
/** * Generates a dummy cache from the given client cache description. */ private static ClientCacheCreation generateDummyCache( String cacheConfig, ClientCacheDescription ccd, DynamicRegionFactory.Config dynamicRegionConfig, String fn) { if (dynamicRegionConfig != null) { // must open the DynamicRegionFactory before creating the cache log("Opening the configured DynamicRegionFactory"); DynamicRegionFactory.get().open(dynamicRegionConfig); } // create and configure the dummy cache log("Adding dummy cache from: " + ccd); ClientCacheCreation dummyCache = new ClientCacheCreation(); ResourceManagerCreation dummyResourceManager = new ResourceManagerCreation(); dummyCache.setResourceManagerCreation(dummyResourceManager); ccd.configureDummy(dummyCache); // add the dynamic region factory configuration, if any if (dynamicRegionConfig != null) { dummyCache.setDynamicRegionFactoryConfig(dynamicRegionConfig); } log("Added dummy cache: " + ccd.cacheToString(dummyCache)); // save the cache config for future reference XmlCacheConfigs.put(fn, cacheConfig); return dummyCache; }
public void testClientCache() throws CacheException { ClientCacheCreation cache = new ClientCacheCreation(); cache.setCopyOnRead(true); testXml(cache); GemFireCacheImpl c = (GemFireCacheImpl) getCache(); assertEquals(true, c.getCopyOnRead()); assertEquals(true, c.isClient()); for (ClientRegionShortcut pra: ClientRegionShortcut.values()) { assertNotNull(c.getRegionAttributes(pra.name())); } assertEquals(ClientRegionShortcut.values().length, c.listRegionAttributes().size()); } public void testNormalCache() throws CacheException {
public String getDefaultPoolName() { String result = null; Map m = getPools(); if (m.size() == 1) { Pool p = (Pool)m.values().iterator().next(); result = p.getName(); } else if (m.isEmpty()) { result = "DEFAULT"; } return result; }
defaultPoolName = ccc.getDefaultPoolName(); defaultPoolName = ccc.getDefaultPoolName();
GatewayException, RegionExistsException { cache.setDeclarativeCacheConfig(this.getCacheConfig()); if (!cache.isClient()) { throw new IllegalStateException("You must use ClientCacheFactory when the cache.xml uses client-cache."); Map m = getPools(); if (!m.isEmpty()) { boolean setDefault = m.size() == 1; if (hasResourceManager()) { getResourceManager().configure(cache.getResourceManager()); DiskStoreAttributesCreation pdxRegDSC = initializePdxDiskStore(cache); for (Iterator iter = listDiskStores().iterator(); iter.hasNext();) { DiskStoreAttributesCreation creation = (DiskStoreAttributesCreation) iter.next(); if (creation != pdxRegDSC) { createDiskStore(creation, cache); for (Iterator iter = listDiskStores().iterator(); iter.hasNext();) { DiskStoreAttributesCreation creation = (DiskStoreAttributesCreation) iter.next(); if (hasDynamicRegionFactory()) { DynamicRegionFactory.get().open(getDynamicRegionFactoryConfig()); if (hasCopyOnRead()) { cache.setCopyOnRead(getCopyOnRead());
public void testPROXY() throws CacheException { ClientCacheCreation cache = new ClientCacheCreation(); RegionCreation root = (RegionCreation) cache.createRegion("proxy", "PROXY"); testXml(cache); GemFireCacheImpl c = (GemFireCacheImpl) getCache(); assertEquals(true, c.isClient()); Region r = c.getRegion("proxy"); assertNotNull(r); RegionAttributes ra = r.getAttributes(); assertEquals(DataPolicy.EMPTY, ra.getDataPolicy()); assertEquals(Scope.LOCAL, ra.getScope()); assertEquals("DEFAULT", ra.getPoolName()); } public void testCACHING_PROXY() throws CacheException {
public void testTXManagerOnClientCache() { ClientCacheCreation cc = new ClientCacheCreation(); //CacheCreation cc = new CacheCreation(); CacheTransactionManagerCreation txMgrCreation = new CacheTransactionManagerCreation(); txMgrCreation.addListener(new TestTXListener()); cc.addCacheTransactionManagerCreation(txMgrCreation); testXml(cc); Cache c = getCache(); assertTrue(c instanceof ClientCache); c.loadCacheXml(generate(cc)); ClientCache clientC = (ClientCache) c; CacheTransactionManager mgr = clientC.getCacheTransactionManager(); assertNotNull(mgr); assertTrue(mgr.getListeners()[0] instanceof TestTXListener); }
public String getDefaultPoolName() { String result = null; Map m = getPools(); if (m.size() == 1) { Pool p = (Pool)m.values().iterator().next(); result = p.getName(); } else if (m.isEmpty()) { result = "DEFAULT"; } return result; }
defaultPoolName = ccc.getDefaultPoolName(); defaultPoolName = ccc.getDefaultPoolName();
public void testClientLOCAL_PERSISTENT() throws CacheException { ClientCacheCreation cache = new ClientCacheCreation(); RegionCreation root = (RegionCreation) cache.createRegion("cplocal", "LOCAL_PERSISTENT"); testXml(cache); GemFireCacheImpl c = (GemFireCacheImpl) getCache(); assertEquals(true, c.isClient()); Region r = c.getRegion("cplocal"); assertNotNull(r); RegionAttributes ra = r.getAttributes(); assertEquals(DataPolicy.PERSISTENT_REPLICATE, ra.getDataPolicy()); assertEquals(Scope.LOCAL, ra.getScope()); assertEquals(null, ra.getPoolName()); } public void testClientLOCAL_PERSISTENT_OVERFLOW() throws CacheException {
public Pool getDefaultPool() { return (Pool) getPools().get(getDefaultPoolName()); }
/** * When a <code>client-cache</code> element is first encountered, we create a * {@link ClientCacheCreation}and fill it in appropriately */ private void startClientCache(Attributes atts) { if (this.cache != null) { throw new CacheXmlException("Only a single cache or client-cache element is allowed"); } this.cache = new ClientCacheCreation(true); String copyOnRead = atts.getValue(COPY_ON_READ); if (copyOnRead != null) { this.cache.setCopyOnRead(Boolean.valueOf(copyOnRead).booleanValue()); } stack.push(this.cache); } /**
public void testClientLOCAL() throws CacheException { ClientCacheCreation cache = new ClientCacheCreation(); RegionCreation root = (RegionCreation) cache.createRegion("local", "LOCAL"); testXml(cache); GemFireCacheImpl c = (GemFireCacheImpl) getCache(); assertEquals(true, c.isClient()); Region r = c.getRegion("local"); assertNotNull(r); RegionAttributes ra = r.getAttributes(); assertEquals(DataPolicy.NORMAL, ra.getDataPolicy()); assertEquals(Scope.LOCAL, ra.getScope()); assertEquals(null, ra.getPoolName()); } public void testClientLOCAL_HEAP_LRU() throws CacheException {
/** * Returns the client cache as a string. For use only by {@link * ClientCacheHelper#cacheToString(ClientCache)}. */ protected static synchronized String cacheToString(ClientCache c) { StringBuffer buf = new StringBuffer(); Pool p = null; if (c instanceof ClientCacheCreation) { String pname = ((ClientCacheCreation)c).getDefaultPoolName(); if (pname != null) { p = (Pool)((ClientCacheCreation)c).getPools().get(pname); } } else { p = ((GemFireCacheImpl)c).getDefaultPool(); } if (p == null) { buf.append("\n defaultPool: null"); } else { buf.append("\n defaultPool: " + p.getName() + " with attributes:"); buf.append(PoolDescription.poolToString(p)); buf.append("\n --------------------"); } buf.append("\n pdxDiskStoreName: " + c.getPdxDiskStore()); buf.append("\n pdxIgnoreUnreadFields: " + c.getPdxIgnoreUnreadFields()); buf.append("\n pdxPersistent: " + c.getPdxPersistent()); buf.append("\n pdxReadSerialized: " + c.getPdxReadSerialized()); buf.append("\n pdxSerializer: " + c.getPdxSerializer()); return buf.toString(); }
/** * Creates a new <code>CacheXmlGenerator</code> that generates XML * for a given <code>ClientCache</code>. */ private CacheXmlGenerator(ClientCache cache, boolean useSchema, String version, boolean includeKeysValues) { this.cache = (Cache)cache; this.useSchema = useSchema; this.version = version; this.includeKeysValues = includeKeysValues; this.generateDefaults = true; if (cache instanceof ClientCacheCreation) { this.creation = (ClientCacheCreation) cache; this.creation.startingGenerate(); } else { this.creation = new ClientCacheCreation(); if (generateDefaults() || cache.getCopyOnRead()) { this.creation.setCopyOnRead(cache.getCopyOnRead()); } } } /**