You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ud...@apache.org on 2016/10/11 03:07:37 UTC
[09/20] incubator-geode git commit: GEODE-1914 Removed old dtds from
geode source code(kept 7.0 and above)
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/952ab6fa/geode-core/src/test/java/org/apache/geode/cache30/CacheXml30DUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml30DUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache30/CacheXml30DUnitTest.java
deleted file mode 100644
index 187be8a..0000000
--- a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml30DUnitTest.java
+++ /dev/null
@@ -1,845 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.geode.cache30;
-
-import static org.junit.Assert.*;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.util.Properties;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.xml.sax.SAXException;
-
-import org.apache.geode.cache.CacheException;
-import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.cache.CacheListener;
-import org.apache.geode.cache.CacheLoader;
-import org.apache.geode.cache.CacheLoaderException;
-import org.apache.geode.cache.CacheWriter;
-import org.apache.geode.cache.CacheXmlException;
-import org.apache.geode.cache.Declarable;
-import org.apache.geode.cache.DiskWriteAttributesFactory;
-import org.apache.geode.cache.EvictionAction;
-import org.apache.geode.cache.EvictionAttributes;
-import org.apache.geode.cache.ExpirationAction;
-import org.apache.geode.cache.ExpirationAttributes;
-import org.apache.geode.cache.LoaderHelper;
-import org.apache.geode.cache.MirrorType;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.cache.util.ObjectSizer;
-import org.apache.geode.internal.cache.DiskWriteAttributesImpl;
-import org.apache.geode.internal.cache.xmlcache.CacheCreation;
-import org.apache.geode.internal.cache.xmlcache.CacheXml;
-import org.apache.geode.internal.cache.xmlcache.CacheXmlParser;
-import org.apache.geode.internal.cache.xmlcache.Declarable2;
-import org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation;
-import org.apache.geode.internal.cache.xmlcache.RegionCreation;
-import org.apache.geode.internal.i18n.LocalizedStrings;
-import org.apache.geode.test.dunit.IgnoredException;
-import org.apache.geode.test.dunit.LogWriterUtils;
-import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.util.test.TestUtil;
-
-/**
- * Tests the functionality of loading a declarative caching file when
- * a <code>Cache</code> is {@link CacheFactory#create created}. The
- * fact that it is a subclass of {@link RegionTestCase} allows us to
- * take advantage of methods like getCache().
- *
- * <P>
- *
- * Note that this class only tests the XML syntax allowed in GemFire
- * 3.X (3.0, 3.2, 3.5). Tests for syntax added in subsequent releases
- * is tested by subclasses of this class.
- *
- * @since GemFire 3.0
- */
-@Category(DistributedTest.class)
-public class CacheXml30DUnitTest extends CacheXmlTestCase {
-
- /**
- * Tests creating a cache with a non-existent XML file
- */
- @Test
- public void testNonExistentFile() throws IOException {
-// System.out.println("testNonExistentFile - start: " + System.currentTimeMillis());
- File nonExistent = new File(this.getName() + ".xml");
- nonExistent.delete();
-// System.out.println("testNonExistentFile - deleted: " + System.currentTimeMillis());
- setXmlFile(nonExistent);
-// System.out.println("testNonExistentFile - set: " + System.currentTimeMillis());
-
- IgnoredException expectedException = IgnoredException.addIgnoredException(LocalizedStrings.
- GemFireCache_DECLARATIVE_CACHE_XML_FILERESOURCE_0_DOES_NOT_EXIST.toLocalizedString(nonExistent.getPath()));
- try {
- getCache();
- fail("Should have thrown a CacheXmlException");
-
- } catch (CacheXmlException ex) {
-// System.out.println("testNonExistentFile - caught: " + System.currentTimeMillis());
- // pass...
- } finally {
- expectedException.remove();
- }
- }
-
- /**
- * Tests creating a cache with a XML file that is a directory
- */
- @Test
- public void testXmlFileIsDirectory() {
- File dir = new File(this.getName() + "dir");
- dir.mkdirs();
- dir.deleteOnExit();
- setXmlFile(dir);
-
- IgnoredException expectedException = IgnoredException.addIgnoredException(LocalizedStrings.
- GemFireCache_DECLARATIVE_XML_FILE_0_IS_NOT_A_FILE.toLocalizedString(dir));
- try {
- getCache();
- fail("Should have thrown a CacheXmlException");
-
- } catch (CacheXmlException ex) {
- // pass...
- } finally {
- expectedException.remove();
- }
- }
-
- /**
- * Tests creating a cache with the default lock-timeout, lock-lease,
- * and search-timeout.
- */
- @Test
- public void testDefaultCache() {
- CacheCreation cache = new CacheCreation();
-
- testXml(cache);
- }
-
- /**
- * Tests creating a cache with non-default lock-timeout, lock-lease,
- * and search-timeout.
- */
- @Test
- public void testNonDefaultCache() {
- CacheCreation cache = new CacheCreation();
- cache.setLockTimeout(42);
- cache.setLockLease(43);
- cache.setSearchTimeout(44);
-
- if (getGemFireVersion().compareTo(CacheXml.VERSION_4_0) >= 0) {
- cache.setCopyOnRead(true);
- }
-
- testXml(cache);
- }
-
- /**
- * Tests creating a cache with entries defined in the root region
- */
- @Test
- public void testEntriesInRootRegion() throws CacheException {
- CacheCreation cache = new CacheCreation();
- RegionCreation root = (RegionCreation)
- cache.createRegion("root", new RegionAttributesCreation(cache));
- root.put("KEY1", "VALUE1");
- root.put("KEY2", "VALUE2");
- root.put("KEY3", "VALUE3");
-
- testXml(cache);
- }
-
- /**
- * Tests creating a cache whose keys are constrained
- */
- @Test
- public void testConstrainedKeys() throws CacheException {
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setKeyConstraint(String.class);
- cache.createRegion("root", attrs);
-
- testXml(cache);
- }
-
- /**
- * Tests creating a cache with a various {@link
- * ExpirationAttributes}.
- */
- @Test
- public void testExpirationAttriubutes() throws CacheException {
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setStatisticsEnabled(true);
-
- {
- ExpirationAttributes expire =
- new ExpirationAttributes(42, ExpirationAction.INVALIDATE);
- attrs.setRegionTimeToLive(expire);
- }
-
- {
- ExpirationAttributes expire =
- new ExpirationAttributes(43, ExpirationAction.DESTROY);
- attrs.setRegionIdleTimeout(expire);
- }
-
- {
- ExpirationAttributes expire =
- new ExpirationAttributes(44, ExpirationAction.LOCAL_INVALIDATE);
- attrs.setEntryTimeToLive(expire);
- }
-
- {
- ExpirationAttributes expire =
- new ExpirationAttributes(45, ExpirationAction.LOCAL_DESTROY);
- attrs.setEntryIdleTimeout(expire);
- }
-
- cache.createRegion("root", attrs);
-
- testXml(cache);
- }
-
- /**
- * Tests a cache loader an interesting combination of declarables
- */
- @Test
- public void testCacheLoaderWithDeclarables() throws CacheException {
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
-
- CacheLoaderWithDeclarables loader =
- new CacheLoaderWithDeclarables();
- attrs.setCacheLoader(loader);
-
- cache.createRegion("root", attrs);
-
- testXml(cache);
- }
-
- /**
- * Tests a cache writer with no parameters
- */
- @Test
- public void testCacheWriter() throws CacheException {
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
-
- CacheWriter writer = new MyTestCacheWriter();
- attrs.setCacheWriter(writer);
-
- cache.createRegion("root", attrs);
-
- testXml(cache);
- }
-
- /**
- * Tests a cache listener with no parameters
- */
- @Test
- public void testCacheListener() throws CacheException {
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
-
- CacheListener listener = new MyTestCacheListener();
- attrs.setCacheListener(listener);
-
- cache.createRegion("root", attrs);
-
- testXml(cache);
- }
-
- /**
- * Tests a region with non-default region attributes
- */
- @Test
- public void testNonDefaultRegionAttributes() throws CacheException {
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
-
- attrs.setScope(Scope.DISTRIBUTED_NO_ACK);
- attrs.setMirrorType(MirrorType.KEYS_VALUES);
- attrs.setInitialCapacity(142);
- attrs.setLoadFactor(42.42f);
- attrs.setStatisticsEnabled(false);
-
- cache.createRegion("root", attrs);
-
- testXml(cache);
- }
-
- /**
- * Tests parsing a malformed XML file
- */
- @Test
- public void testMalformed() {
- setXmlFile(findFile("malformed.xml"));
-
- IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
- try {
- getCache();
- fail("Should have thrown a CacheXmlException");
-
- } catch (CacheXmlException ex) {
- assertTrue(ex.getCause() instanceof SAXException);
- } finally {
- expectedException.remove();
- }
- }
-
- /**
- * Tests parsing an XML file with a bad integer
- */
- @Test
- public void testBadInt() {
- setXmlFile(findFile("badInt.xml"));
-
- IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
- try {
- getCache();
- fail("Should have thrown a CacheXmlException");
-
- } catch (CacheXmlException ex) {
- Throwable cause = ex.getCause();
- assertNotNull("Expected a cause", cause);
- assertTrue("Didn't expect cause:" + cause + " (a " +
- cause.getClass().getName() + ")",
- cause instanceof NumberFormatException);
- } finally {
- expectedException.remove();
- }
- }
-
- /**
- * Tests parsing an XML file with a bad float
- */
- @Test
- public void testBadFloat() {
- setXmlFile(findFile("badFloat.xml"));
-
- IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
- try {
- getCache();
- fail("Should have thrown a CacheXmlException");
-
- } catch (CacheXmlException ex) {
- assertTrue(ex.getCause() instanceof NumberFormatException);
- } finally {
- expectedException.remove();
- }
- }
-
- /**
- * Tests parsing an XML file with a bad scope. This error should be
- * caught by the XML parser.
- */
- @Test
- public void testBadScope() {
- setXmlFile(findFile("badScope.xml"));
-
- IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
- try {
- getCache();
- fail("Should have thrown a CacheXmlException");
-
- } catch (CacheXmlException ex) {
- assertTrue(ex.getCause() instanceof SAXException);
- } finally {
- expectedException.remove();
- }
- }
-
- /**
- * Tests parsing an XML file with a non-existent key constraint
- * class.
- */
- @Test
- public void testBadKeyConstraintClass() {
- setXmlFile(findFile("badKeyConstraintClass.xml"));
-
- IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
- try {
- getCache();
- fail("Should have thrown a CacheXmlException");
-
- } catch (CacheXmlException ex) {
- assertTrue(ex.getCause() instanceof ClassNotFoundException);
- } finally {
- expectedException.remove();
- }
- }
-
- /**
- * Tests parsing an XML file that specifies a cache listener that is
- * not {@link Declarable}.
- */
- @Test
- public void testCallbackNotDeclarable() {
- setXmlFile(findFile("callbackNotDeclarable.xml"));
-
- IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
- try {
- getCache();
- fail("Should have thrown a CacheXmlException");
-
- } catch (CacheXmlException ex) {
- Throwable cause = ex.getCause();
- assertNull(/*"Didn't expect a cause of " + cause + " (a " +
- cause.getClass().getName() + ")" + " from " + ex, */
- cause);
- } finally {
- expectedException.remove();
- }
- }
-
- /**
- * Tests parsing an XML file that specifies a cache listener whose
- * constructor throws an {@linkplain AssertionError exception}.
- */
- @Test
- public void testCallbackWithException() {
- setXmlFile(findFile("callbackWithException.xml"));
-
- IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
- try {
- getCache();
- fail("Should have thrown a CacheXmlException");
-
- } catch (CacheXmlException ex) {
- if (!(ex.getCause() instanceof AssertionError)) {
- throw ex;
- }
- } finally {
- expectedException.remove();
- }
-
- }
-
- /**
- * Tests parsing an XML file that specifies a cache listener that is
- * not a <code>CacheLoader</code>.
- */
- @Test
- public void testLoaderNotLoader() {
- setXmlFile(findFile("loaderNotLoader.xml"));
-
- IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
- try {
- getCache();
- fail("Should have thrown a CacheXmlException");
-
- } catch (CacheXmlException ex) {
- Throwable cause = ex.getCause();
- assertNull("Didn't expect a " + cause, cause);
- } finally {
- expectedException.remove();
- }
- }
-
- /**
- * Tests nested regions
- */
- @Test
- public void testNestedRegions() throws CacheException {
- CacheCreation cache = new CacheCreation();
-
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setScope(Scope.DISTRIBUTED_NO_ACK);
-
- RegionCreation root =
- (RegionCreation) cache.createRegion("root", attrs);
-
- {
- attrs = new RegionAttributesCreation(cache);
- attrs.setScope(Scope.DISTRIBUTED_NO_ACK);
- attrs.setMirrorType(MirrorType.KEYS_VALUES);
- attrs.setInitialCapacity(142);
- attrs.setLoadFactor(42.42f);
- attrs.setStatisticsEnabled(false);
-
- root.createSubregion("one", attrs);
- }
-
- {
- attrs = new RegionAttributesCreation(cache);
- attrs.setScope(Scope.DISTRIBUTED_ACK);
- attrs.setMirrorType(MirrorType.KEYS);
- attrs.setInitialCapacity(242);
-
- Region region = root.createSubregion("two", attrs);
-
- {
- attrs = new RegionAttributesCreation(cache);
- attrs.setScope(Scope.GLOBAL);
- attrs.setLoadFactor(43.43f);
-
- region.createSubregion("three", attrs);
- }
- }
-
- testXml(cache);
- }
-
- /**
- * Tests whether or not XML attributes can appear in any order. See
- * bug 30050.
- */
- @Test
- public void testAttributesUnordered() {
- setXmlFile(findFile("attributesUnordered.xml"));
- getCache();
- }
-
- /**
- * Tests disk directories
- */
- @Test
- public void testDiskDirs() throws CacheException {
- CacheCreation cache = new CacheCreation();
-
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- File[] dirs = new File[] {
- new File(this.getUniqueName() + "-dir1"),
- new File(this.getUniqueName() + "-dir2")
- };
- for (int i = 0; i < dirs.length; i++) {
- dirs[i].mkdirs();
- dirs[i].deleteOnExit();
- }
-
- int[] diskSizes = {DiskWriteAttributesImpl.DEFAULT_DISK_DIR_SIZE ,DiskWriteAttributesImpl.DEFAULT_DISK_DIR_SIZE };
- attrs.setDiskDirsAndSize(dirs,diskSizes);
- cache.createRegion("root", attrs);
-
- testXml(cache);
- }
-
- /**
- * Tests the <code>overflowThreshold</code> and
- * <code>persistBackup</code> related attributes
- */
- @Test
- public void testOverflowAndBackup() throws CacheException {
- CacheCreation cache = new CacheCreation();
-
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setMirrorType(MirrorType.KEYS_VALUES);
- attrs.setPersistBackup(true);
-
- cache.createRegion("root", attrs);
-
- testXml(cache);
- }
-
- /**
- * Tests <code>DiskWriteAttributes</code>
- */
- @Test
- public void testDiskWriteAttributes() throws CacheException {
- CacheCreation cache = new CacheCreation();
-// Set properties for Asynch writes
-
-
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
-
- RegionCreation root = (RegionCreation)
- cache.createRegion("root", attrs);
-
- {
- attrs = new RegionAttributesCreation(cache);
- DiskWriteAttributesFactory dwaf = new DiskWriteAttributesFactory();
- dwaf.setSynchronous(true);
- attrs.setDiskWriteAttributes(dwaf.create());
- root.createSubregion("sync", attrs);
- }
-
- {
- attrs = new RegionAttributesCreation(cache);
- DiskWriteAttributesFactory dwaf = new DiskWriteAttributesFactory();
- dwaf.setTimeInterval(123L);
- dwaf.setBytesThreshold(456L);
- attrs.setDiskWriteAttributes(dwaf.create());
- root.createSubregion("async", attrs);
- }
-
- testXml(cache);
- }
-
- /**
- * Tests to make sure that the example cache.xml file in the API
- * documentation conforms to the DTD.
- *
- * @since GemFire 3.2.1
- */
- @Test
- public void testExampleCacheXmlFile() throws Exception {
- // Check for old example files
- String dirName = "examples_" + this.getGemFireVersion();
- File dir = null;
- try {
- dir = findFile(dirName);
- } catch(AssertionError e) {
- //ignore, no directory.
- }
- if (dir != null && dir.exists()) {
- File[] xmlFiles = dir.listFiles(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.endsWith(".xml");
- }
- });
- assertTrue("No XML files in " + dirName, xmlFiles.length > 0);
- for (int i = 0; i < xmlFiles.length; i++) {
- File xmlFile = xmlFiles[i];
- LogWriterUtils.getLogWriter().info("Parsing " + xmlFile);
-
- FileInputStream fis = new FileInputStream(xmlFile);
- CacheXmlParser.parse(fis);
- }
-
- } else {
-
- File example = new File(TestUtil.getResourcePath(getClass(), "/org/apache/geode/cache/doc-files/example-cache.xml"));
- FileInputStream fis = new FileInputStream(example);
- CacheXmlParser.parse(fis);
-
- File example2 = new File(TestUtil.getResourcePath(getClass(), "/org/apache/geode/cache/doc-files/example2-cache.xml"));
- fis = new FileInputStream(example2);
- CacheXmlParser.parse(fis);
-
- File example3 = new File(TestUtil.getResourcePath(getClass(), "/org/apache/geode/cache/doc-files/example3-cache.xml"));
- fis = new FileInputStream(example3);
- CacheXmlParser.parse(fis);
- }
- }
-
- @Test
- public void testEvictionLRUEntryAttributes() throws Exception {
- final String rName = getUniqueName();
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(80, EvictionAction.LOCAL_DESTROY));
- cache.createRegion(rName, attrs);
- testXml(cache);
- }
-
- public static class EvictionObjectSizer implements ObjectSizer, Declarable2 {
- Properties props = new Properties();
- public int sizeof(Object o) { return 1; }
- public Properties getConfig()
- {
- if (null==this.props) {
- this.props = new Properties();
- }
- this.props.setProperty("EvictionObjectSizerColor", "blue");
- return this.props;
- }
-
- public void init(Properties props)
- {
- this.props = props;
- }
-
- public boolean equals(Object obj)
- {
- if (obj == this){
- return true;
- }
- if (! (obj instanceof EvictionObjectSizer)) {
- return false;
- }
- EvictionObjectSizer other = (EvictionObjectSizer) obj;
- if (! this.props.equals(other.props)) {
- return false;
- }
- return true;
- }
- }
- @Test
- public void testEvictionLRUMemoryAttributes() throws Exception {
- final String rName = getUniqueName();
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(10, new EvictionObjectSizer()));
- cache.createRegion(rName, attrs);
- testXml(cache);
- }
-
- @Test
- public void testEvictionLRUHeapAttributes() throws Exception {
- final String rName = getUniqueName();
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setEvictionAttributes(EvictionAttributes
- .createLRUHeapAttributes(new EvictionObjectSizer(), EvictionAction.LOCAL_DESTROY));
- cache.createRegion(rName, attrs);
- testXml(cache);
- }
-
-
- //////////////////////// Inner Classes ////////////////////////
-
- /**
- * A cache listener that is not {@link Declarable}
- *
- * @see #testCallbackNotDeclarable()
- */
- public static class NotDeclarableCacheListener
- extends TestCacheListener {
-
- }
-
-
- public static class AssertionError extends RuntimeException {
- public AssertionError() {
- super("Test Exception");
- }
- }
-
- /**
- * A cache listener whose constructor throws an exception
- *
- * @see #testCallbackWithException()
- */
- public static class ExceptionalCacheListener
- extends TestCacheListener {
-
- public ExceptionalCacheListener() {
- throw new AssertionError();
- }
- }
-
-
- /**
- * A <code>CacheListener</code> that is
- * <code>Declarable</code>, but not <code>Declarable2</code>.
- */
- public static class MyTestCacheListener
- extends TestCacheListener implements Declarable {
-
- public void init(Properties props) { }
-
- public boolean equals(Object o) {
- return o instanceof MyTestCacheListener;
- }
- }
-
- /**
- * A <code>CacheWriter</code> that is
- * <code>Declarable</code>, but not <code>Declarable2</code>.
- */
- public static class MyTestCacheWriter
- extends TestCacheWriter implements Declarable {
-
- public void init(Properties props) { }
-
- public boolean equals(Object o) {
- return o instanceof MyTestCacheWriter;
- }
- }
-
- /**
- * A <code>TransactionListener</code> that is
- * <code>Declarable</code>, but not <code>Declarable2</code>.
- */
- public static class MyTestTransactionListener
- extends TestTransactionListener implements Declarable {
-
- public void init(Properties props) { }
-
- public boolean equals(Object o) {
- return o instanceof MyTestTransactionListener;
- }
- }
-
-
- /**
- * A <code>CacheLoader</code> that is <code>Declarable</code> and
- * has some interesting parameters.
- */
- public static class CacheLoaderWithDeclarables
- implements CacheLoader, Declarable2 {
-
- /** This loader's properties */
- private Properties props;
-
- /** Was this declarable initialized */
- private boolean initialized = false;
-
- /**
- * Creates a new loader and initializes its properties
- */
- public CacheLoaderWithDeclarables() {
- this.props = new Properties();
- props.put("KEY1", "VALUE1");
- props.put("KEY2", new TestDeclarable());
- }
-
- /**
- * Returns whether or not this <code>Declarable</code> was
- * initialized.
- */
- public boolean isInitialized() {
- return this.initialized;
- }
-
- public void init(Properties props) {
- this.initialized = true;
- assertEquals(this.props, props);
- }
-
- public Properties getConfig() {
- return this.props;
- }
-
- public Object load(LoaderHelper helper)
- throws CacheLoaderException {
-
- fail("Loader shouldn't be invoked");
- return null;
- }
-
- public boolean equals(Object o) {
- if (o instanceof CacheLoaderWithDeclarables) {
- CacheLoaderWithDeclarables other =
- (CacheLoaderWithDeclarables) o;
- return this.props.equals(other.props);
-
- } else {
- return false;
- }
- }
-
- public void close() { }
-
- }
-
- public static class TestDeclarable implements Declarable {
- public void init(Properties props) { }
-
- public boolean equals(Object o) {
- return o instanceof TestDeclarable;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/952ab6fa/geode-core/src/test/java/org/apache/geode/cache30/CacheXml40DUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml40DUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache30/CacheXml40DUnitTest.java
deleted file mode 100644
index 952efb2..0000000
--- a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml40DUnitTest.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.geode.cache30;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.cache.CacheException;
-import org.apache.geode.cache.MirrorType;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.cache.server.CacheServer;
-import org.apache.geode.internal.cache.xmlcache.CacheCreation;
-import org.apache.geode.internal.cache.xmlcache.CacheTransactionManagerCreation;
-import org.apache.geode.internal.cache.xmlcache.CacheXml;
-import org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-/**
- * Tests the declarative caching functionality introduced in GemFire
- * 4.0.
- *
- * @since GemFire 4.0
- */
-@Category(DistributedTest.class)
-public class CacheXml40DUnitTest extends CacheXml30DUnitTest {
-
- protected String getGemFireVersion() {
- return CacheXml.VERSION_4_0;
- }
-
- /**
- * Tests the cache server attribute
- *
- * @since GemFire 4.0
- */
- @Test
- public void testServer() {
- CacheCreation cache = new CacheCreation();
- cache.setIsServer(true);
- assertTrue(cache.isServer());
-
- testXml(cache);
- }
-
- /**
- * Tests declarative bridge servers
- *
- * @since GemFire 4.0
- */
- @Test
- public void testBridgeServers() {
- CacheCreation cache = new CacheCreation();
-
- CacheServer bridge1 = cache.addCacheServer();
- setBridgeAttributes(bridge1);
-
- CacheServer bridge2 = cache.addCacheServer();
- setBridgeAttributes(bridge2);
-
- testXml(cache);
- }
-
- /**
- * Used by testBridgeServers to set version specific attributes
- * @param bridge1 the bridge server to set attributes upon
- */
- public void setBridgeAttributes(CacheServer bridge1)
- {
- //@see http://docs.oracle.com/javase/7/docs/api/java/net/InetSocketAddress.html#InetSocketAddress(int)
- bridge1.setPort(0);
- }
-
- /**
- * Tests the is-lock-grantor attribute in xml.
- */
- @Test
- public void testIsLockGrantorAttribute() throws CacheException {
-
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
-
- attrs.setLockGrantor(true);
- attrs.setScope(Scope.GLOBAL);
- attrs.setMirrorType(MirrorType.KEYS_VALUES);
-
- cache.createRegion("root", attrs);
-
- testXml(cache);
- assertEquals(true, cache.getRegion("root").getAttributes().isLockGrantor());
- }
-
- /**
- * Tests a cache listener with no parameters
- *
- * @since GemFire 4.0
- */
- @Test
- public void testTransactionListener() {
- CacheCreation cache = new CacheCreation();
- CacheTransactionManagerCreation txMgrCreation = new CacheTransactionManagerCreation();
- txMgrCreation.setListener(new MyTestTransactionListener());
- cache.addCacheTransactionManagerCreation(txMgrCreation);
- testXml(cache);
- }
-
- /**
- * Tests transaction manager with no listener
- *
- * @since GemFire 4.0
- */
- @Test
- public void testCacheTransactionManager() {
- CacheCreation cache = new CacheCreation();
- CacheTransactionManagerCreation txMgrCreation = new CacheTransactionManagerCreation();
- cache.addCacheTransactionManagerCreation(txMgrCreation);
- testXml(cache);
- }
-
- /**
- * Tests the value constraints region attribute that was added in
- * GemFire 4.0.
- *
- * @since GemFire 4.1
- */
- @Test
- public void testConstrainedValues() throws CacheException {
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setValueConstraint(String.class);
-
- cache.createRegion("root", attrs);
-
- testXml(cache);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/952ab6fa/geode-core/src/test/java/org/apache/geode/cache30/CacheXml41DUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml41DUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache30/CacheXml41DUnitTest.java
deleted file mode 100644
index ae1a98d..0000000
--- a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml41DUnitTest.java
+++ /dev/null
@@ -1,664 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.geode.cache30;
-
-import static org.junit.Assert.*;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.InputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.xml.sax.SAXException;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheException;
-import org.apache.geode.cache.CacheXmlException;
-import org.apache.geode.cache.DynamicRegionFactory;
-import org.apache.geode.cache.ExpirationAction;
-import org.apache.geode.cache.ExpirationAttributes;
-import org.apache.geode.cache.MirrorType;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionAttributes;
-import org.apache.geode.cache.RegionExistsException;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.cache.server.CacheServer;
-import org.apache.geode.internal.cache.xmlcache.CacheCreation;
-import org.apache.geode.internal.cache.xmlcache.CacheXml;
-import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator;
-import org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation;
-import org.apache.geode.internal.i18n.LocalizedStrings;
-import org.apache.geode.test.dunit.Assert;
-import org.apache.geode.test.dunit.IgnoredException;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-/**
- * Tests the declarative caching functionality introduced in GemFire 4.1.
- *
- * @since GemFire 4.1
- */
-
-@Category(DistributedTest.class)
-public class CacheXml41DUnitTest extends CacheXml40DUnitTest
-{
-
- // ////// Constructors
-
- public CacheXml41DUnitTest() {
- super();
- }
-
- // ////// Helper methods
-
- protected String getGemFireVersion()
- {
- return CacheXml.VERSION_4_1;
- }
-
- // ////// Test methods
-
-
- public void setBridgeAttributes(CacheServer bridge1)
- {
- super.setBridgeAttributes(bridge1);
- bridge1.setMaximumTimeBetweenPings(12345);
- bridge1.setNotifyBySubscription(true);
- bridge1.setSocketBufferSize(98765);
- }
-
- /**
- * Tests that named region attributes are registered when the cache is
- * created.
- */
- @Test
- public void testRegisteringNamedRegionAttributes()
- {
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs;
-
- String id1 = "id1";
- attrs = new RegionAttributesCreation(cache);
- attrs.setScope(Scope.DISTRIBUTED_ACK);
- attrs.setMirrorType(MirrorType.KEYS);
- cache.setRegionAttributes(id1, attrs);
-
- String id2 = "id2";
- attrs = new RegionAttributesCreation(cache);
- attrs.setScope(Scope.DISTRIBUTED_NO_ACK);
- attrs.setMirrorType(MirrorType.KEYS_VALUES);
- attrs.setConcurrencyLevel(15);
- cache.setRegionAttributes(id2, attrs);
-
- String id3 = "id3";
- attrs = new RegionAttributesCreation(cache);
- attrs.setScope(Scope.LOCAL);
- attrs.setValueConstraint(Integer.class);
- cache.setRegionAttributes(id3, attrs);
-
- testXml(cache);
- }
-
- /**
- * Tests that a region created with a named attributes has the correct
- * attributes.
- */
- @Test
- public void testNamedAttributes() throws CacheException
- {
- setXmlFile(findFile("namedAttributes.xml"));
-
- Class keyConstraint = String.class;
- Class valueConstraint = Integer.class;
- String id = "id1";
- String regionName = "root";
-
- Cache cache = getCache();
- RegionAttributes attrs = cache.getRegionAttributes(id);
- assertEquals(keyConstraint, attrs.getKeyConstraint());
- assertEquals(valueConstraint, attrs.getValueConstraint());
- assertEquals(45, attrs.getEntryIdleTimeout().getTimeout());
- assertEquals(ExpirationAction.INVALIDATE, attrs.getEntryIdleTimeout().getAction());
-
- Region region = cache.getRegion(regionName);
- assertNotNull(region);
-
- attrs = region.getAttributes();
- assertEquals(keyConstraint, attrs.getKeyConstraint());
- assertEquals(valueConstraint, attrs.getValueConstraint());
- assertEquals(45, attrs.getEntryIdleTimeout().getTimeout());
- assertEquals(ExpirationAction.INVALIDATE, attrs.getEntryIdleTimeout().getAction());
-
- // Make sure that attributes can be "overridden"
- Region subregion = region.getSubregion("subregion");
- assertNotNull(subregion);
-
- attrs = subregion.getAttributes();
- assertEquals(keyConstraint, attrs.getKeyConstraint());
- assertEquals(Long.class, attrs.getValueConstraint());
- assertEquals(90, attrs.getEntryIdleTimeout().getTimeout());
- assertEquals(ExpirationAction.DESTROY, attrs.getEntryIdleTimeout().getAction());
-
- // Make sure that a named region attributes used in a region
- // declaration is registered
- assertNotNull(cache.getRegionAttributes("id2"));
- }
-
- /**
- * Tests that trying to parse an XML file that declares a region whose
- * attributes refer to an unknown named region attributes throws an
- * {@link IllegalStateException}.
- */
- @Test
- public void testUnknownNamedAttributes()
- {
- setXmlFile(findFile("unknownNamedAttributes.xml"));
-
- IgnoredException expectedException = IgnoredException.addIgnoredException(LocalizedStrings.RegionAttributesCreation_CANNOT_REFERENCE_NONEXISTING_REGION_ATTRIBUTES_NAMED_0.toLocalizedString());
- try {
- getCache();
- fail("Should have thrown an IllegalStateException");
-
- }
- catch (IllegalStateException ex) {
- // pass...
- } finally {
- expectedException.remove();
- }
- }
-
- /**
- * Tests to make sure that we cannot create the same region multiple times in
- * a <code>cache.xml</code> file.
- */
- @Test
- public void testCreateSameRegionTwice() throws CacheException
- {
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- String name = "root";
-
- cache.createRegion(name, attrs);
-
- try {
- cache.createRegion(name, attrs);
- fail("Should have thrown a RegionExistsException");
-
- }
- catch (RegionExistsException ex) {
- // pass...
- }
-
- setXmlFile(findFile("sameRootRegion.xml"));
-
- IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
- try {
- getCache();
- fail("Should have thrown a CacheXmlException");
-
- }
- catch (CacheXmlException ex) {
- Throwable cause = ex.getCause();
- assertTrue(cause instanceof SAXException);
- cause = ((SAXException)cause).getException();
- if (!(cause instanceof RegionExistsException)) {
- Assert.fail("Expected a RegionExistsException, not a "
- + cause.getClass().getName(), cause);
- }
- } finally {
- expectedException.remove();
- }
- }
-
- /**
- * Tests to make sure that we cannot create the same subregion multiple times
- * in a <code>cache.xml</code> file.
- */
- @Test
- public void testCreateSameSubregionTwice() throws CacheException
- {
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- String name = this.getUniqueName();
-
- Region root = cache.createRegion("root", attrs);
-
- root.createSubregion(name, attrs);
-
- try {
- root.createSubregion(name, attrs);
- fail("Should have thrown a RegionExistsException");
-
- }
- catch (RegionExistsException ex) {
- // pass...
- }
-
- setXmlFile(findFile("sameSubregion.xml"));
-
- IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
- try {
- getCache();
- fail("Should have thrown a CacheXmlException");
-
- }
- catch (CacheXmlException ex) {
- Throwable cause = ex.getCause();
- assertTrue(cause instanceof SAXException);
- cause = ((SAXException)cause).getException();
- if (!(cause instanceof RegionExistsException)) {
- Assert.fail("Expected a RegionExistsException, not a "
- + cause.getClass().getName(), cause);
- }
- } finally {
- expectedException.remove();
- }
- }
-
- /**
- * Generates XML from the given <code>CacheCreation</code> and returns an
- * <code>InputStream</code> for reading that XML.
- */
- public InputStream generate(CacheCreation creation)
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- final boolean useSchema = getUseSchema();
- final String version = getGemFireVersion();
-
- PrintWriter pw = new PrintWriter(new OutputStreamWriter(baos), true);
- CacheXmlGenerator.generate(creation, pw, useSchema, version);
- pw.close();
-
- byte[] bytes = baos.toByteArray();
- return new ByteArrayInputStream(bytes);
- }
-
- /**
- * Tests that loading cache XML effects mutable cache attributes.
- */
- @Test
- public void testModifyCacheAttributes() throws CacheException
- {
- boolean copyOnRead1 = false;
- boolean isServer1 = true;
- int lockLease1 = 123;
- int lockTimeout1 = 345;
- int searchTimeout1 = 567;
-
- CacheCreation creation = new CacheCreation();
- creation.setCopyOnRead(copyOnRead1);
- creation.setIsServer(isServer1);
- creation.setLockLease(lockLease1);
- creation.setLockTimeout(lockTimeout1);
- creation.setSearchTimeout(searchTimeout1);
-
- testXml(creation);
-
- Cache cache = getCache();
- assertEquals(copyOnRead1, cache.getCopyOnRead());
- assertEquals(isServer1, cache.isServer());
- assertEquals(lockLease1, cache.getLockLease());
- assertEquals(lockTimeout1, cache.getLockTimeout());
- assertEquals(searchTimeout1, cache.getSearchTimeout());
-
- boolean copyOnRead2 = true;
- boolean isServer2 = false;
- int lockLease2 = 234;
- int lockTimeout2 = 456;
- int searchTimeout2 = 678;
-
- creation = new CacheCreation();
- creation.setCopyOnRead(copyOnRead2);
- creation.setIsServer(isServer2);
- creation.setLockLease(lockLease2);
- creation.setLockTimeout(lockTimeout2);
- creation.setSearchTimeout(searchTimeout2);
-
- cache.loadCacheXml(generate(creation));
-
- assertEquals(copyOnRead2, cache.getCopyOnRead());
- assertEquals(isServer2, cache.isServer());
- assertEquals(lockLease2, cache.getLockLease());
- assertEquals(lockTimeout2, cache.getLockTimeout());
- assertEquals(searchTimeout2, cache.getSearchTimeout());
- }
-
- /**
- * Tests that loading cache XML can create a region.
- */
- @Test
- public void testAddRegionViaCacheXml() throws CacheException
- {
- CacheCreation creation = new CacheCreation();
-
- testXml(creation);
-
- Cache cache = getCache();
- assertTrue(cache.rootRegions().isEmpty());
-
- creation = new CacheCreation();
-
- RegionAttributesCreation attrs = new RegionAttributesCreation(creation);
- attrs.setScope(Scope.GLOBAL);
- attrs.setKeyConstraint(Integer.class);
- attrs.setCacheListener(new MyTestCacheListener());
- Region root = creation.createRegion("root", attrs);
-
- attrs = new RegionAttributesCreation(creation);
- attrs.setScope(Scope.LOCAL);
- attrs.setEarlyAck(true);
- attrs.setValueConstraint(String.class);
- Region subregion = root.createSubregion("subregion", attrs);
-
- cache.loadCacheXml(generate(creation));
-
- root = cache.getRegion("root");
- assertNotNull(root);
- assertEquals(Scope.GLOBAL, root.getAttributes().getScope());
- assertEquals(Integer.class, root.getAttributes().getKeyConstraint());
- assertTrue(root.getAttributes().getCacheListener() instanceof MyTestCacheListener);
-
- subregion = root.getSubregion("subregion");
- assertNotNull(subregion);
- assertEquals(Scope.LOCAL, subregion.getAttributes().getScope());
- assertTrue(subregion.getAttributes().getEarlyAck());
- assertFalse(subregion.getAttributes().getMulticastEnabled());
- assertEquals(String.class, subregion.getAttributes().getValueConstraint());
-
- // Create a subregion of a region that already exists
-
- creation = new CacheCreation();
- attrs = new RegionAttributesCreation(creation);
- root = creation.createRegion("root", attrs);
-
- attrs = new RegionAttributesCreation(creation);
- attrs.setScope(Scope.DISTRIBUTED_ACK);
- attrs.setEarlyAck(false);
- attrs.setValueConstraint(Long.class);
- Region subregion2 = root.createSubregion("subregion2", attrs);
-
- cache.loadCacheXml(generate(creation));
-
- subregion2 = root.getSubregion("subregion2");
- assertNotNull(subregion2);
- assertEquals(Scope.DISTRIBUTED_ACK, subregion2.getAttributes().getScope());
- assertTrue(!subregion2.getAttributes().getEarlyAck());
- assertEquals(Long.class, subregion2.getAttributes().getValueConstraint());
- }
-
- /**
- * Tests that loading cache XML can modify a region.
- */
- @Test
- public void testModifyRegionViaCacheXml() throws CacheException
- {
- CacheCreation creation = new CacheCreation();
-
- int timeout1a = 123;
- ExpirationAction action1a = ExpirationAction.LOCAL_DESTROY;
- int timeout1b = 456;
- ExpirationAction action1b = ExpirationAction.DESTROY;
-
- RegionAttributesCreation attrs = new RegionAttributesCreation(creation);
- attrs.setStatisticsEnabled(true);
- attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout1a, action1a));
- Region root = creation.createRegion("root", attrs);
-
- attrs = new RegionAttributesCreation(creation);
- attrs.setStatisticsEnabled(true);
- attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout1b, action1b));
- Region subregion = root.createSubregion("subregion", attrs);
-
- testXml(creation);
-
- Cache cache = getCache();
-
- root = cache.getRegion("root");
- assertEquals(timeout1a, root.getAttributes().getEntryIdleTimeout()
- .getTimeout());
- assertEquals(action1a, root.getAttributes().getEntryIdleTimeout()
- .getAction());
-
- subregion = root.getSubregion("subregion");
- assertEquals(timeout1b, subregion.getAttributes().getEntryIdleTimeout()
- .getTimeout());
- assertEquals(action1b, subregion.getAttributes().getEntryIdleTimeout()
- .getAction());
-
- creation = new CacheCreation();
-
- int timeout2a = 234;
- ExpirationAction action2a = ExpirationAction.LOCAL_INVALIDATE;
- int timeout2b = 567;
- ExpirationAction action2b = ExpirationAction.INVALIDATE;
-
- attrs = new RegionAttributesCreation(creation);
- attrs.setStatisticsEnabled(true);
- attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout2a, action2a));
- attrs.setCacheListener(new MyTestCacheListener());
- root = creation.createRegion("root", attrs);
-
- attrs = new RegionAttributesCreation(creation);
- attrs.setStatisticsEnabled(true);
- attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout2b, action2b));
- subregion = root.createSubregion("subregion", attrs);
-
- cache.loadCacheXml(generate(creation));
-
- root = cache.getRegion("root");
- subregion = root.getSubregion("subregion");
-
- assertEquals(timeout2a, root.getAttributes().getEntryIdleTimeout()
- .getTimeout());
- assertEquals(action2a, root.getAttributes().getEntryIdleTimeout()
- .getAction());
- assertTrue(root.getAttributes().getCacheListener() instanceof MyTestCacheListener);
-
- assertEquals(timeout2b, subregion.getAttributes().getEntryIdleTimeout()
- .getTimeout());
- assertEquals(action2b, subregion.getAttributes().getEntryIdleTimeout()
- .getAction());
- }
-
- /**
- * Tests that loading cache XML can add/update entries to a region.
- */
- @Test
- public void testAddEntriesViaCacheXml() throws CacheException
- {
- String key1 = "KEY1";
- String value1 = "VALUE1";
-
- CacheCreation creation = new CacheCreation();
-
- RegionAttributesCreation attrs = new RegionAttributesCreation(creation);
- attrs.setScope(Scope.LOCAL);
-
- Region root = creation.createRegion("root", attrs);
- root.put(key1, value1);
-
- testXml(creation);
-
- Cache cache = getCache();
- root = cache.getRegion("root");
- assertEquals(1, root.entries(false).size());
- assertEquals(value1, root.get(key1));
-
- creation = new CacheCreation();
-
- attrs = new RegionAttributesCreation(creation);
- attrs.setScope(Scope.LOCAL);
-
- String value2 = "VALUE2";
- String key2 = "KEY2";
- String value3 = "VALUE3";
-
- root = creation.createRegion("root", attrs);
- root.put(key1, value2);
- root.put(key2, value3);
-
- cache.loadCacheXml(generate(creation));
-
- root = cache.getRegion("root");
- assertEquals(2, root.entries(false).size());
- assertEquals(value2, root.get(key1));
- assertEquals(value3, root.get(key2));
-
- }
-
- // this tests an aspect of the CapacityController interface, which is no longer
- // available as of 5.0
- //public void testHeapLRUCapacityController() throws Exception {
- // final String name = getUniqueName();
- // beginCacheXml();
- // AttributesFactory factory = new AttributesFactory();
- // factory.setScope(Scope.LOCAL);
- // factory.setCapacityController(new HeapLRUCapacityController(42, 32, LRUAlgorithm.OVERFLOW_TO_DISK));
- // createRegion(name, factory.create());
- // finishCacheXml(getUniqueName());
- //
- // Region r = getRootRegion().getSubregion(name);
- //
- // HeapLRUCapacityController hlcc = (HeapLRUCapacityController) r.getAttributes().getCapacityController();
- // assertIndexDetailsEquals(hlcc.getEvictionAction(), LRUAlgorithm.OVERFLOW_TO_DISK);
- //
- // Properties p = hlcc.getProperties();
- // assertIndexDetailsEquals(42, Integer.parseInt(p.getProperty(HeapLRUCapacityController.HEAP_PERCENTAGE)));
- // assertIndexDetailsEquals(32, Long.parseLong(p.getProperty(HeapLRUCapacityController.EVICTOR_INTERVAL)));
- // assertIndexDetailsEquals(LRUAlgorithm.OVERFLOW_TO_DISK, p.getProperty(HeapLRUCapacityController.EVICTION_ACTION));
- //}
- /**
- * Test Publisher region attribute
- * @since GemFire 4.2.3
- * @deprecated as of GemFire 6.5.
- */
- @Test
- public void testPublisherAttribute() throws CacheException {
-
-// CacheCreation cache = new CacheCreation();
-// RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
-// attrs.setPublisher(true);
-// cache.createRegion("root", attrs);
-// testXml(cache);
-// assertIndexDetailsEquals(true, cache.getRegion("root").getAttributes().getPublisher());
- }
-
- /**
- * Test EnableBridgeConflation region attribute
- * @since GemFire 4.2
- */
- @Test
- public void testEnableBridgeConflationAttribute() throws CacheException {
-
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setEnableBridgeConflation(true);
- cache.createRegion("root", attrs);
- testXml(cache);
- assertEquals(true, cache.getRegion("root").getAttributes().getEnableBridgeConflation());
- }
-
- /**
- * Test EnableAsyncConflation region attribute
- * @since GemFire 4.2
- */
- @Test
- public void testEnableAsyncConflationAttribute() throws CacheException {
-
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setEnableAsyncConflation(true);
- cache.createRegion("root", attrs);
- testXml(cache);
- assertEquals(true, cache.getRegion("root").getAttributes().getEnableAsyncConflation());
- }
- /**
- * @since GemFire 4.3
- */
- @Test
- public void testDynamicRegionFactoryDefault() throws CacheException {
- CacheCreation cache = new CacheCreation();
- cache.setDynamicRegionFactoryConfig(new DynamicRegionFactory.Config());
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- cache.createRegion("root", attrs);
- // note that testXml can't check if they are same because enabling
- // dynamic regions causes a meta region to be produced.
- testXml(cache, false);
- assertEquals(true, DynamicRegionFactory.get().getConfig().getRegisterInterest());
- assertEquals(true, DynamicRegionFactory.get().getConfig().getPersistBackup());
- assertEquals(true, DynamicRegionFactory.get().isOpen());
- assertEquals(null, DynamicRegionFactory.get().getConfig().getDiskDir());
- Region dr = getCache().getRegion("__DynamicRegions");
- if(dr != null) {
- dr.localDestroyRegion();
- }
-
- }
- @Test
- public void testDynamicRegionFactoryNonDefault() throws CacheException {
- CacheCreation cache = new CacheCreation();
- cache.setDynamicRegionFactoryConfig(new DynamicRegionFactory.Config((File)null, null, false, false));
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- cache.createRegion("root", attrs);
- // note that testXml can't check if they are same because enabling
- // dynamic regions causes a meta region to be produced.
- testXml(cache, false);
- assertEquals(false, DynamicRegionFactory.get().getConfig().getRegisterInterest());
- assertEquals(false, DynamicRegionFactory.get().getConfig().getPersistBackup());
- assertEquals(true, DynamicRegionFactory.get().isOpen());
- assertEquals(null, DynamicRegionFactory.get().getConfig().getDiskDir());
- Region dr = getCache().getRegion("__DynamicRegions");
- if(dr != null) {
- dr.localDestroyRegion();
- }
-
- }
-
- /**
- * @since GemFire 4.3
- */
- @Test
- public void testDynamicRegionFactoryDiskDir() throws CacheException {
- CacheCreation cache = new CacheCreation();
- File f = new File("diskDir");
- f.mkdirs();
- cache.setDynamicRegionFactoryConfig(new DynamicRegionFactory.Config(f, null, true, true));
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- cache.createRegion("root", attrs);
- // note that testXml can't check if they are same because enabling
- // dynamic regions causes a meta region to be produced.
- testXml(cache, false);
- assertEquals(true, DynamicRegionFactory.get().isOpen());
- assertEquals(f.getAbsoluteFile(), DynamicRegionFactory.get().getConfig().getDiskDir());
- Region dr =getCache().getRegion("__DynamicRegions");
- if(dr != null) {
- dr.localDestroyRegion();
- }
- }
-
- /**
- * Remove this override when bug #52052 is fixed.
- */
- @Test
- public void testExampleCacheXmlFile() {
- return;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/952ab6fa/geode-core/src/test/java/org/apache/geode/cache30/CacheXml45DUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml45DUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache30/CacheXml45DUnitTest.java
deleted file mode 100644
index 7c10524..0000000
--- a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml45DUnitTest.java
+++ /dev/null
@@ -1,424 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.geode.cache30;
-
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.junit.Assert.*;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
-
-import com.company.app.DBLoader;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.cache.AttributesFactory;
-import org.apache.geode.cache.AttributesMutator;
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheException;
-import org.apache.geode.cache.CacheListener;
-import org.apache.geode.cache.CacheTransactionManager;
-import org.apache.geode.cache.DataPolicy;
-import org.apache.geode.cache.Declarable;
-import org.apache.geode.cache.EvictionAction;
-import org.apache.geode.cache.EvictionAttributes;
-import org.apache.geode.cache.InterestPolicy;
-import org.apache.geode.cache.LossAction;
-import org.apache.geode.cache.MembershipAttributes;
-import org.apache.geode.cache.MirrorType;
-import org.apache.geode.cache.PartitionAttributes;
-import org.apache.geode.cache.PartitionAttributesFactory;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionAttributes;
-import org.apache.geode.cache.ResumptionAction;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.cache.SubscriptionAttributes;
-import org.apache.geode.cache.TransactionListener;
-import org.apache.geode.cache.server.CacheServer;
-import org.apache.geode.internal.cache.DistributedRegion;
-import org.apache.geode.internal.cache.xmlcache.CacheCreation;
-import org.apache.geode.internal.cache.xmlcache.CacheTransactionManagerCreation;
-import org.apache.geode.internal.cache.xmlcache.CacheXml;
-import org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-/**
- * Tests the declarative caching functionality introduced in GemFire
- * 5.0 (i.e. congo1). Don't be confused by the 45 in my name :-)
- *
- * @since GemFire 5.0
- */
-@Category(DistributedTest.class)
-public class CacheXml45DUnitTest extends CacheXml41DUnitTest {
-
- protected String getGemFireVersion() {
- return CacheXml.VERSION_5_0;
- }
-
- public void setBridgeAttributes(CacheServer bridge1)
- {
- super.setBridgeAttributes(bridge1);
- bridge1.setMaxConnections(100);
- }
-
- @Test
- public void testDataPolicy() throws CacheException {
- CacheCreation cache = new CacheCreation();
-
- {
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setDataPolicy(DataPolicy.NORMAL);
- cache.createRegion("rootNORMAL", attrs);
- }
- {
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setDataPolicy(DataPolicy.NORMAL);
- attrs.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
- cache.createRegion("rootNORMAL_ALL", attrs);
- }
- {
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setMirrorType(MirrorType.KEYS_VALUES);
- cache.createRegion("rootREPLICATE", attrs);
- }
- {
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
- cache.createRegion("rootPERSISTENT_REPLICATE", attrs);
- }
- {
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setDataPolicy(DataPolicy.EMPTY);
- cache.createRegion("rootEMPTY", attrs);
- }
- {
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setDataPolicy(DataPolicy.EMPTY);
- attrs.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
- cache.createRegion("rootEMPTY_ALL", attrs);
- }
-
- testXml(cache);
- }
-
- /**
- * These properties, if any, will be added to the properties used for getSystem calls
- */
- protected Properties xmlProps = null;
-
- public Properties getDistributedSystemProperties() {
- Properties props = super.getDistributedSystemProperties();
- if (this.xmlProps != null) {
- for (Iterator iter = this.xmlProps.entrySet().iterator();
- iter.hasNext(); ) {
- Map.Entry entry = (Map.Entry) iter.next();
- String key = (String) entry.getKey();
- String value = (String) entry.getValue();
- props.setProperty(key, value);
- }
- }
- return props;
- }
-
- /**
- * Test xml support of MembershipAttributes.
- */
- @Test
- public void testMembershipAttributes() throws Exception {
- final String MY_ROLES = "Foo, Bip, BAM";
- final String[][] roles = new String[][] {{"Foo"}, {"Bip", "BAM"}};
-
- final LossAction[] policies = (LossAction[])
- LossAction.VALUES.toArray(
- new LossAction[LossAction.VALUES.size()]);
-
- final ResumptionAction[] actions = (ResumptionAction[])
- ResumptionAction.VALUES.toArray(
- new ResumptionAction[ResumptionAction.VALUES.size()]);
-
- CacheCreation cache = new CacheCreation();
-
- // for each policy, try each action and each role...
- for (int policy = 0; policy < policies.length; policy++) {
- for (int action = 0; action < actions.length; action++) {
- for (int role = 0; role < roles.length; role++) {
- String[] theRoles = roles[role];
- LossAction thePolicy = policies[policy];
- ResumptionAction theAction = actions[action];
-
- //if (theRoles.length == 0 && (thePolicy != LossAction.NONE || theAction != ResumptionAction.NONE
-
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- MembershipAttributes ra = new MembershipAttributes(
- theRoles, thePolicy, theAction);
- attrs.setMembershipAttributes(ra);
- String region = "rootMEMBERSHIP_ATTRIBUTES_" +
- policy + "_" + action + "_" + role;
- cache.createRegion(region, attrs);
- }
- }
- }
-
- {
- // make our system play the roles used by this test so the create regions
- // will not think the a required role is missing
- Properties config = new Properties();
- config.setProperty(ROLES, MY_ROLES);
- this.xmlProps = config;
- }
- DistributedRegion.ignoreReconnect = true;
- try {
- testXml(cache);
- } finally {
- this.xmlProps = null;
- try {
- preTearDown();
- } finally {
- DistributedRegion.ignoreReconnect = false;
- }
- }
- }
-
- /**
- * Tests multiple cache listeners on one region
- * @since GemFire 5.0
- */
- @Test
- public void testMultipleCacheListener() throws CacheException {
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
-
- CacheListener l1 = new MyTestCacheListener();
- CacheListener l2 = new MySecondTestCacheListener();
- attrs.addCacheListener(l1);
- attrs.addCacheListener(l2);
-
- cache.createRegion("root", attrs);
-
- testXml(cache);
- {
- Cache c = getCache();
- Region r = c.getRegion("root");
- assertEquals(Arrays.asList(new CacheListener[]{l1, l2}), Arrays.asList(r.getAttributes().getCacheListeners()));
- AttributesMutator am = r.getAttributesMutator();
- am.removeCacheListener(l2);
- assertEquals(Arrays.asList(new CacheListener[]{l1}), Arrays.asList(r.getAttributes().getCacheListeners()));
- am.removeCacheListener(l1);
- assertEquals(Arrays.asList(new CacheListener[]{}), Arrays.asList(r.getAttributes().getCacheListeners()));
- am.addCacheListener(l1);
- assertEquals(Arrays.asList(new CacheListener[]{l1}), Arrays.asList(r.getAttributes().getCacheListeners()));
- am.addCacheListener(l1);
- assertEquals(Arrays.asList(new CacheListener[]{l1}), Arrays.asList(r.getAttributes().getCacheListeners()));
- am.addCacheListener(l2);
- assertEquals(Arrays.asList(new CacheListener[]{l1,l2}), Arrays.asList(r.getAttributes().getCacheListeners()));
- am.removeCacheListener(l1);
- assertEquals(Arrays.asList(new CacheListener[]{l2}), Arrays.asList(r.getAttributes().getCacheListeners()));
- am.removeCacheListener(l1);
- assertEquals(Arrays.asList(new CacheListener[]{l2}), Arrays.asList(r.getAttributes().getCacheListeners()));
- am.initCacheListeners(new CacheListener[]{l1,l2});
- assertEquals(Arrays.asList(new CacheListener[]{l1,l2}), Arrays.asList(r.getAttributes().getCacheListeners()));
- }
- }
-
- /**
- * A <code>CacheListener</code> that is
- * <code>Declarable</code>, but not <code>Declarable2</code>.
- */
- public static class MySecondTestCacheListener
- extends TestCacheListener implements Declarable {
-
- public void init(Properties props) { }
-
- public boolean equals(Object o) {
- return o instanceof MySecondTestCacheListener;
- }
- }
-
- @Test
- public void testHeapLRUEviction() throws Exception {
- final String name = getUniqueName();
- beginCacheXml();
- AttributesFactory factory = new AttributesFactory();
- factory.setScope(Scope.LOCAL);
- EvictionAttributes ev = EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK);
- factory.setEvictionAttributes(ev);
-// RegionAttributes atts = factory.create();
- createRegion(name, factory.create());
- finishCacheXml(getUniqueName(), getUseSchema(), getGemFireVersion());
- Region r = getRootRegion().getSubregion(name);
-
- EvictionAttributes hlea = r.getAttributes().getEvictionAttributes();
- assertEquals(EvictionAction.OVERFLOW_TO_DISK, hlea.getAction());
- }
-
- /**
- * Tests multiple transaction listeners
- * @since GemFire 5.0
- */
- @Test
- public void testMultipleTXListener() throws CacheException {
- CacheCreation cache = new CacheCreation();
- CacheTransactionManagerCreation txMgrCreation = new CacheTransactionManagerCreation();
- TransactionListener l1 = new MyTestTransactionListener();
- TransactionListener l2 = new MySecondTestTransactionListener();
- txMgrCreation.addListener(l1);
- txMgrCreation.addListener(l2);
- cache.addCacheTransactionManagerCreation(txMgrCreation);
- testXml(cache);
- {
- CacheTransactionManager tm = getCache().getCacheTransactionManager();
- assertEquals(Arrays.asList(new TransactionListener[]{l1, l2}), Arrays.asList(tm.getListeners()));
- tm.removeListener(l2);
- assertEquals(Arrays.asList(new TransactionListener[]{l1}), Arrays.asList(tm.getListeners()));
- tm.removeListener(l1);
- assertEquals(Arrays.asList(new TransactionListener[]{}), Arrays.asList(tm.getListeners()));
- tm.addListener(l1);
- assertEquals(Arrays.asList(new TransactionListener[]{l1}), Arrays.asList(tm.getListeners()));
- tm.addListener(l1);
- assertEquals(Arrays.asList(new TransactionListener[]{l1}), Arrays.asList(tm.getListeners()));
- tm.addListener(l2);
- assertEquals(Arrays.asList(new TransactionListener[]{l1,l2}), Arrays.asList(tm.getListeners()));
- tm.removeListener(l1);
- assertEquals(Arrays.asList(new TransactionListener[]{l2}), Arrays.asList(tm.getListeners()));
- tm.removeListener(l1);
- assertEquals(Arrays.asList(new TransactionListener[]{l2}), Arrays.asList(tm.getListeners()));
- tm.initListeners(new TransactionListener[]{l1,l2});
- assertEquals(Arrays.asList(new TransactionListener[]{l1,l2}), Arrays.asList(tm.getListeners()));
- }
- }
-
- /**
- * A <code>TransactionListener</code> that is
- * <code>Declarable</code>, but not <code>Declarable2</code>.
- */
- public static class MySecondTestTransactionListener
- extends TestTransactionListener implements Declarable {
-
- public void init(Properties props) { }
-
- public boolean equals(Object o) {
- return o instanceof MySecondTestTransactionListener;
- }
- }
-
- /**
- * Tests that a region created with a named attributes has the correct
- * attributes.
- */
- @Test
- public void testPartitionedRegionXML() throws CacheException
- {
- setXmlFile(findFile("partitionedRegion.xml"));
- final String regionName = "pRoot";
-
- Cache cache = getCache();
- Region region = cache.getRegion(regionName);
- assertNotNull(region);
-
- Host host = Host.getHost(0);
- final VM vm0 = host.getVM(0);
- final VM vm1 = host.getVM(1);
-
- CacheSerializableRunnable init = new CacheSerializableRunnable("initUsingPartitionedRegionXML") {
- public void run2() throws CacheException
- {
- final Cache cache;
- try {
- CacheXml30DUnitTest.lonerDistributedSystem = false;
- cache = getCache();
- }
- finally {
- CacheXml30DUnitTest.lonerDistributedSystem = true;
- }
- Region region = cache.getRegion(regionName);
- assertNotNull(region);
- RegionAttributes attrs = region.getAttributes();
- assertNotNull(attrs.getPartitionAttributes());
-
- PartitionAttributes pa = attrs.getPartitionAttributes();
- // assertNull(pa.getCacheWriter());
- assertEquals(pa.getRedundantCopies(), 1);
- assertEquals(pa.getGlobalProperties().getProperty(
- PartitionAttributesFactory.GLOBAL_MAX_MEMORY_PROPERTY), "96");
- assertEquals(pa.getLocalProperties().getProperty(
- PartitionAttributesFactory.LOCAL_MAX_MEMORY_PROPERTY), "32");
- }
- };
-
- init.run2();
- vm0.invoke(init);
- vm1.invoke(init);
- vm0.invoke(new CacheSerializableRunnable("putUsingPartitionedRegionXML1") {
- public void run2() throws CacheException
- {
- final String val = "prValue0";
- final Integer key = new Integer(10);
- Cache cache = getCache();
- Region region = cache.getRegion(regionName);
- assertNotNull(region);
- region.put(key, val);
- assertEquals(val, region.get(key));
- }
- });
- vm1.invoke(new CacheSerializableRunnable("putUsingPartitionedRegionXML2") {
- public void run2() throws CacheException
- {
- final String val = "prValue1";
- final Integer key = new Integer(14);
- Cache cache = getCache();
- Region region = cache.getRegion(regionName);
- assertNotNull(region);
- region.put(key, val);
- assertEquals(val, region.get(key));
- }
- });
- }
-
- /**
- * Tests that a region created with a named attributes has the correct
- * attributes.
- *
- */
- @Test
- public void testPartitionedRegionInstantiation() throws CacheException
- {
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
-
- Properties gp = new Properties();
- gp.setProperty(PartitionAttributesFactory.GLOBAL_MAX_MEMORY_PROPERTY, "2");
- gp.setProperty(PartitionAttributesFactory.GLOBAL_MAX_BUCKETS_PROPERTY, "17");
- Properties lp = new Properties();
- lp.setProperty(PartitionAttributesFactory.LOCAL_MAX_MEMORY_PROPERTY, "4");
- PartitionAttributesFactory paf = new PartitionAttributesFactory();
-
-
-// paf.setEntryTimeToLive(
-// new ExpirationAttributes(10, ExpirationAction.DESTROY)).setCacheLoader(
- paf.setLocalProperties(lp).setGlobalProperties(gp);
- attrs.setCacheLoader(new DBLoader());
- attrs.setPartitionAttributes(paf.create());
- cache.createRegion("pRoot", attrs);
-
- testXml(cache);
- }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/952ab6fa/geode-core/src/test/java/org/apache/geode/cache30/CacheXml51DUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml51DUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache30/CacheXml51DUnitTest.java
deleted file mode 100644
index 30925e5..0000000
--- a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml51DUnitTest.java
+++ /dev/null
@@ -1,375 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.geode.cache30;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheException;
-import org.apache.geode.cache.DataPolicy;
-import org.apache.geode.cache.DiskWriteAttributesFactory;
-import org.apache.geode.cache.PartitionAttributes;
-import org.apache.geode.cache.PartitionAttributesFactory;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionAttributes;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.cache.server.CacheServer;
-import org.apache.geode.internal.AvailablePortHelper;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
-import org.apache.geode.internal.cache.PartitionedRegion;
-import org.apache.geode.internal.cache.xmlcache.CacheCreation;
-import org.apache.geode.internal.cache.xmlcache.CacheXml;
-import org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation;
-import org.apache.geode.internal.cache.xmlcache.RegionCreation;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-/**
- * Tests the declarative caching functionality introduced in the GemFire
- * 5.0 (i.e. congo1). Don't be confused by the 45 in my name :-)
- *
- * @since GemFire 5.0
- */
-
-@Category(DistributedTest.class)
-public class CacheXml51DUnitTest extends CacheXml45DUnitTest
-{
-
- // ////// Constructors
-
- public CacheXml51DUnitTest() {
- super();
- }
-
- // ////// Helper methods
-
- protected String getGemFireVersion()
- {
- return CacheXml.VERSION_5_1;
- }
-
- /**
- * Tests that a region created with a named attributes has the correct
- * attributes.
- */
- @Test
- public void testPartitionedRegionXML() throws CacheException
- {
- setXmlFile(findFile("partitionedRegion51.xml"));
- final String regionName = "pRoot";
-
- Cache cache = getCache();
- Region region = cache.getRegion(regionName);
- assertNotNull(region);
-
- Host host = Host.getHost(0);
- final VM vm0 = host.getVM(0);
- final VM vm1 = host.getVM(1);
-
- CacheSerializableRunnable init = new CacheSerializableRunnable("initUsingPartitionedRegionXML") {
- public void run2() throws CacheException
- {
- final Cache c;
- try {
- CacheXml30DUnitTest.lonerDistributedSystem = false;
- c = getCache();
- }
- finally {
- CacheXml30DUnitTest.lonerDistributedSystem = true;
- }
- Region r = c.getRegion(regionName);
- assertNotNull(r);
- RegionAttributes attrs = r.getAttributes();
- assertNotNull(attrs.getPartitionAttributes());
-
- PartitionAttributes pa = attrs.getPartitionAttributes();
- assertEquals(pa.getRedundantCopies(), 1);
- assertEquals(pa.getLocalMaxMemory(), 32);
- assertEquals(pa.getTotalMaxMemory(), 96);
- assertEquals(pa.getTotalNumBuckets(), 119);
-
- r = c.getRegion("bug37905");
- assertTrue("region should have been an instance of PartitionedRegion but was not",
- r instanceof PartitionedRegion);
- }
- };
-
- init.run2();
- vm0.invoke(init);
- vm1.invoke(init);
- vm0.invoke(new CacheSerializableRunnable("putUsingPartitionedRegionXML1") {
- public void run2() throws CacheException
- {
- final String val = "prValue0";
- final Integer key = new Integer(10);
- Cache c = getCache();
- Region r = c.getRegion(regionName);
- assertNotNull(r);
- r.put(key, val);
- assertEquals(val, r.get(key));
- }
- });
- vm1.invoke(new CacheSerializableRunnable("putUsingPartitionedRegionXML2") {
- public void run2() throws CacheException
- {
- final String val = "prValue1";
- final Integer key = new Integer(14);
- Cache c = getCache();
- Region r = c.getRegion(regionName);
- assertNotNull(r);
- r.put(key, val);
- assertEquals(val, r.get(key));
- }
- });
- }
-
-/**
- * Tests the <code>message-sync-interval</code> attribute of
- * attribute is related to HA of client-queues in gemfire ca
- * framework. This attribute is the frequency at which a messent
- * by the primary cache-server node to all the secondary cache-server nodes to
- * remove the events which have already been dispatched from
- * the queue
- *
- * @throws CacheException
- */
- @Test
- public void testMessageSyncInterval() throws CacheException {
- CacheCreation cache = new CacheCreation();
- cache.setMessageSyncInterval(123);
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setDataPolicy(DataPolicy.NORMAL);
- cache.createVMRegion("rootNORMAL", attrs);
- testXml(cache);
- Cache c = getCache();
- assertNotNull(c);
- assertEquals(123, c.getMessageSyncInterval());
-}
-
-/**
- * Tests the bridge-server attributes (<code>maximum-message-count</code>
- * and <code>message-time-to-live</code>) related to HA of client-queues in
- * gemfire cache-server framework
- *
- * @throws CacheException
- */
- @Test
- public void testBridgeAttributesRelatedToClientQueuesHA() throws CacheException {
- CacheCreation cache = new CacheCreation();
- cache.setMessageSyncInterval(3445);
- CacheServer bs = cache.addCacheServer();
- bs.setMaximumMessageCount(12345);
- bs.setMessageTimeToLive(56789);
- bs.setPort(AvailablePortHelper.getRandomAvailableTCPPort());
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setDataPolicy(DataPolicy.NORMAL);
- cache.createVMRegion("rootNORMAL", attrs);
- testXml(cache);
- Cache c = getCache();
- assertNotNull(c);
- CacheServer server = (CacheServer)cache.getCacheServers().iterator().next();
- assertNotNull(server);
- assertEquals(12345,server.getMaximumMessageCount());
- assertEquals(56789,server.getMessageTimeToLive());
- }
-
- /**
- * Tests that a region created with a named attributes has the correct
- * attributes.
- *
- * This tests currently fails due to (what seem to me as) limitations in the
- * XML generator and the comparison of the XML. I have run this test by hand
- * and looked at the generated XML and there were no significant problems,
- * however because of the limitations, I am disabling this test, but leaving
- * the functionality for future comparisons (by hand of course). -- Mitch
- * Thomas 01/18/2006
- */
- @Test
- public void testPartitionedRegionInstantiation() throws CacheException
- {
- CacheCreation cache = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
-
- PartitionAttributesFactory paf = new PartitionAttributesFactory();
-
- paf.setLocalMaxMemory(4)
- .setTotalNumBuckets(17)
- .setTotalMaxMemory(8);
- attrs.setPartitionAttributes(paf.create());
- cache.createRegion("pRoot", attrs);
- }
-
- /**
- * Tests the bridge-server attributes (<code>max-threads</code>
- *
- * @throws CacheException
- */
- @Test
- public void testBridgeMaxThreads()
- throws CacheException
- {
- CacheCreation cache = new CacheCreation();
-
- CacheServer bs = cache.addCacheServer();
- bs.setMaxThreads(37);
- bs.setMaxConnections(999);
- bs.setPort(AvailablePortHelper.getRandomAvailableTCPPort());
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
- attrs.setDataPolicy(DataPolicy.NORMAL);
- cache.createVMRegion("rootNORMAL", attrs);
- testXml(cache);
- }
-
- /**
- * Tests that loading cache XML with multi-cast set will set the multi-cast
- */
- @Test
- public void testRegionMulticastSetViaCacheXml() throws CacheException
- {
- final String rNameBase = getUniqueName();
- final String r1 = rNameBase + "1";
- final String r2 = rNameBase + "2";
- final String r3 = rNameBase + "3";
-
- // Setting multi-cast via nested region attributes
- CacheCreation creation = new CacheCreation();
- RegionAttributesCreation attrs = new RegionAttributesCreation(creation);
- attrs.setScope(Scope.LOCAL);
- attrs.setEarlyAck(false);
- attrs.setMulticastEnabled(true);
- creation.createRegion(r1, attrs);
-
- // Setting multi-cast via named region attributes
- final String attrId = "region_attrs_with_multicast";
- attrs = new RegionAttributesCreation(creation);
- attrs.setId(attrId);
- attrs.setScope(Scope.DISTRIBUTED_NO_ACK);
- attrs.setEarlyAck(false);
- attrs.setMulticastEnabled(true);
- creation.setRegionAttributes(attrs.getId(), attrs);
- attrs = new RegionAttributesCreation(creation);
- attrs.setRefid(attrId);
- creation.createRegion(r3, attrs);
-
- testXml(creation);
-
- creation = new CacheCreation();
- attrs = new RegionAttributesCreation(creation);
- attrs.setScope(Scope.DISTRIBUTED_ACK);
- attrs.setEarlyAck(false);
- attrs.setMulticastEnabled(true);
- creation.createRegion(r2, attrs);
-
- Cache c = getCache();
- assertTrue(c instanceof GemFireCacheImpl);
- c.loadCacheXml(generate(creation));
-
- {
- Region reg1 = c.getRegion(r1);
- assertNotNull(reg1);
- assertEquals(Scope.LOCAL, reg1.getAttributes().getScope());
- assertFalse(reg1.getAttributes().getEarlyAck());
- assertTrue(reg1.getAttributes().getMulticastEnabled());
- }
-
- {
- Region reg2 = c.getRegion(r2);
- assertNotNull(reg2);
- assertEquals(Scope.DISTRIBUTED_ACK, reg2.getAttributes().getScope());
- assertFalse(reg2.getAttributes().getEarlyAck());
- assertTrue(reg2.getAttributes().getMulticastEnabled());
- }
-
- {
- Region reg3 = c.getRegion(r3);
- assertNotNull(reg3);
- assertEquals(Scope.DISTRIBUTED_NO_ACK, reg3.getAttributes().getScope());
- assertFalse(reg3.getAttributes().getEarlyAck());
- assertTrue(reg3.getAttributes().getMulticastEnabled());
- }
- }
-
- @Test
- public void testRollOplogs() throws CacheException {
- CacheCreation cache = new CacheCreation();
-// Set properties for Asynch writes
-
-
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
-
- RegionCreation root = (RegionCreation)
- cache.createRegion("root", attrs);
-
- {
- attrs = new RegionAttributesCreation(cache);
- DiskWriteAttributesFactory dwaf = new DiskWriteAttributesFactory();
- dwaf.setSynchronous(true);
- dwaf.setRollOplogs(true);
- attrs.setDiskWriteAttributes(dwaf.create());
- root.createSubregion("sync", attrs);
- }
-
- {
- attrs = new RegionAttributesCreation(cache);
- DiskWriteAttributesFactory dwaf = new DiskWriteAttributesFactory();
- dwaf.setTimeInterval(123L);
- dwaf.setBytesThreshold(456L);
- dwaf.setRollOplogs(false);
- attrs.setDiskWriteAttributes(dwaf.create());
- root.createSubregion("async", attrs);
- }
-
- testXml(cache);
- }
-
- @Test
- public void testMaxOplogSize() throws CacheException {
- CacheCreation cache = new CacheCreation();
-// Set properties for Asynch writes
-
-
- RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
-
- RegionCreation root = (RegionCreation)
- cache.createRegion("root", attrs);
-
- {
- attrs = new RegionAttributesCreation(cache);
- DiskWriteAttributesFactory dwaf = new DiskWriteAttributesFactory();
- dwaf.setSynchronous(true);
- dwaf.setMaxOplogSize(1);
- attrs.setDiskWriteAttributes(dwaf.create());
- root.createSubregion("sync", attrs);
- }
-
- {
- attrs = new RegionAttributesCreation(cache);
- DiskWriteAttributesFactory dwaf = new DiskWriteAttributesFactory();
- dwaf.setTimeInterval(123L);
- dwaf.setBytesThreshold(456L);
- dwaf.setMaxOplogSize(1);
- attrs.setDiskWriteAttributes(dwaf.create());
- root.createSubregion("async", attrs);
- }
-
- testXml(cache);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/952ab6fa/geode-core/src/test/java/org/apache/geode/cache30/CacheXml55DUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml55DUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache30/CacheXml55DUnitTest.java
deleted file mode 100644
index fd52580..0000000
--- a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml55DUnitTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.geode.cache30;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.cache.CacheException;
-import org.apache.geode.internal.cache.xmlcache.CacheXml;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-/**
- * Tests the declarative caching functionality introduced in the GemFire
- * 5.0 (i.e. congo1). Don't be confused by the 45 in my name :-)
- *
- * @since GemFire 5.0
- */
-
-@Category(DistributedTest.class)
-public class CacheXml55DUnitTest extends CacheXml51DUnitTest
-{
-
- // ////// Constructors
-
- public CacheXml55DUnitTest() {
- super();
- }
-
- // ////// Helper methods
-
- protected String getGemFireVersion()
- {
- return CacheXml.VERSION_5_5;
- }
-
- /**
- * Tests that a region created with a named attributes has the correct
- * attributes.
- */
- @Test
- public void testEmpty() throws CacheException
- {}
-
-}