Search in sources :

Example 96 with GemFireCacheImpl

use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.

the class CacheXml66DUnitTest method testTransactionWriter.

/**
   * Tests that a region created with a named attributes set programmatically for delta propogation
   * has the correct attributes.
   */
@Test
public void testTransactionWriter() throws Exception {
    CacheCreation creation = new CacheCreation();
    CacheTransactionManagerCreation ctmc = new CacheTransactionManagerCreation();
    ctmc.setWriter(new TestTransactionWriter());
    creation.addCacheTransactionManagerCreation(ctmc);
    testXml(creation);
    Cache c = getCache();
    assertTrue(c instanceof GemFireCacheImpl);
    c.loadCacheXml(generate(creation));
    TransactionWriter tw = c.getCacheTransactionManager().getWriter();
    assertTrue("tw should be TransactionWriter, but it is:" + tw, tw instanceof TestTransactionWriter);
}
Also used : CacheTransactionManagerCreation(org.apache.geode.internal.cache.xmlcache.CacheTransactionManagerCreation) TransactionWriter(org.apache.geode.cache.TransactionWriter) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Example 97 with GemFireCacheImpl

use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.

the class CacheXml66DUnitTest method testPARTITION_REDUNDANT_PERSISTENT.

@Test
public void testPARTITION_REDUNDANT_PERSISTENT() throws Exception {
    CacheCreation cache = new CacheCreation();
    RegionCreation root = (RegionCreation) cache.createRegion("prpartition", "PARTITION_REDUNDANT_PERSISTENT");
    testXml(cache);
    GemFireCacheImpl c = (GemFireCacheImpl) getCache();
    Region r = c.getRegion("prpartition");
    assertNotNull(r);
    RegionAttributes ra = r.getAttributes();
    assertEquals(DataPolicy.PERSISTENT_PARTITION, ra.getDataPolicy());
    assertNotNull(ra.getPartitionAttributes());
    assertEquals(1, ra.getPartitionAttributes().getRedundantCopies());
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) RegionCreation(org.apache.geode.internal.cache.xmlcache.RegionCreation) Test(org.junit.Test)

Example 98 with GemFireCacheImpl

use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.

the class CacheXml66DUnitTest method testClientLOCAL_PERSISTENT.

@Test
public void testClientLOCAL_PERSISTENT() throws Exception {
    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());
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) RegionCreation(org.apache.geode.internal.cache.xmlcache.RegionCreation) Test(org.junit.Test)

Example 99 with GemFireCacheImpl

use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.

the class CacheXml66DUnitTest method testLOCAL_PERSISTENT.

@Test
public void testLOCAL_PERSISTENT() throws Exception {
    CacheCreation cache = new CacheCreation();
    RegionCreation root = (RegionCreation) cache.createRegion("plocal", "LOCAL_PERSISTENT");
    testXml(cache);
    GemFireCacheImpl c = (GemFireCacheImpl) getCache();
    Region r = c.getRegion("plocal");
    assertNotNull(r);
    RegionAttributes ra = r.getAttributes();
    assertEquals(DataPolicy.PERSISTENT_REPLICATE, ra.getDataPolicy());
    assertEquals(Scope.LOCAL, ra.getScope());
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) RegionCreation(org.apache.geode.internal.cache.xmlcache.RegionCreation) Test(org.junit.Test)

Example 100 with GemFireCacheImpl

use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.

the class CacheXmlGenerator method parse.

/**
   * Called by the transformer to parse the "input source". We ignore the input source and, instead,
   * generate SAX events to the {@link #setContentHandler ContentHandler}.
   */
