/** * Creates a generator for a default cache. */ private CacheXmlGenerator() { this.cache = null; this.useSchema = true; this.version = CacheXmlVersion.valueForVersion(VERSION_LATEST); this.generateDefaults = true; this.creation = new CacheCreation(); creation.setLockLease(GemFireCacheImpl.DEFAULT_LOCK_LEASE); creation.setLockTimeout(GemFireCacheImpl.DEFAULT_LOCK_TIMEOUT); creation.setSearchTimeout(GemFireCacheImpl.DEFAULT_SEARCH_TIMEOUT); // No cache proxy creation.setIsServer(false); creation.setCopyOnRead(GemFireCacheImpl.DEFAULT_COPY_ON_READ); }
@Test public void verifyInitializeDeclarablesMapWithDeclarablesPassesExpectedMap() { CacheCreation cacheCreation = new CacheCreation(); Map<Declarable, Properties> expected = new HashMap<>(); Declarable d1 = mock(Declarable.class); cacheCreation.addDeclarableProperties(d1, null); expected.put(d1, null); Declarable d2 = mock(Declarable.class); Properties p2 = new Properties(); p2.setProperty("k2", "v2"); cacheCreation.addDeclarableProperties(d2, p2); expected.put(d2, p2); cacheCreation.initializeDeclarablesMap(this.cache); verify(this.cache, times(1)).addDeclarableProperties(eq(expected)); }
public Region createRegion(String name, String refid) throws RegionExistsException, TimeoutException { RegionCreation region = new RegionCreation(this, name, refid); this.addRootRegion(region); return region; }
@Test public void verifyRunInitializerWithInitializerAndNullPropsCallsInitAndInitialize() { CacheCreation cacheCreation = new CacheCreation(); Declarable initializer = mock(Declarable.class); Properties props = null; cacheCreation.setInitializer(initializer, props); cacheCreation.runInitializer(this.cache); verify(initializer, times(1)).init(eq(props)); verify(initializer, times(1)).initialize(eq(this.cache), eq(props)); }
initializeDeclarablesMap(cache); if (hasFunctionService()) { getFunctionServiceCreation().create(); if (this.hasLockLease()) { cache.setLockLease(this.lockLease); if (this.hasLockTimeout()) { cache.setLockTimeout(this.lockTimeout); if (this.hasSearchTimeout()) { cache.setSearchTimeout(this.searchTimeout); if (this.hasMessageSyncInterval()) { cache.setMessageSyncInterval(this.getMessageSyncInterval()); Map<String, Pool> pools = getPools(); if (!pools.isEmpty()) { for (Pool pool : pools.values()) { if (hasResourceManager()) { getResourceManager().configure(cache.getResourceManager()); DiskStoreAttributesCreation pdxRegDSC = initializePdxDiskStore(cache); DiskStoreAttributesCreation creation = (DiskStoreAttributesCreation) diskStore; if (creation != pdxRegDSC) {
boolean sameConfig = other.getLockLease() == this.getLockLease() && other.getLockTimeout() == this.getLockTimeout() && other.getSearchTimeout() == this.getSearchTimeout() && other.getMessageSyncInterval() == this.getMessageSyncInterval() && other.getCopyOnRead() == this.getCopyOnRead() && other.isServer() == this.isServer(); DynamicRegionFactory.Config drc1 = this.getDynamicRegionFactoryConfig(); if (drc1 != null) { drc2 = ((CacheCreation) other).getDynamicRegionFactoryConfig(); } else { drc2 = DynamicRegionFactory.get().getConfig(); if (((CacheCreation) other).getDynamicRegionFactoryConfig() != null) { return false; Collection<CacheServer> myBridges = this.getCacheServers(); Collection<CacheServer> otherBridges = other.getCacheServers(); if (myBridges.size() != otherBridges.size()) { Map<String, Pool> m1 = getPools(); Map<String, Pool> m2 = other instanceof CacheCreation ? ((CacheCreation) other).getPools() : PoolManager.getAll(); int m1Size = m1.size(); DiskStore ds = other.findDiskStore(name); if (ds == null) { getLogger().fine("Disk store " + name + " not found."); throw new RuntimeException(
@Test public void defaultCacheServerIsNotCreatedWhenDisableDefaultCacheServerIsTrue() { CacheCreation cacheCreation = new CacheCreation(); CacheServerImpl mockServer = mock(CacheServerImpl.class); when(this.cache.addCacheServer()).thenReturn(mockServer); List<CacheServer> cacheServers = new ArrayList<>(); when(this.cache.getCacheServers()).thenReturn(cacheServers); cacheCreation.startCacheServers(cacheCreation.getCacheServers(), this.cache, ServerLauncherParameters.INSTANCE.withDisableDefaultServer(false)); verify(this.cache, never()).addCacheServer(); }
@Test public void shouldCreateGatewaySenderAfterRegions() { CacheCreation cacheCreation = new CacheCreation(); GatewayReceiver receiver = mock(GatewayReceiver.class); cacheCreation.addGatewayReceiver(receiver); cacheCreation.addRootRegion(new RegionCreation(cacheCreation, "region")); InternalCache internalCache = mock(InternalCache.class); GatewayReceiverFactory receiverFactory = mock(GatewayReceiverFactory.class); when(internalCache.createGatewayReceiverFactory()).thenReturn(receiverFactory); when(receiverFactory.create()).thenReturn(receiver); InOrder inOrder = inOrder(internalCache, receiverFactory); cacheCreation.create(internalCache); // inOrder.verify(cache).basicCreateRegion(eq("region"), any()); inOrder.verify(internalCache).createGatewayReceiverFactory(); inOrder.verify(receiverFactory).create(); }
@Test public void verifyInitializeDeclarablesMapWithNoDeclarablesPassesEmptyMap() { CacheCreation cacheCreation = new CacheCreation(); Map<Declarable, Properties> expected = Collections.emptyMap(); cacheCreation.initializeDeclarablesMap(this.cache); verify(this.cache, times(1)).addDeclarableProperties(eq(expected)); }
@Test public void declarativeRegionIsCreated() { CacheCreation cacheCreation = new CacheCreation(); RegionCreation declarativeRegion = mock(RegionCreation.class); when(declarativeRegion.getName()).thenReturn("testRegion"); Map<String, Region<?, ?>> declarativeRegions = new HashMap<>(); declarativeRegions.put("testRegion", declarativeRegion); when(this.cache.getRegion("testRegion")).thenReturn(null); cacheCreation.initializeRegions(declarativeRegions, this.cache); verify(declarativeRegion, times(1)).createRoot(this.cache); }
/** * Creates cache artifacts ({@link Cache}s, etc.) based upon the XML parsed by this parser. */ public void create(InternalCache cache) throws TimeoutException, GatewayException, CacheWriterException, RegionExistsException { if (this.cache == null) { String s = "A cache or client-cache element is required"; throw new CacheXmlException( "No cache element specified."); } this.cache.create(cache); }
private void endInitializer() { Properties props = new Properties(); Object top = stack.pop(); while (top instanceof Parameter) { Parameter param = (Parameter) top; props.put(param.getName(), param.getValue()); top = stack.pop(); } Assert.assertTrue(top instanceof String); String className = (String) top; Object o; try { Class c = InternalDataSerializer.getCachedClass(className); o = c.newInstance(); } catch (Exception ex) { throw new CacheXmlException( String.format("While instantiating a %s", className), ex); } if (!(o instanceof Declarable)) { throw new CacheXmlException( String.format("Class %s is not an instance of Declarable.", className)); } Declarable d = (Declarable) o; this.cache.setInitializer(d, props); }
cache.addDeclarableProperties(d, props);
/** * Test method for {@link RegionCreation#getExtensionPoint()}. * * Assert that method returns a {@link SimpleExtensionPoint} instance and assume that * {@link SimpleExtensionPointJUnitTest} has covered the rest. */ @Test public void testGetExtensionPoint() { final CacheCreation cache = new CacheCreation(); final RegionCreation region = new RegionCreation(cache, "test"); final ExtensionPoint<Region<?, ?>> extensionPoint = region.getExtensionPoint(); assertNotNull(extensionPoint); assertEquals(extensionPoint.getClass(), SimpleExtensionPoint.class); }
@Test(expected = RuntimeException.class) public void shouldThrowExceptionWhenUserTriesToDeclareMultipleCacheServersWithPort() { CacheCreation cacheCreation = new CacheCreation(); cacheCreation.getCacheServers().add(new CacheServerCreation(cacheCreation, false)); cacheCreation.getCacheServers().add(new CacheServerCreation(cacheCreation, false)); Integer configuredServerPort = 50505; String configuredServerBindAddress = "localhost[50505]"; Boolean disableDefaultCacheServer = false; cacheCreation.startCacheServers(cacheCreation.getCacheServers(), this.cache, ServerLauncherParameters.INSTANCE.withPort(configuredServerPort) .withBindAddress(configuredServerBindAddress) .withDisableDefaultServer(disableDefaultCacheServer)); }
@Test public void verifyRunInitializerWithInitializerAndPropsCallsInitAndInitialize() { CacheCreation cacheCreation = new CacheCreation(); Declarable initializer = mock(Declarable.class); Properties props = new Properties(); props.setProperty("key", "value"); cacheCreation.setInitializer(initializer, props); cacheCreation.runInitializer(this.cache); verify(initializer, times(1)).init(eq(props)); verify(initializer, times(1)).initialize(eq(this.cache), eq(props)); }
@Test public void defaultCacheServerIsNotCreatedWithDefaultPortWhenNoDeclarativeServerIsConfigured() { CacheCreation cacheCreation = new CacheCreation(); CacheServerImpl mockServer = mock(CacheServerImpl.class); when(this.cache.addCacheServer()).thenReturn(mockServer); List<CacheServer> cacheServers = new ArrayList<>(); when(this.cache.getCacheServers()).thenReturn(cacheServers); cacheCreation.startCacheServers(cacheCreation.getCacheServers(), this.cache, ServerLauncherParameters.INSTANCE.withDisableDefaultServer(false)); verify(this.cache, never()).addCacheServer(); }
throw new CacheXmlException("Only a single cache or client-cache element is allowed"); this.cache = new CacheCreation(true); String lockLease = atts.getValue(LOCK_LEASE); if (lockLease != null) { this.cache.setLockLease(parseInt(lockLease)); this.cache.setLockTimeout(parseInt(lockTimeout)); this.cache.setSearchTimeout(parseInt(searchTimeout)); this.cache.setMessageSyncInterval(parseInt(messageSyncInterval)); this.cache.setIsServer(b); this.cache.setCopyOnRead(Boolean.valueOf(copyOnRead).booleanValue());
@Test public void verifyInitializeDeclarablesMapWithDeclarableCallInitAndInitialize() { CacheCreation cacheCreation = new CacheCreation(); Declarable d2 = mock(Declarable.class); Properties p2 = new Properties(); p2.setProperty("k2", "v2"); cacheCreation.addDeclarableProperties(d2, p2); cacheCreation.initializeDeclarablesMap(this.cache); verify(d2, times(1)).init(eq(p2)); verify(d2, times(1)).initialize(eq(this.cache), eq(p2)); }
/** * After popping the current <code>RegionCreation</code> off the stack, if the element on top of * the stack is a <code>RegionCreation</code>, then it is the parent region. */ private void endRegion() throws RegionExistsException { RegionCreation region = (RegionCreation) stack.pop(); boolean isRoot = false; if (stack.isEmpty()) { isRoot = true; } else if (!(stack.peek() instanceof RegionCreation)) { isRoot = true; } if (isRoot) { this.cache.addRootRegion(region); } else { RegionCreation parent = (RegionCreation) stack.peek(); parent.addSubregion(region.getName(), region); } }