public void parse(InputSource input) throws SAXException {
    Assert.assertTrue(this.handler != null);
    boolean isClientCache = this.creation instanceof ClientCacheCreation;
    handler.startDocument();
    AttributesImpl atts = new AttributesImpl();
    if (this.useSchema) {
        if (null == version.getSchemaLocation()) {
            // TODO jbarrett - localize
            throw new IllegalStateException("No schema for version " + version.getVersion());
        }
        // add schema location for cache schema.
        handler.startPrefixMapping(W3C_XML_SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_NS_URI);
        addAttribute(atts, W3C_XML_SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_ATTRIBUTE_SCHEMA_LOCATION, version.getNamespace() + " " + version.getSchemaLocation());
        // add cache schema to default prefix.
        handler.startPrefixMapping(XmlConstants.DEFAULT_PREFIX, version.getNamespace());
        addAttribute(atts, VERSION, this.version.getVersion());
    }
    if (creation.hasLockLease()) {
        atts.addAttribute("", "", LOCK_LEASE, "", String.valueOf(creation.getLockLease()));
    }
    if (creation.hasLockTimeout()) {
        atts.addAttribute("", "", LOCK_TIMEOUT, "", String.valueOf(creation.getLockTimeout()));
    }
    if (creation.hasSearchTimeout()) {
        atts.addAttribute("", "", SEARCH_TIMEOUT, "", String.valueOf(creation.getSearchTimeout()));
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_5) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) {
        if (creation.hasMessageSyncInterval()) {
            atts.addAttribute("", "", MESSAGE_SYNC_INTERVAL, "", String.valueOf(creation.getMessageSyncInterval()));
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_0) >= 0) {
        if (creation.hasServer()) {
            atts.addAttribute("", "", IS_SERVER, "", String.valueOf(creation.isServer()));
        }
        if (creation.hasCopyOnRead()) {
            atts.addAttribute("", "", COPY_ON_READ, "", String.valueOf(creation.getCopyOnRead()));
        }
    }
    if (isClientCache) {
        handler.startElement("", CLIENT_CACHE, CLIENT_CACHE, atts);
    } else {
        handler.startElement("", CACHE, CACHE, atts);
    }
    if (this.cache != null) {
        if (!isClientCache) {
            generate(this.cache.getCacheTransactionManager());
        } else if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
            generate(this.cache.getCacheTransactionManager());
        }
        generateDynamicRegionFactory(this.cache);
        if (!isClientCache) {
            if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
                Set<GatewaySender> senderSet = cache.getGatewaySenders();
                for (GatewaySender sender : senderSet) {
                    generateGatewaySender(sender);
                }
                generateGatewayReceiver(this.cache);
                generateAsyncEventQueue(this.cache);
            }
        }
        if (!isClientCache && this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
            if (this.cache.getGatewayConflictResolver() != null) {
                generate(GATEWAY_CONFLICT_RESOLVER, this.cache.getGatewayConflictResolver());
            }
        }
        if (!isClientCache) {
            for (Iterator iter = this.cache.getCacheServers().iterator(); iter.hasNext(); ) {
                CacheServer bridge = (CacheServer) iter.next();
                generate(bridge);
            }
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) {
            Iterator pools;
            if (this.cache instanceof GemFireCacheImpl) {
                pools = PoolManager.getAll().values().iterator();
            } else {
                pools = this.creation.getPools().values().iterator();
            }
            while (pools.hasNext()) {
                Pool cp = (Pool) pools.next();
                generate(cp);
            }
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
            if (this.cache instanceof GemFireCacheImpl) {
                InternalCache gfc = (InternalCache) this.cache;
                for (DiskStore ds : gfc.listDiskStores()) {
                    generate(ds);
                }
            } else {
                for (DiskStore ds : this.creation.listDiskStores()) {
                    generate(ds);
                }
            }
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
            generatePdx();
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_1) >= 0) {
            Map namedAttributes = this.cache.listRegionAttributes();
            for (Iterator iter = namedAttributes.entrySet().iterator(); iter.hasNext(); ) {
                Map.Entry entry = (Map.Entry) iter.next();
                String id = (String) entry.getKey();
                RegionAttributes attrs = (RegionAttributes) entry.getValue();
                // Since CacheCreation predefines these even in later versions
                // we need to exclude them in all versions.
                // It would be better if CacheCreation could only predefine them
                // for versions 6.5 and later but that is not easy to do
                {
                    if (this.creation instanceof ClientCacheCreation) {
                        try {
                            ClientRegionShortcut.valueOf(id);
                            // skip this guy since id mapped to one of the enum types
                            continue;
                        } catch (IllegalArgumentException ignore) {
                        // id is not a shortcut so go ahead and call generate
                        }
                    } else {
                        try {
                            RegionShortcut.valueOf(id);
                            // skip this guy since id mapped to one of the enum types
                            continue;
                        } catch (IllegalArgumentException ignore) {
                        // id is not a shortcut so go ahead and call generate
                        }
                    }
                }
                generate(id, attrs);
            }
        }
        if (cache instanceof GemFireCacheImpl) {
            generateRegions();
        } else {
            TreeSet rSet = new TreeSet(new RegionComparator());
            rSet.addAll(this.cache.rootRegions());
            Iterator it = rSet.iterator();
            while (it.hasNext()) {
                Region root = (Region) it.next();
                generateRegion(root);
            }
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
            generateFunctionService();
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
            generateResourceManager();
            generateSerializerRegistration();
        }
        if (!isClientCache) {
            if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
                if (this.cache instanceof GemFireCacheImpl) {
                    InternalCache internalCache = (InternalCache) this.cache;
                    for (File file : internalCache.getBackupFiles()) {
                        generateBackupFile(file);
                    }
                } else {
                    for (File file : this.creation.getBackupFiles()) {
                        generateBackupFile(file);
                    }
                }
            }
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
            generateInitializer();
        }
    }
    if (cache instanceof Extensible) {
        @SuppressWarnings("unchecked") final Extensible<Cache> extensible = (Extensible<Cache>) cache;
        generate(extensible);
    }
    if (isClientCache) {
        handler.endElement("", CLIENT_CACHE, CLIENT_CACHE);
    } else {
        handler.endElement("", CACHE, CACHE);
    }
    handler.endDocument();
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) InternalCache(org.apache.geode.internal.cache.InternalCache) DiskWriteAttributesImpl(org.apache.geode.internal.cache.DiskWriteAttributesImpl) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) AttributesImpl(org.xml.sax.helpers.AttributesImpl) TreeSet(java.util.TreeSet) Iterator(java.util.Iterator) CacheServer(org.apache.geode.cache.server.CacheServer) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Pool(org.apache.geode.cache.client.Pool) GatewaySender(org.apache.geode.cache.wan.GatewaySender) Extensible(org.apache.geode.internal.cache.extension.Extensible) DiskStore(org.apache.geode.cache.DiskStore) AbstractRegion(org.apache.geode.internal.cache.AbstractRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) Map(java.util.Map) File(java.io.File) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) InternalCache(org.apache.geode.internal.cache.InternalCache) InternalClientCache(org.apache.geode.cache.client.internal.InternalClientCache)

Aggregations

GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)213 Test (org.junit.Test)127 Region (org.apache.geode.cache.Region)86 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)55 LocalRegion (org.apache.geode.internal.cache.LocalRegion)54 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)51 VM (org.apache.geode.test.dunit.VM)49 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)47 Host (org.apache.geode.test.dunit.Host)42 ClientCacheCreation (org.apache.geode.internal.cache.xmlcache.ClientCacheCreation)40 RegionAttributes (org.apache.geode.cache.RegionAttributes)39 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)35 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)33 CacheException (org.apache.geode.cache.CacheException)32 RegionCreation (org.apache.geode.internal.cache.xmlcache.RegionCreation)32 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)31 Properties (java.util.Properties)24 AttributesFactory (org.apache.geode.cache.AttributesFactory)24 Cache (org.apache.geode.cache.Cache)23 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)23